2022-12-31 13:16:30 +08:00
|
|
|
|
//----------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under GNU General Public License v3.0
|
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
|
|
|
|
|
import (
|
2023-01-01 22:19:26 +08:00
|
|
|
|
"github.com/energye/energy/common"
|
2023-01-03 17:12:12 +08:00
|
|
|
|
"github.com/energye/energy/common/assetserve"
|
2022-12-31 13:16:30 +08:00
|
|
|
|
"github.com/energye/energy/consts"
|
2023-01-03 17:12:12 +08:00
|
|
|
|
"github.com/energye/energy/ipc"
|
2023-01-09 11:47:30 +08:00
|
|
|
|
"github.com/energye/golcl/energy/emfs"
|
|
|
|
|
"github.com/energye/golcl/energy/tools"
|
2022-12-31 13:16:30 +08:00
|
|
|
|
"github.com/energye/golcl/lcl"
|
2023-01-03 17:12:12 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/api"
|
2023-01-23 15:21:44 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/types"
|
2022-12-31 13:16:30 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-01-09 12:17:54 +08:00
|
|
|
|
//ViewsFrameworkBrowserWindow 基于CEF views framework 窗口组件
|
2023-01-01 22:19:26 +08:00
|
|
|
|
//
|
|
|
|
|
//该窗口使用CEF内部实现,在linux下107.xx以后版本默认使用GTK3,但无法使用lcl组件集成到窗口中
|
|
|
|
|
//
|
|
|
|
|
//当创建应用配置时 MultiThreadedMessageLoop 和 ExternalMessagePump 属性同时为false(linux系统默认强制false)时启用ViewsFramework窗口
|
2022-12-31 13:16:30 +08:00
|
|
|
|
type ViewsFrameworkBrowserWindow struct {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
isClosing bool //
|
|
|
|
|
windowType consts.WINDOW_TYPE //0:browser 1:devTools 2:viewSource 默认:0
|
|
|
|
|
windowId int32 //
|
|
|
|
|
chromium IChromium //
|
|
|
|
|
browser *ICefBrowser //
|
|
|
|
|
component lcl.IComponent //
|
|
|
|
|
windowComponent *TCEFWindowComponent //
|
|
|
|
|
browserViewComponent *TCEFBrowserViewComponent //
|
|
|
|
|
windowProperty *WindowProperty //窗口属性
|
|
|
|
|
frames TCEFFrame //当前浏览器下的所有frame
|
|
|
|
|
auxTools *auxTools //辅助工具
|
|
|
|
|
tray ITray //托盘
|
|
|
|
|
doOnWindowCreated WindowComponentOnWindowCreated //
|
|
|
|
|
doOnGetInitialBounds WindowComponentOnGetInitialBounds //窗口初始bounds
|
|
|
|
|
regions *TCefDraggableRegions //窗口内html拖拽区域
|
2023-01-01 22:19:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 21:39:46 +08:00
|
|
|
|
//创建 ViewsFrameworkBrowserWindow 窗口
|
2023-01-23 10:52:40 +08:00
|
|
|
|
func NewViewsFrameworkBrowserWindow(chromiumConfig *tCefChromiumConfig, windowProperty WindowProperty, owner ...lcl.IComponent) *ViewsFrameworkBrowserWindow {
|
2023-01-03 21:39:46 +08:00
|
|
|
|
if chromiumConfig == nil {
|
2023-01-09 09:25:17 +08:00
|
|
|
|
chromiumConfig = NewChromiumConfig()
|
|
|
|
|
chromiumConfig.SetEnableViewSource(false)
|
|
|
|
|
chromiumConfig.SetEnableDevTools(false)
|
|
|
|
|
chromiumConfig.SetEnableMenu(false)
|
|
|
|
|
chromiumConfig.SetEnableWindowPopup(false)
|
|
|
|
|
}
|
2023-01-23 10:52:40 +08:00
|
|
|
|
|
2023-01-09 10:09:45 +08:00
|
|
|
|
var component lcl.IComponent
|
|
|
|
|
if len(owner) > 0 {
|
|
|
|
|
component = lcl.NewComponent(owner[0])
|
|
|
|
|
} else {
|
|
|
|
|
component = lcl.NewComponent(nil)
|
|
|
|
|
}
|
2023-01-03 18:50:12 +08:00
|
|
|
|
m := &ViewsFrameworkBrowserWindow{
|
2023-01-23 10:52:40 +08:00
|
|
|
|
windowProperty: &windowProperty,
|
2023-01-03 17:53:01 +08:00
|
|
|
|
component: component,
|
2023-01-03 21:39:46 +08:00
|
|
|
|
chromium: NewChromium(component, chromiumConfig),
|
2023-01-03 17:53:01 +08:00
|
|
|
|
windowComponent: NewWindowComponent(component),
|
|
|
|
|
browserViewComponent: NewBrowserViewComponent(component),
|
|
|
|
|
}
|
2023-01-03 18:50:12 +08:00
|
|
|
|
m.chromium.SetEnableMultiBrowserMode(true)
|
|
|
|
|
m.windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *ICefWindow) {
|
|
|
|
|
if m.chromium.CreateBrowserByBrowserViewComponent(windowProperty.Url, m.browserViewComponent) {
|
|
|
|
|
m.windowComponent.AddChildView(m.browserViewComponent)
|
2023-01-07 16:12:00 +08:00
|
|
|
|
if windowProperty.Title != "" {
|
|
|
|
|
m.windowComponent.SetTitle(windowProperty.Title)
|
|
|
|
|
}
|
2023-01-23 19:14:19 +08:00
|
|
|
|
if windowProperty.EnableCenterWindow {
|
2023-01-06 18:55:13 +08:00
|
|
|
|
m.windowComponent.CenterWindow(NewCefSize(windowProperty.Width, windowProperty.Height))
|
2023-01-03 18:50:12 +08:00
|
|
|
|
}
|
|
|
|
|
if windowProperty.IconFS != "" {
|
2023-01-09 11:47:30 +08:00
|
|
|
|
if emfs.IsExist(windowProperty.IconFS) {
|
|
|
|
|
_ = m.windowComponent.SetWindowAppIconFS(1, windowProperty.IconFS)
|
|
|
|
|
}
|
2023-01-03 18:50:12 +08:00
|
|
|
|
} else if windowProperty.Icon != "" {
|
2023-01-09 11:47:30 +08:00
|
|
|
|
if tools.IsExist(windowProperty.Icon) {
|
|
|
|
|
_ = m.windowComponent.SetWindowAppIcon(1, windowProperty.Icon)
|
|
|
|
|
}
|
2023-01-03 18:50:12 +08:00
|
|
|
|
}
|
|
|
|
|
m.browserViewComponent.RequestFocus()
|
2023-01-07 18:42:17 +08:00
|
|
|
|
m.windowComponent.Show()
|
2023-01-07 21:29:08 +08:00
|
|
|
|
if m.doOnWindowCreated != nil {
|
|
|
|
|
m.doOnWindowCreated(sender, window)
|
|
|
|
|
}
|
2023-01-03 18:50:12 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 21:39:46 +08:00
|
|
|
|
//ViewsFrameworkBrowserWindow 主窗口初始化
|
2023-01-05 22:15:35 +08:00
|
|
|
|
func (m *browser) appContextInitialized(app *TCEFApplication) {
|
2023-01-03 21:39:46 +08:00
|
|
|
|
if !common.Args.IsMain() {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
app.SetOnContextInitialized(func() {
|
2023-01-07 18:42:17 +08:00
|
|
|
|
vFrameBrowserWindow := NewViewsFrameworkBrowserWindow(m.Config.ChromiumConfig(), m.Config.WindowProperty)
|
2023-01-06 23:08:10 +08:00
|
|
|
|
vFrameBrowserWindow.Chromium().SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
|
|
|
|
|
if vFrameBrowserWindow.tray != nil {
|
|
|
|
|
vFrameBrowserWindow.tray.close()
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-09 12:10:06 +08:00
|
|
|
|
vFrameBrowserWindow.ResetWindowPropertyForEvent()
|
2023-01-09 13:11:42 +08:00
|
|
|
|
vFrameBrowserWindow.SetWindowType(consts.WT_MAIN_BROWSER)
|
2023-01-06 18:26:40 +08:00
|
|
|
|
vFrameBrowserWindow.windowId = BrowserWindow.GetNextWindowNum()
|
|
|
|
|
vFrameBrowserWindow.putChromiumWindowInfo()
|
2023-01-04 22:47:30 +08:00
|
|
|
|
vFrameBrowserWindow.registerPopupEvent()
|
|
|
|
|
vFrameBrowserWindow.registerDefaultEvent()
|
|
|
|
|
vFrameBrowserWindow.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
2023-01-03 21:39:46 +08:00
|
|
|
|
*aResult = true
|
|
|
|
|
app.QuitMessageLoop()
|
|
|
|
|
})
|
2023-01-07 21:29:08 +08:00
|
|
|
|
vFrameBrowserWindow.doOnWindowCreated = func(sender lcl.IObject, window *ICefWindow) {
|
|
|
|
|
if m.Config.browserWindowAfterOnEventCallback != nil {
|
|
|
|
|
m.Config.browserWindowAfterOnEventCallback(vFrameBrowserWindow)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-06 19:04:36 +08:00
|
|
|
|
BrowserWindow.mainVFBrowserWindow = vFrameBrowserWindow
|
2023-01-07 18:42:17 +08:00
|
|
|
|
if m.Config.browserWindowOnEventCallback != nil {
|
2023-01-08 17:04:39 +08:00
|
|
|
|
BrowserWindow.browserEvent.chromium = vFrameBrowserWindow.chromium
|
2023-01-07 18:42:17 +08:00
|
|
|
|
m.Config.browserWindowOnEventCallback(BrowserWindow.browserEvent, vFrameBrowserWindow)
|
|
|
|
|
}
|
2023-01-05 13:02:03 +08:00
|
|
|
|
vFrameBrowserWindow.windowComponent.CreateTopLevelWindow()
|
2023-01-03 21:39:46 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 17:12:12 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) registerPopupEvent() {
|
|
|
|
|
var bwEvent = BrowserWindow.browserEvent
|
|
|
|
|
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, beforePopupInfo *BeforePopupInfo, client *ICefClient, noJavascriptAccess *bool) bool {
|
|
|
|
|
if !api.GoBool(BrowserWindow.Config.chromiumConfig.enableWindowPopup) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
2023-01-31 19:44:03 +08:00
|
|
|
|
wp := BrowserWindow.Config.WindowProperty
|
|
|
|
|
wp.Url = beforePopupInfo.TargetUrl
|
|
|
|
|
var vfbw = NewViewsFrameworkBrowserWindow(BrowserWindow.Config.ChromiumConfig(), wp, BrowserWindow.MainWindow().AsViewsFrameworkBrowserWindow().Component())
|
2023-01-03 17:12:12 +08:00
|
|
|
|
var result = false
|
|
|
|
|
if bwEvent.onBeforePopup != nil {
|
2023-01-06 18:26:40 +08:00
|
|
|
|
result = bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, vfbw, noJavascriptAccess)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
2023-01-03 17:53:01 +08:00
|
|
|
|
if !result {
|
2023-01-09 12:10:06 +08:00
|
|
|
|
vfbw.ResetWindowPropertyForEvent()
|
2023-01-06 18:26:40 +08:00
|
|
|
|
vfbw.SetWindowType(consts.WT_POPUP_SUB_BROWSER)
|
|
|
|
|
vfbw.windowId = BrowserWindow.GetNextWindowNum()
|
|
|
|
|
vfbw.putChromiumWindowInfo()
|
|
|
|
|
vfbw.registerPopupEvent()
|
|
|
|
|
vfbw.registerDefaultEvent()
|
|
|
|
|
vfbw.windowComponent.CreateTopLevelWindow()
|
2023-01-05 22:15:35 +08:00
|
|
|
|
result = true
|
2023-01-03 17:53:01 +08:00
|
|
|
|
}
|
2023-01-03 17:12:12 +08:00
|
|
|
|
return result
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 19:04:36 +08:00
|
|
|
|
//重置窗口属性-通过事件函数
|
2023-01-09 12:10:06 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) ResetWindowPropertyForEvent() {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
wp := m.WindowProperty()
|
|
|
|
|
m.windowComponent.SetOnGetInitialBounds(func(sender lcl.IObject, window *ICefWindow, aResult *TCefRect) {
|
|
|
|
|
if wp.EnableCenterWindow {
|
|
|
|
|
m.windowComponent.CenterWindow(NewCefSize(wp.Width, wp.Height))
|
|
|
|
|
aResult.Width = wp.Width
|
|
|
|
|
aResult.Height = wp.Height
|
|
|
|
|
} else {
|
|
|
|
|
aResult.X = wp.X
|
|
|
|
|
aResult.Y = wp.Y
|
|
|
|
|
aResult.Width = wp.Width
|
|
|
|
|
aResult.Height = wp.Height
|
|
|
|
|
}
|
|
|
|
|
if m.doOnGetInitialBounds != nil {
|
|
|
|
|
m.doOnGetInitialBounds(sender, window, aResult)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-07 18:42:17 +08:00
|
|
|
|
m.windowComponent.SetOnCanMinimize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
*aResult = wp.EnableMinimize
|
2023-01-07 18:42:17 +08:00
|
|
|
|
})
|
|
|
|
|
m.windowComponent.SetOnCanResize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
*aResult = wp.EnableResize
|
2023-01-07 18:42:17 +08:00
|
|
|
|
})
|
|
|
|
|
m.windowComponent.SetOnCanMaximize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
*aResult = wp.EnableMaximize
|
2023-01-07 18:42:17 +08:00
|
|
|
|
})
|
|
|
|
|
m.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
*aResult = wp.EnableClose
|
2023-01-07 18:42:17 +08:00
|
|
|
|
})
|
2023-01-28 11:46:09 +08:00
|
|
|
|
m.windowComponent.SetAlwaysOnTop(wp.AlwaysOnTop)
|
|
|
|
|
m.windowComponent.SetBounds(NewCefRect(wp.X, wp.Y, wp.Width, wp.Height))
|
2023-01-06 18:55:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-01 23:24:00 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
|
|
|
|
|
var bwEvent = BrowserWindow.browserEvent
|
2023-01-04 18:41:48 +08:00
|
|
|
|
//默认自定义快捷键
|
|
|
|
|
defaultAcceleratorCustom()
|
2023-01-03 17:12:12 +08:00
|
|
|
|
m.chromium.SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ipc.ICefProcessMessage) bool {
|
|
|
|
|
if bwEvent.onProcessMessageReceived != nil {
|
|
|
|
|
return bwEvent.onProcessMessageReceived(sender, browser, frame, sourceProcess, message)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
2023-01-04 18:41:48 +08:00
|
|
|
|
m.chromium.SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *consts.TCefReturnValue) {
|
|
|
|
|
if assetserve.AssetsServerHeaderKeyValue != "" {
|
|
|
|
|
request.SetHeaderByName(assetserve.AssetsServerHeaderKeyName, assetserve.AssetsServerHeaderKeyValue, true)
|
|
|
|
|
}
|
|
|
|
|
if bwEvent.onBeforeResourceLoad != nil {
|
|
|
|
|
bwEvent.onBeforeResourceLoad(sender, browser, frame, request, callback, result)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-05 22:15:35 +08:00
|
|
|
|
//事件可以覆盖
|
2023-01-04 18:41:48 +08:00
|
|
|
|
m.chromium.SetOnBeforeDownload(func(sender lcl.IObject, browser *ICefBrowser, beforeDownloadItem *DownloadItem, suggestedName string, callback *ICefBeforeDownloadCallback) {
|
|
|
|
|
if bwEvent.onBeforeDownload != nil {
|
|
|
|
|
bwEvent.onBeforeDownload(sender, browser, beforeDownloadItem, suggestedName, callback)
|
|
|
|
|
} else {
|
|
|
|
|
callback.Cont(consts.ExePath+consts.Separator+suggestedName, true)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-09 13:11:42 +08:00
|
|
|
|
//事件可以覆盖
|
2023-01-04 18:41:48 +08:00
|
|
|
|
m.chromium.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
|
|
|
|
|
if bwEvent.onBeforeContextMenu != nil {
|
|
|
|
|
bwEvent.onBeforeContextMenu(sender, browser, frame, params, model)
|
2023-01-09 13:11:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
chromiumOnBeforeContextMenu(sender, browser, frame, params, model)
|
2023-01-04 18:41:48 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-09 13:11:42 +08:00
|
|
|
|
//事件可以覆盖
|
2023-01-04 18:41:48 +08:00
|
|
|
|
m.chromium.SetOnContextMenuCommand(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, commandId consts.MenuId, eventFlags uint32, result *bool) {
|
|
|
|
|
if bwEvent.onContextMenuCommand != nil {
|
|
|
|
|
bwEvent.onContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, result)
|
2023-01-09 13:11:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
chromiumOnContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, result)
|
2023-01-04 18:41:48 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-03 17:12:12 +08:00
|
|
|
|
m.chromium.SetOnFrameCreated(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) {
|
2023-01-08 18:05:03 +08:00
|
|
|
|
BrowserWindow.putBrowserFrame(browser, frame)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
if bwEvent.onFrameCreated != nil {
|
|
|
|
|
bwEvent.onFrameCreated(sender, browser, frame)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnFrameDetached(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) {
|
|
|
|
|
chromiumOnFrameDetached(browser, frame)
|
|
|
|
|
if bwEvent.onFrameDetached != nil {
|
|
|
|
|
bwEvent.onFrameDetached(sender, browser, frame)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
|
|
|
|
|
if chromiumOnAfterCreate(browser) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if bwEvent.onAfterCreated != nil {
|
|
|
|
|
bwEvent.onAfterCreated(sender, browser)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
//事件可以被覆盖
|
|
|
|
|
m.chromium.SetOnKeyEvent(func(sender lcl.IObject, browser *ICefBrowser, event *TCefKeyEvent, result *bool) {
|
2023-01-05 22:15:35 +08:00
|
|
|
|
if bwEvent.onKeyEvent != nil {
|
|
|
|
|
bwEvent.onKeyEvent(sender, browser, event, result)
|
|
|
|
|
} else {
|
|
|
|
|
if api.GoBool(BrowserWindow.Config.chromiumConfig.enableDevTools) {
|
|
|
|
|
if winInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); winInfo != nil {
|
|
|
|
|
if winInfo.WindowType() == consts.WT_DEV_TOOLS || winInfo.WindowType() == consts.WT_VIEW_SOURCE {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if event.WindowsKeyCode == VkF12 && event.Kind == consts.KEYEVENT_RAW_KEYDOWN {
|
|
|
|
|
browser.ShowDevTools()
|
|
|
|
|
*result = true
|
|
|
|
|
} else if event.WindowsKeyCode == VkF12 && event.Kind == consts.KEYEVENT_KEYUP {
|
|
|
|
|
*result = true
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-05 22:15:35 +08:00
|
|
|
|
if KeyAccelerator.accelerator(browser, event, result) {
|
|
|
|
|
return
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) bool {
|
|
|
|
|
chromiumOnBeforeBrowser(browser, frame)
|
|
|
|
|
if bwEvent.onBeforeBrowser != nil {
|
|
|
|
|
return bwEvent.onBeforeBrowser(sender, browser, frame)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnTitleChange(func(sender lcl.IObject, browser *ICefBrowser, title string) {
|
|
|
|
|
if bwEvent.onTitleChange != nil {
|
|
|
|
|
bwEvent.onTitleChange(sender, browser, title)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-08 18:05:03 +08:00
|
|
|
|
m.chromium.SetOnDragEnter(func(sender lcl.IObject, browser *ICefBrowser, dragData *ICefDragData, mask consts.TCefDragOperations, result *bool) {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
*result = !m.WindowProperty().EnableDragFile
|
2023-01-08 18:05:03 +08:00
|
|
|
|
if bwEvent.onDragEnter != nil {
|
|
|
|
|
bwEvent.onDragEnter(sender, browser, dragData, mask, result)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnLoadEnd(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, httpStatusCode int32) {
|
|
|
|
|
if bwEvent.onLoadEnd != nil {
|
|
|
|
|
bwEvent.onLoadEnd(sender, browser, frame, httpStatusCode)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-01-23 10:52:40 +08:00
|
|
|
|
if m.WindowProperty().EnableWebkitAppRegion {
|
2023-01-12 10:07:10 +08:00
|
|
|
|
m.chromium.SetOnDraggableRegionsChanged(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, regions *TCefDraggableRegions) {
|
|
|
|
|
if bwEvent.onDraggableRegionsChanged != nil {
|
|
|
|
|
bwEvent.onDraggableRegionsChanged(sender, browser, frame, regions)
|
|
|
|
|
}
|
|
|
|
|
m.regions = regions
|
|
|
|
|
m.windowComponent.SetDraggableRegions(regions.Regions())
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-01-01 23:24:00 +08:00
|
|
|
|
}
|
2023-01-06 13:50:44 +08:00
|
|
|
|
|
2023-01-09 12:10:06 +08:00
|
|
|
|
//启用所有默认事件行为
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) EnableAllDefaultEvent() {
|
|
|
|
|
m.registerPopupEvent()
|
|
|
|
|
m.registerDefaultEvent()
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetOnWindowCreated(onWindowCreated WindowComponentOnWindowCreated) {
|
|
|
|
|
m.doOnWindowCreated = onWindowCreated
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-28 11:46:09 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetOnGetInitialBounds(onGetInitialBounds WindowComponentOnGetInitialBounds) {
|
|
|
|
|
m.doOnGetInitialBounds = onGetInitialBounds
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 18:42:17 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsViewsFramework() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsLCL() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 18:26:40 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowProperty() *WindowProperty {
|
|
|
|
|
return m.windowProperty
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) putChromiumWindowInfo() {
|
|
|
|
|
BrowserWindow.putWindowInfo(m.windowId, m)
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) BrowserWindow() *ViewsFrameworkBrowserWindow {
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-23 15:21:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Handle() types.HWND {
|
|
|
|
|
return types.HWND(m.WindowComponent().WindowHandle().ToPtr())
|
2023-01-19 14:31:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) AsViewsFrameworkBrowserWindow() IViewsFrameworkBrowserWindow {
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) AsLCLBrowserWindow() ILCLBrowserWindow {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetTitle(title string) {
|
2023-01-06 18:26:40 +08:00
|
|
|
|
m.WindowProperty().Title = title
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 18:55:13 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetWidth(value int32) {
|
|
|
|
|
m.WindowProperty().Width = value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetHeight(value int32) {
|
|
|
|
|
m.WindowProperty().Height = value
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 08:53:01 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Point() *TCefPoint {
|
|
|
|
|
result := m.WindowComponent().Position()
|
|
|
|
|
m.WindowProperty().X = result.X
|
|
|
|
|
m.WindowProperty().Y = result.Y
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Size() *TCefSize {
|
|
|
|
|
result := m.WindowComponent().Size()
|
|
|
|
|
m.WindowProperty().Width = result.Width
|
|
|
|
|
m.WindowProperty().Height = result.Height
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Bounds() *TCefRect {
|
|
|
|
|
result := m.WindowComponent().Bounds()
|
|
|
|
|
m.WindowProperty().X = result.X
|
|
|
|
|
m.WindowProperty().Y = result.Y
|
|
|
|
|
m.WindowProperty().Width = result.Width
|
|
|
|
|
m.WindowProperty().Height = result.Height
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetPoint(x, y int32) {
|
|
|
|
|
m.WindowProperty().X = x
|
|
|
|
|
m.WindowProperty().Y = y
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetSize(width, height int32) {
|
|
|
|
|
m.WindowProperty().Width = width
|
|
|
|
|
m.WindowProperty().Height = height
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetBounds(x, y, width, height int32) {
|
|
|
|
|
m.WindowProperty().X = x
|
|
|
|
|
m.WindowProperty().Y = y
|
|
|
|
|
m.WindowProperty().Width = width
|
|
|
|
|
m.WindowProperty().Height = height
|
2023-01-06 18:55:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) getAuxTools() *auxTools {
|
|
|
|
|
return m.auxTools
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) createAuxTools() {
|
|
|
|
|
if m.auxTools == nil {
|
|
|
|
|
m.auxTools = &auxTools{}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Browser() *ICefBrowser {
|
|
|
|
|
return m.browser
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Frames() TCEFFrame {
|
|
|
|
|
return m.frames
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) createFrames() {
|
|
|
|
|
if m.frames == nil {
|
|
|
|
|
m.frames = make(TCEFFrame)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) setBrowser(browser *ICefBrowser) {
|
|
|
|
|
m.browser = browser
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) addFrame(frame *ICefFrame) {
|
|
|
|
|
m.createFrames()
|
|
|
|
|
m.frames[frame.Id] = frame
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Chromium() IChromium {
|
|
|
|
|
return m.chromium
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Id() int32 {
|
|
|
|
|
return m.windowId
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Show() {
|
|
|
|
|
m.WindowComponent().Show()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Hide() {
|
|
|
|
|
m.WindowComponent().Hide()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Close() {
|
|
|
|
|
m.WindowComponent().Close()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Maximize() {
|
|
|
|
|
m.WindowComponent().Maximize()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Minimize() {
|
|
|
|
|
m.WindowComponent().Minimize()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Restore() {
|
|
|
|
|
m.WindowComponent().Restore()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) CloseBrowserWindow() {
|
2023-01-06 19:04:36 +08:00
|
|
|
|
m.isClosing = true
|
2023-01-06 13:50:44 +08:00
|
|
|
|
m.chromium.CloseBrowser(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) CreateTopLevelWindow() {
|
|
|
|
|
m.WindowComponent().CreateTopLevelWindow()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) CenterWindow(size *TCefSize) {
|
|
|
|
|
m.WindowComponent().CenterWindow(size)
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 12:06:03 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetCenterWindow(value bool) {
|
2023-01-23 19:14:19 +08:00
|
|
|
|
m.WindowProperty().EnableCenterWindow = value
|
2023-01-09 12:06:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:50:44 +08:00
|
|
|
|
//返回窗口关闭状态
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsClosing() bool {
|
|
|
|
|
return m.isClosing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回窗口类型
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowType() consts.WINDOW_TYPE {
|
|
|
|
|
return m.windowType
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置窗口类型
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetWindowType(windowType consts.WINDOW_TYPE) {
|
|
|
|
|
m.windowType = windowType
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//禁用最小化按钮
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) DisableMinimize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMinimize = false
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//禁用最大化按钮
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) DisableMaximize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMaximize = false
|
2023-01-07 18:42:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//禁用调整窗口大小
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) DisableResize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableResize = false
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//启用最小化按钮
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) EnableMinimize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMinimize = true
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//启用最大化按钮
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) EnableMaximize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMaximize = true
|
2023-01-07 18:42:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//启用调整窗口大小
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) EnableResize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableResize = true
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Component() lcl.IComponent {
|
|
|
|
|
return m.component
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowComponent() *TCEFWindowComponent {
|
|
|
|
|
return m.windowComponent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) BrowserViewComponent() *TCEFBrowserViewComponent {
|
|
|
|
|
return m.browserViewComponent
|
|
|
|
|
}
|