2022-12-31 13:16:30 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under GNU General Public License v3.0
|
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
2022-12-13 22:43:31 +08:00
|
|
|
. "github.com/energye/energy/common"
|
2022-12-14 19:18:11 +08:00
|
|
|
"github.com/energye/energy/consts"
|
2022-12-13 22:43:31 +08:00
|
|
|
"github.com/energye/energy/logger"
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TCEFBrowserViewComponent struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2022-12-27 21:38:01 +08:00
|
|
|
func NewBrowserViewComponent(AOwner lcl.IComponent) *TCEFBrowserViewComponent {
|
2022-12-13 22:43:31 +08:00
|
|
|
r1, _, _ := Proc(internale_CEFBrowserViewComponent_Create).Call(lcl.CheckPtr(AOwner))
|
|
|
|
return &TCEFBrowserViewComponent{
|
|
|
|
instance: unsafe.Pointer(r1),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 13:17:53 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) CreateBrowserView(client *ICefClient, url string, requestContextSettings *TCefRequestContextSettings, browserSettings *TCefBrowserSettings, extraInfo *ICefDictionaryValue) {
|
|
|
|
contextSettingsPtr := requestContextSettings.ToPtr()
|
|
|
|
browserSettingsPtr := browserSettings.ToPtr()
|
|
|
|
var dataBytes = []byte{}
|
|
|
|
var dataBytesPtr unsafe.Pointer
|
|
|
|
var dataBytesLen int = 0
|
2022-12-13 22:43:31 +08:00
|
|
|
var argsLen int = 0
|
|
|
|
if extraInfo != nil && extraInfo.dataLen > 0 {
|
|
|
|
defer func() {
|
|
|
|
extraInfo.Clear()
|
|
|
|
extraInfo = nil
|
2022-12-14 13:17:53 +08:00
|
|
|
dataBytes = nil
|
|
|
|
dataBytesPtr = nil
|
2022-12-13 22:43:31 +08:00
|
|
|
}()
|
2022-12-14 13:17:53 +08:00
|
|
|
dataBytes = extraInfo.Package()
|
2022-12-13 22:43:31 +08:00
|
|
|
argsLen = extraInfo.dataLen
|
2022-12-14 13:17:53 +08:00
|
|
|
dataBytesPtr = unsafe.Pointer(&dataBytes[0])
|
|
|
|
dataBytesLen = len(dataBytes) - 1
|
2022-12-13 22:43:31 +08:00
|
|
|
} else {
|
2022-12-14 13:17:53 +08:00
|
|
|
dataBytesPtr = unsafe.Pointer(&dataBytes)
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
2022-12-14 13:17:53 +08:00
|
|
|
Proc(internale_CEFBrowserViewComponent_CreateBrowserView).Call(uintptr(m.instance), uintptr(client.instance), api.PascalStr(url), uintptr(unsafe.Pointer(&contextSettingsPtr)), uintptr(unsafe.Pointer(&browserSettingsPtr)), uintptr(argsLen), uintptr(dataBytesPtr), uintptr(dataBytesLen))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-27 21:38:01 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) Instance() uintptr {
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
|
|
|
|
2022-12-13 22:43:31 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) GetForBrowser(browser *ICefBrowser) {
|
2022-12-14 19:18:11 +08:00
|
|
|
Proc(internale_CEFBrowserViewComponent_CreateBrowserView).Call(uintptr(m.instance), uintptr(browser.Identifier()))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetPreferAccelerators(preferAccelerators bool) {
|
|
|
|
Proc(internale_CEFBrowserViewComponent_SetPreferAccelerators).Call(uintptr(m.instance), api.PascalBool(preferAccelerators))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCEFBrowserViewComponent) RequestFocus() {
|
2022-12-14 19:18:11 +08:00
|
|
|
Proc(internale_CEFBrowserViewComponent_RequestFocus).Call(uintptr(m.instance))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) Browser() *ICefBrowser {
|
|
|
|
r1, _, _ := Proc(internale_CEFBrowserViewComponent_Browser).Call(uintptr(m.instance))
|
|
|
|
browser := &ICefBrowser{
|
|
|
|
browseId: int32(r1),
|
|
|
|
}
|
|
|
|
return browser
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
//func (m *TCEFBrowserViewComponent) BrowserView() {
|
|
|
|
// Proc(internale_CEFBrowserViewComponent_BrowserView).Call(uintptr(m.instance))
|
|
|
|
//}
|
2022-12-13 22:43:31 +08:00
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnBrowserCreated(fn BrowserViewComponentOnBrowserCreated) {
|
|
|
|
Proc(internale_CEFBrowserViewComponent_SetOnBrowserCreated).Call(uintptr(m.instance), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnBrowserDestroyed(fn BrowserViewComponentOnBrowserDestroyed) {
|
|
|
|
Proc(internale_CEFBrowserViewComponent_SetOnBrowserDestroyed).Call(uintptr(m.instance), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnGetDelegateForPopupBrowserView(fn BrowserViewComponentOnGetDelegateForPopupBrowserView) {
|
|
|
|
Proc(internale_CEFBrowserViewComponent_SetOnGetDelegateForPopupBrowserView).Call(uintptr(m.instance), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnPopupBrowserViewCreated(fn BrowserViewComponentOnPopupBrowserViewCreated) {
|
|
|
|
Proc(internale_CEFBrowserViewComponent_SetOnPopupBrowserViewCreated).Call(uintptr(m.instance), api.MakeEventDataPtr(fn))
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2022-12-14 19:18:11 +08:00
|
|
|
func (m *TCEFBrowserViewComponent) SetOnGetChromeToolbarType(fn BrowserViewComponentOnGetChromeToolbarType) {
|
|
|
|
Proc(internale_CEFBrowserViewComponent_SetOnGetChromeToolbarType).Call(uintptr(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 {
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
2022-12-30 16:54:42 +08:00
|
|
|
logger.Error("TCEFBrowserViewComponent Error:", err)
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
}()
|
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:
|
|
|
|
browserView := &ICefBrowserView{
|
|
|
|
instance: getPtr(1),
|
|
|
|
}
|
|
|
|
browser := &ICefBrowser{
|
|
|
|
browseId: int32(getVal(2)),
|
|
|
|
}
|
|
|
|
fn.(BrowserViewComponentOnBrowserCreated)(lcl.AsObject(getPtr(0)), browserView, browser)
|
|
|
|
case BrowserViewComponentOnBrowserDestroyed:
|
|
|
|
browserView := &ICefBrowserView{
|
|
|
|
instance: getPtr(1),
|
|
|
|
}
|
|
|
|
browser := &ICefBrowser{
|
|
|
|
browseId: int32(getVal(2)),
|
|
|
|
}
|
|
|
|
fn.(BrowserViewComponentOnBrowserDestroyed)(lcl.AsObject(getPtr(0)), browserView, browser)
|
|
|
|
case BrowserViewComponentOnGetDelegateForPopupBrowserView:
|
|
|
|
browserView := &ICefBrowserView{
|
|
|
|
instance: getPtr(1),
|
|
|
|
}
|
|
|
|
browserSettingsPtr := (*tCefBrowserSettingsPtr)(getPtr(2))
|
|
|
|
browserSettings := browserSettingsPtr.Convert()
|
|
|
|
client := &ICefClient{
|
|
|
|
instance: getPtr(3),
|
|
|
|
}
|
|
|
|
result := &ICefBrowserViewDelegate{
|
|
|
|
instance: getPtr(5),
|
|
|
|
}
|
|
|
|
fn.(BrowserViewComponentOnGetDelegateForPopupBrowserView)(lcl.AsObject(getPtr(0)), browserView, browserSettings, client, api.GoBool(getVal(4)), result)
|
|
|
|
case BrowserViewComponentOnPopupBrowserViewCreated:
|
|
|
|
browserView := &ICefBrowserView{
|
|
|
|
instance: getPtr(1),
|
|
|
|
}
|
|
|
|
popupBrowserView := &ICefBrowserView{
|
|
|
|
instance: getPtr(2),
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|