You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-09-30 21:28:55 +02:00
GTK3 demos for Lazarus adapted to the new TBufferPanel events.
This commit is contained in:
@@ -33,8 +33,7 @@ procedure CustomWidgetSetFinalization;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
gtk3int, Forms, xlib,
|
gtk3int, Forms, xlib;
|
||||||
uCEFLinuxFunctions;
|
|
||||||
|
|
||||||
function CustomX11ErrorHandler(Display:PDisplay; ErrorEv:PXErrorEvent):longint;cdecl;
|
function CustomX11ErrorHandler(Display:PDisplay; ErrorEv:PXErrorEvent):longint;cdecl;
|
||||||
begin
|
begin
|
||||||
|
@@ -6,13 +6,13 @@ object Form1: TForm1
|
|||||||
Caption = ' Initializing browser. Please wait...'
|
Caption = ' Initializing browser. Please wait...'
|
||||||
ClientHeight = 630
|
ClientHeight = 630
|
||||||
ClientWidth = 1001
|
ClientWidth = 1001
|
||||||
|
LCLVersion = '4.2.0.0'
|
||||||
OnActivate = FormActivate
|
OnActivate = FormActivate
|
||||||
OnCloseQuery = FormCloseQuery
|
OnCloseQuery = FormCloseQuery
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnDestroy = FormDestroy
|
OnDestroy = FormDestroy
|
||||||
OnHide = FormHide
|
OnHide = FormHide
|
||||||
OnShow = FormShow
|
OnShow = FormShow
|
||||||
LCLVersion = '3.0.0.3'
|
|
||||||
object AddressPnl: TPanel
|
object AddressPnl: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
Height = 30
|
Height = 30
|
||||||
@@ -21,7 +21,7 @@ object Form1: TForm1
|
|||||||
Align = alTop
|
Align = alTop
|
||||||
ClientHeight = 30
|
ClientHeight = 30
|
||||||
ClientWidth = 1001
|
ClientWidth = 1001
|
||||||
TabOrder = 1
|
TabOrder = 0
|
||||||
object AddressEdt: TEdit
|
object AddressEdt: TEdit
|
||||||
Left = 1
|
Left = 1
|
||||||
Height = 28
|
Height = 28
|
||||||
@@ -50,12 +50,16 @@ object Form1: TForm1
|
|||||||
Height = 600
|
Height = 600
|
||||||
Top = 30
|
Top = 30
|
||||||
Width = 1001
|
Width = 1001
|
||||||
|
OnGdkKeyPress = Panel1GdkKeyPress
|
||||||
|
OnGdkKeyRelease = Panel1GdkKeyRelease
|
||||||
Align = alClient
|
Align = alClient
|
||||||
Caption = 'Panel1'
|
Caption = 'Panel1'
|
||||||
Color = clWhite
|
Color = clWhite
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
TabOrder = 0
|
TabOrder = 1
|
||||||
OnClick = Panel1Click
|
TabStop = True
|
||||||
|
OnEnter = Panel1Enter
|
||||||
|
OnExit = Panel1Exit
|
||||||
OnMouseDown = Panel1MouseDown
|
OnMouseDown = Panel1MouseDown
|
||||||
OnMouseMove = Panel1MouseMove
|
OnMouseMove = Panel1MouseMove
|
||||||
OnMouseUp = Panel1MouseUp
|
OnMouseUp = Panel1MouseUp
|
||||||
@@ -63,20 +67,9 @@ object Form1: TForm1
|
|||||||
OnResize = Panel1Resize
|
OnResize = Panel1Resize
|
||||||
OnMouseEnter = Panel1MouseEnter
|
OnMouseEnter = Panel1MouseEnter
|
||||||
OnMouseLeave = Panel1MouseLeave
|
OnMouseLeave = Panel1MouseLeave
|
||||||
object FocusWorkaroundEdt: TEdit
|
|
||||||
Left = -9000
|
|
||||||
Height = 20
|
|
||||||
Top = -9000
|
|
||||||
Width = 80
|
|
||||||
BorderStyle = bsNone
|
|
||||||
ReadOnly = True
|
|
||||||
TabOrder = 0
|
|
||||||
OnEnter = FocusWorkaroundEdtEnter
|
|
||||||
OnExit = FocusWorkaroundEdtExit
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
object Chromium1: TChromium
|
object Chromium1: TChromium
|
||||||
OnCanFocus = Chromium1CanFocus
|
OnSetFocus = Chromium1SetFocus
|
||||||
OnTooltip = Chromium1Tooltip
|
OnTooltip = Chromium1Tooltip
|
||||||
OnCursorChange = Chromium1CursorChange
|
OnCursorChange = Chromium1CursorChange
|
||||||
OnBeforePopup = Chromium1BeforePopup
|
OnBeforePopup = Chromium1BeforePopup
|
||||||
|
@@ -6,22 +6,24 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
|
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
|
||||||
LCLType, ComCtrls, Types, SyncObjs, LMessages,
|
LCLType, ComCtrls, Types, LMessages,
|
||||||
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFBufferPanel,
|
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFBufferPanel,
|
||||||
uCEFChromiumEvents;
|
LazGdk3;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
TForm1 = class(TForm)
|
TForm1 = class(TForm)
|
||||||
AddressEdt: TEdit;
|
AddressEdt: TEdit;
|
||||||
FocusWorkaroundEdt: TEdit;
|
|
||||||
SaveDialog1: TSaveDialog;
|
SaveDialog1: TSaveDialog;
|
||||||
GoBtn: TButton;
|
GoBtn: TButton;
|
||||||
Panel1: TBufferPanel;
|
Panel1: TBufferPanel;
|
||||||
Chromium1: TChromium;
|
Chromium1: TChromium;
|
||||||
AddressPnl: TPanel;
|
AddressPnl: TPanel;
|
||||||
|
|
||||||
procedure Panel1Click(Sender: TObject);
|
procedure Panel1Enter(Sender: TObject);
|
||||||
|
procedure Panel1Exit(Sender: TObject);
|
||||||
|
procedure Panel1GdkKeyPress(Sender: TObject; aEvent: PGdkEventKey; var aHandled: boolean);
|
||||||
|
procedure Panel1GdkKeyRelease(Sender: TObject; aEvent: PGdkEventKey; var aHandled: boolean);
|
||||||
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||||
procedure Panel1MouseEnter(Sender: TObject);
|
procedure Panel1MouseEnter(Sender: TObject);
|
||||||
procedure Panel1MouseLeave(Sender: TObject);
|
procedure Panel1MouseLeave(Sender: TObject);
|
||||||
@@ -41,24 +43,22 @@ type
|
|||||||
procedure Chromium1Paint(Sender: TObject; const browser: ICefBrowser; type_: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth, aHeight: Integer);
|
procedure Chromium1Paint(Sender: TObject; const browser: ICefBrowser; type_: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth, aHeight: Integer);
|
||||||
procedure Chromium1PopupShow(Sender: TObject; const browser: ICefBrowser; aShow: Boolean);
|
procedure Chromium1PopupShow(Sender: TObject; const browser: ICefBrowser; aShow: Boolean);
|
||||||
procedure Chromium1PopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
|
procedure Chromium1PopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
|
||||||
|
procedure Chromium1SetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean);
|
||||||
procedure Chromium1Tooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
procedure Chromium1Tooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
||||||
procedure Chromium1CanFocus(Sender: TObject);
|
|
||||||
|
|
||||||
procedure FormCreate(Sender: TObject);
|
|
||||||
procedure FormDestroy(Sender: TObject);
|
|
||||||
procedure FormActivate(Sender: TObject);
|
procedure FormActivate(Sender: TObject);
|
||||||
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
||||||
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure FormDestroy(Sender: TObject);
|
||||||
procedure FormHide(Sender: TObject);
|
procedure FormHide(Sender: TObject);
|
||||||
procedure FormShow(Sender: TObject);
|
procedure FormShow(Sender: TObject);
|
||||||
|
|
||||||
|
procedure Application_OnActivate(Sender: TObject);
|
||||||
|
procedure Application_OnDeactivate(Sender: TObject);
|
||||||
|
|
||||||
procedure GoBtnClick(Sender: TObject);
|
procedure GoBtnClick(Sender: TObject);
|
||||||
procedure GoBtnEnter(Sender: TObject);
|
procedure GoBtnEnter(Sender: TObject);
|
||||||
|
|
||||||
procedure FocusWorkaroundEdtEnter(Sender: TObject);
|
|
||||||
procedure FocusWorkaroundEdtExit(Sender: TObject);
|
|
||||||
|
|
||||||
procedure AddressEdtEnter(Sender: TObject);
|
procedure AddressEdtEnter(Sender: TObject);
|
||||||
private
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
FPopUpBitmap : TBitmap;
|
FPopUpBitmap : TBitmap;
|
||||||
@@ -68,8 +68,6 @@ type
|
|||||||
FPendingResize : boolean;
|
FPendingResize : boolean;
|
||||||
FCanClose : boolean;
|
FCanClose : boolean;
|
||||||
FClosing : boolean;
|
FClosing : boolean;
|
||||||
FFirstLoad : boolean;
|
|
||||||
FConnectedSignals : boolean;
|
|
||||||
|
|
||||||
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
function getModifiers(Shift: TShiftState): TCefEventFlags;
|
||||||
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
function GetButton(Button: TMouseButton): TCefMouseButtonType;
|
||||||
@@ -79,9 +77,6 @@ type
|
|||||||
procedure WMMove(var Message: TLMMove); message LM_MOVE;
|
procedure WMMove(var Message: TLMMove); message LM_MOVE;
|
||||||
procedure WMSize(var Message: TLMSize); message LM_SIZE;
|
procedure WMSize(var Message: TLMSize); message LM_SIZE;
|
||||||
procedure WMWindowPosChanged(var Message: TLMWindowPosChanged); message LM_WINDOWPOSCHANGED;
|
procedure WMWindowPosChanged(var Message: TLMWindowPosChanged); message LM_WINDOWPOSCHANGED;
|
||||||
|
|
||||||
public
|
|
||||||
function SendCEFKeyEvent(const aCefEvent : TCefKeyEvent): boolean;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@@ -97,11 +92,6 @@ implementation
|
|||||||
// with a different executable for the Chromium subprocesses and an external
|
// with a different executable for the Chromium subprocesses and an external
|
||||||
// message pump
|
// message pump
|
||||||
|
|
||||||
// Chromium needs the key press data available in the GDK signals
|
|
||||||
// "key-press-event" and "key-release-event" but Lazarus doesn't expose that
|
|
||||||
// information so we have to call g_signal_connect to receive that information
|
|
||||||
// in the GTKKeyPress function.
|
|
||||||
|
|
||||||
// Chromium renders the web contents asynchronously. It uses multiple processes
|
// Chromium renders the web contents asynchronously. It uses multiple processes
|
||||||
// and threads which makes it complicated to keep the correct browser size.
|
// and threads which makes it complicated to keep the correct browser size.
|
||||||
|
|
||||||
@@ -155,11 +145,11 @@ implementation
|
|||||||
// destroyed. FCanClose is set to True and we can close the form safely.
|
// destroyed. FCanClose is set to True and we can close the form safely.
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math,
|
Math, gtk3procs,
|
||||||
LazGdk3, LazGtk3, LazGObject2, LazGLib2, gtk3procs, gtk3objects, gtk3widgets,
|
uCEFMiscFunctions, uCEFApplication, uCEFWorkScheduler, uCEFLinuxFunctions;
|
||||||
uCEFMiscFunctions, uCEFApplication, uCEFBitmapBitBuffer, uCEFWorkScheduler,
|
|
||||||
uCEFLinuxFunctions, uCEFLinuxConstants;
|
|
||||||
|
|
||||||
|
{GlobalCEFApp functions}
|
||||||
|
{%Region}
|
||||||
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);
|
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);
|
||||||
begin
|
begin
|
||||||
if (GlobalCEFWorkScheduler <> nil) then
|
if (GlobalCEFWorkScheduler <> nil) then
|
||||||
@@ -192,117 +182,46 @@ begin
|
|||||||
GlobalCEFApp.StartMainProcess;
|
GlobalCEFApp.StartMainProcess;
|
||||||
GlobalCEFWorkScheduler.CreateThread;
|
GlobalCEFWorkScheduler.CreateThread;
|
||||||
end;
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
function GTKKeyPress(Widget: PGtkWidget; Event: PGdkEventKey; Data: gPointer) : GBoolean; cdecl;
|
{TBufferPanel events}
|
||||||
var
|
{%Region}
|
||||||
TempCefEvent : TCefKeyEvent;
|
procedure TForm1.Panel1Enter(Sender: TObject);
|
||||||
begin
|
|
||||||
Result := False;
|
|
||||||
GdkEventKeyToCEFKeyEvent(Event, TempCefEvent);
|
|
||||||
|
|
||||||
if (Event^.type_ = GDK_KEY_PRESS) or (TempCefEvent.windows_key_code = VKEY_RETURN) then
|
|
||||||
begin
|
|
||||||
TempCefEvent.kind := KEYEVENT_RAWKEYDOWN;
|
|
||||||
if Form1.SendCEFKeyEvent(TempCefEvent) then
|
|
||||||
begin
|
|
||||||
TempCefEvent.kind := KEYEVENT_CHAR;
|
|
||||||
Result := Form1.SendCEFKeyEvent(TempCefEvent);
|
|
||||||
end;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
TempCefEvent.kind := KEYEVENT_KEYUP;
|
|
||||||
Result := Form1.SendCEFKeyEvent(TempCefEvent);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function ConnectKeyPressReleaseEvents(const aWidget : PGtkWidget): boolean;
|
|
||||||
begin
|
|
||||||
Result := (g_signal_connect_data(aWidget, 'key-press-event', TGCallback(@GTKKeyPress), nil, nil, G_CONNECT_DEFAULT) <> 0) and
|
|
||||||
(g_signal_connect_data(aWidget, 'key-release-event', TGCallback(@GTKKeyPress), nil, nil, G_CONNECT_DEFAULT) <> 0);
|
|
||||||
end;
|
|
||||||
|
|
||||||
{ TForm1 }
|
|
||||||
|
|
||||||
function TForm1.SendCEFKeyEvent(const aCefEvent : TCefKeyEvent): boolean;
|
|
||||||
begin
|
|
||||||
if FocusWorkaroundEdt.Focused then
|
|
||||||
begin
|
|
||||||
Chromium1.SendKeyEvent(@aCefEvent);
|
|
||||||
Result := True;
|
|
||||||
end
|
|
||||||
else
|
|
||||||
Result := False;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.GoBtnClick(Sender: TObject);
|
|
||||||
begin
|
|
||||||
FResizing := False;
|
|
||||||
FPendingResize := False;
|
|
||||||
|
|
||||||
Chromium1.LoadURL(AddressEdt.Text);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
|
||||||
begin
|
|
||||||
// Now the browser is fully initialized we can initialize the UI.
|
|
||||||
Caption := 'OSR External Pump Browser';
|
|
||||||
|
|
||||||
Chromium1.NotifyMoveOrResizeStarted;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.AddressEdtEnter(Sender: TObject);
|
|
||||||
begin
|
|
||||||
Chromium1.SetFocus(False);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.Panel1Click(Sender: TObject);
|
|
||||||
begin
|
|
||||||
// GTK3 can't set the focus on a custom panel so we use an invisible edit box
|
|
||||||
FocusWorkaroundEdt.SetFocus;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.Chromium1CanFocus(Sender: TObject);
|
|
||||||
begin
|
|
||||||
if FocusWorkaroundEdt.Focused then
|
|
||||||
Chromium1.SetFocus(True)
|
|
||||||
else
|
|
||||||
FocusWorkaroundEdt.SetFocus;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.FocusWorkaroundEdtExit(Sender: TObject);
|
|
||||||
begin
|
|
||||||
Chromium1.SetFocus(False);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.FocusWorkaroundEdtEnter(Sender: TObject);
|
|
||||||
begin
|
begin
|
||||||
Chromium1.SetFocus(True);
|
Chromium1.SetFocus(True);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.FormActivate(Sender: TObject);
|
procedure TForm1.Panel1Exit(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
// You *MUST* call CreateBrowser to create and initialize the browser.
|
Chromium1.SetFocus(False);
|
||||||
// This will trigger the AfterCreated event when the browser is fully
|
end;
|
||||||
// initialized and ready to receive commands.
|
|
||||||
|
|
||||||
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
procedure TForm1.Panel1GdkKeyPress(Sender: TObject; aEvent: PGdkEventKey;
|
||||||
// If it's not initialized yet, we use a simple timer to create the browser later.
|
var aHandled: boolean);
|
||||||
|
var
|
||||||
|
TempCefEvent : TCefKeyEvent;
|
||||||
|
begin
|
||||||
|
aHandled := True;
|
||||||
|
|
||||||
// Linux needs a visible form to create a browser so we need to use the
|
GdkEventKeyToCEFKeyEvent(aEvent, TempCefEvent);
|
||||||
// TForm.OnActivate event instead of the TForm.OnShow event
|
|
||||||
|
|
||||||
if not(Chromium1.Initialized) then
|
TempCefEvent.kind := KEYEVENT_RAWKEYDOWN;
|
||||||
begin
|
Chromium1.SendKeyEvent(@TempCefEvent);
|
||||||
// We have to update the DeviceScaleFactor here to get the scale of the
|
TempCefEvent.kind := KEYEVENT_CHAR;
|
||||||
// monitor where the main application form is located.
|
Chromium1.SendKeyEvent(@TempCefEvent);
|
||||||
GlobalCEFApp.UpdateDeviceScaleFactor;
|
end;
|
||||||
|
|
||||||
// opaque white background color
|
procedure TForm1.Panel1GdkKeyRelease(Sender: TObject; aEvent: PGdkEventKey;
|
||||||
Chromium1.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
|
var aHandled: boolean);
|
||||||
Chromium1.DefaultURL := UTF8Decode(AddressEdt.Text);
|
var
|
||||||
Chromium1.CreateBrowser;
|
TempCefEvent : TCefKeyEvent;
|
||||||
end;
|
begin
|
||||||
|
aHandled := True;
|
||||||
|
|
||||||
|
GdkEventKeyToCEFKeyEvent(aEvent, TempCefEvent);
|
||||||
|
|
||||||
|
TempCefEvent.kind := KEYEVENT_KEYUP;
|
||||||
|
Chromium1.SendKeyEvent(@TempCefEvent);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
|
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
|
||||||
@@ -385,26 +304,16 @@ procedure TForm1.Panel1Resize(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
DoResize;
|
DoResize;
|
||||||
end;
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
function TForm1.getModifiers(Shift: TShiftState): TCefEventFlags;
|
{TChromium events}
|
||||||
|
{%Region}
|
||||||
|
procedure TForm1.Chromium1AfterCreated(Sender: TObject; const browser: ICefBrowser);
|
||||||
begin
|
begin
|
||||||
Result := EVENTFLAG_NONE;
|
// Now the browser is fully initialized we can initialize the UI.
|
||||||
|
Caption := 'OSR External Pump Browser';
|
||||||
|
|
||||||
if (ssShift in Shift) then Result := Result or EVENTFLAG_SHIFT_DOWN;
|
Chromium1.NotifyMoveOrResizeStarted;
|
||||||
if (ssAlt in Shift) then Result := Result or EVENTFLAG_ALT_DOWN;
|
|
||||||
if (ssCtrl in Shift) then Result := Result or EVENTFLAG_CONTROL_DOWN;
|
|
||||||
if (ssLeft in Shift) then Result := Result or EVENTFLAG_LEFT_MOUSE_BUTTON;
|
|
||||||
if (ssRight in Shift) then Result := Result or EVENTFLAG_RIGHT_MOUSE_BUTTON;
|
|
||||||
if (ssMiddle in Shift) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TForm1.GetButton(Button: TMouseButton): TCefMouseButtonType;
|
|
||||||
begin
|
|
||||||
case Button of
|
|
||||||
TMouseButton.mbRight : Result := MBT_RIGHT;
|
|
||||||
TMouseButton.mbMiddle : Result := MBT_MIDDLE;
|
|
||||||
else Result := MBT_LEFT;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.Chromium1BeforeClose(Sender: TObject;
|
procedure TForm1.Chromium1BeforeClose(Sender: TObject;
|
||||||
@@ -637,12 +546,47 @@ begin
|
|||||||
FPopUpRect.Bottom := rect^.y + rect^.height - 1;
|
FPopUpRect.Bottom := rect^.y + rect^.height - 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Chromium1SetFocus(Sender: TObject; const browser: ICefBrowser;
|
||||||
|
source: TCefFocusSource; out Result: Boolean);
|
||||||
|
begin
|
||||||
|
Result := not(Panel1.Focused);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.Chromium1Tooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
procedure TForm1.Chromium1Tooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
||||||
begin
|
begin
|
||||||
Panel1.hint := aText;
|
Panel1.hint := UTF8Encode(aText);
|
||||||
Panel1.ShowHint := (length(aText) > 0);
|
Panel1.ShowHint := (length(aText) > 0);
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
|
{TForm events}
|
||||||
|
{%Region}
|
||||||
|
procedure TForm1.FormActivate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
// You *MUST* call CreateBrowser to create and initialize the browser.
|
||||||
|
// This will trigger the AfterCreated event when the browser is fully
|
||||||
|
// initialized and ready to receive commands.
|
||||||
|
|
||||||
|
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
|
||||||
|
// If it's not initialized yet, we use a simple timer to create the browser later.
|
||||||
|
|
||||||
|
// Linux needs a visible form to create a browser so we need to use the
|
||||||
|
// TForm.OnActivate event instead of the TForm.OnShow event
|
||||||
|
|
||||||
|
if not(Chromium1.Initialized) then
|
||||||
|
begin
|
||||||
|
// We have to update the DeviceScaleFactor here to get the scale of the
|
||||||
|
// monitor where the main application form is located.
|
||||||
|
GlobalCEFApp.UpdateDeviceScaleFactor;
|
||||||
|
Panel1.ConnectSignals;
|
||||||
|
|
||||||
|
// opaque white background color
|
||||||
|
Chromium1.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
|
||||||
|
Chromium1.DefaultURL := UTF8Decode(AddressEdt.Text);
|
||||||
|
Chromium1.CreateBrowser;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
||||||
begin
|
begin
|
||||||
@@ -658,7 +602,6 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.FormCreate(Sender: TObject);
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FConnectedSignals := False;
|
|
||||||
FPopUpBitmap := nil;
|
FPopUpBitmap := nil;
|
||||||
FPopUpRect := rect(0, 0, 0, 0);
|
FPopUpRect := rect(0, 0, 0, 0);
|
||||||
FShowPopUp := False;
|
FShowPopUp := False;
|
||||||
@@ -666,9 +609,11 @@ begin
|
|||||||
FPendingResize := False;
|
FPendingResize := False;
|
||||||
FCanClose := False;
|
FCanClose := False;
|
||||||
FClosing := False;
|
FClosing := False;
|
||||||
FFirstLoad := True;
|
|
||||||
|
|
||||||
Chromium1.DefaultURL := AddressEdt.Text;
|
Chromium1.DefaultURL := UTF8Decode(AddressEdt.Text);
|
||||||
|
|
||||||
|
Application.OnActivate := @Application_OnActivate;
|
||||||
|
Application.OnDeactivate := @Application_OnDeactivate;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.FormDestroy(Sender: TObject);
|
procedure TForm1.FormDestroy(Sender: TObject);
|
||||||
@@ -685,18 +630,47 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.FormShow(Sender: TObject);
|
procedure TForm1.FormShow(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
if not(FConnectedSignals) then
|
|
||||||
FConnectedSignals := ConnectKeyPressReleaseEvents(TGtk3Window(FocusWorkaroundEdt.Handle).widget);
|
|
||||||
|
|
||||||
Chromium1.WasHidden(False);
|
Chromium1.WasHidden(False);
|
||||||
Chromium1.SetFocus(True);
|
Chromium1.SetFocus(True);
|
||||||
end;
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
|
{TApplication events}
|
||||||
|
{%Region}
|
||||||
|
procedure TForm1.Application_OnActivate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Chromium1.SetFocus(Panel1.Focused);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.Application_OnDeactivate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Chromium1.SetFocus(False);
|
||||||
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
|
{Other events}
|
||||||
|
{%Region}
|
||||||
|
procedure TForm1.GoBtnClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
FResizing := False;
|
||||||
|
FPendingResize := False;
|
||||||
|
|
||||||
|
Chromium1.LoadURL(UTF8Decode(AddressEdt.Text));
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TForm1.GoBtnEnter(Sender: TObject);
|
procedure TForm1.GoBtnEnter(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Chromium1.SetFocus(False);
|
Chromium1.SetFocus(False);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.AddressEdtEnter(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Chromium1.SetFocus(False);
|
||||||
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
|
{Misc functions}
|
||||||
|
{%Region}
|
||||||
procedure TForm1.DoResize;
|
procedure TForm1.DoResize;
|
||||||
begin
|
begin
|
||||||
if FResizing then
|
if FResizing then
|
||||||
@@ -711,6 +685,30 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TForm1.getModifiers(Shift: TShiftState): TCefEventFlags;
|
||||||
|
begin
|
||||||
|
Result := EVENTFLAG_NONE;
|
||||||
|
|
||||||
|
if (ssShift in Shift) then Result := Result or EVENTFLAG_SHIFT_DOWN;
|
||||||
|
if (ssAlt in Shift) then Result := Result or EVENTFLAG_ALT_DOWN;
|
||||||
|
if (ssCtrl in Shift) then Result := Result or EVENTFLAG_CONTROL_DOWN;
|
||||||
|
if (ssLeft in Shift) then Result := Result or EVENTFLAG_LEFT_MOUSE_BUTTON;
|
||||||
|
if (ssRight in Shift) then Result := Result or EVENTFLAG_RIGHT_MOUSE_BUTTON;
|
||||||
|
if (ssMiddle in Shift) then Result := Result or EVENTFLAG_MIDDLE_MOUSE_BUTTON;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TForm1.GetButton(Button: TMouseButton): TCefMouseButtonType;
|
||||||
|
begin
|
||||||
|
case Button of
|
||||||
|
TMouseButton.mbRight : Result := MBT_RIGHT;
|
||||||
|
TMouseButton.mbMiddle : Result := MBT_MIDDLE;
|
||||||
|
else Result := MBT_LEFT;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
|
{Message handlers}
|
||||||
|
{%Region}
|
||||||
procedure TForm1.WMMove(var Message: TLMMove);
|
procedure TForm1.WMMove(var Message: TLMMove);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
@@ -728,6 +726,7 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
Chromium1.NotifyMoveOrResizeStarted;
|
Chromium1.NotifyMoveOrResizeStarted;
|
||||||
end;
|
end;
|
||||||
|
{%Endregion}
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@@ -53,9 +53,9 @@ type
|
|||||||
procedure Chromium1Paint(Sender: TObject; const browser: ICefBrowser; type_: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth, aHeight: Integer);
|
procedure Chromium1Paint(Sender: TObject; const browser: ICefBrowser; type_: TCefPaintElementType; dirtyRectsCount: NativeUInt; const dirtyRects: PCefRectArray; const buffer: Pointer; aWidth, aHeight: Integer);
|
||||||
procedure Chromium1PopupShow(Sender: TObject; const browser: ICefBrowser; aShow: Boolean);
|
procedure Chromium1PopupShow(Sender: TObject; const browser: ICefBrowser; aShow: Boolean);
|
||||||
procedure Chromium1PopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
|
procedure Chromium1PopupSize(Sender: TObject; const browser: ICefBrowser; const rect: PCefRect);
|
||||||
|
procedure Chromium1ProcessMessageReceived(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: Boolean);
|
||||||
procedure Chromium1SetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean);
|
procedure Chromium1SetFocus(Sender: TObject; const browser: ICefBrowser; source: TCefFocusSource; out Result: Boolean);
|
||||||
procedure Chromium1Tooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
procedure Chromium1Tooltip(Sender: TObject; const browser: ICefBrowser; var aText: ustring; out Result: Boolean);
|
||||||
procedure Chromium1ProcessMessageReceived(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; sourceProcess: TCefProcessId; const message: ICefProcessMessage; out Result: Boolean);
|
|
||||||
|
|
||||||
procedure FormActivate(Sender: TObject);
|
procedure FormActivate(Sender: TObject);
|
||||||
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
|
||||||
@@ -747,7 +747,6 @@ begin
|
|||||||
// We have to update the DeviceScaleFactor here to get the scale of the
|
// We have to update the DeviceScaleFactor here to get the scale of the
|
||||||
// monitor where the main application form is located.
|
// monitor where the main application form is located.
|
||||||
GlobalCEFApp.UpdateDeviceScaleFactor;
|
GlobalCEFApp.UpdateDeviceScaleFactor;
|
||||||
Panel1.UpdateDeviceScaleFactor;
|
|
||||||
Panel1.ConnectSignals;
|
Panel1.ConnectSignals;
|
||||||
UpdatePanelOffset;
|
UpdatePanelOffset;
|
||||||
|
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 771,
|
"InternalVersion" : 772,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "139.0.28"
|
"Version" : "139.0.28"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user