Skip to content

Commit d34ef18

Browse files
committed
A: CEF 130 > ChromiumCore API, SimulateKeyEvent, SimulateMouseEvent, SimulateTouchEvent, SimulateEditingCommand, ClearCertificateExceptions, ClearHttpAuthCredentials, GetNavigationEntries, SavePreferences, ExecuteTaskOnCefThread
1 parent 23a8caa commit d34ef18

File tree

7 files changed

+444
-22
lines changed

7 files changed

+444
-22
lines changed

cef/chromium_proc.go

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ type IChromiumProc interface {
213213
AsTargetWindow() target.IWindow
214214
IsClosing() bool
215215
setClosing(v bool)
216+
SimulateKeyEvent(keyEvent TSimulateKeyEvent, timestamp float32, text, unmodifiedtext, keyIdentifier, code, key string)
217+
SimulateMouseEvent(mouseEvent TSimulateMouseEvent, x, y, timestamp, force, tangentialPressure, tiltX, tiltY, deltaX, deltaY float32)
218+
SimulateTouchEvent(type_ TCefSimulatedTouchEventType, touchPoints []*TCefSimulatedTouchPoint, modifiers int32, timestamp float32)
219+
SimulateEditingCommand(command TCefEditingCommand)
220+
ClearCertificateExceptions(clearImmediately bool) bool
221+
ClearHttpAuthCredentials(clearImmediately bool) bool
222+
GetNavigationEntries(currentOnly bool)
223+
SavePreferences(fileName string)
224+
ExecuteTaskOnCefThread(cefThreadId TCefThreadId, taskID uint32, delayMs int64) bool
216225
}
217226

218227
// IsValid 实例有效
@@ -1388,7 +1397,7 @@ func (m *TCEFChromium) ClearDataForOrigin(origin string, storageTypes ...TCefCle
13881397
if len(storageTypes) > 0 {
13891398
st = storageTypes[0]
13901399
}
1391-
imports.Proc(def.CEFChromium_ClearDataForOrigin).Call(m.Instance(), api.PascalStr(origin), st.ToPtr())
1400+
imports.Proc(def.CEFChromium_ClearDataForOrigin).Call(m.Instance(), api.PascalStr(origin), uintptr(st))
13921401
}
13931402

13941403
func (m *TCEFChromium) ClearCache() {
@@ -1799,3 +1808,78 @@ func (m *TCEFChromium) IsClosing() bool {
17991808
func (m *TCEFChromium) setClosing(v bool) {
18001809
m.isClosing = v
18011810
}
1811+
1812+
func (m *TCEFChromium) SimulateKeyEvent(keyEvent TSimulateKeyEvent, timestamp float32, text, unmodifiedtext, keyIdentifier, code, key string) {
1813+
if !m.IsValid() {
1814+
return
1815+
}
1816+
imports.Proc(def.CEFChromium_SimulateKeyEvent).Call(m.Instance(), uintptr(unsafePointer(&keyEvent)), uintptr(unsafePointer(&timestamp)), api.PascalStr(text),
1817+
api.PascalStr(unmodifiedtext), api.PascalStr(keyIdentifier), api.PascalStr(code), api.PascalStr(key))
1818+
}
1819+
1820+
func (m *TCEFChromium) SimulateMouseEvent(mouseEvent TSimulateMouseEvent, x, y, timestamp, force, tangentialPressure, tiltX, tiltY, deltaX, deltaY float32) {
1821+
if !m.IsValid() {
1822+
return
1823+
}
1824+
imports.Proc(def.CEFChromium_SimulateMouseEvent).Call(m.Instance(), uintptr(unsafePointer(&mouseEvent)), uintptr(unsafePointer(&x)),
1825+
uintptr(unsafePointer(&y)), uintptr(unsafePointer(&timestamp)), uintptr(unsafePointer(&force)), uintptr(unsafePointer(&tangentialPressure)),
1826+
uintptr(unsafePointer(&tiltX)), uintptr(unsafePointer(&tiltY)), uintptr(unsafePointer(&deltaX)), uintptr(unsafePointer(&deltaY)))
1827+
}
1828+
1829+
func (m *TCEFChromium) SimulateTouchEvent(type_ TCefSimulatedTouchEventType, touchPoints []*TCefSimulatedTouchPoint, modifiers int32, timestamp float32) {
1830+
if !m.IsValid() {
1831+
return
1832+
}
1833+
var size = len(touchPoints)
1834+
touchPointsPtr := make([]tCefSimulatedTouchPointPtr, size, size)
1835+
for i := 0; i < size; i++ {
1836+
tp := touchPoints[i]
1837+
touchPointsPtr[i] = *tp.ToPtr()
1838+
}
1839+
imports.Proc(def.CEFChromium_SimulateTouchEvent).Call(m.Instance(), uintptr(type_), uintptr(unsafePointer(&touchPointsPtr[0])), uintptr(int32(size)), uintptr(modifiers), uintptr(unsafePointer(&timestamp)))
1840+
}
1841+
1842+
func (m *TCEFChromium) SimulateEditingCommand(command TCefEditingCommand) {
1843+
if !m.IsValid() {
1844+
return
1845+
}
1846+
imports.Proc(def.CEFChromium_SimulateEditingCommand).Call(m.Instance(), uintptr(command))
1847+
}
1848+
1849+
func (m *TCEFChromium) ClearCertificateExceptions(clearImmediately bool) bool {
1850+
if !m.IsValid() {
1851+
return false
1852+
}
1853+
r1, _, _ := imports.Proc(def.CEFChromium_ClearCertificateExceptions).Call(m.Instance(), api.PascalBool(clearImmediately))
1854+
return api.GoBool(r1)
1855+
}
1856+
1857+
func (m *TCEFChromium) ClearHttpAuthCredentials(clearImmediately bool) bool {
1858+
if !m.IsValid() {
1859+
return false
1860+
}
1861+
r1, _, _ := imports.Proc(def.CEFChromium_ClearHttpAuthCredentials).Call(m.Instance(), api.PascalBool(clearImmediately))
1862+
return api.GoBool(r1)
1863+
}
1864+
1865+
func (m *TCEFChromium) GetNavigationEntries(currentOnly bool) {
1866+
if !m.IsValid() {
1867+
return
1868+
}
1869+
imports.Proc(def.CEFChromium_GetNavigationEntries).Call(m.Instance(), api.PascalBool(currentOnly))
1870+
}
1871+
1872+
func (m *TCEFChromium) SavePreferences(fileName string) {
1873+
if !m.IsValid() {
1874+
return
1875+
}
1876+
imports.Proc(def.CEFChromium_SavePreferences).Call(m.Instance(), api.PascalStr(fileName))
1877+
}
1878+
1879+
func (m *TCEFChromium) ExecuteTaskOnCefThread(cefThreadId TCefThreadId, taskID uint32, delayMs int64) bool {
1880+
if !m.IsValid() {
1881+
return false
1882+
}
1883+
r1, _, _ := imports.Proc(def.CEFChromium_ExecuteTaskOnCefThread).Call(m.Instance(), uintptr(cefThreadId), uintptr(taskID), uintptr(unsafePointer(&delayMs)))
1884+
return api.GoBool(r1)
1885+
}

cef/internal/def/proc_def.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,15 @@ func init() {
10101010
dllimports.NewEnergyImport("CEFChromium_GetContentSetting", 0),
10111011
dllimports.NewEnergyImport("CEFChromium_SetContentSetting", 0),
10121012
dllimports.NewEnergyImport("CEFChromium_WindowHandle", 0),
1013+
dllimports.NewEnergyImport("CEFChromium_SimulateKeyEvent", 0),
1014+
dllimports.NewEnergyImport("CEFChromium_SimulateMouseEvent", 0),
1015+
dllimports.NewEnergyImport("CEFChromium_SimulateTouchEvent", 0),
1016+
dllimports.NewEnergyImport("CEFChromium_SimulateEditingCommand", 0),
1017+
dllimports.NewEnergyImport("CEFChromium_ClearCertificateExceptions", 0),
1018+
dllimports.NewEnergyImport("CEFChromium_ClearHttpAuthCredentials", 0),
1019+
dllimports.NewEnergyImport("CEFChromium_GetNavigationEntries", 0),
1020+
dllimports.NewEnergyImport("CEFChromium_SavePreferences", 0),
1021+
dllimports.NewEnergyImport("CEFChromium_ExecuteTaskOnCefThread", 0),
10131022
// TChromiumOptions
10141023
dllimports.NewEnergyImport("ChromiumOptions_SetJavascript", 0),
10151024
dllimports.NewEnergyImport("ChromiumOptions_SetJavascriptCloseWindows", 0),

cef/internal/def/proc_def_index.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,15 @@ const (
10101010
CEFChromium_GetContentSetting
10111011
CEFChromium_SetContentSetting
10121012
CEFChromium_WindowHandle
1013+
CEFChromium_SimulateKeyEvent
1014+
CEFChromium_SimulateMouseEvent
1015+
CEFChromium_SimulateTouchEvent
1016+
CEFChromium_SimulateEditingCommand
1017+
CEFChromium_ClearCertificateExceptions
1018+
CEFChromium_ClearHttpAuthCredentials
1019+
CEFChromium_GetNavigationEntries
1020+
CEFChromium_SavePreferences
1021+
CEFChromium_ExecuteTaskOnCefThread
10131022
// TChromiumOptions
10141023
ChromiumOptions_SetJavascript
10151024
ChromiumOptions_SetJavascriptCloseWindows

cef/types_cef.go

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ type TCefInsets struct {
268268
// <para><see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/internal/cef_types.h">CEF source file: /include/internal/cef_types.h (cef_pdf_print_settings_t)</see></para>
269269
type TCefPdfPrintSettings struct {
270270
// Set to true (1) for landscape mode or false (0) for portrait mode.
271-
Landscape int32 // Integer
271+
Landscape int32 // int32
272272
// Set to true (1) to print background graphics.
273-
PrintBackground int32 // Integer
273+
PrintBackground int32 // int32
274274
// The percentage to scale the PDF by before printing (e.g. .5 is 50%).
275275
// If this value is less than or equal to zero the default value of 1.0
276276
// will be used.
@@ -282,7 +282,7 @@ type TCefPdfPrintSettings struct {
282282
PaperHeight float64 // double
283283
// Set to true (1) to prefer page size as defined by css. Defaults to false
284284
// (0), in which case the content will be scaled to fit the paper size.
285-
PreferCssPageSize int32 // Integer
285+
PreferCssPageSize int32 // int32
286286
// Margin type.
287287
MarginType consts.TCefPdfPrintMarginType // TCefPdfPrintMarginType
288288
// Margins in inches. Only used if |margin_type| is set to
@@ -301,7 +301,7 @@ type TCefPdfPrintSettings struct {
301301
PageRanges string // TCefString
302302
// Set to true (1) to display the header and/or footer. Modify
303303
// |header_template| and/or |footer_template| to customize the display.
304-
DisplayHeaderFooter int32 // Integer
304+
DisplayHeaderFooter int32 // int32
305305
// HTML template for the print header. Only displayed if
306306
// |display_header_footer| is true (1). Should be valid HTML markup with
307307
// the following classes used to inject printing values into them:
@@ -319,9 +319,9 @@ type TCefPdfPrintSettings struct {
319319
// |header_template|.
320320
FooterTemplate string // TCefString
321321
// Set to true (1) to generate tagged (accessible) PDF.
322-
GenerateTaggedPdf int32 // Integer
322+
GenerateTaggedPdf int32 // int32
323323
// Set to true (1) to generate a document outline.
324-
GenerateDocumentOutline int32 // Integer
324+
GenerateDocumentOutline int32 // int32
325325
}
326326

327327
// include/internal/cef_types.h (cef_popup_features_t)
@@ -478,3 +478,52 @@ func (m *TCefKeyEvent) KeyDown() bool {
478478
func (m *TCefKeyEvent) KeyUp() bool {
479479
return m.Kind == consts.KEYEVENT_KEYUP
480480
}
481+
482+
// Structure representing a simulated touch point.
483+
// <para><see href="https://chromedevtools.github.io/devtools-protocol/tot/Input/#type-TouchPoint">See the Input.TouchPoint type in the DevTools docs.</see></para>
484+
type TCefSimulatedTouchPoint struct {
485+
// Identifier used to track touch sources between events, must be unique within an event. This is an optional value.
486+
Id int32
487+
// X coordinate of the event relative to the main frame's viewport in CSS pixels.
488+
X int32
489+
// Y coordinate of the event relative to the main frame's viewport in CSS pixels. 0 refers to the top of the viewport and Y increases as it proceeds towards the bottom of the viewport.
490+
Y int32
491+
// X radius of the touch area (default: 1.0). This is an optional value.
492+
RadiusX float32
493+
// Y radius of the touch area (default: 1.0). This is an optional value.
494+
RadiusY float32
495+
// Rotation angle (default: 0.0). This is an optional value.
496+
RotationAngle float32
497+
// Force (default: 1.0). This is an optional value.
498+
Force float32
499+
// The normalized tangential pressure, which has a range of [-1,1] (default: 0). This is an optional value.
500+
TangentialPressure float32
501+
// The plane angle between the Y-Z plane and the plane containing both the stylus axis and the Y axis, in degrees of the range [-90,90], a positive tiltX is to the right (default: 0) This is an optional value.
502+
TiltX int32
503+
// The plane angle between the X-Z plane and the plane containing both the stylus axis and the X axis, in degrees of the range [-90,90], a positive tiltY is towards the user (default: 0). This is an optional value.
504+
TiltY int32
505+
// The clockwise rotation of a pen stylus around its own major axis, in degrees in the range [0,359] (default: 0). This is an optional value.
506+
Twist int32
507+
}
508+
509+
type TSimulateKeyEvent struct {
510+
Type_ consts.TSimulatedCefKeyEventType
511+
Modifiers int32
512+
WindowsVirtualKeyCode int32
513+
NativeVirtualKeyCode int32
514+
AutoRepeat bool
515+
IsKeypad bool
516+
IsSystemKey bool
517+
Location consts.TCefKeyLocation
518+
Commands consts.TCefEditingCommand
519+
}
520+
521+
type TSimulateMouseEvent struct {
522+
Type_ consts.TCefSimulatedMouseEventType
523+
Modifiers int32
524+
Button consts.TCefSimulatedMouseButton
525+
Buttons int32
526+
ClickCount int32
527+
Twist int32
528+
PointerType consts.TCefSimulatedPointerType
529+
}

cef/types_cef_ptr.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,36 @@ func (m *TCefCompositionUnderline) ToPtr() *tCefCompositionUnderlinePtr {
245245
}
246246
}
247247

248+
type tCefSimulatedTouchPointPtr struct {
249+
Id uintptr //int32
250+
X uintptr //int32
251+
Y uintptr //int32
252+
RadiusX uintptr //float32
253+
RadiusY uintptr //float32
254+
RotationAngle uintptr //float32
255+
Force uintptr //float32
256+
TangentialPressure uintptr //float32
257+
TiltX uintptr //int32
258+
TiltY uintptr //int32
259+
Twist uintptr //int32
260+
}
261+
262+
func (m *TCefSimulatedTouchPoint) ToPtr() *tCefSimulatedTouchPointPtr {
263+
return &tCefSimulatedTouchPointPtr{
264+
Id: uintptr(m.Id),
265+
X: uintptr(m.X),
266+
Y: uintptr(m.Y),
267+
RadiusX: uintptr(unsafePointer(&m.RadiusX)),
268+
RadiusY: uintptr(unsafePointer(&m.RadiusY)),
269+
RotationAngle: uintptr(unsafePointer(&m.RotationAngle)),
270+
Force: uintptr(unsafePointer(&m.Force)),
271+
TangentialPressure: uintptr(unsafePointer(&m.TangentialPressure)),
272+
TiltX: uintptr(m.TiltX),
273+
TiltY: uintptr(m.TiltY),
274+
Twist: uintptr(m.Twist),
275+
}
276+
}
277+
248278
// ================
249279

250280
type tCefProxyPtr struct {

0 commit comments

Comments
 (0)