energy/cef/types-browser.go

592 lines
15 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
// CEF Browser 实例
2023-05-31 17:41:14 +08:00
// 直接在 browser 使用 browser host 功能函数
2022-10-04 13:21:05 +08:00
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
2023-05-31 18:00:34 +08:00
"github.com/energye/energy/v2/cef/ipc/target"
"github.com/energye/energy/v2/common"
"github.com/energye/energy/v2/common/imports"
. "github.com/energye/energy/v2/consts"
2022-10-04 13:21:05 +08:00
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"github.com/energye/golcl/lcl/types"
"unsafe"
)
type frameNamesPtr struct {
Name uintptr
Value uintptr
}
type FrameNames struct {
Name string
Value string
}
2023-02-26 19:14:49 +08:00
// Instance 实例
func (m *ICefBrowser) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
2023-05-31 17:41:14 +08:00
2023-03-14 17:07:15 +08:00
func (m *ICefBrowser) IsValid() bool {
2023-05-31 17:41:14 +08:00
if m == nil || m.instance == nil {
return false
}
2023-03-14 17:07:15 +08:00
return m.instance != nil
}
2023-02-26 19:14:49 +08:00
2023-03-26 00:18:23 +08:00
// BrowserId 获取浏览器ID 每一个窗口唯一ID
func (m *ICefBrowser) BrowserId() int32 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
2023-02-26 19:14:49 +08:00
return m.Identifier()
}
2023-03-26 00:18:23 +08:00
// FrameId 获取FrameID 一个窗口中可以有多Frame
func (m *ICefBrowser) FrameId() int64 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
2023-02-26 19:14:49 +08:00
return m.MainFrame().Identifier()
}
2023-02-26 19:14:49 +08:00
// Identifier ICefBrowser ID
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) Identifier() int32 {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CEFBrowser_GetIdentifier).Call(m.Instance())
2023-02-26 19:14:49 +08:00
return int32(r1)
2022-10-04 13:21:05 +08:00
}
// HostWindowHandle 获取窗口句柄, Browser窗口句柄
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) HostWindowHandle() types.HWND {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CEFBrowser_GetHostWindowHandle).Call(m.Instance())
2022-10-04 13:21:05 +08:00
return r1
}
// CloseBrowser 关闭浏览器,同时关闭窗口
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) CloseBrowser(forceClose bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_CloseBrowser).Call(m.Instance(), api.PascalBool(forceClose))
2022-10-04 13:21:05 +08:00
}
// TryCloseBrowser 尝试关闭浏览器,同时尝试关闭窗口
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) TryCloseBrowser() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_TryCloseBrowser).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
// SetFocus 设置焦点
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SetFocus(focus bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SetFocus).Call(m.Instance(), api.PascalBool(focus))
2022-10-04 13:21:05 +08:00
}
// GetZoomLevel 获取缩放级别
func (m *ICefBrowser) GetZoomLevel() (result float64) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_GetZoomLevel).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return result
2022-10-04 13:21:05 +08:00
}
// SetZoomLevel 设置缩放级别
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SetZoomLevel(zoomLevel float64) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SetZoomLevel).Call(m.Instance(), uintptr(unsafe.Pointer(&zoomLevel)))
2022-10-04 13:21:05 +08:00
}
// RunFileDialog 运行文件选择窗口, 可配合在下载文件事件中使用
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) RunFileDialog(mode int32, title, defaultFilePath string, acceptFilters *lcl.TStrings) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_RunFileDialog).Call(m.Instance(), uintptr(mode), api.PascalStr(title), api.PascalStr(defaultFilePath), acceptFilters.Instance())
2022-10-04 13:21:05 +08:00
}
// StartDownload 开始下载
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) StartDownload(url string) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_StartDownload).Call(m.Instance(), api.PascalStr(url))
2022-10-04 13:21:05 +08:00
}
// DownloadImage 开始下载图片
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) DownloadImage(imageUrl string, isFavicon bool, maxImageSize int32, bypassCache bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_DownloadImage).Call(m.Instance(), api.PascalStr(imageUrl), api.PascalBool(isFavicon), uintptr(maxImageSize), api.PascalBool(bypassCache))
2022-10-04 13:21:05 +08:00
}
// Print
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) Print() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_Print).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-26 19:14:49 +08:00
// MainFrame 获取当前窗口的主Frame
func (m *ICefBrowser) MainFrame() *ICefFrame {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
2023-02-26 19:14:49 +08:00
return nil
2022-10-04 13:21:05 +08:00
}
2023-05-31 17:41:14 +08:00
if m.mainFrame == nil || m.mainFrame.instance == nil || !m.mainFrame.IsValid() {
2023-03-01 14:18:39 +08:00
var result uintptr
imports.Proc(def.CEFBrowser_GetMainFrame).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
2023-03-01 14:18:39 +08:00
m.mainFrame = &ICefFrame{instance: unsafe.Pointer(result)}
}
return m.mainFrame
2022-10-04 13:21:05 +08:00
}
2023-02-26 19:14:49 +08:00
// GetFocusedFrame 获取当前窗口有焦点的Frame
func (m *ICefBrowser) GetFocusedFrame() *ICefFrame {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
2023-02-26 19:14:49 +08:00
return nil
2022-10-04 13:21:05 +08:00
}
2023-02-26 19:14:49 +08:00
var result uintptr
imports.Proc(def.CEFBrowser_GetFocusedFrame).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
2023-05-31 17:41:14 +08:00
if result != 0 {
return &ICefFrame{instance: unsafe.Pointer(result)}
}
return nil
2022-10-04 13:21:05 +08:00
}
// GetFrameById 根据FrameId获取Frame对象
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) GetFrameById(frameId int64) *ICefFrame {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
2023-02-26 19:14:49 +08:00
return nil
2022-10-04 13:21:05 +08:00
}
2023-05-31 17:41:14 +08:00
if m.idFrames == nil {
m.idFrames = make(map[int64]*ICefFrame)
}
if frame, ok := m.idFrames[frameId]; ok {
if frame.instance != nil && frame.IsValid() {
return frame
}
delete(m.idFrames, frameId)
}
2023-02-26 19:14:49 +08:00
var result uintptr
imports.Proc(def.CEFBrowser_GetFrameById).Call(m.Instance(), uintptr(unsafe.Pointer(&frameId)), uintptr(unsafe.Pointer(&result)))
2023-05-31 17:41:14 +08:00
if result != 0 {
frame := &ICefFrame{instance: unsafe.Pointer(result)}
m.idFrames[frameId] = frame
return frame
}
return nil
2022-10-04 13:21:05 +08:00
}
// GetFrameByName 根据FrameName获取Frame对象
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) GetFrameByName(frameName string) *ICefFrame {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
2023-02-26 19:14:49 +08:00
return nil
2022-10-04 13:21:05 +08:00
}
2023-05-31 17:41:14 +08:00
if m.nameFrames == nil {
m.nameFrames = make(map[string]*ICefFrame)
}
if frame, ok := m.nameFrames[frameName]; ok {
if frame.instance != nil && frame.IsValid() {
return frame
}
delete(m.nameFrames, frameName)
}
2023-02-26 19:14:49 +08:00
var result uintptr
imports.Proc(def.CEFBrowser_GetFrameByName).Call(m.Instance(), api.PascalStr(frameName), uintptr(unsafe.Pointer(&result)))
2023-05-31 17:41:14 +08:00
if result != 0 {
frame := &ICefFrame{instance: unsafe.Pointer(result)}
m.nameFrames[frameName] = frame
return frame
}
return nil
2022-10-04 13:21:05 +08:00
}
2023-03-01 20:25:21 +08:00
// PrintToPdf
2023-03-01 23:02:14 +08:00
func (m *ICefBrowser) PrintToPdf(path string, settings *CefPdfPrintSettings, callback *ICefPdfPrintCallback) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
2023-03-01 23:02:14 +08:00
var settingsPtr uintptr = 0
var setPtr *cefPdfPrintSettingsPtr
if callback == nil {
callback = PdfPrintCallbackRef.New()
}
if settings == nil {
settings = &CefPdfPrintSettings{}
}
setPtr = settings.ToPtr()
settingsPtr = uintptr(unsafe.Pointer(setPtr))
imports.Proc(def.CEFBrowser_PrintToPdf).Call(m.Instance(), api.PascalStr(path), settingsPtr, callback.Instance())
2023-03-01 20:25:21 +08:00
}
2022-10-04 13:21:05 +08:00
2023-05-31 17:41:14 +08:00
// SendDevToolsMessage 发送开发者工具消息
func (m *ICefBrowser) SendDevToolsMessage(message string) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendDevToolsMessage).Call(m.Instance(), api.PascalStr(message))
2023-05-31 17:41:14 +08:00
}
// ExecuteDevToolsMethod 执行开发者工具方法
2023-02-26 19:14:49 +08:00
func (m *ICefBrowser) ExecuteDevToolsMethod(messageId int32, method string, dictionaryValue *ICefDictionaryValue) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() || dictionaryValue == nil {
2023-02-26 19:14:49 +08:00
return
2022-10-04 13:21:05 +08:00
}
imports.Proc(def.CEFBrowser_ExecuteDevToolsMethod).Call(m.Instance(), uintptr(messageId), api.PascalStr(method), dictionaryValue.Instance())
2022-10-04 13:21:05 +08:00
}
// SendKeyEvent 发送模拟键盘事件
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SendKeyEvent(event *TCefKeyEvent) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendKeyEvent).Call(m.Instance(), uintptr(unsafe.Pointer(event)))
2022-10-04 13:21:05 +08:00
}
// SetAudioMuted
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SetAudioMuted(mute bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SetAudioMuted).Call(m.Instance(), api.PascalBool(mute))
2022-10-04 13:21:05 +08:00
}
// IsAudioMuted
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) IsAudioMuted() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_IsAudioMuted).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
// SetAutoResizeEnabled 设置启用自动调整大小
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SetAutoResizeEnabled(enabled bool, minSize, maxSize *TCefSize) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SetAutoResizeEnabled).Call(m.Instance(), api.PascalBool(enabled), uintptr(unsafe.Pointer(minSize)), uintptr(unsafe.Pointer(maxSize)))
2022-10-04 13:21:05 +08:00
}
// SetAccessibilityState 设置可访问性状态
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SetAccessibilityState(accessibilityState TCefState) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SetAccessibilityState).Call(m.Instance(), uintptr(accessibilityState))
2022-10-04 13:21:05 +08:00
}
// NotifyMoveOrResizeStarted 通用移动或大小开始
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) NotifyMoveOrResizeStarted() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_NotifyMoveOrResizeStarted).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
// NotifyScreenInfoChanged 通知屏幕改变
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) NotifyScreenInfoChanged() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_NotifyScreenInfoChanged).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
// SendCaptureLostEvent 发送失去标题事件
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SendCaptureLostEvent() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendCaptureLostEvent).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
// SendTouchEvent 发送触摸事件
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SendTouchEvent(event *TCefTouchEvent) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendTouchEvent).Call(m.Instance(), uintptr(unsafe.Pointer(event)))
2022-10-04 13:21:05 +08:00
}
// SendMouseWheelEvent 发送鼠标滚轮事件
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SendMouseWheelEvent(event *TCefMouseEvent, deltaX, deltaY int32) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendMouseWheelEvent).Call(m.Instance(), uintptr(unsafe.Pointer(event)), uintptr(deltaX), uintptr(deltaY))
2022-10-04 13:21:05 +08:00
}
// SendMouseMoveEvent 发送鼠标移动事件
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SendMouseMoveEvent(event *TCefMouseEvent, mouseLeave bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendMouseMoveEvent).Call(m.Instance(), uintptr(unsafe.Pointer(event)), api.PascalBool(mouseLeave))
2022-10-04 13:21:05 +08:00
}
// SendMouseClickEvent 发送鼠标点击事件
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) SendMouseClickEvent(event *TCefMouseEvent, type_ TCefMouseButtonType, mouseUp bool, clickCount int32) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_SendMouseClickEvent).Call(m.Instance(), uintptr(unsafe.Pointer(event)), uintptr(type_), api.PascalBool(mouseUp), uintptr(clickCount))
2022-10-04 13:21:05 +08:00
}
// ViewSource 显示网页源码
2023-02-26 19:14:49 +08:00
func (m *ICefBrowser) ViewSource() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
2023-02-26 19:14:49 +08:00
m.createBrowserViewSource()
2022-10-04 13:21:05 +08:00
}
// ShowDevTools 显示开发者工具
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) ShowDevTools() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
2022-10-04 13:21:05 +08:00
if browserWinInfo := BrowserWindow.GetWindowInfo(m.Identifier()); browserWinInfo != nil {
m.createBrowserDevTools(browserWinInfo)
2022-10-04 13:21:05 +08:00
}
}
// CloseDevTools 关闭开发者工具
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) CloseDevTools() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_CloseDevTools).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-05-31 17:41:14 +08:00
// HasDevTools
func (m *ICefBrowser) HasView() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_HasView).Call(m.Instance())
2023-05-31 17:41:14 +08:00
return api.GoBool(r1)
}
// HasDevTools
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) HasDevTools() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_HasDevTools).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
// CanGoBack 是否允许后退
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) CanGoBack() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_CanGoBack).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
// GoBack 历史-后退
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) GoBack() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
2022-10-04 13:21:05 +08:00
if m.CanGoBack() {
imports.Proc(def.CEFBrowser_GoBack).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
}
// CanGoForward 是否允许前进
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) CanGoForward() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_CanGoForward).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
// GoForward 历史-前进
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) GoForward() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
2022-10-04 13:21:05 +08:00
if m.CanGoForward() {
imports.Proc(def.CEFBrowser_GoForward).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
}
// IsLoading 是否正在加载
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) IsLoading() bool {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFBrowser_IsLoading).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
// Reload 重新加载
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) Reload() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_Reload).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
// ReloadIgnoreCache 重新加载忽略缓存
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) ReloadIgnoreCache() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_ReloadIgnoreCache).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
// StopLoad 停止加载
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) StopLoad() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_StopLoad).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
// FrameCount 获取当前窗口Frame数量
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) FrameCount() int {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CEFBrowser_FrameCount).Call(m.Instance())
2022-10-04 13:21:05 +08:00
return int(r1)
}
// GetFrameNames 获取当前窗口所有Frame名称
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) GetFrameNames() []*FrameNames {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return nil
}
2022-10-04 13:21:05 +08:00
var result uintptr
var resultSize int32
imports.Proc(def.CEFBrowser_GetFrameNames).Call(m.Instance(), uintptr(unsafe.Pointer(&result)), uintptr(unsafe.Pointer(&resultSize)))
2022-10-04 13:21:05 +08:00
frameNames := make([]*FrameNames, resultSize, resultSize)
for i := 0; i < int(resultSize); i++ {
fnsPtr := (*frameNamesPtr)(unsafe.Pointer(common.GetParamOf(i, result)))
2022-10-04 13:21:05 +08:00
frameNames[i] = &FrameNames{
2022-12-03 21:56:51 +08:00
Name: api.GoStr(fnsPtr.Name),
Value: api.GoStr(fnsPtr.Value),
2022-10-04 13:21:05 +08:00
}
}
result = 0
resultSize = 0
return frameNames
}
2023-05-31 17:41:14 +08:00
// Target
// IPC消息接收目标, 当前窗口
// 参数: targetType 可选, 接收类型
func (m *ICefBrowser) Target(targetType ...target.Type) target.ITarget {
if !m.IsValid() {
return nil
}
return target.NewTarget(m.Identifier(), m.MainFrame().Identifier(), targetType...)
}
// Find 检索页面文本
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) Find(searchText string, forward, matchCase, findNext bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_Find).Call(m.Instance(), api.PascalStr(searchText), api.PascalBool(forward), api.PascalBool(matchCase), api.PascalBool(findNext))
2022-10-04 13:21:05 +08:00
}
// StopFinding 停止加载
2022-10-04 13:21:05 +08:00
func (m *ICefBrowser) StopFinding(clearSelection bool) {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
imports.Proc(def.CEFBrowser_StopFinding).Call(m.Instance(), api.PascalBool(clearSelection))
2022-12-05 10:44:24 +08:00
}
2023-03-04 11:19:45 +08:00
2023-05-31 17:41:14 +08:00
// GetRequestContext -> ICefBrowserHost -> ICefRequestContext
func (m *ICefBrowser) GetRequestContext() *ICefRequestContext {
if !m.IsValid() {
return nil
}
if m.requestContext != nil && m.requestContext.IsValid() {
return m.requestContext
}
var result uintptr
imports.Proc(def.CEFBrowser_GetRequestContext).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
2023-05-31 17:41:14 +08:00
if result != 0 {
m.requestContext = &ICefRequestContext{instance: unsafe.Pointer(result)}
return m.requestContext
}
return nil
}
2023-03-09 19:27:00 +08:00
func (m *ICefBrowser) Free() {
2023-05-31 17:41:14 +08:00
if !m.IsValid() {
return
}
if m.idFrames != nil {
for _, frame := range m.idFrames {
frame.Free()
}
m.idFrames = nil
}
if m.nameFrames != nil {
for _, frame := range m.nameFrames {
frame.Free()
}
m.nameFrames = nil
}
if m.requestContext != nil {
m.requestContext.Free()
m.requestContext = nil
}
2023-03-12 15:29:46 +08:00
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
2023-03-09 19:27:00 +08:00
}
2023-03-04 11:19:45 +08:00
// BrowserRef -> ICefBrowser
var BrowserRef browser
// browser
type browser uintptr
func (*browser) UnWrap(data *ICefBrowser) *ICefBrowser {
var result uintptr
imports.Proc(def.CEFBrowserRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
2023-03-04 11:58:35 +08:00
data.instance = unsafe.Pointer(result)
return data
2023-03-04 11:19:45 +08:00
}