energy/cef/chromium-config.go

106 lines
2.9 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
//
//----------------------------------------
2023-05-31 17:41:14 +08:00
// Chromium 配置
2022-10-04 13:21:05 +08:00
package cef
import "github.com/energye/golcl/lcl/api"
// tCefChromiumConfig Chromium的基础配置
2022-10-04 13:21:05 +08:00
type tCefChromiumConfig struct {
enableMenu uintptr //bool 启用右键菜单
enableViewSource uintptr //bool 启用查看源代码
enableDevTools uintptr //bool 启用开发者工具
enableWindowPopup uintptr //bool 启用弹出新窗口
enableOpenUrlTab uintptr //bool 启用tab签打开新窗口(需自定义实现)
enabledJavascript uintptr //bool 启用Javascript
}
2023-02-20 00:20:01 +08:00
// NewChromiumConfig 创建默认禁用相关功能
2022-10-04 13:21:05 +08:00
func NewChromiumConfig() *tCefChromiumConfig {
return &tCefChromiumConfig{
enableMenu: api.PascalBool(true),
enableViewSource: api.PascalBool(true),
enableDevTools: api.PascalBool(true),
enableWindowPopup: api.PascalBool(true),
2022-12-03 21:56:51 +08:00
enableOpenUrlTab: api.PascalBool(false),
enabledJavascript: api.PascalBool(false),
2022-10-04 13:21:05 +08:00
}
}
2023-02-20 00:20:01 +08:00
// SetEnableMenu 设置启用右键菜单
2022-10-04 13:21:05 +08:00
func (m *tCefChromiumConfig) SetEnableMenu(value bool) *tCefChromiumConfig {
2022-12-03 21:56:51 +08:00
m.enableMenu = api.PascalBool(value)
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
func (m *tCefChromiumConfig) EnableMenu() bool {
return api.GoBool(m.enableMenu)
}
// SetEnableViewSource 设置启用查看源文件
2022-10-04 13:21:05 +08:00
func (m *tCefChromiumConfig) SetEnableViewSource(value bool) *tCefChromiumConfig {
2022-12-03 21:56:51 +08:00
m.enableViewSource = api.PascalBool(value)
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
func (m *tCefChromiumConfig) EnableViewSource() bool {
return api.GoBool(m.enableViewSource)
}
2023-02-20 00:20:01 +08:00
// SetEnableDevTools 设置启用开发者工具
2022-10-04 13:21:05 +08:00
func (m *tCefChromiumConfig) SetEnableDevTools(value bool) *tCefChromiumConfig {
2022-12-03 21:56:51 +08:00
m.enableDevTools = api.PascalBool(value)
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
func (m *tCefChromiumConfig) EnableDevTools() bool {
return api.GoBool(m.enableDevTools)
}
// SetEnableWindowPopup 设置启用弹出新窗口
// 与tab互斥
2022-10-04 13:21:05 +08:00
func (m *tCefChromiumConfig) SetEnableWindowPopup(value bool) *tCefChromiumConfig {
2022-12-03 21:56:51 +08:00
m.enableWindowPopup = api.PascalBool(value)
2023-05-31 17:41:14 +08:00
if value {
m.SetEnableOpenUrlTab(false)
}
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
func (m *tCefChromiumConfig) EnableWindowPopup() bool {
return api.GoBool(m.enableWindowPopup)
}
// SetEnableOpenUrlTab 设置启用打开新tab
// 与popup互斥
2022-10-04 13:21:05 +08:00
func (m *tCefChromiumConfig) SetEnableOpenUrlTab(value bool) *tCefChromiumConfig {
2022-12-03 21:56:51 +08:00
m.enableOpenUrlTab = api.PascalBool(value)
2023-05-31 17:41:14 +08:00
if value {
m.SetEnableWindowPopup(false)
}
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
func (m *tCefChromiumConfig) EnableOpenUrlTab() bool {
return api.GoBool(m.enableOpenUrlTab)
}
2023-02-20 00:20:01 +08:00
// SetEnabledJavascript 设置启用Javascript
2022-10-04 13:21:05 +08:00
func (m *tCefChromiumConfig) SetEnabledJavascript(value bool) *tCefChromiumConfig {
2022-12-03 21:56:51 +08:00
m.enabledJavascript = api.PascalBool(value)
2022-10-04 13:21:05 +08:00
return m
}
2023-05-31 17:41:14 +08:00
func (m *tCefChromiumConfig) EnabledJavascript() bool {
return api.GoBool(m.enabledJavascript)
}