2022-10-04 13:21:05 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2022-10-04 16:38:43 +08:00
|
|
|
// Licensed under GNU General Public License v3.0
|
2022-10-04 13:21:05 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-10-04 22:34:57 +08:00
|
|
|
. "github.com/energye/energy/consts"
|
2022-12-14 11:11:33 +08:00
|
|
|
. "github.com/energye/energy/types"
|
2022-10-04 13:21:05 +08:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2022-12-13 22:43:31 +08:00
|
|
|
type TCefCloseBrowsesAction = CBS
|
2022-10-04 13:21:05 +08:00
|
|
|
|
|
|
|
type ICefCookie struct {
|
|
|
|
Url, Name, Value, Domain, Path string
|
|
|
|
Secure, Httponly, HasExpires bool
|
|
|
|
Creation, LastAccess, Expires time.Time
|
|
|
|
Count, Total, ID int32
|
|
|
|
SameSite TCefCookieSameSite
|
|
|
|
Priority TCefCookiePriority
|
|
|
|
SetImmediately bool
|
|
|
|
DeleteCookie bool
|
|
|
|
Result bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type TCefKeyEvent struct {
|
|
|
|
Kind TCefKeyEventType // called 'type' in the original CEF source code
|
|
|
|
Modifiers TCefEventFlags
|
2022-12-14 11:11:33 +08:00
|
|
|
WindowsKeyCode Int32
|
|
|
|
NativeKeyCode Int32
|
|
|
|
IsSystemKey Int32
|
|
|
|
Character UInt16
|
|
|
|
UnmodifiedCharacter UInt16
|
|
|
|
FocusOnEditableField Int32
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 22:43:31 +08:00
|
|
|
type TCefRequestContextSettings struct {
|
2022-12-14 11:11:33 +08:00
|
|
|
Size UInt32
|
2022-12-13 22:43:31 +08:00
|
|
|
CachePath TCefString
|
2022-12-14 11:11:33 +08:00
|
|
|
PersistSessionCookies Int32
|
|
|
|
PersistUserPreferences Int32
|
2022-12-13 22:43:31 +08:00
|
|
|
AcceptLanguageList TCefString
|
|
|
|
CookieableSchemesList TCefString
|
2022-12-14 11:11:33 +08:00
|
|
|
CookieableSchemesExcludeDefaults Int32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefRequestContextSettings) ToPtr() *tCefRequestContextSettingsPtr {
|
|
|
|
return &tCefRequestContextSettingsPtr{
|
|
|
|
Size: m.Size.ToPtr(),
|
|
|
|
CachePath: m.CachePath.ToPtr(),
|
|
|
|
PersistSessionCookies: m.PersistSessionCookies.ToPtr(),
|
|
|
|
PersistUserPreferences: m.PersistUserPreferences.ToPtr(),
|
|
|
|
AcceptLanguageList: m.AcceptLanguageList.ToPtr(),
|
|
|
|
CookieableSchemesList: m.CookieableSchemesList.ToPtr(),
|
|
|
|
CookieableSchemesExcludeDefaults: m.CookieableSchemesExcludeDefaults.ToPtr(),
|
|
|
|
}
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type TCefBrowserSettings struct {
|
|
|
|
Size NativeUInt
|
|
|
|
WindowlessFrameRate Integer
|
|
|
|
StandardFontFamily TCefString
|
|
|
|
FixedFontFamily TCefString
|
|
|
|
SerifFontFamily TCefString
|
|
|
|
SansSerifFontFamily TCefString
|
|
|
|
CursiveFontFamily TCefString
|
|
|
|
FantasyFontFamily TCefString
|
|
|
|
DefaultFontSize Integer
|
|
|
|
DefaultFixedFontSize Integer
|
|
|
|
MinimumFontSize Integer
|
|
|
|
MinimumLogicalFontSize Integer
|
|
|
|
DefaultEncoding TCefString
|
|
|
|
RemoteFonts TCefState
|
|
|
|
Javascript TCefState
|
|
|
|
JavascriptCloseWindows TCefState
|
|
|
|
JavascriptAccessClipboard TCefState
|
|
|
|
JavascriptDomPaste TCefState
|
|
|
|
ImageLoading TCefState
|
|
|
|
ImageShrinkStandaLonetoFit TCefState
|
|
|
|
TextAreaResize TCefState
|
|
|
|
TabToLinks TCefState
|
|
|
|
LocalStorage TCefState
|
|
|
|
Databases TCefState
|
|
|
|
Webgl TCefState
|
|
|
|
BackgroundColor TCefColor
|
|
|
|
AcceptLanguageList TCefString
|
|
|
|
ChromeStatusBubble TCefState
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
2022-12-13 22:43:31 +08:00
|
|
|
func (m *TCefBrowserSettings) ToPtr() *TCefBrowserSettingsPtr {
|
|
|
|
return &TCefBrowserSettingsPtr{
|
|
|
|
Size: m.Size.ToPtr(),
|
|
|
|
WindowlessFrameRate: m.WindowlessFrameRate.ToPtr(),
|
|
|
|
StandardFontFamily: m.StandardFontFamily.ToPtr(),
|
|
|
|
FixedFontFamily: m.FixedFontFamily.ToPtr(),
|
|
|
|
SerifFontFamily: m.SerifFontFamily.ToPtr(),
|
|
|
|
SansSerifFontFamily: m.SansSerifFontFamily.ToPtr(),
|
|
|
|
CursiveFontFamily: m.CursiveFontFamily.ToPtr(),
|
|
|
|
FantasyFontFamily: m.FantasyFontFamily.ToPtr(),
|
|
|
|
DefaultFontSize: m.DefaultFontSize.ToPtr(),
|
|
|
|
DefaultFixedFontSize: m.DefaultFixedFontSize.ToPtr(),
|
|
|
|
MinimumFontSize: m.MinimumFontSize.ToPtr(),
|
|
|
|
MinimumLogicalFontSize: m.MinimumLogicalFontSize.ToPtr(),
|
|
|
|
DefaultEncoding: m.DefaultEncoding.ToPtr(),
|
|
|
|
RemoteFonts: m.RemoteFonts.ToPtr(),
|
|
|
|
Javascript: m.Javascript.ToPtr(),
|
|
|
|
JavascriptCloseWindows: m.JavascriptCloseWindows.ToPtr(),
|
|
|
|
JavascriptAccessClipboard: m.JavascriptAccessClipboard.ToPtr(),
|
|
|
|
JavascriptDomPaste: m.JavascriptDomPaste.ToPtr(),
|
|
|
|
ImageLoading: m.ImageLoading.ToPtr(),
|
|
|
|
ImageShrinkStandaLonetoFit: m.ImageShrinkStandaLonetoFit.ToPtr(),
|
|
|
|
TextAreaResize: m.TextAreaResize.ToPtr(),
|
|
|
|
TabToLinks: m.TabToLinks.ToPtr(),
|
|
|
|
LocalStorage: m.LocalStorage.ToPtr(),
|
|
|
|
Databases: m.Databases.ToPtr(),
|
|
|
|
Webgl: m.Webgl.ToPtr(),
|
|
|
|
BackgroundColor: m.BackgroundColor.ToPtr(),
|
|
|
|
AcceptLanguageList: m.AcceptLanguageList.ToPtr(),
|
|
|
|
ChromeStatusBubble: m.ChromeStatusBubble.ToPtr(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type TCefCommandLine struct {
|
|
|
|
commandLines map[string]string
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type TCefProxy struct {
|
|
|
|
ProxyType TCefProxyType
|
|
|
|
ProxyScheme TCefProxyScheme
|
|
|
|
ProxyServer string
|
|
|
|
ProxyPort int32
|
|
|
|
ProxyUsername string
|
|
|
|
ProxyPassword string
|
|
|
|
ProxyScriptURL string
|
|
|
|
ProxyByPassList string
|
|
|
|
MaxConnectionsPerProxy int32
|
|
|
|
CustomHeaderName string
|
|
|
|
CustomHeaderValue string
|
|
|
|
}
|
|
|
|
|
|
|
|
type TCefTouchEvent struct {
|
|
|
|
Id int32
|
|
|
|
X float32
|
|
|
|
Y float32
|
|
|
|
RadiusX float32
|
|
|
|
RadiusY float32
|
|
|
|
RotationAngle float32
|
|
|
|
Pressure float32
|
|
|
|
Type TCefTouchEeventType
|
|
|
|
Modifiers TCefEventFlags
|
|
|
|
PointerType TCefPointerType
|
|
|
|
}
|
|
|
|
|
|
|
|
type TCefMouseEvent struct {
|
|
|
|
X int32
|
|
|
|
Y int32
|
|
|
|
Modifiers TCefEventFlags
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
type TCefSize struct {
|
|
|
|
Width int32
|
|
|
|
Height int32
|
|
|
|
}
|
|
|
|
|
2022-10-04 13:21:05 +08:00
|
|
|
type BeforePopupInfo struct {
|
|
|
|
TargetUrl string
|
|
|
|
TargetFrameName string
|
|
|
|
TargetDisposition TCefWindowOpenDisposition
|
|
|
|
UserGesture bool
|
|
|
|
}
|
|
|
|
|
|
|
|
type TCefRect struct {
|
|
|
|
X int32
|
|
|
|
Y int32
|
|
|
|
Width int32
|
|
|
|
Height int32
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
type TCefPoint struct {
|
|
|
|
X int32
|
|
|
|
Y int32
|
|
|
|
}
|
|
|
|
|
2022-12-12 18:09:31 +08:00
|
|
|
type TCefDraggableRegion struct {
|
|
|
|
Bounds TCefRect
|
|
|
|
Draggable int32
|
|
|
|
}
|
|
|
|
|
2022-12-13 09:14:59 +08:00
|
|
|
type ICefDisplay struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2022-12-13 11:49:32 +08:00
|
|
|
type ICefWindow struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2022-10-04 13:21:05 +08:00
|
|
|
type ICefClient struct {
|
2022-12-12 17:34:57 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *ICefWindow) SetWindow(window *ICefWindow) {
|
|
|
|
m.instance = window.instance
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *ICefClient) SetClient(client *ICefClient) {
|
|
|
|
m.instance = client.instance
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefCommandLine) AppendSwitch(name, value string) {
|
|
|
|
m.commandLines[name] = value
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefCommandLine) AppendArgument(argument string) {
|
|
|
|
m.commandLines[argument] = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefCommandLine) toString() string {
|
|
|
|
var str bytes.Buffer
|
|
|
|
var i = 0
|
|
|
|
var replace = func(s, old, new string) string {
|
|
|
|
return strings.ReplaceAll(s, old, new)
|
|
|
|
}
|
|
|
|
for name, value := range m.commandLines {
|
|
|
|
if i > 0 {
|
|
|
|
str.WriteString(" ")
|
|
|
|
}
|
|
|
|
if value != "" {
|
|
|
|
str.WriteString(replace(replace(name, " ", ""), "=", ""))
|
|
|
|
str.WriteString("=")
|
|
|
|
str.WriteString(replace(replace(value, " ", ""), "=", ""))
|
|
|
|
} else {
|
|
|
|
str.WriteString(replace(name, " ", ""))
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return str.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefKeyEvent) KeyDown() bool {
|
|
|
|
return m.Kind == KEYEVENT_RAW_KEYDOWN || m.Kind == KEYEVENT_KEYDOWN
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefKeyEvent) KeyUp() bool {
|
|
|
|
return m.Kind == KEYEVENT_KEYUP
|
|
|
|
}
|