mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-05-13 21:46:53 +02:00
Changed Demo BrowserWindow (Lazarus_any_OS) to use ContextInitialized Handler
This commit is contained in:
parent
605d31f8cf
commit
d37e72c010
@ -51,7 +51,7 @@ unit GlobalCefApplication;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
uCEFApplication, uCEFWorkScheduler, FileUtil;
|
uCEFApplication, uCEFWorkScheduler, uCEFLazApplication, FileUtil;
|
||||||
|
|
||||||
procedure CreateGlobalCEFApp;
|
procedure CreateGlobalCEFApp;
|
||||||
|
|
||||||
@ -75,7 +75,8 @@ begin
|
|||||||
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
|
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
GlobalCEFApp := TCefApplication.Create;
|
GlobalCEFApp := TCefLazApplication.Create;
|
||||||
|
GlobalCEFApp.CheckCEFFiles := False;
|
||||||
{$IFDEF USE_MULTI_THREAD_LOOP}
|
{$IFDEF USE_MULTI_THREAD_LOOP}
|
||||||
// On Windows/Linux CEF can use threads for the message-loop
|
// On Windows/Linux CEF can use threads for the message-loop
|
||||||
GlobalCEFApp.MultiThreadedMessageLoop := True;
|
GlobalCEFApp.MultiThreadedMessageLoop := True;
|
||||||
|
@ -47,7 +47,7 @@ uses
|
|||||||
LResources,
|
LResources,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
|
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
|
||||||
uCEFLinkedWinControlBase, Forms, ExtCtrls, Classes, sysutils;
|
uCEFLinkedWinControlBase, uCEFLazApplication, Forms, ExtCtrls, Classes, sysutils;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -112,6 +112,7 @@ type
|
|||||||
FTimer : TTimer;
|
FTimer : TTimer;
|
||||||
|
|
||||||
procedure DoCreateBrowser(Sender: TObject);
|
procedure DoCreateBrowser(Sender: TObject);
|
||||||
|
procedure DoCreateBrowserAfterContext(Sender: TObject);
|
||||||
protected
|
protected
|
||||||
function GetChromium: TChromium; override;
|
function GetChromium: TChromium; override;
|
||||||
procedure DestroyHandle; override;
|
procedure DestroyHandle; override;
|
||||||
@ -330,7 +331,8 @@ end;
|
|||||||
|
|
||||||
procedure TLazarusBrowserWindow.DoCreateBrowser(Sender: TObject);
|
procedure TLazarusBrowserWindow.DoCreateBrowser(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FTimer.Enabled := False;
|
if FTimer <> nil then
|
||||||
|
FTimer.Enabled := False;
|
||||||
|
|
||||||
case FChromiumWrapper.FChromiumState of
|
case FChromiumWrapper.FChromiumState of
|
||||||
csCreatingBrowser, csHasBrowser: begin
|
csCreatingBrowser, csHasBrowser: begin
|
||||||
@ -351,11 +353,26 @@ begin
|
|||||||
if GlobalCEFApp.ExternalMessagePump then
|
if GlobalCEFApp.ExternalMessagePump then
|
||||||
GlobalCEFApp.DoMessageLoopWork;
|
GlobalCEFApp.DoMessageLoopWork;
|
||||||
|
|
||||||
|
if FTimer = nil then
|
||||||
|
FTimer := TTimer.Create(Self);
|
||||||
|
FTimer.OnTimer := @DoCreateBrowser;
|
||||||
FTimer.Interval := 100;
|
FTimer.Interval := 100;
|
||||||
FTimer.Enabled := True;
|
FTimer.Enabled := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TLazarusBrowserWindow.DoCreateBrowserAfterContext(Sender: TObject);
|
||||||
|
begin
|
||||||
|
{$IFDEF LINUX}
|
||||||
|
FTimer := TTimer.Create(Self);
|
||||||
|
FTimer.Interval := 20;
|
||||||
|
FTimer.OnTimer := @DoCreateBrowser;
|
||||||
|
FTimer.Enabled := True;
|
||||||
|
{$ELSE}
|
||||||
|
DoCreateBrowser(nil);
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
function TLazarusBrowserWindow.GetChromium: TChromium;
|
function TLazarusBrowserWindow.GetChromium: TChromium;
|
||||||
begin
|
begin
|
||||||
Result := FChromiumWrapper.FChromium;
|
Result := FChromiumWrapper.FChromium;
|
||||||
@ -368,10 +385,11 @@ begin
|
|||||||
(* On Windows we can create the browser immediately.
|
(* On Windows we can create the browser immediately.
|
||||||
But at least on Linux, we need to wait
|
But at least on Linux, we need to wait
|
||||||
*)
|
*)
|
||||||
FTimer := TTimer.Create(Self);
|
|
||||||
FTimer.Interval := 20;
|
if GlobalCEFApp is TCefLazApplication then
|
||||||
FTimer.OnTimer := @DoCreateBrowser;
|
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
|
||||||
FTimer.Enabled := True;
|
else
|
||||||
|
DoCreateBrowserAfterContext(nil);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user