energy/cef/types-browser-view-delegate.go

145 lines
4.8 KiB
Go
Raw Normal View History

//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
2022-12-14 19:18:11 +08:00
package cef
2023-07-03 18:24:06 +08:00
import (
2023-07-03 19:05:11 +08:00
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/common/imports"
2023-07-03 18:24:06 +08:00
"github.com/energye/energy/v2/consts"
2023-07-03 19:05:11 +08:00
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"unsafe"
2023-07-03 18:24:06 +08:00
)
2023-07-03 19:05:11 +08:00
// BrowserViewDelegateRef -> ICefBrowserViewDelegate
var BrowserViewDelegateRef browserViewDelegate
type browserViewDelegate uintptr
func (*browserViewDelegate) New() *ICefBrowserViewDelegate {
var result uintptr
imports.Proc(def.BrowserViewDelegateRef_Create).Call(uintptr(unsafe.Pointer(&result)))
if result != 0 {
return &ICefBrowserViewDelegate{&ICefViewDelegate{instance: unsafe.Pointer(result)}}
}
return nil
}
func (*browserViewDelegate) NewForCustom(browserViewDelegate *TCEFBrowserViewComponent) *ICefBrowserViewDelegate {
if !browserViewDelegate.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.BrowserViewDelegateRef_CreateForCustom).Call(browserViewDelegate.Instance(), uintptr(unsafe.Pointer(&result)))
if result != 0 {
return &ICefBrowserViewDelegate{&ICefViewDelegate{instance: unsafe.Pointer(result), ct: consts.CtOther}}
}
return nil
}
2023-07-02 22:06:51 +08:00
// Instance 实例
func (m *ICefBrowserViewDelegate) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
func (m *ICefBrowserViewDelegate) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
func (m *ICefBrowserViewDelegate) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
2023-07-03 18:24:06 +08:00
2023-07-03 19:05:11 +08:00
func (m *ICefBrowserViewDelegate) SetOnBrowserCreated(fn onBrowserCreated) {
2023-07-03 19:12:42 +08:00
if !m.IsValid() || m.IsOtherEvent() {
2023-07-03 19:05:11 +08:00
return
}
imports.Proc(def.BrowserViewDelegate_SetOnBrowserCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefBrowserViewDelegate) SetOnBrowserDestroyed(fn onBrowserDestroyed) {
2023-07-03 19:12:42 +08:00
if !m.IsValid() || m.IsOtherEvent() {
2023-07-03 19:05:11 +08:00
return
}
imports.Proc(def.BrowserViewDelegate_SetOnBrowserDestroyed).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefBrowserViewDelegate) SetOnGetDelegateForPopupBrowserView(fn onGetDelegateForPopupBrowserView) {
2023-07-03 19:12:42 +08:00
if !m.IsValid() || m.IsOtherEvent() {
2023-07-03 19:05:11 +08:00
return
}
imports.Proc(def.BrowserViewDelegate_SetOnGetDelegateForPopupBrowserView).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefBrowserViewDelegate) SetOnPopupBrowserViewCreated(fn onPopupBrowserViewCreated) {
2023-07-03 19:12:42 +08:00
if !m.IsValid() || m.IsOtherEvent() {
2023-07-03 19:05:11 +08:00
return
}
imports.Proc(def.BrowserViewDelegate_SetOnPopupBrowserViewCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefBrowserViewDelegate) GetChromeToolbarType() consts.TCefChromeToolbarType {
2023-07-03 19:12:42 +08:00
if !m.IsValid() || m.IsOtherEvent() {
2023-07-03 19:05:11 +08:00
return 0
}
r1, _, _ := imports.Proc(def.BrowserViewDelegate_GetChromeToolbarType).Call(m.Instance())
return consts.TCefChromeToolbarType(r1)
}
2023-07-03 18:24:06 +08:00
type onBrowserCreated func(browserView *ICefBrowserView, browser *ICefBrowser)
type onBrowserDestroyed func(browserView *ICefBrowserView, browser *ICefBrowser)
2023-07-03 19:05:11 +08:00
type onGetDelegateForPopupBrowserView func(browserView *ICefBrowserView, browserSettings *TCefBrowserSettings, client *ICefClient, isDevtools bool) *ICefBrowserViewDelegate
2023-07-03 18:24:06 +08:00
type onPopupBrowserViewCreated func(browserView, popupBrowserView *ICefBrowserView, isDevtools bool, aResult *bool)
2023-07-03 19:05:11 +08:00
func init() {
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
getPtr := func(i int) unsafe.Pointer {
return unsafe.Pointer(getVal(i))
}
switch fn.(type) {
case onBrowserCreated:
browserView := &ICefBrowserView{&ICefView{instance: getPtr(0)}}
browser := &ICefBrowser{instance: getPtr(1)}
fn.(onBrowserCreated)(browserView, browser)
case onBrowserDestroyed:
browserView := &ICefBrowserView{&ICefView{instance: getPtr(0)}}
browser := &ICefBrowser{instance: getPtr(1)}
fn.(onBrowserDestroyed)(browserView, browser)
case onGetDelegateForPopupBrowserView:
browserView := &ICefBrowserView{&ICefView{instance: getPtr(0)}}
browserSettingsPtr := (*tCefBrowserSettingsPtr)(getPtr(1))
browserSettings := browserSettingsPtr.Convert()
client := &ICefClient{instance: getPtr(2)}
resultPtr := (*uintptr)(getPtr(4))
result := fn.(onGetDelegateForPopupBrowserView)(browserView, browserSettings, client, api.GoBool(getVal(3)))
if result != nil {
*resultPtr = result.Instance()
}
case onPopupBrowserViewCreated:
browserView := &ICefBrowserView{&ICefView{instance: getPtr(0)}}
popupBrowserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
fn.(onPopupBrowserViewCreated)(browserView, popupBrowserView, api.GoBool(getVal(2)), (*bool)(getPtr(3)))
default:
return false
}
return true
})
}