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-05-31 17:41:14 +08:00
|
|
|
// VF 窗口组件 BrowserView
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
|
|
|
"github.com/energye/energy/v2/consts"
|
2022-12-12 17:34:57 +08:00
|
|
|
"github.com/energye/golcl/lcl"
|
2022-12-13 22:43:31 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
2022-12-12 17:34:57 +08:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// TCEFBrowserViewComponent
|
2022-12-12 17:34:57 +08:00
|
|
|
type TCEFBrowserViewComponent struct {
|
2023-01-01 22:19:26 +08:00
|
|
|
lcl.IComponent
|
2022-12-12 17:34:57 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// NewBrowserViewComponent
|
2022-12-27 21:38:01 +08:00
|
|
|
func NewBrowserViewComponent(AOwner lcl.IComponent) *TCEFBrowserViewComponent {
|
2023-02-26 19:14:49 +08:00
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_Create).Call(lcl.CheckPtr(AOwner), uintptr(unsafe.Pointer(&result)))
|
2023-02-28 21:52:13 +08:00
|
|
|
return &TCEFBrowserViewComponent{instance: unsafe.Pointer(result)}
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// CreateBrowserView
|
2023-02-26 19:14:49 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) CreateBrowserView(client *ICefClient, url string, requestContextSettings *TCefRequestContextSettings, browserSettings *TCefBrowserSettings, extraInfo *ICefDictionaryValue) {
|
2022-12-14 13:17:53 +08:00
|
|
|
contextSettingsPtr := requestContextSettings.ToPtr()
|
|
|
|
browserSettingsPtr := browserSettings.ToPtr()
|
2023-02-26 19:14:49 +08:00
|
|
|
if extraInfo == nil {
|
|
|
|
extraInfo = DictionaryValueRef.New()
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_CreateBrowserView).Call(m.Instance(), uintptr(client.instance), api.PascalStr(url), uintptr(unsafe.Pointer(&contextSettingsPtr)), uintptr(unsafe.Pointer(&browserSettingsPtr)), extraInfo.Instance())
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// Instance
|
2022-12-27 21:38:01 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) Instance() uintptr {
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
|
|
|
|
2023-07-03 19:05:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) IsValid() bool {
|
|
|
|
if m == nil || m.instance == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return m.instance != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCEFBrowserViewComponent) Free() {
|
|
|
|
if m.instance != nil {
|
|
|
|
m.instance = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// GetForBrowser
|
2022-12-13 22:43:31 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) GetForBrowser(browser *ICefBrowser) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_GetForBrowser).Call(m.Instance(), browser.Instance())
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// SetPreferAccelerators
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetPreferAccelerators(preferAccelerators bool) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_SetPreferAccelerators).Call(m.Instance(), api.PascalBool(preferAccelerators))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// RequestFocus
|
2022-12-13 22:43:31 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) RequestFocus() {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_RequestFocus).Call(m.Instance())
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// Browser
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) Browser() *ICefBrowser {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return nil
|
|
|
|
}
|
2023-02-26 19:14:49 +08:00
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_Browser).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-02-28 21:52:13 +08:00
|
|
|
return &ICefBrowser{instance: unsafe.Pointer(result)}
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-07-03 19:12:42 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) BrowserView() *ICefBrowserView {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
|
|
|
imports.Proc(def.CEFBrowserViewComponent_BrowserView).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
|
|
|
return &ICefBrowserView{&ICefView{instance: unsafe.Pointer(result)}}
|
|
|
|
}
|
2022-12-13 22:43:31 +08:00
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// SetOnBrowserCreated
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnBrowserCreated(fn BrowserViewComponentOnBrowserCreated) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_SetOnBrowserCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// SetOnBrowserDestroyed
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnBrowserDestroyed(fn BrowserViewComponentOnBrowserDestroyed) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_SetOnBrowserDestroyed).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// SetOnGetDelegateForPopupBrowserView
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnGetDelegateForPopupBrowserView(fn BrowserViewComponentOnGetDelegateForPopupBrowserView) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_SetOnGetDelegateForPopupBrowserView).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// SetOnPopupBrowserViewCreated
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnPopupBrowserViewCreated(fn BrowserViewComponentOnPopupBrowserViewCreated) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_SetOnPopupBrowserViewCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
// SetOnGetChromeToolbarType
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnGetChromeToolbarType(fn BrowserViewComponentOnGetChromeToolbarType) {
|
2023-07-03 19:12:42 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CEFBrowserViewComponent_SetOnGetChromeToolbarType).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
|
2022-12-14 19:18:11 +08:00
|
|
|
getPtr := func(i int) unsafe.Pointer {
|
|
|
|
return unsafe.Pointer(getVal(i))
|
|
|
|
}
|
2022-12-13 22:43:31 +08:00
|
|
|
switch fn.(type) {
|
2022-12-14 19:18:11 +08:00
|
|
|
case BrowserViewComponentOnBrowserCreated:
|
2023-07-02 22:06:51 +08:00
|
|
|
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
|
2023-02-26 19:14:49 +08:00
|
|
|
browser := &ICefBrowser{instance: getPtr(2)}
|
2022-12-14 19:18:11 +08:00
|
|
|
fn.(BrowserViewComponentOnBrowserCreated)(lcl.AsObject(getPtr(0)), browserView, browser)
|
|
|
|
case BrowserViewComponentOnBrowserDestroyed:
|
2023-07-02 22:06:51 +08:00
|
|
|
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
|
2023-02-26 19:14:49 +08:00
|
|
|
browser := &ICefBrowser{instance: getPtr(2)}
|
2022-12-14 19:18:11 +08:00
|
|
|
fn.(BrowserViewComponentOnBrowserDestroyed)(lcl.AsObject(getPtr(0)), browserView, browser)
|
|
|
|
case BrowserViewComponentOnGetDelegateForPopupBrowserView:
|
2023-07-02 22:06:51 +08:00
|
|
|
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
|
2022-12-14 19:18:11 +08:00
|
|
|
browserSettingsPtr := (*tCefBrowserSettingsPtr)(getPtr(2))
|
|
|
|
browserSettings := browserSettingsPtr.Convert()
|
2023-02-28 21:52:13 +08:00
|
|
|
client := &ICefClient{instance: getPtr(3)}
|
2023-07-03 19:05:11 +08:00
|
|
|
resultPtr := (*uintptr)(getPtr(5))
|
|
|
|
result := fn.(BrowserViewComponentOnGetDelegateForPopupBrowserView)(lcl.AsObject(getPtr(0)), browserView, browserSettings, client, api.GoBool(getVal(4)))
|
|
|
|
if result != nil {
|
|
|
|
*resultPtr = result.Instance()
|
|
|
|
}
|
2022-12-14 19:18:11 +08:00
|
|
|
case BrowserViewComponentOnPopupBrowserViewCreated:
|
2023-07-02 22:06:51 +08:00
|
|
|
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
|
|
|
|
popupBrowserView := &ICefBrowserView{&ICefView{instance: getPtr(2)}}
|
2022-12-14 19:18:11 +08:00
|
|
|
fn.(BrowserViewComponentOnPopupBrowserViewCreated)(lcl.AsObject(getPtr(0)), browserView, popupBrowserView, api.GoBool(getVal(3)), (*bool)(getPtr(4)))
|
|
|
|
case BrowserViewComponentOnGetChromeToolbarType:
|
|
|
|
fn.(BrowserViewComponentOnGetChromeToolbarType)(lcl.AsObject(getPtr(0)), (*consts.TCefChromeToolbarType)(getPtr(1)))
|
2022-12-13 22:43:31 +08:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|