2022-12-31 13:16:30 +08:00
|
|
|
|
//----------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
|
//
|
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2022-12-31 13:16:30 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// VF窗口组件定义和实现
|
2023-05-31 17:41:14 +08:00
|
|
|
|
|
2022-12-31 13:16:30 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
|
|
|
|
import (
|
2023-05-31 18:00:34 +08:00
|
|
|
|
"github.com/energye/energy/v2/cef/internal/ipc"
|
|
|
|
|
"github.com/energye/energy/v2/cef/internal/window"
|
|
|
|
|
"github.com/energye/energy/v2/cef/process"
|
|
|
|
|
"github.com/energye/energy/v2/consts"
|
|
|
|
|
"github.com/energye/energy/v2/logger"
|
|
|
|
|
"github.com/energye/energy/v2/pkgs/assetserve"
|
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-07-14 18:50:14 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/api"
|
2023-01-23 15:21:44 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/types"
|
2023-07-14 18:50:14 +08:00
|
|
|
|
"runtime"
|
2022-12-31 13:16:30 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-02-12 17:28:31 +08:00
|
|
|
|
// ViewsFrameworkBrowserWindow 基于CEF views framework 窗口组件
|
2023-01-01 22:19:26 +08:00
|
|
|
|
//
|
2023-02-12 17:28:31 +08:00
|
|
|
|
// 该窗口使用CEF内部实现,在linux下107.xx以后版本默认使用GTK3,但无法使用lcl组件集成到窗口中
|
2023-01-01 22:19:26 +08:00
|
|
|
|
//
|
2023-02-12 17:28:31 +08:00
|
|
|
|
// 当创建应用配置时 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 //
|
|
|
|
|
component lcl.IComponent //
|
|
|
|
|
windowComponent *TCEFWindowComponent //
|
|
|
|
|
browserViewComponent *TCEFBrowserViewComponent //
|
|
|
|
|
windowProperty *WindowProperty //窗口属性
|
|
|
|
|
auxTools *auxTools //辅助工具
|
|
|
|
|
tray ITray //托盘
|
2023-02-14 15:25:02 +08:00
|
|
|
|
doOnWindowCreated WindowComponentOnWindowCreated //窗口创建
|
2023-01-28 11:46:09 +08:00
|
|
|
|
doOnGetInitialBounds WindowComponentOnGetInitialBounds //窗口初始bounds
|
|
|
|
|
regions *TCefDraggableRegions //窗口内html拖拽区域
|
2023-07-25 12:36:51 +08:00
|
|
|
|
context *ICefRequestContext //
|
|
|
|
|
extraInfo *ICefDictionaryValue //
|
|
|
|
|
screen *lcl.TScreen //屏幕
|
2023-01-01 22:19:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// NewViewsFrameworkBrowserWindow 创建 ViewsFrameworkBrowserWindow 窗口
|
2023-06-19 12:41:52 +08:00
|
|
|
|
func NewViewsFrameworkBrowserWindow(config *TCefChromiumConfig, windowProperty WindowProperty, owner ...lcl.IComponent) *ViewsFrameworkBrowserWindow {
|
|
|
|
|
if config == nil {
|
|
|
|
|
config = NewChromiumConfig()
|
2023-01-09 09:25:17 +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-06-19 12:41:52 +08:00
|
|
|
|
chromium: NewChromium(component, config),
|
2023-07-04 11:59:45 +08:00
|
|
|
|
windowComponent: WindowComponentRef.New(component),
|
|
|
|
|
browserViewComponent: BrowserViewComponentRef.New(component),
|
2023-01-03 17:53:01 +08:00
|
|
|
|
}
|
2023-02-03 08:36:26 +08:00
|
|
|
|
m.SetWindowType(windowProperty.WindowType)
|
2023-01-03 18:50:12 +08:00
|
|
|
|
m.chromium.SetEnableMultiBrowserMode(true)
|
|
|
|
|
m.windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *ICefWindow) {
|
2023-07-07 15:27:26 +08:00
|
|
|
|
if m.chromium.CreateBrowserByBrowserViewComponent(windowProperty.Url, m.browserViewComponent, m.context, m.extraInfo) {
|
2023-01-03 18:50:12 +08:00
|
|
|
|
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) {
|
2023-03-01 13:38:43 +08:00
|
|
|
|
if err := m.windowComponent.SetWindowAppIconByFSFile(1, windowProperty.IconFS); err != nil {
|
|
|
|
|
logger.Error("set window application icon error:", err.Error())
|
|
|
|
|
}
|
2023-01-09 11:47:30 +08:00
|
|
|
|
}
|
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) {
|
2023-03-01 13:38:43 +08:00
|
|
|
|
if err := m.windowComponent.SetWindowAppIconByFile(1, windowProperty.Icon); err != nil {
|
|
|
|
|
logger.Error("set window application icon error:", err.Error())
|
|
|
|
|
}
|
2023-01-09 11:47:30 +08:00
|
|
|
|
}
|
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-02-12 17:28:31 +08:00
|
|
|
|
// ViewsFrameworkBrowserWindow 主窗口初始化
|
2023-03-04 11:19:45 +08:00
|
|
|
|
func (m *browserWindow) appContextInitialized(app *TCEFApplication) {
|
2023-07-23 00:04:20 +08:00
|
|
|
|
// 仅主进程初始化主窗口,
|
|
|
|
|
// 子进程也不会初始, 判断一下省着多调用函数了
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if !process.Args.IsMain() {
|
2023-01-03 21:39:46 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2023-07-23 00:04:20 +08:00
|
|
|
|
// VF 主窗口在 application 上下文初始化时创建
|
2023-01-03 21:39:46 +08:00
|
|
|
|
app.SetOnContextInitialized(func() {
|
2023-02-03 08:36:26 +08:00
|
|
|
|
m.Config.WindowProperty.WindowType = consts.WT_MAIN_BROWSER
|
2023-07-23 00:04:20 +08:00
|
|
|
|
// main window
|
|
|
|
|
vfMainWindow := NewViewsFrameworkBrowserWindow(m.Config.ChromiumConfig(), m.Config.WindowProperty)
|
|
|
|
|
// 主窗口关闭流程 before close
|
|
|
|
|
// OnCanClose如果阻止关闭,该函数不会执行
|
|
|
|
|
vfMainWindow.Chromium().SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
chromiumOnBeforeClose(browser)
|
2023-07-23 00:04:20 +08:00
|
|
|
|
if vfMainWindow.tray != nil {
|
|
|
|
|
vfMainWindow.tray.close()
|
2023-01-06 23:08:10 +08:00
|
|
|
|
}
|
2023-07-09 15:40:10 +08:00
|
|
|
|
app.QuitMessageLoop()
|
2023-01-06 23:08:10 +08:00
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// 重置窗口属性, 注册默认实现事件
|
2023-07-23 00:04:20 +08:00
|
|
|
|
vfMainWindow.ResetWindowPropertyForEvent()
|
|
|
|
|
vfMainWindow.registerPopupEvent(true)
|
|
|
|
|
vfMainWindow.registerDefaultEvent()
|
|
|
|
|
vfMainWindow.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
|
|
|
|
*aResult = vfMainWindow.Chromium().TryCloseBrowser()
|
2023-01-03 21:39:46 +08:00
|
|
|
|
})
|
2023-07-23 00:04:20 +08:00
|
|
|
|
// 设置到 MainBrowser
|
|
|
|
|
BrowserWindow.mainVFBrowserWindow = vfMainWindow
|
2023-01-07 18:42:17 +08:00
|
|
|
|
if m.Config.browserWindowOnEventCallback != nil {
|
2023-07-23 00:04:20 +08:00
|
|
|
|
BrowserWindow.browserEvent.chromium = vfMainWindow.chromium
|
|
|
|
|
m.Config.browserWindowOnEventCallback(BrowserWindow.browserEvent, vfMainWindow)
|
2023-01-07 18:42:17 +08:00
|
|
|
|
}
|
2023-07-23 00:04:20 +08:00
|
|
|
|
ipc.SetProcessMessage(vfMainWindow.Chromium().(*TCEFChromium))
|
|
|
|
|
vfMainWindow.CreateTopLevelWindow()
|
2023-07-23 17:42:29 +08:00
|
|
|
|
//创建完窗口之后设置窗口属性
|
|
|
|
|
vfMainWindow.createAfterWindowPropertyForEvent()
|
2023-01-03 21:39:46 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-23 17:42:29 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) createAfterWindowPropertyForEvent() {
|
|
|
|
|
wp := m.WindowProperty()
|
|
|
|
|
if wp.EnableResize {
|
2023-07-23 22:46:34 +08:00
|
|
|
|
// VF MinimumSize & MaximumSize 在事件中设置
|
|
|
|
|
// 如果动态设置,需要自己实现该回调函数
|
2023-07-23 17:42:29 +08:00
|
|
|
|
if wp.MinWidth > 0 && wp.MinHeight > 0 {
|
|
|
|
|
m.windowComponent.SetOnGetMinimumSize(func(view *ICefView, result *TCefSize) {
|
|
|
|
|
result.Width = int32(wp.MinWidth)
|
|
|
|
|
result.Height = int32(wp.MinHeight)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if wp.MaxWidth > 0 && wp.MaxHeight > 0 {
|
|
|
|
|
m.windowComponent.SetOnGetMaximumSize(func(view *ICefView, result *TCefSize) {
|
|
|
|
|
result.Width = int32(wp.MaxWidth)
|
|
|
|
|
result.Height = int32(wp.MaxHeight)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// registerPopupEvent 注册弹出子窗口事件
|
2023-07-09 15:40:10 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) registerPopupEvent(isMain bool) {
|
2023-01-03 17:12:12 +08:00
|
|
|
|
var bwEvent = BrowserWindow.browserEvent
|
2023-07-09 15:40:10 +08:00
|
|
|
|
if !isMain {
|
2023-07-23 00:04:20 +08:00
|
|
|
|
// 子窗口关闭流程
|
2023-07-09 15:40:10 +08:00
|
|
|
|
m.chromium.SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
|
|
|
|
|
chromiumOnBeforeClose(browser)
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-07-23 00:04:20 +08:00
|
|
|
|
m.Chromium().SetOnOpenUrlFromTab(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, targetUrl string, targetDisposition consts.TCefWindowOpenDisposition, userGesture bool) bool {
|
|
|
|
|
if !m.Chromium().Config().EnableOpenUrlTab() {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
m.Chromium().SetOnBeforePopup(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, beforePopupInfo *BeforePopupInfo, client *ICefClient, noJavascriptAccess *bool) bool {
|
|
|
|
|
if !m.Chromium().Config().EnableWindowPopup() {
|
2023-01-03 17:12:12 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
2023-07-23 00:04:20 +08:00
|
|
|
|
wp := *m.windowProperty //clone
|
2023-01-31 19:44:03 +08:00
|
|
|
|
wp.Url = beforePopupInfo.TargetUrl
|
2023-02-03 08:36:26 +08:00
|
|
|
|
wp.WindowType = consts.WT_POPUP_SUB_BROWSER
|
2023-07-23 22:17:50 +08:00
|
|
|
|
var vFrameBrowserWindow = NewViewsFrameworkBrowserWindow(NewChromiumConfig(), wp, BrowserWindow.MainWindow().AsViewsFrameworkBrowserWindow().Component())
|
2023-01-03 17:12:12 +08:00
|
|
|
|
var result = false
|
|
|
|
|
if bwEvent.onBeforePopup != nil {
|
2023-07-09 15:40:10 +08:00
|
|
|
|
result = bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, vFrameBrowserWindow, noJavascriptAccess)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
2023-01-03 17:53:01 +08:00
|
|
|
|
if !result {
|
2023-07-09 15:40:10 +08:00
|
|
|
|
vFrameBrowserWindow.ResetWindowPropertyForEvent()
|
|
|
|
|
vFrameBrowserWindow.registerPopupEvent(false)
|
|
|
|
|
vFrameBrowserWindow.registerDefaultEvent()
|
|
|
|
|
vFrameBrowserWindow.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-02-20 00:20:01 +08:00
|
|
|
|
// ResetWindowPropertyForEvent 重置窗口属性-通过事件函数
|
2023-01-09 12:10:06 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) ResetWindowPropertyForEvent() {
|
2023-01-28 11:46:09 +08:00
|
|
|
|
wp := m.WindowProperty()
|
2023-07-23 17:42:29 +08:00
|
|
|
|
m.windowComponent.SetOnGetInitialShowState(func(sender lcl.IObject, window *ICefWindow, aResult *consts.TCefShowState) {
|
|
|
|
|
*aResult = consts.TCefShowState(wp.WindowInitState + 1) // CEF 要 + 1
|
|
|
|
|
})
|
2023-01-28 11:46:09 +08:00
|
|
|
|
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-02-12 17:28:31 +08:00
|
|
|
|
m.windowComponent.SetOnIsFrameless(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
|
|
|
|
|
*aResult = wp.EnableHideCaption
|
|
|
|
|
})
|
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-02-20 00:20:01 +08:00
|
|
|
|
// registerDefaultEvent 注册默认事件
|
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-02-26 21:17:28 +08:00
|
|
|
|
m.chromium.SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) bool {
|
2023-01-03 17:12:12 +08:00
|
|
|
|
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-02-28 09:55:20 +08:00
|
|
|
|
m.chromium.SetOnBeforeDownload(func(sender lcl.IObject, browser *ICefBrowser, beforeDownloadItem *ICefDownloadItem, suggestedName string, callback *ICefBeforeDownloadCallback) {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
if bwEvent.onBeforeDownload != nil {
|
|
|
|
|
bwEvent.onBeforeDownload(sender, browser, beforeDownloadItem, suggestedName, callback)
|
|
|
|
|
} else {
|
|
|
|
|
callback.Cont(consts.ExePath+consts.Separator+suggestedName, true)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
|
2023-07-23 00:04:20 +08:00
|
|
|
|
var flag bool
|
2023-01-04 18:41:48 +08:00
|
|
|
|
if bwEvent.onBeforeContextMenu != nil {
|
|
|
|
|
bwEvent.onBeforeContextMenu(sender, browser, frame, params, model)
|
2023-07-23 00:04:20 +08:00
|
|
|
|
}
|
|
|
|
|
if !flag {
|
|
|
|
|
chromiumOnBeforeContextMenu(m, browser, frame, params, model)
|
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-07-23 00:04:20 +08:00
|
|
|
|
if !*result {
|
|
|
|
|
chromiumOnContextMenuCommand(m, browser, frame, params, commandId, eventFlags, result)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
|
2023-07-23 00:04:20 +08:00
|
|
|
|
var flag bool
|
2023-01-03 17:12:12 +08:00
|
|
|
|
if bwEvent.onAfterCreated != nil {
|
2023-07-23 00:04:20 +08:00
|
|
|
|
flag = bwEvent.onAfterCreated(sender, browser)
|
|
|
|
|
}
|
|
|
|
|
if !flag {
|
|
|
|
|
chromiumOnAfterCreate(browser)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.chromium.SetOnKeyEvent(func(sender lcl.IObject, browser *ICefBrowser, event *TCefKeyEvent, osEvent *consts.TCefEventHandle, result *bool) {
|
2023-01-05 22:15:35 +08:00
|
|
|
|
if bwEvent.onKeyEvent != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onKeyEvent(sender, browser, event, osEvent, m, result)
|
2023-07-23 00:04:20 +08:00
|
|
|
|
}
|
|
|
|
|
if !*result {
|
|
|
|
|
if m.WindowType() == consts.WT_DEV_TOOLS || m.WindowType() == consts.WT_VIEW_SOURCE {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if m.Chromium().Config().EnableDevTools() {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if event.WindowsKeyCode == consts.VkF12 && event.Kind == consts.KEYEVENT_RAW_KEYDOWN {
|
2023-01-05 22:15:35 +08:00
|
|
|
|
browser.ShowDevTools()
|
|
|
|
|
*result = true
|
2023-05-31 17:41:14 +08:00
|
|
|
|
} else if event.WindowsKeyCode == consts.VkF12 && event.Kind == consts.KEYEVENT_KEYUP {
|
2023-01-05 22:15:35 +08:00
|
|
|
|
*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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.chromium.SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, userGesture, isRedirect bool) bool {
|
2023-01-03 17:12:12 +08:00
|
|
|
|
if bwEvent.onBeforeBrowser != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
return bwEvent.onBeforeBrowser(sender, browser, frame, request, userGesture, isRedirect, m)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnTitleChange(func(sender lcl.IObject, browser *ICefBrowser, title string) {
|
|
|
|
|
if bwEvent.onTitleChange != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onTitleChange(sender, browser, title, m)
|
2023-01-03 17:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
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 {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onDragEnter(sender, browser, dragData, mask, m, result)
|
2023-01-08 18:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.chromium.SetOnLoadEnd(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, httpStatusCode int32) {
|
|
|
|
|
if bwEvent.onLoadEnd != nil {
|
|
|
|
|
bwEvent.onLoadEnd(sender, browser, frame, httpStatusCode)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-25 09:12:28 +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 {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onDraggableRegionsChanged(sender, browser, frame, regions, m)
|
2023-01-12 10:07:10 +08:00
|
|
|
|
}
|
|
|
|
|
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-02-20 00:20:01 +08:00
|
|
|
|
// EnableAllDefaultEvent 启用所有默认事件行为
|
2023-01-09 12:10:06 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) EnableAllDefaultEvent() {
|
2023-07-09 15:40:10 +08:00
|
|
|
|
m.registerPopupEvent(false)
|
2023-01-09 12:10:06 +08:00
|
|
|
|
m.registerDefaultEvent()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetOnWindowCreated 窗口创建
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetOnWindowCreated(onWindowCreated WindowComponentOnWindowCreated) {
|
|
|
|
|
m.doOnWindowCreated = onWindowCreated
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetOnGetInitialBounds 窗口初始坐标和大小
|
2023-01-28 11:46:09 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetOnGetInitialBounds(onGetInitialBounds WindowComponentOnGetInitialBounds) {
|
|
|
|
|
m.doOnGetInitialBounds = onGetInitialBounds
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-07 15:27:26 +08:00
|
|
|
|
// SetCreateBrowserExtraInfo
|
|
|
|
|
// 设置 Chromium 创建浏览器时设置的扩展信息
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetCreateBrowserExtraInfo(_ string, context *ICefRequestContext, extraInfo *ICefDictionaryValue) {
|
|
|
|
|
m.context = context
|
|
|
|
|
m.extraInfo = extraInfo
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// IsViewsFramework 返回是否VF窗口组件,这里返回true
|
2023-01-07 18:42:17 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsViewsFramework() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// IsLCL 返回是否LCL窗口组件,这里返回false
|
2023-01-07 18:42:17 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsLCL() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowProperty 部分提供部分窗口属性设置
|
2023-01-06 18:26:40 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowProperty() *WindowProperty {
|
|
|
|
|
return m.windowProperty
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// BrowserWindow 返回VF窗口组件实现
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) BrowserWindow() *ViewsFrameworkBrowserWindow {
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Handle 返回窗口句柄
|
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-02-20 00:20:01 +08:00
|
|
|
|
// AsViewsFrameworkBrowserWindow 转换为VF窗口组件,这里返回VF窗口组件
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) AsViewsFrameworkBrowserWindow() IViewsFrameworkBrowserWindow {
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// AsLCLBrowserWindow 转换为LCL窗口组件,这里返回nil
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) AsLCLBrowserWindow() ILCLBrowserWindow {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetTitle 设置窗口标题
|
2023-01-06 13:50:44 +08:00
|
|
|
|
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-02-20 00:20:01 +08:00
|
|
|
|
// SetWidth 设置窗口宽
|
2023-01-06 18:55:13 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetWidth(value int32) {
|
|
|
|
|
m.WindowProperty().Width = value
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetHeight 设置窗口高
|
2023-01-06 18:55:13 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetHeight(value int32) {
|
|
|
|
|
m.WindowProperty().Height = value
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Point 返回窗口坐标
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Size 返回窗口宽高
|
2023-01-09 08:53:01 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Size() *TCefSize {
|
|
|
|
|
result := m.WindowComponent().Size()
|
|
|
|
|
m.WindowProperty().Width = result.Width
|
|
|
|
|
m.WindowProperty().Height = result.Height
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Bounds 返回窗口坐标和宽高
|
2023-01-09 08:53:01 +08:00
|
|
|
|
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-02-20 00:20:01 +08:00
|
|
|
|
// SetPoint 设置窗口坐标
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetPoint(x, y int32) {
|
|
|
|
|
m.WindowProperty().X = x
|
|
|
|
|
m.WindowProperty().Y = y
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetSize 设置窗口宽高
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetSize(width, height int32) {
|
|
|
|
|
m.WindowProperty().Width = width
|
|
|
|
|
m.WindowProperty().Height = height
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetBounds 设置窗口坐标和宽高
|
2023-01-07 21:29:08 +08:00
|
|
|
|
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-02-20 00:20:01 +08:00
|
|
|
|
// getAuxTools 获取辅助工具-开发者工具
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) getAuxTools() *auxTools {
|
|
|
|
|
return m.auxTools
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// createAuxTools 创建辅助工具-开发者工具
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) createAuxTools() {
|
|
|
|
|
if m.auxTools == nil {
|
|
|
|
|
m.auxTools = &auxTools{}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Browser 返回browser
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Browser() *ICefBrowser {
|
2023-02-26 19:14:49 +08:00
|
|
|
|
return m.Chromium().Browser()
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Chromium 返回 chromium
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Chromium() IChromium {
|
|
|
|
|
return m.chromium
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Id 获取窗口ID
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Id() int32 {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if m.windowId == 0 {
|
|
|
|
|
m.windowId = m.Chromium().BrowserId()
|
|
|
|
|
}
|
2023-01-06 13:50:44 +08:00
|
|
|
|
return m.windowId
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Show 显示窗口
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Show() {
|
|
|
|
|
m.WindowComponent().Show()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Hide 隐藏窗口
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Hide() {
|
|
|
|
|
m.WindowComponent().Hide()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Close 关闭窗口,一搬不使用
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Close() {
|
|
|
|
|
m.WindowComponent().Close()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowState 返回窗口最小化、最大化、全屏状态
|
2023-02-14 15:25:02 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowState() types.TWindowState {
|
|
|
|
|
if m.windowComponent.IsMinimized() {
|
|
|
|
|
return types.WsMinimized
|
|
|
|
|
} else if m.windowComponent.IsMaximized() {
|
|
|
|
|
return types.WsMaximized
|
|
|
|
|
} else if m.windowComponent.IsFullscreen() {
|
|
|
|
|
return types.WsFullScreen
|
|
|
|
|
}
|
|
|
|
|
return types.WsNormal
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Maximize 窗口最大化/还原
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Maximize() {
|
2023-07-23 17:42:29 +08:00
|
|
|
|
if m.WindowState() == types.WsNormal {
|
2023-02-14 15:25:02 +08:00
|
|
|
|
m.WindowComponent().Maximize()
|
|
|
|
|
} else {
|
|
|
|
|
m.Restore()
|
|
|
|
|
}
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-23 22:46:34 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) FullScreen() {
|
|
|
|
|
m.WindowComponent().SetFullscreen(true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) ExitFullScreen() {
|
|
|
|
|
m.WindowComponent().SetFullscreen(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsFullScreen() bool {
|
|
|
|
|
return m.WindowComponent().IsFullscreen()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Minimize 窗口最小化
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Minimize() {
|
|
|
|
|
m.WindowComponent().Minimize()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Restore 窗口还原
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Restore() {
|
|
|
|
|
m.WindowComponent().Restore()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// CloseBrowserWindow 关闭浏览器窗口
|
2023-01-06 13:50:44 +08:00
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// CreateTopLevelWindow 创建顶层窗口
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) CreateTopLevelWindow() {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if m.WindowType() != consts.WT_DEV_TOOLS {
|
|
|
|
|
window.CurrentBrowseWindowCache = m
|
|
|
|
|
}
|
2023-01-06 13:50:44 +08:00
|
|
|
|
m.WindowComponent().CreateTopLevelWindow()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// CenterWindow 设置窗口居中,同时指定窗口大小
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) CenterWindow(size *TCefSize) {
|
|
|
|
|
m.WindowComponent().CenterWindow(size)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetCenterWindow 设置窗口居中显示
|
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-02-20 00:20:01 +08:00
|
|
|
|
// IsClosing 返回窗口是否正在关闭/或已关闭 true正在或已关闭
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) IsClosing() bool {
|
|
|
|
|
return m.isClosing
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowType 返回窗口类型
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowType() consts.WINDOW_TYPE {
|
|
|
|
|
return m.windowType
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetWindowType 设置窗口类型
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) SetWindowType(windowType consts.WINDOW_TYPE) {
|
|
|
|
|
m.windowType = windowType
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableMinimize 禁用最小化按钮
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) DisableMinimize() {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMinimize = false
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableMaximize 禁用最大化按钮
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableResize 禁用调整窗口大小
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableMinimize 启用最小化按钮
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableMaximize 启用最大化按钮
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableResize 启用允许调整窗口大小
|
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
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Component 返回窗口父组件
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Component() lcl.IComponent {
|
|
|
|
|
return m.component
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowComponent 返回窗口组件
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) WindowComponent() *TCEFWindowComponent {
|
|
|
|
|
return m.windowComponent
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// BrowserViewComponent 返回浏览器显示组件
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) BrowserViewComponent() *TCEFBrowserViewComponent {
|
|
|
|
|
return m.browserViewComponent
|
|
|
|
|
}
|
2023-07-14 18:50:14 +08:00
|
|
|
|
|
2023-07-25 12:36:51 +08:00
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) Screen() *lcl.TScreen {
|
|
|
|
|
if m.screen == nil && m.BrowserViewComponent() != nil {
|
|
|
|
|
m.screen = lcl.NewScreen(m.BrowserViewComponent())
|
|
|
|
|
}
|
|
|
|
|
return m.screen
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 18:50:14 +08:00
|
|
|
|
// RunOnMainThread
|
|
|
|
|
// 在主线程中运行
|
|
|
|
|
func (m *ViewsFrameworkBrowserWindow) RunOnMainThread(fn func()) {
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
if api.DMainThreadId() == api.DCurrentThreadId() {
|
|
|
|
|
fn()
|
|
|
|
|
} else {
|
|
|
|
|
lcl.ThreadSync(func() {
|
|
|
|
|
fn()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|