Ready to fix some problems on linux

This commit is contained in:
杨红岩 2022-12-27 21:38:01 +08:00
parent fd311cabab
commit edcf60310c
7 changed files with 78 additions and 18 deletions

View File

@ -79,6 +79,10 @@ func (m *TCEFApplication) RunMessageLoop() {
Proc(internale_CEFApplication_RunMessageLoop).Call()
}
func (m *TCEFApplication) QuitMessageLoop() {
Proc(internale_CEFApplication_QuitMessageLoop).Call()
}
func (m *TCEFApplication) StopScheduler() {
Proc(internale_CEFApplication_StopScheduler).Call()
}

View File

@ -13,7 +13,7 @@ type TCEFBrowserViewComponent struct {
instance unsafe.Pointer
}
func NewBrowserViewComponent(AOwner lcl.TComponent) *TCEFBrowserViewComponent {
func NewBrowserViewComponent(AOwner lcl.IComponent) *TCEFBrowserViewComponent {
r1, _, _ := Proc(internale_CEFBrowserViewComponent_Create).Call(lcl.CheckPtr(AOwner))
return &TCEFBrowserViewComponent{
instance: unsafe.Pointer(r1),
@ -44,6 +44,10 @@ func (m *TCEFBrowserViewComponent) CreateBrowserView(client *ICefClient, url str
Proc(internale_CEFBrowserViewComponent_CreateBrowserView).Call(uintptr(m.instance), uintptr(client.instance), api.PascalStr(url), uintptr(unsafe.Pointer(&contextSettingsPtr)), uintptr(unsafe.Pointer(&browserSettingsPtr)), uintptr(argsLen), uintptr(dataBytesPtr), uintptr(dataBytesLen))
}
func (m *TCEFBrowserViewComponent) Instance() uintptr {
return uintptr(m.instance)
}
func (m *TCEFBrowserViewComponent) GetForBrowser(browser *ICefBrowser) {
Proc(internale_CEFBrowserViewComponent_CreateBrowserView).Call(uintptr(m.instance), uintptr(browser.Identifier()))
}

View File

@ -38,6 +38,7 @@ type IChromiumProc interface {
ResetZoomLevel()
CloseAllBrowsers()
CreateBrowser(window ITCefWindow) bool
CreateBrowserByBrowserViewComponent(homePage string, browserViewComponent *TCEFBrowserViewComponent) bool
Initialized() bool
BrowserId() int32
IsSameBrowser(browser *ICefBrowser) bool
@ -67,6 +68,7 @@ type IChromiumProc interface {
SetFocus(value bool)
SendCaptureLostEvent()
FrameIsFocused() bool
TryCloseBrowser() bool
}
func (m *TCEFChromium) IsValid() bool {
@ -173,6 +175,10 @@ func (m *TCEFChromium) CreateBrowser(window ITCefWindow) bool {
return false
}
func (m *TCEFChromium) CreateBrowserByBrowserViewComponent(homePage string, browserViewComponent *TCEFBrowserViewComponent) bool {
return _CEFChromium_CreateBrowserByBrowserViewComponent(m.Instance(), api.PascalStr(homePage), browserViewComponent.Instance())
}
func (m *TCEFChromium) Initialized() bool {
return _CEFChromium_Initialized(m.Instance())
}
@ -322,6 +328,10 @@ func (m *TCEFChromium) FrameIsFocused() bool {
return api.GoBool(_CEFChromium_FrameIsFocused(m.Instance()))
}
func (m *TCEFChromium) TryCloseBrowser() bool {
return api.GoBool(_CEFChromium_TryCloseBrowser(m.Instance()))
}
//--------TCEFChromium proc begin--------
// TCEFChromium _CEFChromium_Create
@ -392,6 +402,12 @@ func _CEFChromium_CreateBrowseByLinkedWindow(instance, window uintptr) bool {
return api.GoBool(r1)
}
// TCEFChromium _CEFChromium_CreateBrowserByBrowserViewComponent
func _CEFChromium_CreateBrowserByBrowserViewComponent(instance, homePage, browserViewComponent uintptr) bool {
r1, _, _ := Proc(internale_CEFChromium_CreateBrowserByBrowserViewComponent).Call(instance, homePage, browserViewComponent)
return api.GoBool(r1)
}
// TCEFChromium _CEFChromium_Initialized
func _CEFChromium_Initialized(instance uintptr) bool {
r1, _, _ := Proc(internale_CEFChromium_Initialized).Call(instance)
@ -576,4 +592,9 @@ func _CEFChromium_FrameIsFocused(instance uintptr) uintptr {
return r1
}
func _CEFChromium_TryCloseBrowser(instance uintptr) uintptr {
r1, _, _ := Proc(internale_CEFChromium_TryCloseBrowser).Call(instance)
return r1
}
//--------TCEFChromium proc end--------

View File

@ -34,6 +34,7 @@ func init() {
dllimports.NewEnergyImport("AddCustomCommandLine", 0),
//application
dllimports.NewEnergyImport("CEFApplication_RunMessageLoop", 0),
dllimports.NewEnergyImport("CEFApplication_QuitMessageLoop", 0),
dllimports.NewEnergyImport("CEFApplication_Create", 0),
dllimports.NewEnergyImport("CEFApplication_Destroy", 0),
dllimports.NewEnergyImport("CEFApplication_Free", 0),
@ -238,6 +239,7 @@ func init() {
dllimports.NewEnergyImport("CEFChromium_CloseAllBrowsers", 0),
dllimports.NewEnergyImport("CEFChromium_CreateBrowserByWindow", 0),
dllimports.NewEnergyImport("CEFChromium_CreateBrowserByLinkedWindow", 0),
dllimports.NewEnergyImport("CEFChromium_CreateBrowserByBrowserViewComponent", 0),
dllimports.NewEnergyImport("CEFChromium_Initialized", 0),
dllimports.NewEnergyImport("CEFChromium_GetBrowserId", 0),
dllimports.NewEnergyImport("CEFChromium_IsSameBrowser", 0),
@ -266,6 +268,7 @@ func init() {
dllimports.NewEnergyImport("CEFChromium_SetFocus", 0),
dllimports.NewEnergyImport("CEFChromium_SendCaptureLostEvent", 0),
dllimports.NewEnergyImport("CEFChromium_FrameIsFocused", 0),
dllimports.NewEnergyImport("CEFChromium_TryCloseBrowser", 0),
//ICefBeforeDownloadCallback
dllimports.NewEnergyImport("CEFChromium_SetDownloadPath", 0),
//ICefFrame
@ -383,6 +386,7 @@ func init() {
dllimports.NewEnergyImport("CEFWindowComponent_IsFullscreen", 0),
dllimports.NewEnergyImport("CEFWindowComponent_IsMaximized", 0),
dllimports.NewEnergyImport("CEFWindowComponent_IsMinimized", 0),
dllimports.NewEnergyImport("CEFWindowComponent_AddChildView", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetOnWindowCreated", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetOnWindowDestroyed", 0),
dllimports.NewEnergyImport("CEFWindowComponent_SetOnWindowActivationChanged", 0),
@ -436,6 +440,7 @@ const (
internale_AddCustomCommandLine
//application
internale_CEFApplication_RunMessageLoop
internale_CEFApplication_QuitMessageLoop
internale_CEFApplication_Create
internale_CEFApplication_Destroy
internale_CEFApplication_Free
@ -641,6 +646,7 @@ const (
internale_CEFChromium_CloseAllBrowsers
internale_CEFChromium_CreateBrowserByWindow
internale_CEFChromium_CreateBrowserByLinkedWindow
internale_CEFChromium_CreateBrowserByBrowserViewComponent
internale_CEFChromium_Initialized
internale_CEFChromium_GetBrowserId
internale_CEFChromium_IsSameBrowser
@ -669,6 +675,7 @@ const (
internale_CEFChromium_SetFocus
internale_CEFChromium_SendCaptureLostEvent
internale_CEFChromium_FrameIsFocused
internale_CEFChromium_TryCloseBrowser
//ICefBeforeDownloadCallback
internale_CEFChromium_SetDownloadPath
//ICefFrame
@ -786,6 +793,7 @@ const (
internale_CEFWindowComponent_IsFullscreen
internale_CEFWindowComponent_IsMaximized
internale_CEFWindowComponent_IsMinimized
internale_CEFWindowComponent_AddChildView
internale_CEFWindowComponent_SetOnWindowCreated
internale_CEFWindowComponent_SetOnWindowDestroyed
internale_CEFWindowComponent_SetOnWindowActivationChanged

View File

@ -206,6 +206,13 @@ type ICefClient struct {
instance unsafe.Pointer
}
func NewCefSize(width, height int32) *TCefSize {
return &TCefSize{
Width: width,
Height: height,
}
}
func (m *ICefWindow) SetWindow(window *ICefWindow) {
m.instance = window.instance
}

View File

@ -33,8 +33,8 @@ func (m *TCEFWindowComponent) Hide() {
Proc(internale_CEFWindowComponent_Hide).Call(uintptr(m.instance))
}
func (m *TCEFWindowComponent) CenterWindow(size TCefSize) {
Proc(internale_CEFWindowComponent_CenterWindow).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&size)))
func (m *TCEFWindowComponent) CenterWindow(size *TCefSize) {
Proc(internale_CEFWindowComponent_CenterWindow).Call(uintptr(m.instance), uintptr(unsafe.Pointer(size)))
}
func (m *TCEFWindowComponent) Close() {
@ -179,6 +179,10 @@ func (m *TCEFWindowComponent) IsMinimized() bool {
return api.GoBool(r1)
}
func (m *TCEFWindowComponent) AddChildView(browserViewComponent *TCEFBrowserViewComponent) {
Proc(internale_CEFWindowComponent_AddChildView).Call(uintptr(m.instance), browserViewComponent.Instance())
}
func (m *TCEFWindowComponent) SetOnWindowCreated(fn WindowComponentOnWindowCreated) {
Proc(internale_CEFWindowComponent_SetOnWindowCreated).Call(uintptr(m.instance), api.MakeEventDataPtr(fn))
}

View File

@ -18,31 +18,43 @@ func main() {
//config.SetChromeRuntime(true)
application := cef.NewCEFApplication(config)
application.SetOnContextInitialized(func() {
fmt.Println("OnContextInitialized()")
component := lcl.NewComponent(nil)
fmt.Println("OnContextInitialized(", component)
chromiumConfig := cef.NewChromiumConfig()
chromium := cef.NewChromium(component, chromiumConfig)
chromium.SetOnBeforeClose(func(sender lcl.IObject, browser *cef.ICefBrowser) {
fmt.Println("OnBeforeClose")
application.QuitMessageLoop()
})
chromium.SetOnTitleChange(func(sender lcl.IObject, browser *cef.ICefBrowser, title string) {
fmt.Println("OnTitleChange", title)
})
browserViewComponent := cef.NewBrowserViewComponent(component)
windowComponent := cef.NewWindowComponent(component)
windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
fmt.Println("OnWindowCreated")
b := chromium.CreateBrowserByBrowserViewComponent("https://www.baidu.com", browserViewComponent)
fmt.Println("\tCreateBrowserByBrowserViewComponent", b)
windowComponent.AddChildView(browserViewComponent)
windowComponent.CenterWindow(cef.NewCefSize(1024, 768))
browserViewComponent.RequestFocus()
windowComponent.Show()
})
windowComponent.SetOnCanClose(func(sender lcl.IObject, window *cef.ICefWindow, aResult *bool) {
fmt.Println("OnCanClose")
chromium.TryCloseBrowser()
})
windowComponent.CreateTopLevelWindow()
})
application.SetOnGetDefaultClient(func(client *cef.ICefClient) {
fmt.Println("OnGetDefaultClient")
})
//chromiumConfig := cef.NewChromiumConfig()
//chromium := cef.NewChromium(component, chromiumConfig)
//chromium.SetOnBeforeClose(func(sender lcl.IObject, browser *cef.ICefBrowser) {
// fmt.Println("OnBeforeClose")
//})
//
//windowComponent := cef.NewWindowComponent(component)
//windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
// fmt.Println("OnWindowCreated")
//})
//windowComponent.SetOnGetInitialBounds(func(sender lcl.IObject, window *cef.ICefWindow, aResult *cef.TCefRect) {
// fmt.Println("OnGetInitialBounds")
//})
process := application.StartMainProcess()
fmt.Println("application.StartMainProcess()", process)
if process {
fmt.Println("application.RunMessageLoop()")
application.RunMessageLoop()
}
fmt.Println("end")
}