From 3a66f948aeb859d59c81ec9da1efff13c294e337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Wed, 3 Jan 2024 19:01:01 +0800 Subject: [PATCH] =?UTF-8?q?U:=20=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86CEF49?= =?UTF-8?q?=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84API=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cef/application_config.go | 15 +++++++++---- examples/windows/windowsxp/windowsxp.go | 30 +++++++++++++++++++------ go.mod | 1 + go.sum | 2 ++ 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/cef/application_config.go b/cef/application_config.go index 729ff25e..8ea8433e 100644 --- a/cef/application_config.go +++ b/cef/application_config.go @@ -200,12 +200,17 @@ func (m *TCEFApplication) SetMultiThreadedMessageLoop(value bool) { } func (m *TCEFApplication) ExternalMessagePump() bool { - r1, _, _ := imports.Proc(def.CEFAppConfig_ExternalMessagePump).Call() - return api.GoBool(r1) + if !m.IsSpecVer49() { + r1, _, _ := imports.Proc(def.CEFAppConfig_ExternalMessagePump).Call() + return api.GoBool(r1) + } + return false } func (m *TCEFApplication) SetExternalMessagePump(value bool) { - imports.Proc(def.CEFAppConfig_SetExternalMessagePump).Call(api.PascalBool(value)) + if !m.IsSpecVer49() { + imports.Proc(def.CEFAppConfig_SetExternalMessagePump).Call(api.PascalBool(value)) + } } func (m *TCEFApplication) WindowlessRenderingEnabled() bool { @@ -705,7 +710,9 @@ func (m *TCEFApplication) EnablePrintPreview() bool { } func (m *TCEFApplication) SetEnablePrintPreview(value bool) { - imports.Proc(def.CEFAppConfig_SetEnablePrintPreview).Call(api.PascalBool(value)) + if !m.IsSpecVer49() { + imports.Proc(def.CEFAppConfig_SetEnablePrintPreview).Call(api.PascalBool(value)) + } } func (m *TCEFApplication) DefaultEncoding() string { diff --git a/examples/windows/windowsxp/windowsxp.go b/examples/windows/windowsxp/windowsxp.go index 22bf244a..4ef01d3c 100644 --- a/examples/windows/windowsxp/windowsxp.go +++ b/examples/windows/windowsxp/windowsxp.go @@ -61,22 +61,38 @@ func (m *BrowserWindow) OnFormCreate(sender lcl.IObject) { // 3. 触发后将canClose设置为true, 发送消息到主窗口关闭,触发 m.SetOnCloseQuery m.chromium.SetOnBeforeClose(m.chromiumBeforeClose) - m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, client *cef.ICefClient, browserSettings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool { + m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, + popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, client *cef.ICefClient, browserSettings *cef.TCefBrowserSettings, + resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool { fmt.Println("beforePopupInfo:", beforePopupInfo.TargetUrl, beforePopupInfo.TargetDisposition, beforePopupInfo.TargetFrameName, beforePopupInfo.UserGesture) fmt.Println(*noJavascriptAccess) fmt.Println(browser.BrowserId(), frame.Identifier(), frame.Url(), frame.V8Context().Frame().Url()) fmt.Printf("windowInfo: %+v\n", windowInfo) fmt.Printf("browserSettings: %+v\n", browserSettings) fmt.Printf("popupFeatures: %+v\n", popupFeatures) - extraInfo := cef.DictionaryValueRef.New() - *resultExtraInfo = *extraInfo + + wp := cef.NewWindowProperty() + wp.Url = "https://www.baidu.com" + //window := cef.NewLCLWindow(wp) + //window.Show() return true }) - //m.chromium.SetOnRenderCompMsg(func(sender lcl.IObject, message *types.TMessage, lResult *types.LRESULT, aHandled *bool) { - // fmt.Println("SetOnRenderCompMsg", *lResult, *aHandled) - // //*aHandled = true - //}) + m.chromium.SetOnRenderCompMsg(func(sender lcl.IObject, message *types.TMessage, lResult *types.LRESULT, aHandled *bool) { + fmt.Println("SetOnRenderCompMsg", *lResult, *aHandled) + //*aHandled = true + }) + + m.chromium.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, params *cef.ICefContextMenuParams, model *cef.ICefMenuModel) { + fmt.Println("SetOnBeforeContextMenu") + }) + m.chromium.SetOnContextMenuCommand(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, params *cef.ICefContextMenuParams, commandId consts.MenuId, eventFlags uint32) bool { + fmt.Println("SetOnContextMenuCommand") + return false + }) + m.chromium.SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, request *cef.ICefRequest, callback *cef.ICefCallback, result *consts.TCefReturnValue) { + fmt.Println("SetOnBeforeResourceLoad", frame.Url()) + }) } func (m *BrowserWindow) show(sender lcl.IObject) { diff --git a/go.mod b/go.mod index 41f540b0..d966d361 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/godbus/dbus/v5 v5.1.0 github.com/jessevdk/go-flags v1.5.0 github.com/json-iterator/go v1.1.12 + github.com/kenshaw/snaker v0.2.0 // indirect github.com/lithammer/fuzzysearch v1.1.8 github.com/mattn/go-pointer v0.0.1 github.com/pterm/pterm v0.12.66 diff --git a/go.sum b/go.sum index c5774f8a..dc7f539a 100644 --- a/go.sum +++ b/go.sum @@ -53,6 +53,8 @@ github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= +github.com/kenshaw/snaker v0.2.0 h1:DPlxCtAv9mw1wSsvIN1khUAPJUIbFJUckMIDWSQ7TC8= +github.com/kenshaw/snaker v0.2.0/go.mod h1:DNyRUqHMZ18/zioxr6R7m4kSxxf2+QmB0BXoORsXRaY= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.10/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=