mirror of
https://gitee.com/energye/energy.git
synced 2024-11-30 02:37:46 +08:00
93 lines
2.5 KiB
Go
93 lines
2.5 KiB
Go
//----------------------------------------
|
|
//
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
//
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
//----------------------------------------
|
|
|
|
package cef
|
|
|
|
import "github.com/energye/golcl/lcl"
|
|
|
|
// ICEFChromiumBrowser
|
|
// CEFChromium浏览器接口
|
|
type ICEFChromiumBrowser interface {
|
|
CreateBrowser() // 创建浏览器
|
|
Chromium() IChromium // 返回 chromium
|
|
WindowParent() ICEFWindowParent // 返回 chromium window 组件
|
|
IsCreated() bool // 创建浏览器是否成功
|
|
}
|
|
|
|
// TCEFChromiumBrowser
|
|
// CEFChromium浏览器包装结构
|
|
type TCEFChromiumBrowser struct {
|
|
chromium IChromium // chromium
|
|
windowParent ICEFWindowParent // chromium window 组件
|
|
isCreated bool // chromium browser is created
|
|
createTimer *lcl.TTimer // loop check and create chromium browser
|
|
}
|
|
|
|
// NewChromiumBrowser
|
|
// 初始创建一个 chromium 浏览器
|
|
func NewChromiumBrowser(owner lcl.IWinControl, config *tCefChromiumConfig) ICEFChromiumBrowser {
|
|
var m = new(TCEFChromiumBrowser)
|
|
m.chromium = NewChromium(owner, config)
|
|
m.windowParent = NewCEFWindow(owner)
|
|
m.windowParent.SetParent(owner)
|
|
m.windowParent.SetChromium(m.chromium, 0)
|
|
m.createTimer = lcl.NewTimer(owner)
|
|
m.createTimer.SetInterval(200)
|
|
m.createTimer.SetOnTimer(m.checkAndCreateBrowser)
|
|
return m
|
|
}
|
|
|
|
// checkAndCreateBrowser
|
|
// 创建浏览器
|
|
// 创建时如果未创建成功, 使用定时器创建直到成功
|
|
func (m *TCEFChromiumBrowser) checkAndCreateBrowser(sender lcl.IObject) {
|
|
if m.chromium == nil || m.createTimer == nil {
|
|
return
|
|
}
|
|
m.createTimer.SetEnabled(false)
|
|
if m.isCreated { // 成功创建 释放定时器
|
|
m.createTimer.Free()
|
|
m.createTimer = nil
|
|
return
|
|
}
|
|
m.chromium.Initialized()
|
|
m.isCreated = m.chromium.CreateBrowser(m.windowParent)
|
|
if !m.isCreated {
|
|
m.createTimer.SetEnabled(true)
|
|
} else {
|
|
m.windowParent.UpdateSize()
|
|
}
|
|
}
|
|
|
|
// CreateBrowser
|
|
// 创建浏览器
|
|
// 创建时如果未创建成功, 使用定时任务创建直到成功
|
|
func (m *TCEFChromiumBrowser) CreateBrowser() {
|
|
m.checkAndCreateBrowser(nil)
|
|
}
|
|
|
|
// Chromium
|
|
// 返回 chromium
|
|
func (m *TCEFChromiumBrowser) Chromium() IChromium {
|
|
return m.chromium
|
|
}
|
|
|
|
// WindowParent
|
|
// 返回 chromium window 组件
|
|
func (m *TCEFChromiumBrowser) WindowParent() ICEFWindowParent {
|
|
return m.windowParent
|
|
}
|
|
|
|
// IsCreated
|
|
// 创建浏览器是否成功
|
|
func (m *TCEFChromiumBrowser) IsCreated() bool {
|
|
return m.isCreated
|
|
}
|