U: IPC NewTarget IWindow > Add Chromium

This commit is contained in:
杨红岩 2024-04-09 12:50:57 +08:00
parent 4ed6668c7c
commit 62df11e108
4 changed files with 66 additions and 9 deletions

View File

@ -576,7 +576,7 @@ func (m *LCLBrowserWindow) ChromiumCreate(config *TCefChromiumConfig, defaultUrl
//windowParent
m.WindowParent().DefaultAnchors()
m.WindowParent().SetOnEnter(func(sender lcl.IObject) {
if m.isClosing {
if m.IsClosing() {
return
}
m.Chromium().Initialized()
@ -584,7 +584,7 @@ func (m *LCLBrowserWindow) ChromiumCreate(config *TCefChromiumConfig, defaultUrl
m.Chromium().SetFocus(true)
})
m.WindowParent().SetOnExit(func(sender lcl.IObject) {
if m.isClosing {
if m.IsClosing() {
return
}
m.Chromium().SendCaptureLostEvent()
@ -846,7 +846,7 @@ func (m *LCLBrowserWindow) resize(sender lcl.IObject) {
}
}
if !ret {
if m.isClosing {
if m.IsClosing() {
return
}
m.setCurrentProperty()
@ -882,7 +882,7 @@ func (m *LCLBrowserWindow) activate(sender lcl.IObject) {
ret = m.onActivate(sender)
}
if !ret {
if m.isClosing {
if m.IsClosing() {
return
}
if m.chromiumBrowser != nil && !m.chromiumBrowser.IsCreated() {
@ -945,18 +945,24 @@ func (m *LCLBrowserWindow) CloseBrowserWindow() {
m.Close()
} else {
//sub window close
m.isClosing = true
m.setClosing(true)
m.Hide()
m.Chromium().CloseBrowser(true)
}
} else {
m.isClosing = true
m.setClosing(true)
m.Hide()
m.Chromium().CloseBrowser(true)
}
})
}
// 窗口关闭时设置为true
func (m *LCLBrowserWindow) setClosing(v bool) {
m.isClosing = v
m.Chromium().setClosing(v)
}
// TryCloseWindowAndTerminate
// 尝试关闭窗口并退出应用,
// EnableMainWindow = false
@ -1020,8 +1026,8 @@ func (m *LCLBrowserWindow) closeQuery(sender lcl.IObject, close *bool) {
*close = m.canClose
}
RunOnMainThread(func() {
if !m.isClosing {
m.isClosing = true
if !m.IsClosing() {
m.setClosing(true)
m.Chromium().CloseBrowser(true)
if IsDarwin() {
m.Show() // mac 主窗口未得到焦点时应用不退出, 所以show一下

View File

@ -40,6 +40,7 @@ type TCEFChromium struct {
widgetHandle types.HWND
renderHandle types.HWND
initialized bool
isClosing bool
}
// NewChromium 创建一个新的 TCEFChromium

View File

@ -200,6 +200,9 @@ type IChromiumProc interface {
InitializeDragAndDrop(dropTargetCtrl lcl.IWinControl)
Fullscreen() bool
ExitFullscreen(willCauseResize bool)
AsTargetWindow() target.IWindow
IsClosing() bool
setClosing(v bool)
}
// IsValid 实例有效
@ -1678,3 +1681,43 @@ func (m *TCEFChromium) ExitFullscreen(willCauseResize bool) {
}
imports.Proc(def.CEFChromium_ExitFullscreen).Call(m.Instance(), api.PascalBool(willCauseResize))
}
// Target
//
// IPC消息接收目标, 当前窗口chromium发送
// 参数: targetType 可选, 接收类型
func (m *TCEFChromium) Target(targetType ...target.Type) target.ITarget {
if !m.IsValid() {
return nil
}
browse := m.Browser()
if !browse.IsValid() {
return nil
}
return target.NewTarget(m, browse.Identifier(), browse.MainFrame().Identifier(), targetType...)
}
// ProcessMessage
//
// IPC消息触发当前Chromium
func (m *TCEFChromium) ProcessMessage() target.IProcessMessage {
if m == nil {
return nil
}
return m
}
// AsTargetWindow 转换为 IPC 目标接收窗口
func (m *TCEFChromium) AsTargetWindow() target.IWindow {
return m
}
// IsClosing 返回窗口是否正在关闭/或已关闭 true正在或已关闭
func (m *TCEFChromium) IsClosing() bool {
return m.isClosing
}
// 当窗口关闭时设置为true
func (m *TCEFChromium) setClosing(v bool) {
m.isClosing = v
}

View File

@ -150,7 +150,14 @@ func (m *ICefFrame) SendProcessMessageForJSONBytes(messageName string, targetPro
if !m.IsValid() || application.IsSpecVer49() {
return
}
imports.Proc(def.CEFFrame_SendProcessMessageForJSONBytes).Call(m.Instance(), api.PascalStr(messageName), targetProcess.ToPtr(), uintptr(unsafe.Pointer(&data[0])), uintptr(uint32(len(data))))
var (
dataPtr uintptr
count = uint32(len(data))
)
if count > 0 {
dataPtr = uintptr(unsafe.Pointer(&data[0]))
}
imports.Proc(def.CEFFrame_SendProcessMessageForJSONBytes).Call(m.Instance(), api.PascalStr(messageName), targetProcess.ToPtr(), dataPtr, uintptr(count))
}
// SendProcessMessageForV8Value 发送进程消息