1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Added keyboard support to the FMXExternalPumpBrowser2 demo in Linux thanks to Christoph Schneider

Moved most of the Linux constants, types and functions to new units.
This commit is contained in:
Salvador Diaz Fau
2021-01-28 19:29:04 +01:00
parent 8d5797b01f
commit 77a5766367
19 changed files with 4992 additions and 2285 deletions

View File

@@ -125,6 +125,7 @@ object FMXExternalPumpBrowserFrm: TFMXExternalPumpBrowserFrm
OnLoadError = chrmosrLoadError
OnLoadingStateChange = chrmosrLoadingStateChange
OnTooltip = chrmosrTooltip
OnCursorChange = chrmosrCursorChange
OnBeforePopup = chrmosrBeforePopup
OnAfterCreated = chrmosrAfterCreated
OnBeforeClose = chrmosrBeforeClose

View File

@@ -49,16 +49,6 @@ uses
uCEFInterfaces, uCEFTypes, uCEFConstants, uCEFChromiumCore;
type
PRGBQuad = ^TRGBQuad;
tagRGBQUAD = record
rgbBlue: Byte;
rgbGreen: Byte;
rgbRed: Byte;
rgbReserved: Byte;
end;
TRGBQuad = tagRGBQUAD;
RGBQUAD = tagRGBQUAD;
TFMXExternalPumpBrowserFrm = class(TForm)
AddressPnl: TPanel;
AddressEdt: TEdit;
@@ -108,12 +98,12 @@ type
procedure chrmosrLoadingStateChange(Sender: TObject; const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
procedure chrmosrLoadError(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);
procedure Timer1Timer(Sender: TObject);
procedure AddressEdtEnter(Sender: TObject);
procedure SnapshotBtnClick(Sender: TObject);
procedure SnapshotBtnEnter(Sender: TObject);
protected
FPopUpBitmap : TBitmap;
FPopUpRect : TRect;
@@ -137,6 +127,7 @@ type
procedure NotifyMoveOrResizeStarted;
procedure SendCaptureLostEvent;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
procedure SendCEFKeyEvent(const aCefEvent : TCefKeyEvent);
end;
var
@@ -172,8 +163,40 @@ implementation
{$R *.fmx}
uses
System.SysUtils, System.Math, FMX.Platform,
uCEFMiscFunctions, uCEFApplication;
System.SysUtils, System.Math, FMX.Platform, FMX.Platform.Linux,
uCEFMiscFunctions, uCEFApplication, uCEFLinuxTypes, uCEFLinuxConstants,
uCEFLinuxFunctions;
function GTKKeyPress(Widget: PGtkWidget; Event: PGdkEventKey; Data: gPointer) : GBoolean; cdecl;
var
TempCefEvent : TCefKeyEvent;
begin
if FMXExternalPumpBrowserFrm.Panel1.IsFocused then
begin
GdkEventKeyToCEFKeyEvent(Event, TempCefEvent);
if (Event^._type = GDK_KEY_PRESS) then
begin
TempCefEvent.kind := KEYEVENT_RAWKEYDOWN;
FMXExternalPumpBrowserFrm.SendCEFKeyEvent(TempCefEvent);
TempCefEvent.kind := KEYEVENT_CHAR;
FMXExternalPumpBrowserFrm.SendCEFKeyEvent(TempCefEvent);
end
else
begin
TempCefEvent.kind := KEYEVENT_KEYUP;
FMXExternalPumpBrowserFrm.SendCEFKeyEvent(TempCefEvent);
end;
end;
Result := True;
end;
procedure ConnectKeyPressReleaseEvents(const aWidget : PGtkWidget);
begin
g_signal_connect(aWidget, 'key-press-event', TGCallback(@GTKKeyPress), nil);
g_signal_connect(aWidget, 'key-release-event', TGCallback(@GTKKeyPress), nil);
end;
procedure TFMXExternalPumpBrowserFrm.FormActivate(Sender: TObject);
var
@@ -201,13 +224,17 @@ begin
end);
end
else
if not(chrmosr.Initialized) then
begin
// opaque white background color
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
begin
ConnectKeyPressReleaseEvents(TLinuxWindowHandle(Handle).NativeHandle);
if not(chrmosr.CreateBrowser) then Timer1.Enabled := True;
end;
if not(chrmosr.Initialized) then
begin
// opaque white background color
chrmosr.Options.BackgroundColor := CefColorSetARGB($FF, $FF, $FF, $FF);
if not(chrmosr.CreateBrowser) then Timer1.Enabled := True;
end;
end;
end;
procedure TFMXExternalPumpBrowserFrm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
@@ -797,6 +824,11 @@ begin
if PositionChanged then NotifyMoveOrResizeStarted;
end;
procedure TFMXExternalPumpBrowserFrm.SendCEFKeyEvent(const aCefEvent : TCefKeyEvent);
begin
chrmosr.SendKeyEvent(@aCefEvent);
end;
procedure TFMXExternalPumpBrowserFrm.NotifyMoveOrResizeStarted;
begin
if (chrmosr <> nil) then chrmosr.NotifyMoveOrResizeStarted;

View File

@@ -20,9 +20,9 @@
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<TopLine Value="187"/>
<CursorPos Y="352"/>
<FoldState Value=" TJmA1{32 pjZlg1@4 pmOoL1{D1q"/>
<TopLine Value="168"/>
<CursorPos X="52" Y="196"/>
<FoldState Value=" TJmA1{32 pjZlg1@311]B8qW1JF"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
@@ -119,7 +119,7 @@
<OtherDefines Count="1">
<Define0 Value="UseCThreads"/>
</OtherDefines>
<JumpHistory Count="5" HistoryIndex="4">
<JumpHistory Count="6" HistoryIndex="5">
<Position1>
<Filename Value="uMiniBrowser.pas"/>
<Caret Line="865" TopLine="829"/>
@@ -140,6 +140,10 @@
<Filename Value="uMiniBrowser.pas"/>
<Caret Line="222" Column="47" TopLine="210"/>
</Position5>
<Position6>
<Filename Value="uMiniBrowser.pas"/>
<Caret Line="352" TopLine="188"/>
</Position6>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>

View File

@@ -193,7 +193,7 @@ implementation
{$R *.lfm}
uses
uCEFMiscFunctions, uCefClient;
uCEFMiscFunctions, uCefClient, uCEFLinuxConstants;
const
CEF_UPDATEADDRESS = 1;

View File

@@ -3,11 +3,11 @@
<ProjectSession>
<Version Value="11"/>
<BuildModes Active="Default"/>
<Units Count="112">
<Units Count="113">
<Unit0>
<Filename Value="OSRExternalPumpBrowser.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="1"/>
<EditorIndex Value="4"/>
<TopLine Value="31"/>
<CursorPos X="20" Y="72"/>
<UsageCount Value="91"/>
@@ -21,15 +21,15 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="uOSRExternalPumpBrowser"/>
<IsVisibleTab Value="True"/>
<TopLine Value="189"/>
<CursorPos X="4" Y="199"/>
<TopLine Value="177"/>
<CursorPos X="21" Y="195"/>
<UsageCount Value="91"/>
<Bookmarks Count="6">
<Item0 Y="704" ID="2"/>
<Item1 X="9" Y="602" ID="3"/>
<Item2 X="13" Y="315" ID="9"/>
<Item3 Y="689" ID="8"/>
<Item4 X="41" Y="280" ID="7"/>
<Item0 Y="705" ID="2"/>
<Item1 X="9" Y="603" ID="3"/>
<Item2 X="13" Y="316" ID="9"/>
<Item3 Y="690" ID="8"/>
<Item4 X="41" Y="281" ID="7"/>
<Item5 X="52" Y="187" ID="1"/>
</Bookmarks>
<Loaded Value="True"/>
@@ -94,10 +94,11 @@
</Unit9>
<Unit10>
<Filename Value="../../../source/uCEFMiscFunctions.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="184"/>
<CursorPos X="22" Y="211"/>
<EditorIndex Value="3"/>
<TopLine Value="40"/>
<CursorPos X="51" Y="63"/>
<UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
<Filename Value="/usr/share/lazarus/2.0.10/lcl/interfaces/gtk2/gtk2int.pas"/>
@@ -145,13 +146,11 @@
</Unit16>
<Unit17>
<Filename Value="../../../source/uCEFApplicationCore.pas"/>
<EditorIndex Value="-1"/>
<TopLine Value="340"/>
<CursorPos X="40" Y="377"/>
<EditorIndex Value="1"/>
<TopLine Value="604"/>
<CursorPos X="71" Y="623"/>
<UsageCount Value="10"/>
<Bookmarks Count="1">
<Item0 X="3" Y="2235" ID="3"/>
</Bookmarks>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="../../../source/uCEFApplication.pas"/>
@@ -826,6 +825,14 @@
<CursorPos X="78" Y="45"/>
<UsageCount Value="10"/>
</Unit111>
<Unit112>
<Filename Value="../../../source/uCEFLinuxFunctions.pas"/>
<EditorIndex Value="2"/>
<TopLine Value="62"/>
<CursorPos X="19" Y="81"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit112>
</Units>
<OtherDefines Count="2">
<Define0 Value="UseCthreads"/>
@@ -834,123 +841,123 @@
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="708" TopLine="682"/>
<Caret Line="328" Column="58" TopLine="308"/>
</Position1>
<Position2>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="709" Column="22" TopLine="682"/>
<Caret Line="216" Column="77" TopLine="205"/>
</Position2>
<Position3>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="706" Column="39" TopLine="682"/>
<Caret Line="87" Column="22" TopLine="60"/>
</Position3>
<Position4>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="72" Column="32" TopLine="54"/>
<Caret Line="73" Column="13" TopLine="63"/>
</Position4>
<Position5>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="117" Column="33" TopLine="92"/>
<Caret Line="410" Column="3" TopLine="406"/>
</Position5>
<Position6>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="88" Column="22" TopLine="61"/>
<Caret Line="277" Column="73" TopLine="237"/>
</Position6>
<Position7>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="328" Column="58" TopLine="308"/>
<Caret Line="86" Column="24" TopLine="81"/>
</Position7>
<Position8>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="216" Column="77" TopLine="205"/>
<Caret Line="768" TopLine="54"/>
</Position8>
<Position9>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="87" Column="22" TopLine="60"/>
<Caret Line="195" Column="47" TopLine="172"/>
</Position9>
<Position10>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="73" Column="13" TopLine="63"/>
<Caret Line="220" Column="36" TopLine="197"/>
</Position10>
<Position11>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="410" Column="3" TopLine="406"/>
<Caret Line="221" Column="51" TopLine="197"/>
</Position11>
<Position12>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="277" Column="73" TopLine="237"/>
<Caret Line="235" Column="62" TopLine="208"/>
</Position12>
<Position13>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="86" Column="24" TopLine="81"/>
<Caret Line="240" Column="47" TopLine="205"/>
</Position13>
<Position14>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="768" TopLine="54"/>
<Caret Line="331" TopLine="310"/>
</Position14>
<Position15>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="195" Column="47" TopLine="172"/>
<Caret Line="722" TopLine="713"/>
</Position15>
<Position16>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="220" Column="36" TopLine="197"/>
<Caret Line="96" TopLine="74"/>
</Position16>
<Position17>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="221" Column="51" TopLine="197"/>
<Caret Line="95" TopLine="73"/>
</Position17>
<Position18>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="235" Column="62" TopLine="208"/>
<Caret Line="317" Column="82" TopLine="291"/>
</Position18>
<Position19>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="240" Column="47" TopLine="205"/>
<Caret Line="79" Column="15" TopLine="65"/>
</Position19>
<Position20>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="331" TopLine="310"/>
<Caret Line="620" Column="34" TopLine="596"/>
</Position20>
<Position21>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="722" TopLine="713"/>
<Filename Value="OSRExternalPumpBrowser.lpr"/>
<Caret Line="72" Column="20" TopLine="31"/>
</Position21>
<Position22>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="96" TopLine="74"/>
<Caret Line="689" TopLine="644"/>
</Position22>
<Position23>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="95" TopLine="73"/>
<Caret Line="687" Column="3" TopLine="644"/>
</Position23>
<Position24>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="317" Column="82" TopLine="291"/>
<Caret Line="231" TopLine="174"/>
</Position24>
<Position25>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="79" Column="15" TopLine="65"/>
<Caret Line="199" Column="4" TopLine="189"/>
</Position25>
<Position26>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="620" Column="34" TopLine="596"/>
<Filename Value="../../../source/uCEFApplicationCore.pas"/>
<Caret Line="623" Column="71" TopLine="604"/>
</Position26>
<Position27>
<Filename Value="OSRExternalPumpBrowser.lpr"/>
<Caret Line="72" Column="20" TopLine="31"/>
<Filename Value="../../../source/uCEFMiscFunctions.pas"/>
<Caret Line="70" Column="7" TopLine="39"/>
</Position27>
<Position28>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="689" TopLine="644"/>
<Filename Value="../../../source/uCEFLinuxFunctions.pas"/>
<Caret Line="55" Column="19" TopLine="33"/>
</Position28>
<Position29>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="687" Column="3" TopLine="644"/>
<Filename Value="../../../source/uCEFMiscFunctions.pas"/>
<Caret Line="74" Column="66" TopLine="39"/>
</Position29>
<Position30>
<Filename Value="uosrexternalpumpbrowser.pas"/>
<Caret Line="231" TopLine="174"/>
<Caret Line="191" Column="60" TopLine="189"/>
</Position30>
</JumpHistory>
<RunParams>

View File

@@ -191,7 +191,8 @@ implementation
uses
Math, gtk2, glib2, gdk2, gtk2proc, gtk2int,
uCEFMiscFunctions, uCEFApplication, uCEFBitmapBitBuffer, uCEFWorkScheduler;
uCEFMiscFunctions, uCEFApplication, uCEFBitmapBitBuffer, uCEFWorkScheduler,
uCEFLinuxFunctions;
procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);
begin

View File

@@ -20,8 +20,8 @@
<ResourceBaseClass Value="Form"/>
<UnitName Value="uSimpleOSRBrowser"/>
<IsVisibleTab Value="True"/>
<TopLine Value="187"/>
<CursorPos X="72" Y="225"/>
<TopLine Value="213"/>
<CursorPos X="78" Y="229"/>
<UsageCount Value="83"/>
<Bookmarks Count="2">
<Item0 X="49" Y="223" ID="2"/>
@@ -802,7 +802,7 @@
<Define0 Value="UseCthreads"/>
<Define1 Value="EnabledGtkThreading"/>
</OtherDefines>
<JumpHistory Count="20" HistoryIndex="19">
<JumpHistory Count="21" HistoryIndex="20">
<Position1>
<Filename Value="usimpleosrbrowser.pas"/>
<Caret Line="56" Column="63" TopLine="51"/>
@@ -883,6 +883,10 @@
<Filename Value="usimpleosrbrowser.pas"/>
<Caret Line="85" Column="15" TopLine="68"/>
</Position20>
<Position21>
<Filename Value="usimpleosrbrowser.pas"/>
<Caret Line="225" Column="72" TopLine="187"/>
</Position21>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>

View File

@@ -226,7 +226,7 @@ implementation
uses
Math, gtk2, glib2, gdk2, gtk2proc, gtk2int,
uCEFMiscFunctions, uCEFApplication, uCEFBitmapBitBuffer;
uCEFMiscFunctions, uCEFApplication, uCEFBitmapBitBuffer, uCEFLinuxFunctions;
const
CEF_UPDATE_CURSOR = $A0D;