mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2024-11-15 15:55:56 +01:00
Improved Linux support thanks to Christoph Schneider
Added more code comments in the TabbedBrowser2 demo. Removed FastMM4 from the SimpleOSRBrowser demo. Modified TCEFWorkScheduler for FPC in Linux.
This commit is contained in:
parent
28958bf7b6
commit
858f1a1625
@ -51,7 +51,7 @@ uses
|
||||
Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, AppEvnts,
|
||||
{$ENDIF}
|
||||
uCEFChromium, uCEFTypes, uCEFInterfaces, uCEFConstants, uCEFBufferPanel, uCEFWorkScheduler,
|
||||
uCEFSentinel, uCEFChromiumCore;
|
||||
uCEFChromiumCore;
|
||||
|
||||
type
|
||||
TOSRExternalPumpBrowserFrm = class(TForm)
|
||||
|
@ -39,7 +39,7 @@ program SimpleOSRBrowser;
|
||||
|
||||
{$I cef.inc}
|
||||
|
||||
uses FastMM4,
|
||||
uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
Vcl.Forms,
|
||||
WinApi.Windows,
|
||||
|
@ -142,14 +142,20 @@ uses
|
||||
// event which will be used in TBrowserTab to send a CEF_DESTROYTAB message
|
||||
// to the main form to free the tab.
|
||||
|
||||
// This demo also uses custom forms to open popup browsers in the same way as
|
||||
// the PopupBrowser2 demo. Please, read the code comments in that demo for all
|
||||
// details about handling the custom child forms.
|
||||
|
||||
// To close safely this demo you must close all the browser tabs first following
|
||||
// this steps :
|
||||
//
|
||||
// 1. FormCloseQuery sets CanClose to FALSE and calls CloseAllTabs and FClosing
|
||||
// 1. FormCloseQuery sets CanClose to FALSE and calls CloseAllBrowsers and FClosing
|
||||
// is set to TRUE.
|
||||
// 2. Each tab will send a CEF_DESTROYTAB message to free that tab.
|
||||
// 3. When TPageControl has no tabs then we can set FCanClose to TRUE and send a
|
||||
// WM_CLOSE to the main form to close the application.
|
||||
// 2. Each tab will send a CEF_DESTROYTAB message to the main form to free that tab.
|
||||
// 3. Each child form will send a CEF_CHILDDESTROYED message to the main form.
|
||||
// 3. When TPageControl has no tabs and all the child forms are also closed then we
|
||||
// can set FCanClose to TRUE and send a WM_CLOSE message to the main form to
|
||||
// close the application.
|
||||
|
||||
procedure GlobalCEFApp_OnContextInitialized;
|
||||
begin
|
||||
|
@ -2,8 +2,8 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
Left = 0
|
||||
Top = 0
|
||||
Caption = 'Web page snapshot'
|
||||
ClientHeight = 486
|
||||
ClientWidth = 711
|
||||
ClientHeight = 737
|
||||
ClientWidth = 1032
|
||||
Color = clBtnFace
|
||||
Font.Charset = DEFAULT_CHARSET
|
||||
Font.Color = clWindowText
|
||||
@ -19,8 +19,8 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
object Image1: TImage
|
||||
Left = 0
|
||||
Top = 25
|
||||
Width = 711
|
||||
Height = 442
|
||||
Width = 1032
|
||||
Height = 693
|
||||
Align = alClient
|
||||
AutoSize = True
|
||||
Center = True
|
||||
@ -32,18 +32,20 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
end
|
||||
object StatusBar1: TStatusBar
|
||||
Left = 0
|
||||
Top = 467
|
||||
Width = 711
|
||||
Top = 718
|
||||
Width = 1032
|
||||
Height = 19
|
||||
Panels = <
|
||||
item
|
||||
Width = 1000
|
||||
end>
|
||||
ExplicitTop = 467
|
||||
ExplicitWidth = 711
|
||||
end
|
||||
object NavigationPnl: TPanel
|
||||
Left = 0
|
||||
Top = 0
|
||||
Width = 711
|
||||
Width = 1032
|
||||
Height = 25
|
||||
Align = alTop
|
||||
BevelOuter = bvNone
|
||||
@ -52,8 +54,9 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
Padding.Right = 2
|
||||
Padding.Bottom = 2
|
||||
TabOrder = 1
|
||||
ExplicitWidth = 711
|
||||
object GoBtn: TButton
|
||||
Left = 634
|
||||
Left = 955
|
||||
Top = 2
|
||||
Width = 75
|
||||
Height = 21
|
||||
@ -61,15 +64,17 @@ object WebpageSnapshotFrm: TWebpageSnapshotFrm
|
||||
Caption = 'Go'
|
||||
TabOrder = 0
|
||||
OnClick = GoBtnClick
|
||||
ExplicitLeft = 634
|
||||
end
|
||||
object AddressEdt: TEdit
|
||||
Left = 2
|
||||
Top = 2
|
||||
Width = 632
|
||||
Width = 953
|
||||
Height = 21
|
||||
Align = alClient
|
||||
TabOrder = 1
|
||||
Text = 'https://www.google.com'
|
||||
ExplicitWidth = 632
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -8,10 +8,10 @@
|
||||
<Unit0>
|
||||
<Filename Value="SimpleOSRBrowser.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="18"/>
|
||||
<CursorPos X="61" Y="60"/>
|
||||
<TopLine Value="38"/>
|
||||
<CursorPos X="11" Y="46"/>
|
||||
<UsageCount Value="20"/>
|
||||
<Loaded Value="True"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
@ -37,14 +37,16 @@
|
||||
<HasResources Value="True"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="-1"/>
|
||||
<TopLine Value="334"/>
|
||||
<CursorPos X="25" Y="343"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<TopLine Value="804"/>
|
||||
<CursorPos X="70" Y="818"/>
|
||||
<UsageCount Value="42"/>
|
||||
<Bookmarks Count="2">
|
||||
<Item0 X="40" Y="302" ID="4"/>
|
||||
<Item1 X="41" Y="262" ID="1"/>
|
||||
</Bookmarks>
|
||||
<Loaded Value="True"/>
|
||||
<LoadedDesigner Value="True"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
@ -249,9 +251,6 @@
|
||||
<UsageCount Value="10"/>
|
||||
</Unit29>
|
||||
</Units>
|
||||
<General>
|
||||
<ActiveWindowIndexAtStart Value="-1"/>
|
||||
</General>
|
||||
<JumpHistory HistoryIndex="-1"/>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
|
@ -51,7 +51,12 @@ interface
|
||||
uses
|
||||
{$IFDEF DELPHI16_UP}
|
||||
{$IFDEF MSWINDOWS}
|
||||
WinApi.Windows, WinApi.ActiveX,{$IFNDEF FMX} Vcl.Forms,{$ENDIF}
|
||||
WinApi.Windows, WinApi.ActiveX,
|
||||
{$IFDEF FMX}
|
||||
FMX.Forms,
|
||||
{$ELSE}
|
||||
Vcl.Forms,
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
System.Classes, System.UITypes,
|
||||
{$ELSE}
|
||||
|
@ -1167,8 +1167,14 @@ begin
|
||||
TempArgs.instance := HINSTANCE{$IFDEF FPC}(){$ENDIF};
|
||||
{$ELSE}
|
||||
{$IFDEF LINUX}
|
||||
TempArgs.argc := argc;
|
||||
TempArgs.argv := argv;
|
||||
{$IFDEF FPC}
|
||||
TempArgs.argc := argc;
|
||||
TempArgs.argv := argv;
|
||||
{$ELSE}
|
||||
// TODO: Find a way to set the TCefMainArgs values in Delphi FMX for Linux
|
||||
TempArgs.argc := 0;
|
||||
TempArgs.argv := 0;
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
TempArgs.argc := 0;
|
||||
TempArgs.argv := 0;
|
||||
@ -1247,8 +1253,14 @@ begin
|
||||
TempArgs.instance := HINSTANCE{$IFDEF FPC}(){$ENDIF};
|
||||
{$ELSE}
|
||||
{$IFDEF LINUX}
|
||||
TempArgs.argc := argc;
|
||||
TempArgs.argv := argv;
|
||||
{$IFDEF FPC}
|
||||
TempArgs.argc := argc;
|
||||
TempArgs.argv := argv;
|
||||
{$ELSE}
|
||||
// TODO: Find a way to set the TCefMainArgs values in Delphi FMX for Linux
|
||||
TempArgs.argc := 0;
|
||||
TempArgs.argv := 0;
|
||||
{$ENDIF}
|
||||
{$ELSE}
|
||||
TempArgs.argc := 0;
|
||||
TempArgs.argv := 0;
|
||||
@ -2181,7 +2193,11 @@ begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
FLibHandle := LoadLibraryExW(PWideChar(LibCefPath), 0, LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||
{$ELSE}
|
||||
FLibHandle := LoadLibrary(LibCefPath);
|
||||
{$IFDEF FPC}
|
||||
FLibHandle := LoadLibrary(LibCefPath);
|
||||
{$ELSE}
|
||||
FLibHandle := LoadLibrary(PChar(LibCefPath));
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
if (FLibHandle = 0) then
|
||||
|
@ -127,9 +127,16 @@ function CefPostTask(aThreadId : TCefThreadId; const aTask: ICefTask) : boolean;
|
||||
function CefPostDelayedTask(aThreadId : TCefThreadId; const aTask : ICefTask; aDelayMs : Int64) : boolean;
|
||||
function CefCurrentlyOn(aThreadId : TCefThreadId) : boolean;
|
||||
|
||||
{$IFNDEF MACOS}
|
||||
{$IFDEF MSWINDOWS}
|
||||
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
|
||||
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
|
||||
{$ELSE}
|
||||
{$IFDEF LINUX}
|
||||
{$IFDEF FPC}
|
||||
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
|
||||
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
|
||||
@ -492,10 +499,9 @@ begin
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
{$IFNDEF MACOS}
|
||||
{$IFDEF MSWINDOWS}
|
||||
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
Result.wYear := dt.year;
|
||||
Result.wMonth := dt.month;
|
||||
Result.wDayOfWeek := dt.day_of_week;
|
||||
@ -504,21 +510,10 @@ begin
|
||||
Result.wMinute := dt.minute;
|
||||
Result.wSecond := dt.second;
|
||||
Result.wMilliseconds := dt.millisecond;
|
||||
{$ELSE}
|
||||
Result.Year := dt.year;
|
||||
Result.Month := dt.month;
|
||||
Result.DayOfWeek := dt.day_of_week;
|
||||
Result.Day := dt.day_of_month;
|
||||
Result.Hour := dt.hour;
|
||||
Result.Minute := dt.minute;
|
||||
Result.Second := dt.second;
|
||||
Result.Millisecond := dt.millisecond;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
|
||||
begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
Result.year := dt.wYear;
|
||||
Result.month := dt.wMonth;
|
||||
Result.day_of_week := dt.wDayOfWeek;
|
||||
@ -527,7 +522,24 @@ begin
|
||||
Result.minute := dt.wMinute;
|
||||
Result.second := dt.wSecond;
|
||||
Result.millisecond := dt.wMilliseconds;
|
||||
{$ELSE}
|
||||
end;
|
||||
{$ELSE}
|
||||
{$IFDEF LINUX}
|
||||
{$IFDEF FPC}
|
||||
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
|
||||
begin
|
||||
Result.Year := dt.year;
|
||||
Result.Month := dt.month;
|
||||
Result.DayOfWeek := dt.day_of_week;
|
||||
Result.Day := dt.day_of_month;
|
||||
Result.Hour := dt.hour;
|
||||
Result.Minute := dt.minute;
|
||||
Result.Second := dt.second;
|
||||
Result.Millisecond := dt.millisecond;
|
||||
end;
|
||||
|
||||
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
|
||||
begin
|
||||
Result.year := dt.Year;
|
||||
Result.month := dt.Month;
|
||||
Result.day_of_week := dt.DayOfWeek;
|
||||
@ -536,8 +548,9 @@ begin
|
||||
Result.minute := dt.Minute;
|
||||
Result.second := dt.Second;
|
||||
Result.millisecond := dt.Millisecond;
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
|
||||
@ -825,7 +838,12 @@ begin
|
||||
{$IFDEF MACOS}
|
||||
TempString := 'PID: ' + IntToStr(TNSProcessInfo.Wrap(TNSProcessInfo.OCClass.processInfo).processIdentifier) + ', TID: ' + IntToStr(TThread.Current.ThreadID);
|
||||
{$ELSE}
|
||||
TempString := 'PID: ' + IntToStr(GetProcessID()) + ', TID: ' + IntToStr(GetCurrentThreadID());
|
||||
{$IFDEF FPC}
|
||||
TempString := 'PID: ' + IntToStr(GetProcessID()) + ', TID: ' + IntToStr(GetCurrentThreadID());
|
||||
{$ELSE}
|
||||
// TODO: Find the equivalent function to get the process ID in Delphi FMX for Linux
|
||||
// TempString := 'PID: ' + IntToStr(GetProcessID()) + ', TID: ' + IntToStr(GetCurrentThreadID());
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
|
||||
@ -2238,7 +2256,12 @@ begin
|
||||
{$IFDEF MACOS}
|
||||
Result := trunc(MainScreen.backingScaleFactor);
|
||||
{$ELSE}
|
||||
Result := screen.PrimaryMonitor.PixelsPerInch;
|
||||
{$IFDEF FPC}
|
||||
Result := screen.PrimaryMonitor.PixelsPerInch;
|
||||
{$ELSE}
|
||||
// TODO: Find a way to get the screen scale in Delphi FMX for Linux
|
||||
Result := 96;
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
@ -267,9 +267,14 @@ type
|
||||
TCefEventHandle = Pointer; // /include/internal/cef_types_mac.h (cef_event_handle_t)
|
||||
{$ENDIF}
|
||||
{$IFDEF LINUX}
|
||||
TCefWindowHandle = culong; // /include/internal/cef_types_linux.h (cef_window_handle_t)
|
||||
TCefCursorHandle = culong; // /include/internal/cef_types_linux.h (cef_cursor_handle_t)
|
||||
TCefEventHandle = PXEvent; // /include/internal/cef_types_linux.h (cef_event_handle_t)
|
||||
{$IFDEF FPC}
|
||||
TCefWindowHandle = culong; // /include/internal/cef_types_linux.h (cef_window_handle_t)
|
||||
TCefCursorHandle = culong; // /include/internal/cef_types_linux.h (cef_cursor_handle_t)
|
||||
{$ELSE}
|
||||
TCefWindowHandle = LongWord; // /include/internal/cef_types_linux.h (cef_window_handle_t)
|
||||
TCefCursorHandle = LongWord; // /include/internal/cef_types_linux.h (cef_cursor_handle_t)
|
||||
{$ENDIF}
|
||||
TCefEventHandle = PXEvent; // /include/internal/cef_types_linux.h (cef_event_handle_t)
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
|
@ -54,7 +54,7 @@ uses
|
||||
{$ELSE}
|
||||
{$IFDEF MSWINDOWS}Windows,{$ENDIF} Classes,
|
||||
{$IFDEF FPC}
|
||||
LCLProc, LCLType, LCLIntf, LResources, LMessages, InterfaceBase,
|
||||
LCLProc, LCLType, LCLIntf, LResources, LMessages, InterfaceBase, {$IFNDEF MSWINDOWS}forms,{$ENDIF}
|
||||
{$ELSE}
|
||||
Messages,
|
||||
{$ENDIF}
|
||||
@ -65,7 +65,6 @@ type
|
||||
{$IFNDEF FPC}{$IFDEF DELPHI16_UP}[ComponentPlatformsAttribute(pidWin32 or pidWin64)]{$ENDIF}{$ENDIF}
|
||||
TCEFWorkScheduler = class(TComponent)
|
||||
protected
|
||||
FCompHandle : HWND;
|
||||
FThread : TCEFWorkSchedulerThread;
|
||||
FDepleteWorkCycles : cardinal;
|
||||
FDepleteWorkDelay : cardinal;
|
||||
@ -73,16 +72,21 @@ type
|
||||
FStopped : boolean;
|
||||
{$IFDEF MSWINDOWS}
|
||||
{$WARN SYMBOL_PLATFORM OFF}
|
||||
FCompHandle : HWND;
|
||||
FPriority : TThreadPriority;
|
||||
{$WARN SYMBOL_PLATFORM ON}
|
||||
{$ENDIF}
|
||||
|
||||
procedure CreateThread;
|
||||
procedure DestroyThread;
|
||||
procedure DeallocateWindowHandle;
|
||||
procedure DepleteWork;
|
||||
{$IFDEF MSWINDOWS}
|
||||
procedure WndProc(var aMessage: TMessage);
|
||||
procedure DeallocateWindowHandle;
|
||||
{$ELSE}
|
||||
{$IFDEF FPC}
|
||||
procedure ScheduleWorkAsync(Data: PtrInt);
|
||||
{$ENDIF}
|
||||
{$ENDIF}
|
||||
procedure NextPulse(aInterval : integer);
|
||||
procedure ScheduleWork(const delay_ms : int64);
|
||||
@ -145,10 +149,10 @@ begin
|
||||
inherited Create(AOwner);
|
||||
|
||||
FThread := nil;
|
||||
FCompHandle := 0;
|
||||
FStopped := False;
|
||||
{$IFDEF MSWINDOWS}
|
||||
{$WARN SYMBOL_PLATFORM OFF}
|
||||
FCompHandle := 0;
|
||||
FPriority := tpNormal;
|
||||
{$WARN SYMBOL_PLATFORM ON}
|
||||
{$ENDIF}
|
||||
@ -160,8 +164,9 @@ end;
|
||||
destructor TCEFWorkScheduler.Destroy;
|
||||
begin
|
||||
DestroyThread;
|
||||
{$IFDEF MSWINDOWS}
|
||||
DeallocateWindowHandle;
|
||||
|
||||
{$ENDIF}
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -226,7 +231,6 @@ begin
|
||||
else
|
||||
aMessage.Result := DefWindowProc(FCompHandle, aMessage.Msg, aMessage.WParam, aMessage.LParam);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TCEFWorkScheduler.DeallocateWindowHandle;
|
||||
begin
|
||||
@ -236,6 +240,7 @@ begin
|
||||
FCompHandle := 0;
|
||||
end;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
procedure TCEFWorkScheduler.DoMessageLoopWork;
|
||||
begin
|
||||
@ -277,15 +282,27 @@ begin
|
||||
{$IFDEF MSWINDOWS}
|
||||
if not(FStopped) and (FCompHandle <> 0) then
|
||||
PostMessage(FCompHandle, CEF_PUMPHAVEWORK, 0, LPARAM(delay_ms));
|
||||
{$ELSE}
|
||||
if not(FStopped) then
|
||||
Application.QueueAsyncCall(@ScheduleWorkAsync, integer(delay_ms));
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{$IFNDEF MSWINDOWS}{$IFDEF FPC}
|
||||
procedure TCEFWorkScheduler.ScheduleWorkAsync(Data: PtrInt);
|
||||
begin
|
||||
ScheduleWork(integer(Data));
|
||||
end;
|
||||
{$ENDIF}{$ENDIF}
|
||||
|
||||
procedure TCEFWorkScheduler.StopScheduler;
|
||||
begin
|
||||
FStopped := True;
|
||||
NextPulse(0);
|
||||
DepleteWork;
|
||||
{$IFDEF MSWINDOWS}
|
||||
DeallocateWindowHandle;
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
procedure TCEFWorkScheduler.Thread_OnPulse(Sender: TObject);
|
||||
|
@ -2,7 +2,7 @@
|
||||
"UpdateLazPackages" : [
|
||||
{
|
||||
"ForceNotify" : true,
|
||||
"InternalVersion" : 209,
|
||||
"InternalVersion" : 210,
|
||||
"Name" : "cef4delphi_lazarus.lpk",
|
||||
"Version" : "87.1.12.0"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user