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
|
||||
|
||||
uses
|
||||
uCEFApplication, uCEFWorkScheduler, FileUtil;
|
||||
uCEFApplication, uCEFWorkScheduler, uCEFLazApplication, FileUtil;
|
||||
|
||||
procedure CreateGlobalCEFApp;
|
||||
|
||||
@ -75,7 +75,8 @@ begin
|
||||
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
|
||||
{$ENDIF}
|
||||
|
||||
GlobalCEFApp := TCefApplication.Create;
|
||||
GlobalCEFApp := TCefLazApplication.Create;
|
||||
GlobalCEFApp.CheckCEFFiles := False;
|
||||
{$IFDEF USE_MULTI_THREAD_LOOP}
|
||||
// On Windows/Linux CEF can use threads for the message-loop
|
||||
GlobalCEFApp.MultiThreadedMessageLoop := True;
|
||||
|
@ -47,7 +47,7 @@ uses
|
||||
LResources,
|
||||
{$ENDIF}
|
||||
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
|
||||
uCEFLinkedWinControlBase, Forms, ExtCtrls, Classes, sysutils;
|
||||
uCEFLinkedWinControlBase, uCEFLazApplication, Forms, ExtCtrls, Classes, sysutils;
|
||||
|
||||
type
|
||||
|
||||
@ -112,6 +112,7 @@ type
|
||||
FTimer : TTimer;
|
||||
|
||||
procedure DoCreateBrowser(Sender: TObject);
|
||||
procedure DoCreateBrowserAfterContext(Sender: TObject);
|
||||
protected
|
||||
function GetChromium: TChromium; override;
|
||||
procedure DestroyHandle; override;
|
||||
@ -330,6 +331,7 @@ end;
|
||||
|
||||
procedure TLazarusBrowserWindow.DoCreateBrowser(Sender: TObject);
|
||||
begin
|
||||
if FTimer <> nil then
|
||||
FTimer.Enabled := False;
|
||||
|
||||
case FChromiumWrapper.FChromiumState of
|
||||
@ -351,11 +353,26 @@ begin
|
||||
if GlobalCEFApp.ExternalMessagePump then
|
||||
GlobalCEFApp.DoMessageLoopWork;
|
||||
|
||||
if FTimer = nil then
|
||||
FTimer := TTimer.Create(Self);
|
||||
FTimer.OnTimer := @DoCreateBrowser;
|
||||
FTimer.Interval := 100;
|
||||
FTimer.Enabled := True;
|
||||
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;
|
||||
begin
|
||||
Result := FChromiumWrapper.FChromium;
|
||||
@ -368,10 +385,11 @@ begin
|
||||
(* On Windows we can create the browser immediately.
|
||||
But at least on Linux, we need to wait
|
||||
*)
|
||||
FTimer := TTimer.Create(Self);
|
||||
FTimer.Interval := 20;
|
||||
FTimer.OnTimer := @DoCreateBrowser;
|
||||
FTimer.Enabled := True;
|
||||
|
||||
if GlobalCEFApp is TCefLazApplication then
|
||||
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
|
||||
else
|
||||
DoCreateBrowserAfterContext(nil);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user