From b4ec717eea8e416d777985cce73285b291260092 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Tue, 21 Nov 2023 23:09:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?U:=20=E5=A2=9E=E5=8A=A0=20Views=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96=E5=85=B3=E7=B3=BB=E5=9B=BE=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cef/chromium_browser.go | 8 ++++++++ cef/types.go | 38 ++++++++++++++++++++++++++++++++++++++ pkgs/channel/channel.go | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/cef/chromium_browser.go b/cef/chromium_browser.go index d0d98b48..10098fdc 100644 --- a/cef/chromium_browser.go +++ b/cef/chromium_browser.go @@ -15,6 +15,7 @@ import ( ) // ICEFChromiumBrowser +// // CEFChromium浏览器接口 type ICEFChromiumBrowser interface { SetCreateBrowserExtraInfo(windowName string, context *ICefRequestContext, extraInfo *ICefDictionaryValue) // @@ -25,6 +26,7 @@ type ICEFChromiumBrowser interface { } // TCEFChromiumBrowser +// // CEFChromium浏览器包装结构 type TCEFChromiumBrowser struct { chromium IChromium // chromium @@ -37,6 +39,7 @@ type TCEFChromiumBrowser struct { } // NewChromiumBrowser +// // 初始创建一个 chromium 浏览器 func NewChromiumBrowser(owner lcl.IWinControl, config *TCefChromiumConfig) ICEFChromiumBrowser { var m = new(TCEFChromiumBrowser) @@ -51,6 +54,7 @@ func NewChromiumBrowser(owner lcl.IWinControl, config *TCefChromiumConfig) ICEFC } // checkAndCreateBrowser +// // 创建浏览器 // 创建时如果未创建成功, 使用定时器创建直到成功 func (m *TCEFChromiumBrowser) checkAndCreateBrowser(sender lcl.IObject) { @@ -79,6 +83,7 @@ func (m *TCEFChromiumBrowser) SetCreateBrowserExtraInfo(windowName string, conte } // CreateBrowser +// // 创建浏览器 // 创建时如果未创建成功, 使用定时任务创建直到成功 func (m *TCEFChromiumBrowser) CreateBrowser() { @@ -86,18 +91,21 @@ func (m *TCEFChromiumBrowser) CreateBrowser() { } // Chromium +// // 返回 chromium func (m *TCEFChromiumBrowser) Chromium() IChromium { return m.chromium } // WindowParent +// // 返回 chromium window 组件 func (m *TCEFChromiumBrowser) WindowParent() ICEFWindowParent { return m.windowParent } // IsCreated +// // 创建浏览器是否成功 func (m *TCEFChromiumBrowser) IsCreated() bool { return m.isCreated diff --git a/cef/types.go b/cef/types.go index c084bc93..b3937a39 100644 --- a/cef/types.go +++ b/cef/types.go @@ -540,6 +540,44 @@ type ICefTextfield struct { *ICefView } +/* +********************************* +************* Views ************* +********************************* + +(*) Has CEF creation function +(d) Has delegate + +---------------- ---------------------- +| TCefView (d) | -------> | TCefTextfield (*d) | +---------------- | ---------------------- + | + | ---------------------- + |---> | TCefScrollView (*) | + | ---------------------- + | + | ------------------ ------------------- + |---> | TCefPanel (*d) | -------> | TCefWindow (*d) | + | ------------------ ------------------- + | + | ------------------------ + |---> | TCefBrowserView (*d) | + | ------------------------ + | + | ------------------ ----------------------- ----------------------- + |---> | TCefButton (d) | -------> | TCefLabelButton (*) | -------> | TCefMenuButton (*d) | + ------------------ ----------------------- ----------------------- + + +-------------- ----------------- +| TCefLayout | -------> | TCefBoxLayout | +-------------- | ----------------- + | + | ------------------ + |---> | TCefFillLayout | + ------------------ +*/ + // ICefView // /include/capi/views/cef_view_capi.h (cef_view_t) type ICefView struct { diff --git a/pkgs/channel/channel.go b/pkgs/channel/channel.go index bfac9a84..972842de 100644 --- a/pkgs/channel/channel.go +++ b/pkgs/channel/channel.go @@ -47,7 +47,7 @@ var ( port = 19878 // net ipc default: 19878 ) -//mt 消息类型 +// mt 消息类型 type mt int8 const ( From f4407092df809506fb8f131356182e6afa8980a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Tue, 21 Nov 2023 23:10:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?A:=20=E5=A2=9E=E5=8A=A0=E4=B8=80=E7=AA=97?= =?UTF-8?q?=E5=8F=A3=E5=A4=9AChromium=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/build-examples/build_examples.go | 2 +- example/many-browser/many_browser.go | 42 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/example/build-examples/build_examples.go b/example/build-examples/build_examples.go index 3e6cecd7..b7f3ca39 100644 --- a/example/build-examples/build_examples.go +++ b/example/build-examples/build_examples.go @@ -34,7 +34,7 @@ func main() { "frameless", "html5test", "i18n", "internal-http-server", "ipc-on-emit/go-composite-type", "ipc-on-emit/go-to-go", "ipc-on-emit/go-to-js", "ipc-on-emit/js-to-go", "key-event", "lib-checkupdate", "load-html-url", "local-load", "mockevent", "msgbox", "popup-sub-window", "print-pdf", "process-type", "proxy", "response-filter", - "scheme", "screen", "screenshot", "search-text", "simple", "simple-local-load", "sub-process/main-process", "sub-process/sub-process", "sys-dialog", + "scheme", "screen", "screenshot", "search-text", "simple", "simple-local-load", "helper-process", "helper-process/helper", "sys-dialog", "sys-menu", "tempdll", "view-source", "vue", "window/close-for-hidden", "window/close-for-minimize", "window/default-hidden-window", "window/new-window", "webkit-register", "window/close-for-hidden", "window/close-for-minimize", "window/default-hidden-window", "zoom"} var ( diff --git a/example/many-browser/many_browser.go b/example/many-browser/many_browser.go index 79058077..e533f847 100644 --- a/example/many-browser/many_browser.go +++ b/example/many-browser/many_browser.go @@ -1,5 +1,47 @@ package main +import ( + "github.com/energye/energy/v2/cef" + "github.com/energye/golcl/lcl" + "github.com/energye/golcl/lcl/types" +) + func main() { + //全局初始化 每个应用都必须调用的 + cef.GlobalInit(nil, nil) + //创建应用 + app := cef.NewApplication() + //指定一个URL地址,或本地html文件目录 + cef.BrowserWindow.Config.Url = "https://www.runoob.com/" + cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) { + if window.IsLCL() { + // 在这里改变主窗口的默认行为 + bw := window.AsLCLBrowserWindow().BrowserWindow() + wp := bw.WindowParent() + wp.RevertCustomAnchors() // 恢复默认根据窗口定位, + wp.SetLeft(50) + wp.SetTop(50) + wp.SetWidth(400) + wp.SetHeight(600) + // 设置根据窗口位置大小自动调整browser窗口 + wp.SetAnchors(types.NewSet(types.AkTop, types.AkLeft, types.AkRight, types.AkBottom)) + // + chromium := cef.NewChromiumBrowser(bw, nil) + rect2 := chromium.WindowParent().BoundsRect() + rect2.Left = 460 + rect2.Top = 50 + rect2.SetSize(400, 600) + chromium.WindowParent().SetBoundsRect(rect2) + chromium.WindowParent().SetAnchors(types.NewSet(types.AkTop, types.AkRight, types.AkBottom)) + chromium.Chromium().SetDefaultURL("https://www.baidu.com") + chromium.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, request *cef.ICefRequest, userGesture, isRedirect bool) bool { + // 在这里更新 WindowParent 大小, 以保证渲染到窗口中 + chromium.WindowParent().UpdateSize() + return false + }) + } + }) + //运行应用 + cef.Run(app) }