1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-05-13 21:46:53 +02:00

Merge pull request #355 from User4martin/fpc-work-6

Fpc work 6
This commit is contained in:
Salvador Díaz Fau 2021-03-22 10:27:10 +01:00 committed by GitHub
commit 5d7183a711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 394 additions and 310 deletions

View File

@ -51,7 +51,7 @@ unit GlobalCefApplication;
interface interface
uses uses
uCEFApplication, uCEFWorkScheduler, uCEFLazApplication, FileUtil; uCEFApplication, uCEFWorkScheduler, FileUtil;
procedure CreateGlobalCEFApp; procedure CreateGlobalCEFApp;
@ -75,8 +75,8 @@ begin
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil); GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
{$ENDIF} {$ENDIF}
GlobalCEFApp := TCefLazApplication.Create; GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.CheckCEFFiles := False; //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;

View File

@ -61,14 +61,14 @@ object Form1: TForm1
Text = 'https://www.google.com' Text = 'https://www.google.com'
end end
end end
object LazarusBrowserWindow1: TLazarusBrowserWindow object BrowserWindow1: TBrowserWindow
Left = 0 Left = 0
Height = 566 Height = 566
Top = 23 Top = 23
Width = 967 Width = 967
Align = alClient Align = alClient
TabOrder = 1 TabOrder = 1
OnBrowserCreated = LazarusBrowserWindow1BrowserCreated OnBrowserCreated = BrowserWindow1BrowserCreated
OnBrowserClosed = LazarusBrowserWindow1BrowserClosed OnBrowserClosed = BrowserWindow1BrowserClosed
end end
end end

View File

@ -48,7 +48,7 @@ uses
SysUtils, Messages, Forms, Controls, SysUtils, Messages, Forms, Controls,
Dialogs, ExtCtrls, StdCtrls, LMessages, Dialogs, ExtCtrls, StdCtrls, LMessages,
uCEFTypes, uCEFInterfaces, uCEFTypes, uCEFInterfaces,
uCEFWorkScheduler, uCEFLazarusBrowserWindow, Classes; uCEFWorkScheduler, uCEFBrowserWindow;
type type
@ -58,7 +58,7 @@ type
AddressEdt: TComboBox; AddressEdt: TComboBox;
GoBtn: TButton; GoBtn: TButton;
AddressPnl: TPanel; AddressPnl: TPanel;
LazarusBrowserWindow1: TLazarusBrowserWindow; BrowserWindow1: TBrowserWindow;
procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean); procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean);
procedure Chromium1OpenUrlFromTab(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; out Result: Boolean); procedure Chromium1OpenUrlFromTab(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; out Result: Boolean);
@ -66,8 +66,8 @@ type
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure GoBtnClick(Sender: TObject); procedure GoBtnClick(Sender: TObject);
procedure LazarusBrowserWindow1BrowserClosed(Sender: TObject); procedure BrowserWindow1BrowserClosed(Sender: TObject);
procedure LazarusBrowserWindow1BrowserCreated(Sender: TObject); procedure BrowserWindow1BrowserCreated(Sender: TObject);
protected protected
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
@ -117,15 +117,15 @@ uses
procedure TForm1.GoBtnClick(Sender: TObject); procedure TForm1.GoBtnClick(Sender: TObject);
begin begin
LazarusBrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text)); BrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text));
end; end;
procedure TForm1.LazarusBrowserWindow1BrowserClosed(Sender: TObject); procedure TForm1.BrowserWindow1BrowserClosed(Sender: TObject);
begin begin
Close; Close;
end; end;
procedure TForm1.LazarusBrowserWindow1BrowserCreated(Sender: TObject); procedure TForm1.BrowserWindow1BrowserCreated(Sender: TObject);
begin begin
Caption := 'BrowserWindow'; Caption := 'BrowserWindow';
end; end;
@ -169,14 +169,14 @@ end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin begin
LazarusBrowserWindow1.CloseBrowser(True); BrowserWindow1.CloseBrowser(True);
CanClose := LazarusBrowserWindow1.IsClosed; CanClose := BrowserWindow1.IsClosed;
end; end;
procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
begin begin
LazarusBrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text)); BrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text));
end; end;
initialization initialization

View File

@ -51,7 +51,7 @@ unit GlobalCefApplication;
interface interface
uses uses
uCEFApplication, uCEFWorkScheduler, uCEFLazApplication, FileUtil, uCEFApplication, uCEFWorkScheduler, FileUtil,
uHelperProcessDom; uHelperProcessDom;
procedure CreateGlobalCEFApp; procedure CreateGlobalCEFApp;
@ -76,8 +76,8 @@ begin
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil); GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
{$ENDIF} {$ENDIF}
GlobalCEFApp := TCefLazApplication.Create; GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.CheckCEFFiles := False; //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;

View File

@ -61,13 +61,13 @@ object Form1: TForm1
Text = 'https://www.google.com' Text = 'https://www.google.com'
end end
end end
object LazarusBrowserWindow1: TLazarusBrowserWindow object BrowserWindow1: TBrowserWindow
Left = 0 Left = 0
Height = 566 Height = 566
Top = 23 Top = 23
Width = 967 Width = 967
Align = alClient Align = alClient
TabOrder = 1 TabOrder = 1
OnBrowserClosed = LazarusBrowserWindow1BrowserClosed OnBrowserClosed = BrowserWindow1BrowserClosed
end end
end end

View File

@ -48,7 +48,7 @@ uses
SysUtils, Messages, Forms, Controls, SysUtils, Messages, Forms, Controls,
Dialogs, ExtCtrls, StdCtrls, LMessages, Menus, Dialogs, ExtCtrls, StdCtrls, LMessages, Menus,
uCEFTypes, uCEFInterfaces, uHelperProcessDom, uCEFTypes, uCEFInterfaces, uHelperProcessDom,
uCEFWorkScheduler, uCEFLazarusBrowserWindow, uCEFProcessMessage, Classes; uCEFWorkScheduler, uCEFBrowserWindow, uCEFProcessMessage, Classes;
type type
@ -58,7 +58,7 @@ type
AddressEdt: TComboBox; AddressEdt: TComboBox;
GoBtn: TButton; GoBtn: TButton;
AddressPnl: TPanel; AddressPnl: TPanel;
LazarusBrowserWindow1: TLazarusBrowserWindow; BrowserWindow1: TBrowserWindow;
mDomHere: TMenuItem; mDomHere: TMenuItem;
procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean); procedure Chromium1BeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean);
@ -67,7 +67,7 @@ type
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure GoBtnClick(Sender: TObject); procedure GoBtnClick(Sender: TObject);
procedure LazarusBrowserWindow1BrowserClosed(Sender: TObject); procedure BrowserWindow1BrowserClosed(Sender: TObject);
private private
FContextXY: TPoint; FContextXY: TPoint;
@ -130,10 +130,10 @@ uses
procedure TForm1.GoBtnClick(Sender: TObject); procedure TForm1.GoBtnClick(Sender: TObject);
begin begin
LazarusBrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text)); BrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text));
end; end;
procedure TForm1.LazarusBrowserWindow1BrowserClosed(Sender: TObject); procedure TForm1.BrowserWindow1BrowserClosed(Sender: TObject);
begin begin
Close; Close;
end; end;
@ -149,7 +149,7 @@ end;
procedure TForm1.DoCaptureMenuXY; procedure TForm1.DoCaptureMenuXY;
begin begin
FContextXY := LazarusBrowserWindow1.ScreenToClient(Mouse.CursorPos); FContextXY := BrowserWindow1.ScreenToClient(Mouse.CursorPos);
end; end;
procedure TForm1.DoContextMenuCmd(Sender: TObject; const browser: ICefBrowser; procedure TForm1.DoContextMenuCmd(Sender: TObject; const browser: ICefBrowser;
@ -163,7 +163,7 @@ begin
TempMsg := TCefProcessMessageRef.New(MSG_REQUEST_DOM); // Same name than TCefCustomRenderProcessHandler.MessageName TempMsg := TCefProcessMessageRef.New(MSG_REQUEST_DOM); // Same name than TCefCustomRenderProcessHandler.MessageName
TempMsg.ArgumentList.SetInt(0, FContextXY.X); TempMsg.ArgumentList.SetInt(0, FContextXY.X);
TempMsg.ArgumentList.SetInt(1, FContextXY.Y); TempMsg.ArgumentList.SetInt(1, FContextXY.Y);
LazarusBrowserWindow1.Chromium.SendProcessMessage(PID_RENDERER, TempMsg); BrowserWindow1.Chromium.SendProcessMessage(PID_RENDERER, TempMsg);
end; end;
end; end;
@ -220,18 +220,18 @@ end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin begin
LazarusBrowserWindow1.CloseBrowser(True); BrowserWindow1.CloseBrowser(True);
CanClose := LazarusBrowserWindow1.IsClosed; CanClose := BrowserWindow1.IsClosed;
end; end;
procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
begin begin
LazarusBrowserWindow1.Chromium.OnBeforeContextMenu := @DoBeforeContextMenu; BrowserWindow1.Chromium.OnBeforeContextMenu := @DoBeforeContextMenu;
LazarusBrowserWindow1.Chromium.OnContextMenuCommand := @DoContextMenuCmd; BrowserWindow1.Chromium.OnContextMenuCommand := @DoContextMenuCmd;
LazarusBrowserWindow1.Chromium.OnProcessMessageReceived := @DoProcessMessageReceived; BrowserWindow1.Chromium.OnProcessMessageReceived := @DoProcessMessageReceived;
LazarusBrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text)); BrowserWindow1.LoadURL(UTF8Decode(AddressEdt.Text));
end; end;
initialization initialization

View File

@ -86,7 +86,7 @@ begin
GlobalCEFApp.OnScheduleMessagePumpWork := @GlobalCEFApp_OnScheduleMessagePumpWork; GlobalCEFApp.OnScheduleMessagePumpWork := @GlobalCEFApp_OnScheduleMessagePumpWork;
{$ENDIF} {$ENDIF}
GlobalCEFApp.CheckCEFFiles := false; //GlobalCEFApp.CheckCEFFiles := false;
{$IFnDEF MACOSX} {$IFnDEF MACOSX}
{$IFDEF USE_APP_HELPER} {$IFDEF USE_APP_HELPER}

View File

@ -48,7 +48,7 @@ uses
SysUtils, Messages, Forms, Controls, SysUtils, Messages, Forms, Controls,
Dialogs, ExtCtrls, StdCtrls, LMessages, Buttons, Dialogs, ExtCtrls, StdCtrls, LMessages, Buttons,
uCEFTypes, uCEFInterfaces, uCEFTypes, uCEFInterfaces,
uCEFWorkScheduler, uCEFLazarusBrowserWindow, Classes; uCEFWorkScheduler, uCEFBrowserWindow, Classes;
type type
@ -98,7 +98,7 @@ type
procedure MaybeTerminateApp(Sender: TObject); procedure MaybeTerminateApp(Sender: TObject);
procedure MaybeCloseApp(Sender: TObject); procedure MaybeCloseApp(Sender: TObject);
protected protected
FBrowserLeft, FBrowserRight: TLazarusBrowserWindow; FBrowserLeft, FBrowserRight: TBrowserWindow;
FClosingBrowsers: TList; FClosingBrowsers: TList;
{$IFDEF WINDOWS} {$IFDEF WINDOWS}
@ -150,7 +150,7 @@ uses
procedure TForm1.OpenBtnLeftClick(Sender: TObject); procedure TForm1.OpenBtnLeftClick(Sender: TObject);
begin begin
FBrowserLeft := TLazarusBrowserWindow.Create(Self); FBrowserLeft := TBrowserWindow.Create(Self);
FBrowserLeft.Chromium.OnBeforePopup := @Chromium1BeforePopup; FBrowserLeft.Chromium.OnBeforePopup := @Chromium1BeforePopup;
FBrowserLeft.Chromium.OnOpenUrlFromTab := @Chromium1OpenUrlFromTab; FBrowserLeft.Chromium.OnOpenUrlFromTab := @Chromium1OpenUrlFromTab;
FBrowserLeft.OnBrowserCreated := @LeftBrowserCreated; FBrowserLeft.OnBrowserCreated := @LeftBrowserCreated;
@ -191,7 +191,7 @@ end;
procedure TForm1.OpenBtnRightClick(Sender: TObject); procedure TForm1.OpenBtnRightClick(Sender: TObject);
begin begin
FBrowserRight := TLazarusBrowserWindow.Create(Self); FBrowserRight := TBrowserWindow.Create(Self);
FBrowserRight.Chromium.OnBeforePopup := @Chromium1BeforePopup; FBrowserRight.Chromium.OnBeforePopup := @Chromium1BeforePopup;
FBrowserRight.Chromium.OnOpenUrlFromTab := @Chromium1OpenUrlFromTab; FBrowserRight.Chromium.OnOpenUrlFromTab := @Chromium1OpenUrlFromTab;
FBrowserRight.OnBrowserCreated := @RightBrowserCreated; FBrowserRight.OnBrowserCreated := @RightBrowserCreated;

View File

@ -51,7 +51,7 @@ unit GlobalCefApplication;
interface interface
uses uses
uCEFApplication, uCEFWorkScheduler, uCEFLazApplication, FileUtil, uCEFApplication, uCEFWorkScheduler, FileUtil,
uHelperProcessDom; uHelperProcessDom;
procedure CreateGlobalCEFApp; procedure CreateGlobalCEFApp;
@ -76,8 +76,8 @@ begin
GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil); GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
{$ENDIF} {$ENDIF}
GlobalCEFApp := TCefLazApplication.Create; GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.CheckCEFFiles := False; //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;
@ -88,8 +88,6 @@ begin
GlobalCEFApp.OnScheduleMessagePumpWork := @GlobalCEFApp_OnScheduleMessagePumpWork; GlobalCEFApp.OnScheduleMessagePumpWork := @GlobalCEFApp_OnScheduleMessagePumpWork;
{$ENDIF} {$ENDIF}
GlobalCEFApp.CheckCEFFiles := false;
{$IFnDEF MACOSX} {$IFnDEF MACOSX}
{$IFDEF USE_APP_HELPER} {$IFDEF USE_APP_HELPER}
(* Use AppHelper as subprocess, instead of the main exe *) (* Use AppHelper as subprocess, instead of the main exe *)

View File

@ -61,7 +61,7 @@ object Form1: TForm1
Text = 'https://www.google.com' Text = 'https://www.google.com'
end end
end end
object LazarusOsrBrowserWindow1: TLazarusOsrBrowserWindow object OsrBrowserWindow1: TOsrBrowserWindow
Left = 0 Left = 0
Height = 566 Height = 566
Top = 23 Top = 23
@ -69,8 +69,8 @@ object Form1: TForm1
CopyOriginalBuffer = True CopyOriginalBuffer = True
Align = alClient Align = alClient
TabOrder = 1 TabOrder = 1
OnMouseMove = LazarusOsrBrowserWindow1MouseMove OnMouseMove = OsrBrowserWindow1MouseMove
OnBrowserClosed = LazarusBrowserWindow1BrowserClosed OnBrowserClosed = OsrBrowserWindow1BrowserClosed
end end
object PopupMenu1: TPopupMenu object PopupMenu1: TPopupMenu
left = 418 left = 418

View File

@ -47,8 +47,8 @@ uses
uCEFLazarusCocoa, // required for Cocoa uCEFLazarusCocoa, // required for Cocoa
SysUtils, Messages, Forms, Controls, Dialogs, ExtCtrls, StdCtrls, LMessages, SysUtils, Messages, Forms, Controls, Dialogs, ExtCtrls, StdCtrls, LMessages,
Menus, Graphics, uCEFTypes, uCEFInterfaces, uHelperProcessDom, Menus, Graphics, uCEFTypes, uCEFInterfaces, uHelperProcessDom,
uCEFWorkScheduler, uCEFLazarusBrowserWindow, uCEFProcessMessage, uCEFWorkScheduler, uCEFBrowserWindow, uCEFProcessMessage,
uCEFLazarusOsrBrowserWindow, Classes; uCEFOsrBrowserWindow, Classes;
type type
@ -58,7 +58,7 @@ type
AddressEdt: TComboBox; AddressEdt: TComboBox;
GoBtn: TButton; GoBtn: TButton;
AddressPnl: TPanel; AddressPnl: TPanel;
LazarusOsrBrowserWindow1: TLazarusOsrBrowserWindow; OsrBrowserWindow1: TOsrBrowserWindow;
mDomHere: TMenuItem; mDomHere: TMenuItem;
MenuItem1: TMenuItem; MenuItem1: TMenuItem;
PopupMenu1: TPopupMenu; PopupMenu1: TPopupMenu;
@ -69,8 +69,8 @@ type
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure GoBtnClick(Sender: TObject); procedure GoBtnClick(Sender: TObject);
procedure LazarusBrowserWindow1BrowserClosed(Sender: TObject); procedure OsrBrowserWindow1BrowserClosed(Sender: TObject);
procedure LazarusOsrBrowserWindow1MouseMove(Sender: TObject; procedure OsrBrowserWindow1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
private private
FCurRect: TRect; FCurRect: TRect;
@ -109,15 +109,15 @@ uses
procedure TForm1.GoBtnClick(Sender: TObject); procedure TForm1.GoBtnClick(Sender: TObject);
begin begin
LazarusOsrBrowserWindow1.Chromium.LoadURL(UTF8Decode(AddressEdt.Text)); OsrBrowserWindow1.Chromium.LoadURL(UTF8Decode(AddressEdt.Text));
end; end;
procedure TForm1.LazarusBrowserWindow1BrowserClosed(Sender: TObject); procedure TForm1.OsrBrowserWindow1BrowserClosed(Sender: TObject);
begin begin
Close; Close;
end; end;
procedure TForm1.LazarusOsrBrowserWindow1MouseMove(Sender: TObject; procedure TForm1.OsrBrowserWindow1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
var var
TempMsg : ICefProcessMessage; TempMsg : ICefProcessMessage;
@ -125,7 +125,7 @@ begin
TempMsg := TCefProcessMessageRef.New(MSG_REQUEST_DOM_R); // Same name than TCefCustomRenderProcessHandler.MessageName TempMsg := TCefProcessMessageRef.New(MSG_REQUEST_DOM_R); // Same name than TCefCustomRenderProcessHandler.MessageName
TempMsg.ArgumentList.SetInt(0, X); TempMsg.ArgumentList.SetInt(0, X);
TempMsg.ArgumentList.SetInt(1, Y); TempMsg.ArgumentList.SetInt(1, Y);
LazarusOsrBrowserWindow1.Chromium.SendProcessMessage(PID_RENDERER, TempMsg); OsrBrowserWindow1.Chromium.SendProcessMessage(PID_RENDERER, TempMsg);
end; end;
procedure TForm1.DoOnMouseDown(Sender: TObject; Button: TMouseButton; procedure TForm1.DoOnMouseDown(Sender: TObject; Button: TMouseButton;
@ -147,10 +147,10 @@ end;
procedure TForm1.DoOnPaint(Sender: TObject); procedure TForm1.DoOnPaint(Sender: TObject);
begin begin
if (FCurRect.Width > 0) and (FCurRect.Height > 0) then begin if (FCurRect.Width > 0) and (FCurRect.Height > 0) then begin
LazarusOsrBrowserWindow1.Canvas.Brush.Style := bsClear; OsrBrowserWindow1.Canvas.Brush.Style := bsClear;
LazarusOsrBrowserWindow1.Canvas.Pen.Style := psSolid; OsrBrowserWindow1.Canvas.Pen.Style := psSolid;
LazarusOsrBrowserWindow1.Canvas.Pen.Color := clRed; OsrBrowserWindow1.Canvas.Pen.Color := clRed;
LazarusOsrBrowserWindow1.Canvas.Rectangle(FCurRect); OsrBrowserWindow1.Canvas.Rectangle(FCurRect);
end; end;
end; end;
@ -167,7 +167,7 @@ begin
FCurRect.Width := message.ArgumentList.GetInt(2); FCurRect.Width := message.ArgumentList.GetInt(2);
FCurRect.Height := message.ArgumentList.GetInt(3); FCurRect.Height := message.ArgumentList.GetInt(3);
Result := True; Result := True;
LazarusOsrBrowserWindow1.Invalidate; OsrBrowserWindow1.Invalidate;
end; end;
end; end;
end; end;
@ -194,10 +194,10 @@ begin
if (GlobalCEFApp <> nil) then if (GlobalCEFApp <> nil) then
GlobalCEFApp.UpdateDeviceScaleFactor; GlobalCEFApp.UpdateDeviceScaleFactor;
if (LazarusOsrBrowserWindow1.Chromium <> nil) then if (OsrBrowserWindow1.Chromium <> nil) then
begin begin
LazarusOsrBrowserWindow1.Chromium.NotifyScreenInfoChanged; OsrBrowserWindow1.Chromium.NotifyScreenInfoChanged;
LazarusOsrBrowserWindow1.Chromium.WasResized; OsrBrowserWindow1.Chromium.WasResized;
end; end;
end; end;
@ -226,20 +226,20 @@ end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin begin
LazarusOsrBrowserWindow1.CloseBrowser(True); OsrBrowserWindow1.CloseBrowser(True);
CanClose := LazarusOsrBrowserWindow1.IsClosed; CanClose := OsrBrowserWindow1.IsClosed;
end; end;
procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject);
begin begin
FCurRect.Width := 0; FCurRect.Width := 0;
LazarusOsrBrowserWindow1.Chromium.OnProcessMessageReceived := @DoProcessMessageReceived; OsrBrowserWindow1.Chromium.OnProcessMessageReceived := @DoProcessMessageReceived;
LazarusOsrBrowserWindow1.OnMouseDown := @DoOnMouseDown; OsrBrowserWindow1.OnMouseDown := @DoOnMouseDown;
LazarusOsrBrowserWindow1.OnMouseUp := @DoOnMouseUp; OsrBrowserWindow1.OnMouseUp := @DoOnMouseUp;
LazarusOsrBrowserWindow1.OnPaint := @DoOnPaint; OsrBrowserWindow1.OnPaint := @DoOnPaint;
LazarusOsrBrowserWindow1.Chromium.LoadURL(UTF8Decode(AddressEdt.Text)); OsrBrowserWindow1.Chromium.LoadURL(UTF8Decode(AddressEdt.Text));
end; end;
initialization initialization

View File

@ -22,7 +22,7 @@
<Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/> <Description Value="CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi or Lazarus/FPC."/>
<License Value="MPL 1.1"/> <License Value="MPL 1.1"/>
<Version Major="89" Release="7"/> <Version Major="89" Release="7"/>
<Files Count="202"> <Files Count="201">
<Item1> <Item1>
<Filename Value="..\source\uCEFAccessibilityHandler.pas"/> <Filename Value="..\source\uCEFAccessibilityHandler.pas"/>
<UnitName Value="uCEFAccessibilityHandler"/> <UnitName Value="uCEFAccessibilityHandler"/>
@ -833,22 +833,18 @@
</Item198> </Item198>
<Item199> <Item199>
<Filename Value="..\source\uceflazaruscocoa.pas"/> <Filename Value="..\source\uceflazaruscocoa.pas"/>
<UnitName Value="uceflazaruscocoa"/> <UnitName Value="uCEFLazarusCocoa"/>
</Item199> </Item199>
<Item200> <Item200>
<Filename Value="..\source\uceflazarusbrowserwindow.pas"/> <Filename Value="..\source\uCEFBrowserWindow.pas"/>
<HasRegisterProc Value="True"/> <HasRegisterProc Value="True"/>
<UnitName Value="uceflazarusbrowserwindow"/> <UnitName Value="uCEFBrowserWindow"/>
</Item200> </Item200>
<Item201> <Item201>
<Filename Value="..\source\uCEFLazApplication.pas"/> <Filename Value="..\source\uCEFOsrBrowserWindow.pas"/>
<UnitName Value="uCEFLazApplication"/>
</Item201>
<Item202>
<Filename Value="..\source\uCEFLazarusOsrBrowserWindow.pas"/>
<HasRegisterProc Value="True"/> <HasRegisterProc Value="True"/>
<UnitName Value="uCEFLazarusOsrBrowserWindow"/> <UnitName Value="uCEFOsrBrowserWindow"/>
</Item202> </Item201>
</Files> </Files>
<CompatibilityMode Value="True"/> <CompatibilityMode Value="True"/>
<RequiredPkgs Count="5"> <RequiredPkgs Count="5">

View File

@ -66,8 +66,7 @@ uses
uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback, uCEFPrintDialogCallback, uCEFPrintHandler, uCEFPrintJobCallback,
uCEFLinuxFunctions, uCEFLinuxTypes, uCEFLinuxConstants, uCEFLinuxFunctions, uCEFLinuxTypes, uCEFLinuxConstants,
uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, uCEFLazarusCocoa, uCEFWorkSchedulerQueueThread, uCEFLinkedWinControlBase, uCEFLazarusCocoa,
uCEFLazarusBrowserWindow, uCEFLazApplication, uCEFLazarusOsrBrowserWindow, uCEFBrowserWindow, uCEFOsrBrowserWindow, LazarusPackageIntf;
LazarusPackageIntf;
implementation implementation
@ -90,9 +89,8 @@ begin
RegisterUnit('uCEFPanelComponent', @uCEFPanelComponent.Register); RegisterUnit('uCEFPanelComponent', @uCEFPanelComponent.Register);
RegisterUnit('uCEFScrollViewComponent', @uCEFScrollViewComponent.Register); RegisterUnit('uCEFScrollViewComponent', @uCEFScrollViewComponent.Register);
RegisterUnit('uCEFTextfieldComponent', @uCEFTextfieldComponent.Register); RegisterUnit('uCEFTextfieldComponent', @uCEFTextfieldComponent.Register);
RegisterUnit('uCEFLazarusBrowserWindow', @uCEFLazarusBrowserWindow.Register); RegisterUnit('uCEFBrowserWindow', @uCEFBrowserWindow.Register);
RegisterUnit('uCEFLazarusOsrBrowserWindow', RegisterUnit('uCEFOsrBrowserWindow', @uCEFOsrBrowserWindow.Register);
@uCEFLazarusOsrBrowserWindow.Register);
end; end;
initialization initialization

View File

@ -0,0 +1,38 @@
LazarusResources.Add('tlazarusbrowserwindow','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#2#0#0#0'o'#21#170#175
+#0#0#0#9'pHYs'#0#0#13#215#0#0#13#215#1'B('#155'x'#0#0#0#7'tIME'#7#226#5#11#10
+#31#18#187#205#226'X'#0#0#3#10'IDAT8'#203#173#149'Ml'#27'U'#16#199'g'#158'7'
+#222#197'Qk'#183'IIBl#'#156'JM'#12'V'#137#168#16'E *8Qn'#17' '#142#168#226
+#200#181#189'p'#228#128#212'['#213#3'\'#171#194#165'= TQ'#129'P'#131#26#138
+'d'#167#20'PE'#212'H'#9'_'#18'i'#226#218#241'G'#214'~'#187#222'}3'#195'a#w'
+#243'Q)'#144#206'i5o'#222'_3'#191#153'y'#139'"'#2#143#195','#215'u'#23#23#23
+#247#169'R,'#22#161'\.'#19#145#236#195#136#168'\.+"RJ'#237''''#29#165#20#17
+#237'I'#162'g'#246#192#232'Q'#7'k.\-'#223#191#241#253'M'#1#4#128#4#192#169
+#215'_}'#231#197#241#177#131#143#22'b'#230'm'#222'Oo5'#191#190'v'#205'NZ'#153
+'L'#26#5#1#128#133'ggg'#175'_'#15#222#255#224#204#187#147#187'4Z'#1#128#136
+'p'#204'.'#220'l^'#186#252#133#149't'#208'Jv'#180#239'j'#175#165#187#237#142
+'6'#146#224'D'#242#147#243#23#206']Y'#142#199'G'#3#180#153'Q'#127#154'j'#30
+#206#207#223'N$'#157#182#246#200#176#31#154#227#133#209#3#169#228'j'#203#183
+#5#6#149#12#165#7#239#222#254'a'#253#244'3'#135#156#205'+'#136#184')'#20'e'
+#20'y'#231#254#30'('#30'+'#212'j'#235'n'#167'{4w'#248#243#143#222'^m'#19#139
+'d3'#214#221#127#186':'#228#148'm'#245#180'k'#148'b'#14#251']'#3#0'+R!'#162
+#200'['#249'y!?>'#246#236'sS_~'#245#237#220#197'3'#31'_Y'#178#7#20'"z~xvfb'
+#249#129#7#28#218#142#179#244#231#253'L'#225'p'#31#144#136#168#168#180'X'#193
+'@l'#242#217#209#247'N'#191#242#203#239#27#141#166#214':'#208#186#215'r{'#183
+'~'#171#167#146#9'f'#16#129'-P'#153'w)'#141'X'#136#152#133#166'&'''#218#186
+'Wk{'#134#24#17'Z:'#232#6#6#128#1#0#1#12#131'!V'#24'+'#173#159'Q$'#20#132#20
+#24#177'mY'#217#8'_'#155#28'Zu'#189#7']'#31#1#12'K'#169#144#209#1'#'#2#3#244
+#136'@'#152#5#250#211'cE*}F'''#166#167#23#238'-'#140#28'9d)u'#227#158#251#217
+#135'/|sgMD'#222'x~'#196'0'#136#0' 4'#154#237'\6K'#180#209#135#205#204#219#25
+#189'<'#214#233't}'#207'7'#134#184#222#9#175#222'i'#13#13#165#237#212#224#210
+#154'oH'#16' 4'#208#236#132#25#232'lc'#180'} '#135#147#193'K'''#166'W'#170'u'
+#207#15'{'#129#17#162#229#170'n'#235#224#216'S'#131'!'#177#14#229#143#149'Zv'
+'|'#212#134'`'#247#129#140'o'#201'['#185#134#147'(}'#247#227#175#169''''#236
+'t'#250'`h'#248#228#241#225#182'G'#213'zk'#221#13#158#206#231'rV3'#190'T'#15
+#187#22'g'#20#217#169#145'F'#241#205#137#185'j'#166'2'#255#211#147#233#129
+#191'V'#209#13'h'#234'h'#225#228#145#214#1#171#190'5v'#171#208#206#189#29#182
+'{3'#249#234'L>'#23#243'U'#1'`G <d'#244'x'#222#236' '#8#148'R'#142#227#252'o'
+#9'D'#212'Zc'#163#209#168'T*'#158#231#25'c'#254#235#31#5#17#17#209'q'#156'R'
+#169#132#241#203';I'#237#229#193#142'>'#254#5'Ixq'#26'FW'#221'b'#0#0#0#0'IEN'
+'D'#174'B`'#130
]);

View File

@ -60,7 +60,11 @@ uses
{$ENDIF} {$ENDIF}
System.Classes, System.UITypes, System.Classes, System.UITypes,
{$ELSE} {$ELSE}
{$IFDEF MSWINDOWS}Windows, Forms, ActiveX,{$ENDIF} Classes, Controls, {$IFDEF FPC}dynlibs,{$ENDIF} Forms,
{$IFDEF MSWINDOWS}Windows, ActiveX,{$ENDIF} Classes, Controls, {$IFDEF FPC}dynlibs,{$ENDIF}
{$ENDIF}
{$IFDEF FPC}
LCLProc,
{$ENDIF} {$ENDIF}
uCEFApplicationCore, uCEFTypes; uCEFApplicationCore, uCEFTypes;
@ -83,6 +87,12 @@ type
protected protected
FDestroyApplicationObject : boolean; FDestroyApplicationObject : boolean;
FDestroyAppWindows : boolean; FDestroyAppWindows : boolean;
{$IFDEF FPC}
FContextInitializedHandlers: TMethodList;
FContextInitializedDone: Boolean;
procedure CallContextInitializedHandlers(Data: PtrInt);
{$ENDIF}
procedure BeforeInitSubProcess; override; procedure BeforeInitSubProcess; override;
@ -93,6 +103,13 @@ type
property DestroyApplicationObject: boolean read FDestroyApplicationObject write FDestroyApplicationObject; property DestroyApplicationObject: boolean read FDestroyApplicationObject write FDestroyApplicationObject;
property DestroyAppWindows : boolean read FDestroyAppWindows write FDestroyAppWindows; property DestroyAppWindows : boolean read FDestroyAppWindows write FDestroyAppWindows;
{$IFDEF FPC}
procedure Internal_OnContextInitialized; override; // In UI thread
Procedure AddContextInitializedHandler(AHandler: TNotifyEvent);
Procedure RemoveContextInitializedHandler(AHandler: TNotifyEvent);
{$ENDIF}
end; end;
TCEFDirectoryDeleterThread = uCEFApplicationCore.TCEFDirectoryDeleterThread; TCEFDirectoryDeleterThread = uCEFApplicationCore.TCEFDirectoryDeleterThread;
@ -187,6 +204,10 @@ end;
constructor TCefApplication.Create; constructor TCefApplication.Create;
begin begin
{$IFDEF FPC}
FContextInitializedHandlers := TMethodList.Create;
{$ENDIF}
inherited Create; inherited Create;
if GlobalCEFApp = nil then if GlobalCEFApp = nil then
GlobalCEFApp := Self; GlobalCEFApp := Self;
@ -200,6 +221,10 @@ begin
if GlobalCEFApp = Self then if GlobalCEFApp = Self then
GlobalCEFApp := nil; GlobalCEFApp := nil;
inherited Destroy; inherited Destroy;
{$IFDEF FPC}
FContextInitializedHandlers.Free;
{$ENDIF}
end; end;
procedure TCefApplication.UpdateDeviceScaleFactor; procedure TCefApplication.UpdateDeviceScaleFactor;
@ -238,6 +263,34 @@ begin
{$ENDIF} {$ENDIF}
end; end;
{$IFDEF FPC}
procedure TCefApplication.Internal_OnContextInitialized;
begin
inherited Internal_OnContextInitialized;
Application.QueueAsyncCall(@CallContextInitializedHandlers, 0);
end;
procedure TCefApplication.AddContextInitializedHandler(AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Add(TMethod(AHandler));
if FContextInitializedDone then
AHandler(Self);
end;
procedure TCefApplication.RemoveContextInitializedHandler(AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Remove(TMethod(AHandler));
end;
{$ENDIF}
{$IFDEF FPC}
procedure TCefApplication.CallContextInitializedHandlers(Data: PtrInt);
begin
FContextInitializedHandlers.CallNotifyEvents(Self);
FContextInitializedDone := True;
end;
{$ENDIF}
procedure TCefApplication.BeforeInitSubProcess; procedure TCefApplication.BeforeInitSubProcess;
{$IFNDEF FPC} {$IFNDEF FPC}
{$IFNDEF FMX} {$IFNDEF FMX}

View File

@ -35,7 +35,7 @@
* *
*) *)
unit uCEFLazarusBrowserWindow; unit uCEFBrowserWindow;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{$i cef.inc} {$i cef.inc}
@ -47,7 +47,7 @@ uses
LResources, PropEdits, LResources, PropEdits,
{$ENDIF} {$ENDIF}
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium, uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBrowserViewComponent, uCEFLinkedWinControlBase, uCEFBrowserViewComponent,
uCEFChromiumEvents, Forms, ExtCtrls, Controls, Classes, sysutils; uCEFChromiumEvents, Forms, ExtCtrls, Controls, Classes, sysutils;
type type
@ -57,14 +57,26 @@ type
only close once that event was finished. only close once that event was finished.
*) *)
{ TLazChromium } { TEmbeddedChromium
TLazChromium = class(TChromium) 1) TEmbeddedChromium keeps track of the browser while it is created.
This allows for CloseBrowser to function, even if the Browser object is not
yet known.
Also calls to "LoadUrl" are cached until the browser object is created.
2) TEmbeddedChromium adds InternalEvents that can be hooked by the
component that owns the TEmbeddedChromium.
This means the default published events are available to the end user.
Published events that should not be available are hidden via THiddenPropertyEditor
* Hidden event properties must not be assigned by any end user code. *
}
TEmbeddedChromium = class(TChromium)
private type private type
TLazChromiumState = (csNoBrowser, csCreatingBrowser, csHasBrowser, csClosingBrowser, csCloseAfterCreate); TChromiumBrowserState = (csNoBrowser, csCreatingBrowser, csHasBrowser, csClosingBrowser, csCloseAfterCreate);
private private
FInternalOnGotFocus: TOnGotFocus; FInternalOnGotFocus: TOnGotFocus;
FState : TLazChromiumState; FState : TChromiumBrowserState;
FInternalOnBrowserClosed : TNotifyEvent; FInternalOnBrowserClosed : TNotifyEvent;
FInternalOnBrowserCreated : TNotifyEvent; FInternalOnBrowserCreated : TNotifyEvent;
@ -108,7 +120,8 @@ type
property HasBrowser: Boolean read GetHasBrowser; // Includes browser in creation property HasBrowser: Boolean read GetHasBrowser; // Includes browser in creation
property IsClosing : Boolean read GetIsClosing; property IsClosing : Boolean read GetIsClosing;
(* - Events to be called in main thread (* - Events for use by the Owning component ONLY
- Events are called in main thread
- OnBrowserCreated: the parent event may be called when procedure Initialized is still false. - OnBrowserCreated: the parent event may be called when procedure Initialized is still false.
- OnBrowserCreated: may not be called, if the CloseBrowser has already been called - OnBrowserCreated: may not be called, if the CloseBrowser has already been called
*) *)
@ -117,7 +130,7 @@ type
property InternalOnGotFocus : TOnGotFocus read FInternalOnGotFocus write FInternalOnGotFocus; property InternalOnGotFocus : TOnGotFocus read FInternalOnGotFocus write FInternalOnGotFocus;
end; end;
TLazarusBrowserWindow = class; TBrowserWindow = class;
{ TChromiumWrapper } { TChromiumWrapper }
@ -125,9 +138,9 @@ type
protected type protected type
TWrapperState = (wsNone, wsWaitingForClose, wsSentCloseEventAfterWait, wsDestroyAfterWait); TWrapperState = (wsNone, wsWaitingForClose, wsSentCloseEventAfterWait, wsDestroyAfterWait);
protected protected
FChromium : TLazChromium; FChromium : TEmbeddedChromium;
FWrapperState : TWrapperState; FWrapperState : TWrapperState;
FBrowserWindow : TLazarusBrowserWindow; FBrowserWindow : TBrowserWindow;
procedure DoOnAfterCreated(Sender: TObject); procedure DoOnAfterCreated(Sender: TObject);
procedure DoOnBeforeClose(Sender: TObject); procedure DoOnBeforeClose(Sender: TObject);
@ -139,7 +152,7 @@ type
procedure MaybeDestroy; procedure MaybeDestroy;
public public
constructor Create(AOwner: TLazarusBrowserWindow); reintroduce; constructor Create(AOwner: TBrowserWindow); reintroduce;
destructor Destroy; override; destructor Destroy; override;
function CreateBrowser: boolean; function CreateBrowser: boolean;
@ -147,23 +160,64 @@ type
procedure CloseBrowser(aForceClose: boolean); procedure CloseBrowser(aForceClose: boolean);
function IsClosed: boolean; function IsClosed: boolean;
(* WaitForBrowserClosed calls ProcessMessages. (* WaitForBrowserClosed calls ProcessMessages.
It therefore is possible that the TLazarusBrowserWindow will be destroyed It therefore is possible that the TBrowserWindow will be destroyed
when this method returns. when this method returns.
It is the callers responsibility to take any necessary precaution. It is the callers responsibility to take any necessary precaution.
*) *)
procedure WaitForBrowserClosed; procedure WaitForBrowserClosed;
published published
property Chromium: TLazChromium read FChromium; property Chromium: TEmbeddedChromium read FChromium;
end; end;
{ TLazarusBrowserWindow } { TBrowserWindow
(* On MacOs TLazarusBrowserWindow must wait for OnBrowserClosed before it can A simple "drop on the Form" component for an full embedded browser.
be destroyed or before its handle can be closed
*)
TLazarusBrowserWindow = class(TCEFLinkedWinControlBase) The component handles most events required by CEF.
The only additions needed to be made by the User in their code are:
* Implement TForm.OnCloseQuery
CEF must be able to destroy the browser, before the main form is closed.
(That is while the Form still has a Handle, and the event loop is still
running)
It is adviced to do the same for any other form (other than the main form).
TForm.OnCloseQuery should call (for each TBrowserWindow)
TBrowserWindow.CloseBrowser(True);
The Form can be allowed to close by setting (checking for all BrowserWindows)
CanClose := BrowserWindow.IsClosed;
On Windows and Linux it is also possible to Destroy the TBrowserWindow.
This will wait for the browser to close, and after that the form can be closed.
- However, this must be done in OnCloseQuery (or before).
- Once TForm.Destroy is called, it is to late. By that time the event loop
no longer runs.
*** IMPORTANT: (MacOS) ***
On MacOs CloseBrowser() must be called, and the *event* must be awaited.
Neither destroying the component, nor waiting with App.ProcessMessages will
work.
On MacOS, CEF will not finish until the OnCloseQuery event returned to the
main event loop. (Hence ProcessMessage does not work).
The same is true for any action taken in OnClick or other event.
CEF always waits for any event to return to the main event loop.
See also the BrowserWindowEX example how that affect modal forms.
* Implement TBrowserWindow.OnBrowserClosed
If TForm.OnCloseQuery called CloseBrowser, this callback can be used to
call Form.Close again (the callback should check if the browser was
closed by OnCloseQuery.
* On Windows:
handle the WM_ENTERMENULOOP and WM_EXITMENULOOP, as shown in examples
* Optional prevent pop-up windows by implementing
Chromium.BeforePopup
Chromium.OpenUrlFromTab
}
TBrowserWindow = class(TCEFLinkedWinControlBase)
private private
FChromiumWrapper : TChromiumWrapper; FChromiumWrapper : TChromiumWrapper;
@ -173,7 +227,7 @@ type
procedure DoCreateBrowser(Sender: TObject); procedure DoCreateBrowser(Sender: TObject);
procedure DoCreateBrowserAfterContext(Sender: TObject); procedure DoCreateBrowserAfterContext(Sender: TObject);
function GetLazChromium: TLazChromium; function GetEmbeddedChromium: TEmbeddedChromium;
protected protected
function GetChromium: TChromium; override; function GetChromium: TChromium; override;
procedure DestroyHandle; override; procedure DestroyHandle; override;
@ -195,10 +249,10 @@ type
procedure LoadURL(aURL: ustring); procedure LoadURL(aURL: ustring);
published published
property Chromium: TLazChromium read GetLazChromium; property Chromium: TEmbeddedChromium read GetEmbeddedChromium;
property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated; property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated;
(* OnBrowserClosed will not be called, if the TLazarusBrowserWindow is (* OnBrowserClosed will not be called, if the TBrowserWindow is
destroyed/destroying before the browser is closed. destroyed/destroying before the browser is closed.
*) *)
property OnBrowserClosed : TNotifyEvent read FOnBrowserClosed write FOnBrowserClosed; property OnBrowserClosed : TNotifyEvent read FOnBrowserClosed write FOnBrowserClosed;
@ -210,24 +264,24 @@ procedure Register;
implementation implementation
{ TLazChromium } { TEmbeddedChromium }
function TLazChromium.GetIsClosing: Boolean; function TEmbeddedChromium.GetIsClosing: Boolean;
begin begin
Result := FState in [csCloseAfterCreate, csClosingBrowser]; Result := FState in [csCloseAfterCreate, csClosingBrowser];
end; end;
procedure TLazChromium.SetInternalOnClose(AValue: TOnClose); procedure TEmbeddedChromium.SetInternalOnClose(AValue: TOnClose);
begin begin
inherited OnClose := AValue; inherited OnClose := AValue;
end; end;
function TLazChromium.GetHasBrowser: boolean; function TEmbeddedChromium.GetHasBrowser: boolean;
begin begin
Result := (FState <> csNoBrowser) or (inherited GetHasBrowser); Result := (FState <> csNoBrowser) or (inherited GetHasBrowser);
end; end;
procedure TLazChromium.doOnBeforeClose(const ABrowser: ICefBrowser); procedure TEmbeddedChromium.doOnBeforeClose(const ABrowser: ICefBrowser);
begin begin
inherited doOnBeforeClose(ABrowser); inherited doOnBeforeClose(ABrowser);
@ -235,7 +289,7 @@ begin
Application.QueueAsyncCall(@DoOnClosed, 0); Application.QueueAsyncCall(@DoOnClosed, 0);
end; end;
procedure TLazChromium.doOnAfterCreated(const ABrowser: ICefBrowser); procedure TEmbeddedChromium.doOnAfterCreated(const ABrowser: ICefBrowser);
begin begin
inherited doOnAfterCreated(ABrowser); inherited doOnAfterCreated(ABrowser);
(* We may still be in Chromium.CreateBrowserSync (* We may still be in Chromium.CreateBrowserSync
@ -245,20 +299,20 @@ begin
Application.QueueAsyncCall(@DoCreated, 0); Application.QueueAsyncCall(@DoCreated, 0);
end; end;
procedure TLazChromium.doOnGotFocus(const Abrowser: ICefBrowser); procedure TEmbeddedChromium.doOnGotFocus(const Abrowser: ICefBrowser);
begin begin
inherited doOnGotFocus(Abrowser); inherited doOnGotFocus(Abrowser);
if Assigned(FInternalOnGotFocus) then if Assigned(FInternalOnGotFocus) then
FInternalOnGotFocus(Self, Abrowser); FInternalOnGotFocus(Self, Abrowser);
end; end;
function TLazChromium.MustCreateFocusHandler: boolean; function TEmbeddedChromium.MustCreateFocusHandler: boolean;
begin begin
Result := assigned(FInternalOnGotFocus) or Result := assigned(FInternalOnGotFocus) or
inherited MustCreateFocusHandler; inherited MustCreateFocusHandler;
end; end;
procedure TLazChromium.DoCreated(Data: PtrInt); procedure TEmbeddedChromium.DoCreated(Data: PtrInt);
var var
u, f: ustring; u, f: ustring;
begin begin
@ -282,25 +336,27 @@ begin
end; end;
end; end;
procedure TLazChromium.DoOnClosed(Data: PtrInt); procedure TEmbeddedChromium.DoOnClosed(Data: PtrInt);
begin begin
if (FInternalOnBrowserClosed <> nil) then if (FInternalOnBrowserClosed <> nil) then
FInternalOnBrowserClosed(Self); FInternalOnBrowserClosed(Self);
end; end;
constructor TLazChromium.Create(AOwner: TComponent); constructor TEmbeddedChromium.Create(AOwner: TComponent);
begin begin
FState := csNoBrowser; FState := csNoBrowser;
inherited Create(AOwner); inherited Create(AOwner);
SetSubComponent(True);
Name := 'Chromium';
end; end;
destructor TLazChromium.Destroy; destructor TEmbeddedChromium.Destroy;
begin begin
inherited Destroy; inherited Destroy;
Application.RemoveAsyncCalls(Self); Application.RemoveAsyncCalls(Self);
end; end;
function TLazChromium.CreateBrowser(const aBrowserParent: TWinControl; function TEmbeddedChromium.CreateBrowser(const aBrowserParent: TWinControl;
const aWindowName: ustring; const aContext: ICefRequestContext; const aWindowName: ustring; const aContext: ICefRequestContext;
const aExtraInfo: ICefDictionaryValue): boolean; const aExtraInfo: ICefDictionaryValue): boolean;
begin begin
@ -311,7 +367,7 @@ begin
DoCreated(0); DoCreated(0);
end; end;
function TLazChromium.CreateBrowser(aParentHandle: TCefWindowHandle; function TEmbeddedChromium.CreateBrowser(aParentHandle: TCefWindowHandle;
aParentRect: TRect; const aWindowName: ustring; aParentRect: TRect; const aWindowName: ustring;
const aContext: ICefRequestContext; const aExtraInfo: ICefDictionaryValue): boolean; const aContext: ICefRequestContext; const aExtraInfo: ICefDictionaryValue): boolean;
begin begin
@ -322,7 +378,7 @@ begin
DoCreated(0); DoCreated(0);
end; end;
procedure TLazChromium.CreateBrowser(const aWindowName: ustring); procedure TEmbeddedChromium.CreateBrowser(const aWindowName: ustring);
begin begin
FState := csCreatingBrowser; FState := csCreatingBrowser;
inherited CreateBrowser(aWindowName); inherited CreateBrowser(aWindowName);
@ -330,7 +386,7 @@ begin
DoCreated(0); DoCreated(0);
end; end;
function TLazChromium.CreateBrowser(const aURL: ustring; function TEmbeddedChromium.CreateBrowser(const aURL: ustring;
const aBrowserViewComp: TCEFBrowserViewComponent; const aBrowserViewComp: TCEFBrowserViewComponent;
const aContext: ICefRequestContext; const aExtraInfo: ICefDictionaryValue const aContext: ICefRequestContext; const aExtraInfo: ICefDictionaryValue
): boolean; ): boolean;
@ -341,7 +397,7 @@ begin
DoCreated(0); DoCreated(0);
end; end;
procedure TLazChromium.CloseBrowser(aForceClose: boolean); procedure TEmbeddedChromium.CloseBrowser(aForceClose: boolean);
begin begin
if FState = csCreatingBrowser then begin if FState = csCreatingBrowser then begin
FState := csCloseAfterCreate; FState := csCloseAfterCreate;
@ -355,7 +411,7 @@ begin
end; end;
end; end;
procedure TLazChromium.LoadURL(const aURL: ustring; const aFrameName: ustring); procedure TEmbeddedChromium.LoadURL(const aURL: ustring; const aFrameName: ustring);
begin begin
FLoadUrl := ''; FLoadUrl := '';
FFrameName := ''; FFrameName := '';
@ -410,6 +466,8 @@ end;
procedure TChromiumWrapper.MaybeDestroy; procedure TChromiumWrapper.MaybeDestroy;
begin begin
if FChromium.Owner <> nil then
FBrowserWindow.RemoveComponent(FChromium);
CloseBrowser(True); CloseBrowser(True);
FBrowserWindow := nil; FBrowserWindow := nil;
@ -420,12 +478,12 @@ begin
Destroy; Destroy;
end; end;
constructor TChromiumWrapper.Create(AOwner: TLazarusBrowserWindow); constructor TChromiumWrapper.Create(AOwner: TBrowserWindow);
begin begin
FBrowserWindow := AOwner; FBrowserWindow := AOwner;
FWrapperState := wsNone; FWrapperState := wsNone;
FChromium := TLazChromium.Create(nil); FChromium := TEmbeddedChromium.Create(AOwner);
if not(csDesigning in AOwner.ComponentState) then if not(csDesigning in AOwner.ComponentState) then
begin begin
FChromium.OnClose := {$IFDEF FPC}@{$ENDIF}BrowserThread_OnClose; FChromium.OnClose := {$IFDEF FPC}@{$ENDIF}BrowserThread_OnClose;
@ -498,9 +556,9 @@ begin
FWrapperState := wsNone; FWrapperState := wsNone;
end; end;
{ TLazarusBrowserWindow } { TBrowserWindow }
procedure TLazarusBrowserWindow.DoCreateBrowser(Sender: TObject); procedure TBrowserWindow.DoCreateBrowser(Sender: TObject);
begin begin
if FTimer <> nil then if FTimer <> nil then
FTimer.Enabled := False; FTimer.Enabled := False;
@ -531,7 +589,7 @@ begin
end; end;
end; end;
procedure TLazarusBrowserWindow.DoCreateBrowserAfterContext(Sender: TObject); procedure TBrowserWindow.DoCreateBrowserAfterContext(Sender: TObject);
begin begin
{$IFnDEF WINDOWS} {$IFnDEF WINDOWS}
FTimer := TTimer.Create(Self); FTimer := TTimer.Create(Self);
@ -543,17 +601,17 @@ begin
{$ENDIF} {$ENDIF}
end; end;
function TLazarusBrowserWindow.GetLazChromium: TLazChromium; function TBrowserWindow.GetEmbeddedChromium: TEmbeddedChromium;
begin begin
Result := FChromiumWrapper.Chromium; Result := FChromiumWrapper.Chromium;
end; end;
function TLazarusBrowserWindow.GetChromium: TChromium; function TBrowserWindow.GetChromium: TChromium;
begin begin
Result := FChromiumWrapper.FChromium; Result := FChromiumWrapper.FChromium;
end; end;
procedure TLazarusBrowserWindow.CreateHandle; procedure TBrowserWindow.CreateHandle;
begin begin
inherited CreateHandle; inherited CreateHandle;
if not (csDesigning in ComponentState) then begin if not (csDesigning in ComponentState) then begin
@ -561,14 +619,11 @@ begin
But at least on Linux, we need to wait But at least on Linux, we need to wait
*) *)
if GlobalCEFApp is TCefLazApplication then GlobalCEFApp.AddContextInitializedHandler(@DoCreateBrowserAfterContext);
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
else
DoCreateBrowserAfterContext(nil);
end; end;
end; end;
procedure TLazarusBrowserWindow.DestroyHandle; procedure TBrowserWindow.DestroyHandle;
begin begin
if FTimer <> nil then if FTimer <> nil then
FreeAndNil(FTimer); FreeAndNil(FTimer);
@ -590,7 +645,7 @@ begin
{$ENDIF} {$ENDIF}
end; end;
procedure TLazarusBrowserWindow.RealizeBounds; procedure TBrowserWindow.RealizeBounds;
begin begin
inherited RealizeBounds; inherited RealizeBounds;
@ -598,20 +653,20 @@ begin
Chromium.NotifyMoveOrResizeStarted; Chromium.NotifyMoveOrResizeStarted;
end; end;
procedure TLazarusBrowserWindow.DoEnter; procedure TBrowserWindow.DoEnter;
begin begin
inherited DoEnter; inherited DoEnter;
If not(csDesigning in ComponentState) then Chromium.SetFocus(True); If not(csDesigning in ComponentState) then Chromium.SetFocus(True);
end; end;
procedure TLazarusBrowserWindow.DoExit; procedure TBrowserWindow.DoExit;
begin begin
inherited DoExit; inherited DoExit;
if not(csDesigning in ComponentState) then if not(csDesigning in ComponentState) then
Chromium.SendCaptureLostEvent; Chromium.SendCaptureLostEvent;
end; end;
procedure TLazarusBrowserWindow.DoOnCreated; procedure TBrowserWindow.DoOnCreated;
begin begin
{$IFDEF FPC}{$IFDEF LINUX} {$IFDEF FPC}{$IFDEF LINUX}
Chromium.UpdateXWindowVisibility(Visible); Chromium.UpdateXWindowVisibility(Visible);
@ -621,7 +676,7 @@ begin
FOnBrowserCreated(Self); FOnBrowserCreated(Self);
end; end;
procedure TLazarusBrowserWindow.DoOnClosed(Data: PtrInt); procedure TBrowserWindow.DoOnClosed(Data: PtrInt);
begin begin
if (not(csDestroying in ComponentState)) and if (not(csDestroying in ComponentState)) and
Assigned(FOnBrowserClosed) Assigned(FOnBrowserClosed)
@ -629,40 +684,42 @@ begin
FOnBrowserClosed(Self); FOnBrowserClosed(Self);
end; end;
procedure TLazarusBrowserWindow.DoOnFocus(Data: PtrInt); procedure TBrowserWindow.DoOnFocus(Data: PtrInt);
begin begin
SetFocus; SetFocus;
end; end;
constructor TLazarusBrowserWindow.Create(AOwner: TComponent); constructor TBrowserWindow.Create(AOwner: TComponent);
begin begin
FChromiumWrapper := TChromiumWrapper.Create(Self); FChromiumWrapper := TChromiumWrapper.Create(Self);
inherited Create(AOwner); inherited Create(AOwner);
ControlStyle := ControlStyle + [csOwnedChildrenNotSelectable];
end; end;
destructor TLazarusBrowserWindow.Destroy; destructor TBrowserWindow.Destroy;
begin begin
RemoveComponent(FChromiumWrapper.FChromium);
inherited Destroy; inherited Destroy;
FChromiumWrapper.MaybeDestroy; FChromiumWrapper.MaybeDestroy;
Application.RemoveAsyncCalls(Self); Application.RemoveAsyncCalls(Self);
end; end;
procedure TLazarusBrowserWindow.CloseBrowser(aForceClose: boolean); procedure TBrowserWindow.CloseBrowser(aForceClose: boolean);
begin begin
FChromiumWrapper.CloseBrowser(aForceClose); FChromiumWrapper.CloseBrowser(aForceClose);
end; end;
procedure TLazarusBrowserWindow.WaitForBrowserClosed; procedure TBrowserWindow.WaitForBrowserClosed;
begin begin
FChromiumWrapper.WaitForBrowserClosed; FChromiumWrapper.WaitForBrowserClosed;
end; end;
function TLazarusBrowserWindow.IsClosed: boolean; function TBrowserWindow.IsClosed: boolean;
begin begin
Result := FChromiumWrapper.IsClosed; Result := FChromiumWrapper.IsClosed;
end; end;
procedure TLazarusBrowserWindow.LoadURL(aURL: ustring); procedure TBrowserWindow.LoadURL(aURL: ustring);
begin begin
FChromiumWrapper.LoadURL(aURL); FChromiumWrapper.LoadURL(aURL);
end; end;
@ -671,10 +728,10 @@ end;
procedure Register; procedure Register;
begin begin
{$I res/tlazarusbrowserwindow.lrs} {$I res/TBrowserWindow.lrs}
RegisterComponents('Chromium', [TLazarusBrowserWindow]); RegisterComponents('Chromium', [TBrowserWindow]);
RegisterPropertyEditor(ClassTypeInfo(TLazChromium), nil,'',TClassPropertyEditor); RegisterClass(TEmbeddedChromium);
RegisterPropertyEditor(TypeInfo(TOnClose), TLazChromium, 'OnClose', THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnClose), TEmbeddedChromium, 'OnClose', THiddenPropertyEditor);
end; end;
{$ENDIF} {$ENDIF}

View File

@ -1,80 +0,0 @@
unit uCEFLazApplication;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$I cef.inc}
interface
uses
{$IFDEF DELPHI16_UP}
{$ELSE}
Forms, LclProc, Classes, SysUtils,
{$ENDIF}
uCEFTypes, uCEFApplication;
type
{ TCefLazApplication }
TCefLazApplication = class(TCefApplication)
protected
FContextInitializedHandlers: TMethodList;
FContextInitializedDone: Boolean;
procedure CallContextInitializedHandlers(Data: PtrInt);
public
constructor Create;
destructor Destroy; override;
procedure Internal_OnContextInitialized; override; // In UI thread
Procedure AddContextInitializedHandler(AHandler: TNotifyEvent);
Procedure RemoveContextInitializedHandler(AHandler: TNotifyEvent);
end;
implementation
{ TCefLazApplication }
procedure TCefLazApplication.Internal_OnContextInitialized;
begin
inherited Internal_OnContextInitialized;
Application.QueueAsyncCall(@CallContextInitializedHandlers, 0);
//TThread.Queue(@CallContextInitializedHandlers);
end;
procedure TCefLazApplication.CallContextInitializedHandlers(Data: PtrInt);
begin
FContextInitializedHandlers.CallNotifyEvents(Self);
FContextInitializedDone := True;
end;
constructor TCefLazApplication.Create;
begin
FContextInitializedHandlers := TMethodList.Create;
inherited Create;
end;
destructor TCefLazApplication.Destroy;
begin
inherited Destroy;
FContextInitializedHandlers.Free;
end;
procedure TCefLazApplication.AddContextInitializedHandler(AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Add(TMethod(AHandler));
if FContextInitializedDone then
AHandler(Self);
end;
procedure TCefLazApplication.RemoveContextInitializedHandler(
AHandler: TNotifyEvent);
begin
FContextInitializedHandlers.Remove(TMethod(AHandler));
end;
end.

View File

@ -44,7 +44,7 @@
*) *)
unit uCEFLazarusOsrBrowserWindow; unit uCEFOsrBrowserWindow;
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{$i cef.inc} {$i cef.inc}
@ -52,15 +52,17 @@ unit uCEFLazarusOsrBrowserWindow;
interface interface
uses uses
{$IFDEF DARWIN} // $IFDEF MACOSX
uCEFLazarusCocoa, uCEFLazarusCocoa,
{$ENDIF}
{$IFDEF FPC} {$IFDEF FPC}
LResources, PropEdits, LResources, PropEdits,
{$ENDIF} {$ENDIF}
uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium, uCEFApplication, uCEFChromiumWindow, uCEFTypes, uCEFInterfaces, uCEFChromium,
uCEFLinkedWinControlBase, uCEFLazApplication, uCEFBufferPanel, uCEFLinkedWinControlBase, uCEFBufferPanel,
uCEFLazarusBrowserWindow, uCEFBitmapBitBuffer, uCEFMiscFunctions, uCEFBrowserWindow, uCEFBitmapBitBuffer, uCEFMiscFunctions,
uCEFConstants, uCEFChromiumEvents, Forms, ExtCtrls, LCLType, Graphics, uCEFConstants, uCEFChromiumEvents, Forms, ExtCtrls, LCLType, Graphics,
Controls, syncobjs, LazLogger, Classes, sysutils, math; Controls, syncobjs, Classes, sysutils, math;
type type
@ -77,13 +79,31 @@ type
//TBrowserKeyPressEvent = procedure(Sender: TObject; var Key: char; var AHandled: Boolean) of Object; //TBrowserKeyPressEvent = procedure(Sender: TObject; var Key: char; var AHandled: Boolean) of Object;
TBrowserUTF8KeyPressEvent = procedure(Sender: TObject; var UTF8Key: TUTF8Char; var AHandled: Boolean) of Object; TBrowserUTF8KeyPressEvent = procedure(Sender: TObject; var UTF8Key: TUTF8Char; var AHandled: Boolean) of Object;
(* TEmbeddedOsrChromium
TLazOsrChromium = class(TLazChromium) Hides (THiddenPropertyEditor) any published event that is used by TOsrBrowserWindow
* Hidden events must also not be used by user code *
*)
TEmbeddedOsrChromium = class(TEmbeddedChromium)
end; end;
{ TLazarusOsrBrowserWindow } { TOsrBrowserWindow - Off-Screen-Rendering
TLazarusOsrBrowserWindow = class(TBufferPanel) A simple "drop on the Form" component for an full embedded browser.
See notes an TBrowserWindow for requirements in user code.
Further:
- Some keystrokes may not be sent to KeyDown/KeyPress by the LCL.
They may be available as WM_SYSKEYDOWN/UP message on the containing Form.
This component is still experimental.
- On MacOS Keyboard support is not complete
}
TOsrBrowserWindow = class(TBufferPanel)
private private
FPopUpBitmap : TBitmap; FPopUpBitmap : TBitmap;
FPopUpRect : TRect; FPopUpRect : TRect;
@ -136,7 +156,7 @@ type
AHeight: Integer); AHeight: Integer);
private private
FChromium : TLazOsrChromium; FChromium : TEmbeddedOsrChromium;
FOnBrowserClosed : TNotifyEvent; FOnBrowserClosed : TNotifyEvent;
FOnBrowserCreated : TNotifyEvent; FOnBrowserCreated : TNotifyEvent;
@ -151,7 +171,7 @@ type
procedure DoCreateBrowserAfterContext(Sender: TObject); procedure DoCreateBrowserAfterContext(Sender: TObject);
protected protected
function GetChromium: TLazOsrChromium; function GetChromium: TEmbeddedOsrChromium;
function getModifiers(Shift: TShiftState): TCefEventFlags; function getModifiers(Shift: TShiftState): TCefEventFlags;
function getKeyModifiers(Shift: TShiftState): TCefEventFlags; function getKeyModifiers(Shift: TShiftState): TCefEventFlags;
function GetButton(Button: TMouseButton): TCefMouseButtonType; function GetButton(Button: TMouseButton): TCefMouseButtonType;
@ -193,11 +213,16 @@ type
procedure LoadURL(aURL: ustring); procedure LoadURL(aURL: ustring);
// //
published published
property Chromium : TLazOsrChromium read GetChromium; property Chromium : TEmbeddedOsrChromium read GetChromium;
property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated; property OnBrowserCreated : TNotifyEvent read FOnBrowserCreated write FOnBrowserCreated;
property OnBrowserClosed : TNotifyEvent read FOnBrowserClosed write FOnBrowserClosed; property OnBrowserClosed : TNotifyEvent read FOnBrowserClosed write FOnBrowserClosed;
(* Mouse/Key events
The below events can be used to see mouse/key input before it is sent to CEF.
All events have a "AHandled" parameter, which can be used to prevent the event
from being sent to CEF.
*)
property OnMouseDown: TBrowserMouseEvent read FOnMouseDown write FOnMouseDown; property OnMouseDown: TBrowserMouseEvent read FOnMouseDown write FOnMouseDown;
property OnMouseUp: TBrowserMouseEvent read FOnMouseUp write FOnMouseUp; property OnMouseUp: TBrowserMouseEvent read FOnMouseUp write FOnMouseUp;
property OnMouseMove: TBrowserMouseMoveEvent read FOnMouseMove write FOnMouseMove; property OnMouseMove: TBrowserMouseMoveEvent read FOnMouseMove write FOnMouseMove;
@ -214,14 +239,14 @@ procedure Register;
implementation implementation
{ TLazarusOsrBrowserWindow } { TOsrBrowserWindow }
procedure TLazarusOsrBrowserWindow.AsyncInvalidate(Data: PtrInt); procedure TOsrBrowserWindow.AsyncInvalidate(Data: PtrInt);
begin begin
Invalidate; Invalidate;
end; end;
procedure TLazarusOsrBrowserWindow.AsyncResize(Data: PtrInt); procedure TOsrBrowserWindow.AsyncResize(Data: PtrInt);
begin begin
try try
FResizeCS.Acquire; FResizeCS.Acquire;
@ -241,12 +266,12 @@ begin
end; end;
end; end;
procedure TLazarusOsrBrowserWindow.SyncIMERangeChanged; procedure TOsrBrowserWindow.SyncIMERangeChanged;
begin begin
ChangeCompositionRange(FSelectedRange, FDeviceBounds); ChangeCompositionRange(FSelectedRange, FDeviceBounds);
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumBeforePopup(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; const popupFeatures: TCefPopupFeatures; userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
@ -258,7 +283,7 @@ begin
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]); Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumPopupShow(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumPopupShow(Sender: TObject;
const browser: ICefBrowser; AShow: Boolean); const browser: ICefBrowser; AShow: Boolean);
begin begin
if aShow then if aShow then
@ -272,7 +297,7 @@ begin
end; end;
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumPopupSize(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumPopupSize(Sender: TObject;
const browser: ICefBrowser; const rect: PCefRect); const browser: ICefBrowser; const rect: PCefRect);
begin begin
LogicalToDevice(rect^, ScreenScale); LogicalToDevice(rect^, ScreenScale);
@ -283,7 +308,7 @@ begin
FPopUpRect.Bottom := rect^.y + rect^.height - 1; FPopUpRect.Bottom := rect^.y + rect^.height - 1;
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumTooltip(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumTooltip(Sender: TObject;
const browser: ICefBrowser; var AText: ustring; out Result: Boolean); const browser: ICefBrowser; var AText: ustring; out Result: Boolean);
begin begin
hint := aText; hint := aText;
@ -291,7 +316,7 @@ begin
Result := True; Result := True;
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumIMECompositionRangeChanged( procedure TOsrBrowserWindow.DoGetChromiumIMECompositionRangeChanged(
Sender: TObject; const browser: ICefBrowser; const selected_range: PCefRange; Sender: TObject; const browser: ICefBrowser; const selected_range: PCefRange;
character_boundsCount: NativeUInt; const character_bounds: PCefRect); character_boundsCount: NativeUInt; const character_bounds: PCefRect);
var var
@ -334,7 +359,7 @@ begin
TThread.Synchronize(nil, @SyncIMERangeChanged); TThread.Synchronize(nil, @SyncIMERangeChanged);
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumCursorChange(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumCursorChange(Sender: TObject;
const browser: ICefBrowser; cursor_: TCefCursorHandle; const browser: ICefBrowser; cursor_: TCefCursorHandle;
cursorType: TCefCursorType; const customCursorInfo: PCefCursorInfo; cursorType: TCefCursorType; const customCursorInfo: PCefCursorInfo;
var aResult: boolean); var aResult: boolean);
@ -343,7 +368,7 @@ begin
aResult := True; aResult := True;
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumGetScreenInfo(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumGetScreenInfo(Sender: TObject;
const browser: ICefBrowser; var screenInfo: TCefScreenInfo; out const browser: ICefBrowser; var screenInfo: TCefScreenInfo; out
Result: Boolean); Result: Boolean);
var var
@ -366,7 +391,7 @@ begin
Result := True; Result := True;
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumGetScreenPoint(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumGetScreenPoint(Sender: TObject;
const browser: ICefBrowser; viewX, viewY: Integer; var screenX, const browser: ICefBrowser; viewX, viewY: Integer; var screenX,
screenY: Integer; out Result: Boolean); screenY: Integer; out Result: Boolean);
var var
@ -382,7 +407,7 @@ begin
Result := True; Result := True;
end; end;
procedure TLazarusOsrBrowserWindow.DoGetChromiumViewRect(Sender: TObject; procedure TOsrBrowserWindow.DoGetChromiumViewRect(Sender: TObject;
const browser: ICefBrowser; var rect: TCefRect); const browser: ICefBrowser; var rect: TCefRect);
var var
TempScale : single; TempScale : single;
@ -394,7 +419,7 @@ begin
rect.height := DeviceToLogical(Height, TempScale); rect.height := DeviceToLogical(Height, TempScale);
end; end;
procedure TLazarusOsrBrowserWindow.DoChromiumPaint(Sender: TObject; procedure TOsrBrowserWindow.DoChromiumPaint(Sender: TObject;
const browser: ICefBrowser; kind: TCefPaintElementType; const browser: ICefBrowser; kind: TCefPaintElementType;
dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray;
const ABuffer: Pointer; AWidth, AHeight: Integer); const ABuffer: Pointer; AWidth, AHeight: Integer);
@ -530,12 +555,12 @@ begin
end; end;
end; end;
function TLazarusOsrBrowserWindow.GetChromium: TLazOsrChromium; function TOsrBrowserWindow.GetChromium: TEmbeddedOsrChromium;
begin begin
Result := FChromium; Result := FChromium;
end; end;
function TLazarusOsrBrowserWindow.getModifiers(Shift: TShiftState function TOsrBrowserWindow.getModifiers(Shift: TShiftState
): TCefEventFlags; ): TCefEventFlags;
begin begin
Result := EVENTFLAG_NONE; Result := EVENTFLAG_NONE;
@ -549,7 +574,7 @@ begin
if (ssMiddle in Shift) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON; if (ssMiddle in Shift) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON;
end; end;
function TLazarusOsrBrowserWindow.getKeyModifiers(Shift: TShiftState): TCefEventFlags; function TOsrBrowserWindow.getKeyModifiers(Shift: TShiftState): TCefEventFlags;
begin begin
Result := EVENTFLAG_NONE; Result := EVENTFLAG_NONE;
@ -561,7 +586,7 @@ begin
if (ssCaps in Shift) then Result := Result or EVENTFLAG_CAPS_LOCK_ON; if (ssCaps in Shift) then Result := Result or EVENTFLAG_CAPS_LOCK_ON;
end; end;
function TLazarusOsrBrowserWindow.GetButton(Button: TMouseButton function TOsrBrowserWindow.GetButton(Button: TMouseButton
): TCefMouseButtonType; ): TCefMouseButtonType;
begin begin
case Button of case Button of
@ -571,23 +596,20 @@ begin
end; end;
end; end;
procedure TLazarusOsrBrowserWindow.DoCreateBrowserAfterContext(Sender: TObject); procedure TOsrBrowserWindow.DoCreateBrowserAfterContext(Sender: TObject);
begin begin
FChromium.CreateBrowser(nil); FChromium.CreateBrowser(nil);
end; end;
procedure TLazarusOsrBrowserWindow.CreateHandle; procedure TOsrBrowserWindow.CreateHandle;
begin begin
inherited CreateHandle; inherited CreateHandle;
if not (csDesigning in ComponentState) then begin if not (csDesigning in ComponentState) then begin
if GlobalCEFApp is TCefLazApplication then GlobalCEFApp.AddContextInitializedHandler(@DoCreateBrowserAfterContext);
TCefLazApplication(GlobalCEFApp).AddContextInitializedHandler(@DoCreateBrowserAfterContext)
else
DoCreateBrowserAfterContext(nil);
end; end;
end; end;
procedure TLazarusOsrBrowserWindow.DestroyHandle; procedure TOsrBrowserWindow.DestroyHandle;
begin begin
if (GlobalCEFApp = nil) or if (GlobalCEFApp = nil) or
(not FChromium.HasBrowser) or (not FChromium.HasBrowser) or
@ -601,32 +623,32 @@ begin
inherited DestroyHandle; inherited DestroyHandle;
end; end;
procedure TLazarusOsrBrowserWindow.RealizeBounds; procedure TOsrBrowserWindow.RealizeBounds;
begin begin
inherited RealizeBounds; inherited RealizeBounds;
Chromium.NotifyMoveOrResizeStarted; Chromium.NotifyMoveOrResizeStarted;
AsyncResize(0); AsyncResize(0);
end; end;
procedure TLazarusOsrBrowserWindow.DoEnter; procedure TOsrBrowserWindow.DoEnter;
begin begin
inherited DoEnter; inherited DoEnter;
Chromium.SendFocusEvent(True); Chromium.SendFocusEvent(True);
end; end;
procedure TLazarusOsrBrowserWindow.DoExit; procedure TOsrBrowserWindow.DoExit;
begin begin
inherited DoExit; inherited DoExit;
Chromium.SendFocusEvent(False); Chromium.SendFocusEvent(False);
end; end;
procedure TLazarusOsrBrowserWindow.Click; procedure TOsrBrowserWindow.Click;
begin begin
inherited Click; inherited Click;
SetFocus; SetFocus;
end; end;
procedure TLazarusOsrBrowserWindow.MouseDown(Button: TMouseButton; procedure TOsrBrowserWindow.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
@ -654,7 +676,7 @@ begin
Chromium.SendMouseClickEvent(@TempEvent, GetButton(Button), False, LastClickCount); Chromium.SendMouseClickEvent(@TempEvent, GetButton(Button), False, LastClickCount);
end; end;
procedure TLazarusOsrBrowserWindow.MouseUp(Button: TMouseButton; procedure TOsrBrowserWindow.MouseUp(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
@ -680,7 +702,7 @@ begin
Chromium.SendMouseClickEvent(@TempEvent, GetButton(Button), True, LastClickCount); Chromium.SendMouseClickEvent(@TempEvent, GetButton(Button), True, LastClickCount);
end; end;
procedure TLazarusOsrBrowserWindow.MouseMove(Shift: TShiftState; X, Y: Integer); procedure TOsrBrowserWindow.MouseMove(Shift: TShiftState; X, Y: Integer);
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
IsHandled: Boolean; IsHandled: Boolean;
@ -699,7 +721,7 @@ begin
Chromium.SendMouseMoveEvent(@TempEvent, False); Chromium.SendMouseMoveEvent(@TempEvent, False);
end; end;
procedure TLazarusOsrBrowserWindow.MouseEnter; procedure TOsrBrowserWindow.MouseEnter;
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
TempPoint : TPoint; TempPoint : TPoint;
@ -714,7 +736,7 @@ begin
Chromium.SendMouseMoveEvent(@TempEvent, False); Chromium.SendMouseMoveEvent(@TempEvent, False);
end; end;
procedure TLazarusOsrBrowserWindow.MouseLeave; procedure TOsrBrowserWindow.MouseLeave;
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
TempPoint : TPoint; TempPoint : TPoint;
@ -735,7 +757,7 @@ begin
Chromium.SendMouseMoveEvent(@TempEvent, True); Chromium.SendMouseMoveEvent(@TempEvent, True);
end; end;
function TLazarusOsrBrowserWindow.DoMouseWheel(Shift: TShiftState; function TOsrBrowserWindow.DoMouseWheel(Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint): Boolean; WheelDelta: Integer; MousePos: TPoint): Boolean;
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
@ -760,7 +782,7 @@ begin
Chromium.SendMouseWheelEvent(@TempEvent, 0, WheelDelta); Chromium.SendMouseWheelEvent(@TempEvent, 0, WheelDelta);
end; end;
procedure TLazarusOsrBrowserWindow.KeyDown(var Key: Word; Shift: TShiftState); procedure TOsrBrowserWindow.KeyDown(var Key: Word; Shift: TShiftState);
var var
TempKeyEvent : TCefKeyEvent; TempKeyEvent : TCefKeyEvent;
IsHandled: Boolean; IsHandled: Boolean;
@ -797,7 +819,7 @@ begin
inherited KeyDown(Key, Shift); inherited KeyDown(Key, Shift);
end; end;
procedure TLazarusOsrBrowserWindow.UTF8KeyPress(var UTF8Key: TUTF8Char); procedure TOsrBrowserWindow.UTF8KeyPress(var UTF8Key: TUTF8Char);
var var
TempKeyEvent : TCefKeyEvent; TempKeyEvent : TCefKeyEvent;
TempString : UnicodeString; TempString : UnicodeString;
@ -838,7 +860,7 @@ begin
inherited UTF8KeyPress(UTF8Key); inherited UTF8KeyPress(UTF8Key);
end; end;
procedure TLazarusOsrBrowserWindow.KeyUp(var Key: Word; Shift: TShiftState); procedure TOsrBrowserWindow.KeyUp(var Key: Word; Shift: TShiftState);
var var
TempKeyEvent : TCefKeyEvent; TempKeyEvent : TCefKeyEvent;
IsHandled: Boolean; IsHandled: Boolean;
@ -869,20 +891,20 @@ begin
end; end;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
procedure TLazarusOsrBrowserWindow.DoOnIMECancelComposition; procedure TOsrBrowserWindow.DoOnIMECancelComposition;
begin begin
inherited DoOnIMECancelComposition; inherited DoOnIMECancelComposition;
Chromium.IMECancelComposition; Chromium.IMECancelComposition;
end; end;
procedure TLazarusOsrBrowserWindow.DoOnIMECommitText(const aText: ustring; procedure TOsrBrowserWindow.DoOnIMECommitText(const aText: ustring;
const replacement_range: PCefRange; relative_cursor_pos: integer); const replacement_range: PCefRange; relative_cursor_pos: integer);
begin begin
inherited DoOnIMECommitText(aText, replacement_range, relative_cursor_pos); inherited DoOnIMECommitText(aText, replacement_range, relative_cursor_pos);
Chromium.IMECommitText(aText, replacement_range, relative_cursor_pos);; Chromium.IMECommitText(aText, replacement_range, relative_cursor_pos);;
end; end;
procedure TLazarusOsrBrowserWindow.DoOnIMESetComposition(const aText: ustring; procedure TOsrBrowserWindow.DoOnIMESetComposition(const aText: ustring;
const underlines: TCefCompositionUnderlineDynArray; const replacement_range, const underlines: TCefCompositionUnderlineDynArray; const replacement_range,
selection_range: TCefRange); selection_range: TCefRange);
begin begin
@ -891,20 +913,20 @@ begin
end; end;
{$ENDIF} {$ENDIF}
procedure TLazarusOsrBrowserWindow.CaptureChanged; procedure TOsrBrowserWindow.CaptureChanged;
begin begin
inherited CaptureChanged; inherited CaptureChanged;
if (Chromium <> nil) then Chromium.SendCaptureLostEvent; if (Chromium <> nil) then Chromium.SendCaptureLostEvent;
end; end;
procedure TLazarusOsrBrowserWindow.DoOnCreated(Sender: TObject); procedure TOsrBrowserWindow.DoOnCreated(Sender: TObject);
begin begin
if Assigned(FOnBrowserCreated) then if Assigned(FOnBrowserCreated) then
FOnBrowserCreated(Self); FOnBrowserCreated(Self);
end; end;
procedure TLazarusOsrBrowserWindow.DoOnClosed(Sender: TObject); procedure TOsrBrowserWindow.DoOnClosed(Sender: TObject);
begin begin
if (not(csDestroying in ComponentState)) and if (not(csDestroying in ComponentState)) and
Assigned(FOnBrowserClosed) Assigned(FOnBrowserClosed)
@ -912,7 +934,7 @@ begin
FOnBrowserClosed(Self); FOnBrowserClosed(Self);
end; end;
constructor TLazarusOsrBrowserWindow.Create(AOwner: TComponent); constructor TOsrBrowserWindow.Create(AOwner: TComponent);
begin begin
FResizeCS := TCriticalSection.Create; FResizeCS := TCriticalSection.Create;
@ -920,7 +942,7 @@ begin
FSelectedRange.from := 0; FSelectedRange.from := 0;
FSelectedRange.to_ := 0; FSelectedRange.to_ := 0;
FChromium := TLazOsrChromium.Create(Self); FChromium := TEmbeddedOsrChromium.Create(Self);
FChromium.InternalOnBrowserClosed := {$IFDEF FPC}@{$ENDIF}DoOnClosed; FChromium.InternalOnBrowserClosed := {$IFDEF FPC}@{$ENDIF}DoOnClosed;
FChromium.InternalOnBrowserCreated := {$IFDEF FPC}@{$ENDIF}DoOnCreated; FChromium.InternalOnBrowserCreated := {$IFDEF FPC}@{$ENDIF}DoOnCreated;
@ -936,10 +958,11 @@ begin
FChromium.OnIMECompositionRangeChanged := @DoGetChromiumIMECompositionRangeChanged; FChromium.OnIMECompositionRangeChanged := @DoGetChromiumIMECompositionRangeChanged;
inherited Create(AOwner); inherited Create(AOwner);
ControlStyle := ControlStyle + [csOwnedChildrenNotSelectable];
CopyOriginalBuffer := true; CopyOriginalBuffer := true;
end; end;
destructor TLazarusOsrBrowserWindow.Destroy; destructor TOsrBrowserWindow.Destroy;
begin begin
inherited Destroy; inherited Destroy;
FreeAndNil(FResizeCS); FreeAndNil(FResizeCS);
@ -950,12 +973,12 @@ begin
end; end;
end; end;
procedure TLazarusOsrBrowserWindow.CloseBrowser(aForceClose: boolean); procedure TOsrBrowserWindow.CloseBrowser(aForceClose: boolean);
begin begin
FChromium.CloseBrowser(aForceClose); FChromium.CloseBrowser(aForceClose);
end; end;
procedure TLazarusOsrBrowserWindow.WaitForBrowserClosed; procedure TOsrBrowserWindow.WaitForBrowserClosed;
begin begin
if not FChromium.HasBrowser then if not FChromium.HasBrowser then
exit; exit;
@ -971,12 +994,12 @@ begin
// TODO : sent closed? // TODO : sent closed?
end; end;
function TLazarusOsrBrowserWindow.IsClosed: boolean; function TOsrBrowserWindow.IsClosed: boolean;
begin begin
Result := not FChromium.HasBrowser; Result := not FChromium.HasBrowser;
end; end;
procedure TLazarusOsrBrowserWindow.LoadURL(aURL: ustring); procedure TOsrBrowserWindow.LoadURL(aURL: ustring);
begin begin
FChromium.LoadURL(aURL); FChromium.LoadURL(aURL);
end; end;
@ -985,19 +1008,20 @@ end;
{$IFDEF FPC} {$IFDEF FPC}
procedure Register; procedure Register;
begin begin
// {$I res/tlazarusosrbrowserwindow.lrs} {$I res/TOsrBrowserWindow.lrs}
RegisterComponents('Chromium', [TLazarusOsrBrowserWindow]); RegisterComponents('Chromium', [TOsrBrowserWindow]);
RegisterPropertyEditor(TypeInfo(TOnClose), TLazOsrChromium,'OnClose',THiddenPropertyEditor); RegisterClass(TEmbeddedOsrChromium);
RegisterPropertyEditor(TypeInfo(TOnPaint), TLazOsrChromium,'OnPaint',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnClose), TEmbeddedOsrChromium,'OnClose',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnGetViewRect), TLazOsrChromium,'OnGetViewRect',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnPaint), TEmbeddedOsrChromium,'OnPaint',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnCursorChange), TLazOsrChromium,'OnCursorChange',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnGetViewRect), TEmbeddedOsrChromium,'OnGetViewRect',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnGetScreenPoint), TLazOsrChromium,'OnGetScreenPoint',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnCursorChange), TEmbeddedOsrChromium,'OnCursorChange',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnGetScreenInfo), TLazOsrChromium,'OnGetScreenInfo',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnGetScreenPoint), TEmbeddedOsrChromium,'OnGetScreenPoint',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnPopupShow), TLazOsrChromium,'OnPopupShow',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnGetScreenInfo), TEmbeddedOsrChromium,'OnGetScreenInfo',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnPopupSize), TLazOsrChromium,'OnPopupSize',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnPopupShow), TEmbeddedOsrChromium,'OnPopupShow',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnTooltip), TLazOsrChromium,'OnTooltip',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnPopupSize), TEmbeddedOsrChromium,'OnPopupSize',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnBeforePopup), TLazOsrChromium,'OnBeforePopup',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnTooltip), TEmbeddedOsrChromium,'OnTooltip',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnIMECompositionRangeChanged), TLazOsrChromium,'OnIMECompositionRangeChanged',THiddenPropertyEditor); RegisterPropertyEditor(TypeInfo(TOnBeforePopup), TEmbeddedOsrChromium,'OnBeforePopup',THiddenPropertyEditor);
RegisterPropertyEditor(TypeInfo(TOnIMECompositionRangeChanged), TEmbeddedOsrChromium,'OnIMECompositionRangeChanged',THiddenPropertyEditor);
end; end;
{$ENDIF} {$ENDIF}