2023-05-31 17:41:14 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
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"
|
2023-05-31 17:41:14 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CefClientRef -> ICefClient
|
|
|
|
var CefClientRef cefClient
|
|
|
|
|
|
|
|
type cefClient uintptr
|
|
|
|
|
|
|
|
// New
|
|
|
|
// 创建 Client
|
|
|
|
// 自定义处理器事件
|
|
|
|
func (*cefClient) New() *ICefClient {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClientRef_Create).Call(uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
2023-07-03 17:23:26 +08:00
|
|
|
return &ICefClient{instance: unsafe.Pointer(result)}
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewForChromium
|
|
|
|
// 创建 Client 事件传递至 Chromium Event
|
|
|
|
// 获取处理器对象返回nil, 因为事件已传递至 Chromium Event 对应的事件中
|
|
|
|
func (*cefClient) NewForChromium(chromium IChromium, aDevToolsClient bool) *ICefClient {
|
|
|
|
if chromium == nil || chromium.Instance() == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClientRef_CreateForChromium).Call(chromium.Instance(), api.PascalBool(aDevToolsClient), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
2023-07-03 17:23:26 +08:00
|
|
|
return &ICefClient{instance: unsafe.Pointer(result), ct: consts.CtOther}
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Instance 实例
|
|
|
|
func (m *ICefClient) Instance() uintptr {
|
|
|
|
if m == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) Free() {
|
|
|
|
if m.instance != nil {
|
|
|
|
m.base.Free(m.Instance())
|
|
|
|
m.instance = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 17:23:26 +08:00
|
|
|
func (m *ICefClient) IsSelfEvent() bool {
|
|
|
|
return m.ct == consts.CtSelfOwn
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
2023-07-03 17:23:26 +08:00
|
|
|
func (m *ICefClient) IsOtherEvent() bool {
|
|
|
|
return m.ct == consts.CtOther
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) IsValid() bool {
|
|
|
|
if m == nil || m.instance == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return m.instance != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) SetClient(newClient *ICefClient) {
|
|
|
|
m.instance = newClient.instance
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetAudioHandler() *ICefAudioHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetAudioHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefAudioHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetCommandHandler() *ICefCommandHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetCommandHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefCommandHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetContextMenuHandler() *ICefContextMenuHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetContextMenuHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefContextMenuHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetDialogHandler() *ICefDialogHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetDialogHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefDialogHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetDisplayHandler() *ICefDisplayHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetDisplayHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefDisplayHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetDownloadHandler() *ICefDownloadHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetDownloadHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefDownloadHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetDragHandler() *ICefDragHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetDragHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefDragHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetFindHandler() *ICefFindHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetFindHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefFindHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetFocusHandler() *ICefFocusHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetFocusHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefFocusHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetFrameHandler() *ICefFrameHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetFrameHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefFrameHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetPermissionHandler() *ICefPermissionHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetPermissionHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefPermissionHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetJsdialogHandler() *ICefJsDialogHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetJsdialogHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefJsDialogHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetKeyboardHandler() *ICefKeyboardHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetKeyboardHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefKeyboardHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetLifeSpanHandler() *ICefLifeSpanHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetLifeSpanHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefLifeSpanHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetLoadHandler() *ICefLoadHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetLoadHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefLoadHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetPrintHandler() *ICefPrintHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetPrintHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefPrintHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetRenderHandler() *ICefRenderHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetRenderHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefRenderHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefClient) GetRequestHandler() *ICefRequestHandler {
|
2023-07-03 17:23:26 +08:00
|
|
|
if !m.IsValid() || m.IsOtherEvent() {
|
2023-05-31 17:41:14 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefClient_GetRequestHandler).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefRequestHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|