v2.3.68 vf

This commit is contained in:
杨红岩 2023-01-28 11:46:09 +08:00
parent 926609a981
commit d9598d9683
3 changed files with 58 additions and 45 deletions

View File

@ -26,20 +26,21 @@ import (
//
//当创建应用配置时 MultiThreadedMessageLoop 和 ExternalMessagePump 属性同时为false(linux系统默认强制false)时启用ViewsFramework窗口
type ViewsFrameworkBrowserWindow struct {
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 //
regions *TCefDraggableRegions //窗口内html拖拽区域
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拖拽区域
}
//创建 ViewsFrameworkBrowserWindow 窗口
@ -157,31 +158,36 @@ func (m *ViewsFrameworkBrowserWindow) registerPopupEvent() {
//重置窗口属性-通过事件函数
func (m *ViewsFrameworkBrowserWindow) ResetWindowPropertyForEvent() {
windowProperty := m.WindowProperty()
if windowProperty.EnableCenterWindow {
m.windowComponent.CenterWindow(NewCefSize(m.WindowProperty().Width, m.WindowProperty().Height))
} else {
m.windowComponent.SetOnGetInitialBounds(func(sender lcl.IObject, window *ICefWindow, aResult *TCefRect) {
aResult.X = windowProperty.X
aResult.Y = windowProperty.Y
aResult.Width = windowProperty.Width
aResult.Height = windowProperty.Height
})
}
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)
}
})
m.windowComponent.SetOnCanMinimize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = windowProperty.EnableMinimize
*aResult = wp.EnableMinimize
})
m.windowComponent.SetOnCanResize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = windowProperty.EnableResize
*aResult = wp.EnableResize
})
m.windowComponent.SetOnCanMaximize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = windowProperty.EnableMaximize
*aResult = wp.EnableMaximize
})
m.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = windowProperty.EnableClose
*aResult = wp.EnableClose
})
m.windowComponent.SetAlwaysOnTop(windowProperty.AlwaysOnTop)
m.windowComponent.SetBounds(NewCefRect(windowProperty.X, windowProperty.Y, windowProperty.Width, windowProperty.Height))
m.windowComponent.SetAlwaysOnTop(wp.AlwaysOnTop)
m.windowComponent.SetBounds(NewCefRect(wp.X, wp.Y, wp.Width, wp.Height))
}
func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
@ -313,6 +319,10 @@ func (m *ViewsFrameworkBrowserWindow) SetOnWindowCreated(onWindowCreated WindowC
m.doOnWindowCreated = onWindowCreated
}
func (m *ViewsFrameworkBrowserWindow) SetOnGetInitialBounds(onGetInitialBounds WindowComponentOnGetInitialBounds) {
m.doOnGetInitialBounds = onGetInitialBounds
}
func (m *ViewsFrameworkBrowserWindow) IsViewsFramework() bool {
return true
}
@ -383,13 +393,11 @@ func (m *ViewsFrameworkBrowserWindow) Bounds() *TCefRect {
func (m *ViewsFrameworkBrowserWindow) SetPoint(x, y int32) {
m.WindowProperty().X = x
m.WindowProperty().Y = y
m.WindowComponent().SetPosition(NewCefPoint(x, y))
}
func (m *ViewsFrameworkBrowserWindow) SetSize(width, height int32) {
m.WindowProperty().Width = width
m.WindowProperty().Height = height
m.WindowComponent().SetSize(NewCefSize(width, height))
}
func (m *ViewsFrameworkBrowserWindow) SetBounds(x, y, width, height int32) {
@ -397,7 +405,6 @@ func (m *ViewsFrameworkBrowserWindow) SetBounds(x, y, width, height int32) {
m.WindowProperty().Y = y
m.WindowProperty().Width = width
m.WindowProperty().Height = height
m.WindowComponent().SetBounds(NewCefRect(x, y, width, height))
}
func (m *ViewsFrameworkBrowserWindow) getAuxTools() *auxTools {

View File

@ -129,13 +129,14 @@ type ILCLBrowserWindow interface {
//定义了ViewsFramework常用函数
type IViewsFrameworkBrowserWindow interface {
IBrowserWindow
BrowserWindow() *ViewsFrameworkBrowserWindow //返回 ViewsFrameworkBrowserWindow 窗口结构
CreateTopLevelWindow() //创建窗口, 在窗口组件中需要默认调用Show函数
CenterWindow(size *TCefSize) //设置窗口居中,同时指定窗口大小
Component() lcl.IComponent //窗口父组件
WindowComponent() *TCEFWindowComponent //窗口组件
BrowserViewComponent() *TCEFBrowserViewComponent //窗口浏览器组件
SetOnWindowCreated(onWindowCreated WindowComponentOnWindowCreated) //设置窗口默认的创建回调事件函数
BrowserWindow() *ViewsFrameworkBrowserWindow //返回 ViewsFrameworkBrowserWindow 窗口结构
CreateTopLevelWindow() //创建窗口, 在窗口组件中需要默认调用Show函数
CenterWindow(size *TCefSize) //设置窗口居中,同时指定窗口大小
Component() lcl.IComponent //窗口父组件
WindowComponent() *TCEFWindowComponent //窗口组件
BrowserViewComponent() *TCEFBrowserViewComponent //窗口浏览器组件
SetOnWindowCreated(onWindowCreated WindowComponentOnWindowCreated) //设置窗口默认的创建回调事件函数
SetOnGetInitialBounds(onGetInitialBounds WindowComponentOnGetInitialBounds) //设置窗口初始bounds
}
//创建一个属性配置器,带有窗口默认属性值

View File

@ -12,7 +12,6 @@ import (
"embed"
"fmt"
"github.com/energye/energy/cef"
"github.com/energye/energy/common"
"github.com/energye/energy/common/assetserve"
"github.com/energye/golcl/lcl"
"time"
@ -22,7 +21,6 @@ import (
var resources embed.FS
func main() {
fmt.Println("ARGS", common.Args.ProcessType())
//全局初始化 每个应用都必须调用的
cef.GlobalInit(nil, &resources)
//创建应用
@ -37,8 +35,9 @@ func main() {
cef.BrowserWindow.Config.EnableWebkitAppRegion = true
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
//window.DisableResize()
window.SetCenterWindow(false)
window.SetTitle("这里改变了窗口标题")
window.SetSize(1600, 900)
window.SetSize(1024, 900)
fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window)
fmt.Println("LCL", window.AsLCLBrowserWindow(), "VF", window.AsViewsFrameworkBrowserWindow())
event.SetOnDraggableRegionsChanged(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, regions *cef.TCefDraggableRegions) {
@ -47,13 +46,19 @@ func main() {
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
fmt.Println("IsViewsFramework:", popupWindow.IsViewsFramework())
popupWindow.SetTitle("修改了标题: " + beforePopupInfo.TargetUrl)
popupWindow.SetCenterWindow(true)
popupWindow.SetCenterWindow(false)
popupWindow.EnableResize()
popupWindow.DisableMaximize()
popupWindow.DisableResize()
popupWindow.DisableMinimize()
popupWindow.SetSize(1600, 1600)
browserWindow := popupWindow.AsViewsFrameworkBrowserWindow()
browserWindow.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
fmt.Println("popupWindow.SetOnWindowCreated", window)
})
browserWindow.SetOnGetInitialBounds(func(sender lcl.IObject, window *cef.ICefWindow, aResult *cef.TCefRect) {
fmt.Println("popupWindow.SetOnGetInitialBounds", *aResult)
})
//browserWindow.BrowserWindow().CreateTopLevelWindow()
//browserWindow.BrowserWindow().HideTitle()
fmt.Println("browserWindow:", browserWindow, browserWindow.WindowComponent().WindowHandle())