Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
sxmxta committed Nov 22, 2023
2 parents 606db63 + f440709 commit d088954
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cef/chromium_browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
)

// ICEFChromiumBrowser
//
// CEFChromium浏览器接口
type ICEFChromiumBrowser interface {
SetCreateBrowserExtraInfo(windowName string, context *ICefRequestContext, extraInfo *ICefDictionaryValue) //
Expand All @@ -25,6 +26,7 @@ type ICEFChromiumBrowser interface {
}

// TCEFChromiumBrowser
//
// CEFChromium浏览器包装结构
type TCEFChromiumBrowser struct {
chromium IChromium // chromium
Expand All @@ -37,6 +39,7 @@ type TCEFChromiumBrowser struct {
}

// NewChromiumBrowser
//
// 初始创建一个 chromium 浏览器
func NewChromiumBrowser(owner lcl.IWinControl, config *TCefChromiumConfig) ICEFChromiumBrowser {
var m = new(TCEFChromiumBrowser)
Expand All @@ -51,6 +54,7 @@ func NewChromiumBrowser(owner lcl.IWinControl, config *TCefChromiumConfig) ICEFC
}

// checkAndCreateBrowser
//
// 创建浏览器
// 创建时如果未创建成功, 使用定时器创建直到成功
func (m *TCEFChromiumBrowser) checkAndCreateBrowser(sender lcl.IObject) {
Expand Down Expand Up @@ -79,25 +83,29 @@ func (m *TCEFChromiumBrowser) SetCreateBrowserExtraInfo(windowName string, conte
}

// CreateBrowser
//
// 创建浏览器
// 创建时如果未创建成功, 使用定时任务创建直到成功
func (m *TCEFChromiumBrowser) CreateBrowser() {
m.checkAndCreateBrowser(nil)
}

// 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
Expand Down
38 changes: 38 additions & 0 deletions cef/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion example/build-examples/build_examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
42 changes: 42 additions & 0 deletions example/many-browser/many_browser.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion pkgs/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
port = 19878 // net ipc default: 19878
)

//mt 消息类型
// mt 消息类型
type mt int8

const (
Expand Down

0 comments on commit d088954

Please sign in to comment.