1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Added GlobalCEFApp.TouchEvents property

- Added TChromium.ExecuteTaskOnCefThread function.
- Added TChromium.OnExecuteTaskOnCefThread event.
This commit is contained in:
Salvador Díaz Fau 2019-10-18 17:15:55 +02:00
parent b218368d91
commit 86fd4a0c4d
7 changed files with 129 additions and 1 deletions

View File

@ -182,6 +182,7 @@ type
FDisableSpellChecking : boolean; FDisableSpellChecking : boolean;
FOverrideSpellCheckLang : string; FOverrideSpellCheckLang : string;
FEnablePrintPreview : boolean; FEnablePrintPreview : boolean;
FTouchEvents : TCefState;
FMustCreateResourceBundleHandler : boolean; FMustCreateResourceBundleHandler : boolean;
FMustCreateBrowserProcessHandler : boolean; FMustCreateBrowserProcessHandler : boolean;
@ -424,6 +425,7 @@ type
property EnableProfanityFilter : boolean read FEnableProfanityFilter write FEnableProfanityFilter; // --enable-profanity-filter property EnableProfanityFilter : boolean read FEnableProfanityFilter write FEnableProfanityFilter; // --enable-profanity-filter
property DisableSpellChecking : boolean read FDisableSpellChecking write FDisableSpellChecking; // --disable-spell-checking property DisableSpellChecking : boolean read FDisableSpellChecking write FDisableSpellChecking; // --disable-spell-checking
property OverrideSpellCheckLang : string read FOverrideSpellCheckLang write FOverrideSpellCheckLang; // --override-spell-check-lang property OverrideSpellCheckLang : string read FOverrideSpellCheckLang write FOverrideSpellCheckLang; // --override-spell-check-lang
property TouchEvents : TCefState read FTouchEvents write FTouchEvents; // --touch-events
// Properties used during the CEF initialization // Properties used during the CEF initialization
property WindowsSandboxInfo : Pointer read FWindowsSandboxInfo write FWindowsSandboxInfo; property WindowsSandboxInfo : Pointer read FWindowsSandboxInfo write FWindowsSandboxInfo;
@ -638,6 +640,7 @@ begin
FDisableSpellChecking := False; FDisableSpellChecking := False;
FOverrideSpellCheckLang := ''; FOverrideSpellCheckLang := '';
FEnablePrintPreview := False; FEnablePrintPreview := False;
FTouchEvents := STATE_DEFAULT;
FMustCreateResourceBundleHandler := False; FMustCreateResourceBundleHandler := False;
FMustCreateBrowserProcessHandler := True; FMustCreateBrowserProcessHandler := True;
@ -1551,6 +1554,11 @@ begin
STATE_DISABLED : commandLine.AppendSwitch('--disable-smooth-scrolling'); STATE_DISABLED : commandLine.AppendSwitch('--disable-smooth-scrolling');
end; end;
case FTouchEvents of
STATE_ENABLED : commandLine.AppendSwitchWithValue('--touch-events', 'enabled');
STATE_DISABLED : commandLine.AppendSwitchWithValue('--touch-events', 'disabled');
end;
case FAutoplayPolicy of case FAutoplayPolicy of
appDocumentUserActivationRequired : appDocumentUserActivationRequired :
commandLine.AppendSwitchWithValue('--autoplay-policy', 'document-user-activation-required'); commandLine.AppendSwitchWithValue('--autoplay-policy', 'document-user-activation-required');

View File

@ -252,6 +252,7 @@ type
FOnCertificateExceptionsCleared : TNotifyEvent; FOnCertificateExceptionsCleared : TNotifyEvent;
FOnHttpAuthCredentialsCleared : TNotifyEvent; FOnHttpAuthCredentialsCleared : TNotifyEvent;
FOnAllConnectionsClosed : TNotifyEvent; FOnAllConnectionsClosed : TNotifyEvent;
FOnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread;
{$IFNDEF FPC} {$IFNDEF FPC}
FOnBrowserCompMsg : TOnCompMsgEvent; FOnBrowserCompMsg : TOnCompMsgEvent;
FOnWidgetCompMsg : TOnCompMsgEvent; FOnWidgetCompMsg : TOnCompMsgEvent;
@ -500,6 +501,7 @@ type
procedure doCertificateExceptionsCleared; virtual; procedure doCertificateExceptionsCleared; virtual;
procedure doHttpAuthCredentialsCleared; virtual; procedure doHttpAuthCredentialsCleared; virtual;
procedure doAllConnectionsClosed; virtual; procedure doAllConnectionsClosed; virtual;
procedure doOnExecuteTaskOnCefThread(aTaskID : cardinal); virtual;
function MustCreateLoadHandler : boolean; virtual; function MustCreateLoadHandler : boolean; virtual;
function MustCreateFocusHandler : boolean; virtual; function MustCreateFocusHandler : boolean; virtual;
function MustCreateContextMenuHandler : boolean; virtual; function MustCreateContextMenuHandler : boolean; virtual;
@ -570,6 +572,7 @@ type
procedure ResolveHost(const aURL : ustring); procedure ResolveHost(const aURL : ustring);
function TakeSnapshot(var aBitmap : TBitmap) : boolean; function TakeSnapshot(var aBitmap : TBitmap) : boolean;
function IsSameBrowser(const aBrowser : ICefBrowser) : boolean; function IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
function ExecuteTaskOnCefThread(aCefThreadId : TCefThreadId; aTaskID : cardinal; aDelayMs : Int64 = 0) : boolean;
procedure ShowDevTools(inspectElementAt: TPoint; const aDevTools : TWinControl); procedure ShowDevTools(inspectElementAt: TPoint; const aDevTools : TWinControl);
procedure CloseDevTools(const aDevTools : TWinControl = nil); procedure CloseDevTools(const aDevTools : TWinControl = nil);
@ -715,6 +718,7 @@ type
property OnCertificateExceptionsCleared : TNotifyEvent read FOnCertificateExceptionsCleared write FOnCertificateExceptionsCleared; property OnCertificateExceptionsCleared : TNotifyEvent read FOnCertificateExceptionsCleared write FOnCertificateExceptionsCleared;
property OnHttpAuthCredentialsCleared : TNotifyEvent read FOnHttpAuthCredentialsCleared write FOnHttpAuthCredentialsCleared; property OnHttpAuthCredentialsCleared : TNotifyEvent read FOnHttpAuthCredentialsCleared write FOnHttpAuthCredentialsCleared;
property OnAllConnectionsClosed : TNotifyEvent read FOnAllConnectionsClosed write FOnAllConnectionsClosed; property OnAllConnectionsClosed : TNotifyEvent read FOnAllConnectionsClosed write FOnAllConnectionsClosed;
property OnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread read FOnExecuteTaskOnCefThread write FOnExecuteTaskOnCefThread;
{$IFNDEF FPC} {$IFNDEF FPC}
property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg; property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg;
property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg; property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg;
@ -1220,6 +1224,7 @@ begin
FOnCertificateExceptionsCleared := nil; FOnCertificateExceptionsCleared := nil;
FOnHttpAuthCredentialsCleared := nil; FOnHttpAuthCredentialsCleared := nil;
FOnAllConnectionsClosed := nil; FOnAllConnectionsClosed := nil;
FOnExecuteTaskOnCefThread := nil;
{$IFNDEF FPC} {$IFNDEF FPC}
FOnBrowserCompMsg := nil; FOnBrowserCompMsg := nil;
FOnWidgetCompMsg := nil; FOnWidgetCompMsg := nil;
@ -2633,6 +2638,33 @@ begin
Result := Initialized and (aBrowser <> nil) and FBrowser.IsSame(aBrowser); Result := Initialized and (aBrowser <> nil) and FBrowser.IsSame(aBrowser);
end; end;
// Calling ExecuteTaskOnCefThread function will trigger the TChromium.OnExecuteTaskOnCefThread event.
// "aCefThreadId" indicates the CEF thread on which TChromium.OnExecuteTaskOnCefThread will be executed.
// "aTaskID" is a custom ID used to identify the task that triggered the TChromium.OnExecuteTaskOnCefThread event.
// "aDelayMs" is an optional delay in milliseconds to trigger the TChromium.OnExecuteTaskOnCefThread event.
function TChromium.ExecuteTaskOnCefThread(aCefThreadId : TCefThreadId; aTaskID : cardinal; aDelayMs : Int64) : boolean;
var
TempTask : ICefTask;
begin
Result := False;
try
if Initialized then
begin
TempTask := TCefGenericTask.Create(self, aTaskID);
if (aDelayMs <> 0) then
CefPostDelayedTask(aCefThreadId, TempTask, aDelayMs)
else
CefPostTask(aCefThreadId, TempTask);
Result := True;
end;
finally
TempTask := nil;
end;
end;
procedure TChromium.SimulateMouseWheel(aDeltaX, aDeltaY : integer); procedure TChromium.SimulateMouseWheel(aDeltaX, aDeltaY : integer);
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
@ -3261,6 +3293,11 @@ begin
if assigned(FOnAllConnectionsClosed) then FOnAllConnectionsClosed(self); if assigned(FOnAllConnectionsClosed) then FOnAllConnectionsClosed(self);
end; end;
procedure TChromium.doOnExecuteTaskOnCefThread(aTaskID : cardinal);
begin
if assigned(FOnExecuteTaskOnCefThread) then FOnExecuteTaskOnCefThread(self, aTaskID);
end;
function TChromium.MustCreateLoadHandler : boolean; function TChromium.MustCreateLoadHandler : boolean;
begin begin
Result := assigned(FOnLoadStart) or Result := assigned(FOnLoadStart) or

View File

@ -173,6 +173,7 @@ type
TOnResolvedIPsAvailableEvent = procedure(Sender: TObject; result: TCefErrorCode; const resolvedIps: TStrings) of object; TOnResolvedIPsAvailableEvent = procedure(Sender: TObject; result: TCefErrorCode; const resolvedIps: TStrings) of object;
TOnNavigationVisitorResultAvailableEvent = procedure(const entry: ICefNavigationEntry; current: Boolean; index, total: Integer; var aResult : boolean) of object; TOnNavigationVisitorResultAvailableEvent = procedure(const entry: ICefNavigationEntry; current: Boolean; index, total: Integer; var aResult : boolean) of object;
TOnDownloadImageFinishedEvent = procedure(Sender: TObject; const imageUrl: ustring; httpStatusCode: Integer; const image: ICefImage) of object; TOnDownloadImageFinishedEvent = procedure(Sender: TObject; const imageUrl: ustring; httpStatusCode: Integer; const image: ICefImage) of object;
TOnExecuteTaskOnCefThread = procedure(Sender: TObject; aTaskID : cardinal) of object;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
TOnCompMsgEvent = procedure(var aMessage: TMessage; var aHandled: Boolean) of object; TOnCompMsgEvent = procedure(var aMessage: TMessage; var aHandled: Boolean) of object;
{$ENDIF} {$ENDIF}

View File

@ -235,6 +235,7 @@ type
FOnCertificateExceptionsCleared : TNotifyEvent; FOnCertificateExceptionsCleared : TNotifyEvent;
FOnHttpAuthCredentialsCleared : TNotifyEvent; FOnHttpAuthCredentialsCleared : TNotifyEvent;
FOnAllConnectionsClosed : TNotifyEvent; FOnAllConnectionsClosed : TNotifyEvent;
FOnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
FOnBrowserCompMsg : TOnCompMsgEvent; FOnBrowserCompMsg : TOnCompMsgEvent;
FOnWidgetCompMsg : TOnCompMsgEvent; FOnWidgetCompMsg : TOnCompMsgEvent;
@ -467,6 +468,7 @@ type
procedure doCertificateExceptionsCleared; virtual; procedure doCertificateExceptionsCleared; virtual;
procedure doHttpAuthCredentialsCleared; virtual; procedure doHttpAuthCredentialsCleared; virtual;
procedure doAllConnectionsClosed; virtual; procedure doAllConnectionsClosed; virtual;
procedure doOnExecuteTaskOnCefThread(aTaskID : cardinal); virtual;
function MustCreateLoadHandler : boolean; virtual; function MustCreateLoadHandler : boolean; virtual;
function MustCreateFocusHandler : boolean; virtual; function MustCreateFocusHandler : boolean; virtual;
function MustCreateContextMenuHandler : boolean; virtual; function MustCreateContextMenuHandler : boolean; virtual;
@ -535,6 +537,7 @@ type
procedure SavePreferences(const aFileName : string); procedure SavePreferences(const aFileName : string);
procedure ResolveHost(const aURL : ustring); procedure ResolveHost(const aURL : ustring);
function IsSameBrowser(const aBrowser : ICefBrowser) : boolean; function IsSameBrowser(const aBrowser : ICefBrowser) : boolean;
function ExecuteTaskOnCefThread(aCefThreadId : TCefThreadId; aTaskID : cardinal; aDelayMs : Int64 = 0) : boolean;
procedure ShowDevTools(inspectElementAt: TPoint); procedure ShowDevTools(inspectElementAt: TPoint);
procedure CloseDevTools; procedure CloseDevTools;
@ -674,6 +677,7 @@ type
property OnCertificateExceptionsCleared : TNotifyEvent read FOnCertificateExceptionsCleared write FOnCertificateExceptionsCleared; property OnCertificateExceptionsCleared : TNotifyEvent read FOnCertificateExceptionsCleared write FOnCertificateExceptionsCleared;
property OnHttpAuthCredentialsCleared : TNotifyEvent read FOnHttpAuthCredentialsCleared write FOnHttpAuthCredentialsCleared; property OnHttpAuthCredentialsCleared : TNotifyEvent read FOnHttpAuthCredentialsCleared write FOnHttpAuthCredentialsCleared;
property OnAllConnectionsClosed : TNotifyEvent read FOnAllConnectionsClosed write FOnAllConnectionsClosed; property OnAllConnectionsClosed : TNotifyEvent read FOnAllConnectionsClosed write FOnAllConnectionsClosed;
property OnExecuteTaskOnCefThread : TOnExecuteTaskOnCefThread read FOnExecuteTaskOnCefThread write FOnExecuteTaskOnCefThread;
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg; property OnBrowserCompMsg : TOnCompMsgEvent read FOnBrowserCompMsg write FOnBrowserCompMsg;
property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg; property OnWidgetCompMsg : TOnCompMsgEvent read FOnWidgetCompMsg write FOnWidgetCompMsg;
@ -1123,6 +1127,7 @@ begin
FOnCertificateExceptionsCleared := nil; FOnCertificateExceptionsCleared := nil;
FOnHttpAuthCredentialsCleared := nil; FOnHttpAuthCredentialsCleared := nil;
FOnAllConnectionsClosed := nil; FOnAllConnectionsClosed := nil;
FOnExecuteTaskOnCefThread := nil;
end; end;
function TFMXChromium.CreateBrowser(const aWindowName : ustring; function TFMXChromium.CreateBrowser(const aWindowName : ustring;
@ -2381,6 +2386,33 @@ begin
Result := Initialized and (aBrowser <> nil) and FBrowser.IsSame(aBrowser); Result := Initialized and (aBrowser <> nil) and FBrowser.IsSame(aBrowser);
end; end;
// Calling ExecuteTaskOnCefThread function will trigger the TChromium.OnExecuteTaskOnCefThread event.
// "aCefThreadId" indicates the CEF thread on which TChromium.OnExecuteTaskOnCefThread will be executed.
// "aTaskID" is a custom ID used to identify the task that triggered the TChromium.OnExecuteTaskOnCefThread event.
// "aDelayMs" is an optional delay in milliseconds to trigger the TChromium.OnExecuteTaskOnCefThread event.
function TFMXChromium.ExecuteTaskOnCefThread(aCefThreadId : TCefThreadId; aTaskID : cardinal; aDelayMs : Int64) : boolean;
var
TempTask : ICefTask;
begin
Result := False;
try
if Initialized then
begin
TempTask := TCefGenericTask.Create(self, aTaskID);
if (aDelayMs <> 0) then
CefPostDelayedTask(aCefThreadId, TempTask, aDelayMs)
else
CefPostTask(aCefThreadId, TempTask);
Result := True;
end;
finally
TempTask := nil;
end;
end;
procedure TFMXChromium.SimulateMouseWheel(aDeltaX, aDeltaY : integer); procedure TFMXChromium.SimulateMouseWheel(aDeltaX, aDeltaY : integer);
var var
TempEvent : TCefMouseEvent; TempEvent : TCefMouseEvent;
@ -3003,6 +3035,11 @@ begin
if assigned(FOnAllConnectionsClosed) then FOnAllConnectionsClosed(self); if assigned(FOnAllConnectionsClosed) then FOnAllConnectionsClosed(self);
end; end;
procedure TFMXChromium.doOnExecuteTaskOnCefThread(aTaskID : cardinal);
begin
if assigned(FOnExecuteTaskOnCefThread) then FOnExecuteTaskOnCefThread(self, aTaskID);
end;
function TFMXChromium.MustCreateLoadHandler : boolean; function TFMXChromium.MustCreateLoadHandler : boolean;
begin begin
Result := assigned(FOnLoadStart) or Result := assigned(FOnLoadStart) or

View File

@ -393,6 +393,7 @@ type
procedure doCertificateExceptionsCleared; procedure doCertificateExceptionsCleared;
procedure doHttpAuthCredentialsCleared; procedure doHttpAuthCredentialsCleared;
procedure doAllConnectionsClosed; procedure doAllConnectionsClosed;
procedure doOnExecuteTaskOnCefThread(aTaskID : cardinal);
function MustCreateLoadHandler : boolean; function MustCreateLoadHandler : boolean;
function MustCreateFocusHandler : boolean; function MustCreateFocusHandler : boolean;
function MustCreateContextMenuHandler : boolean; function MustCreateContextMenuHandler : boolean;

View File

@ -113,6 +113,18 @@ type
destructor Destroy; override; destructor Destroy; override;
end; end;
TCefGenericTask = class(TCefTaskOwn)
protected
FEvents : Pointer;
FTaskID : cardinal;
procedure Execute; override;
public
constructor Create(const aEvents : IChromiumEvents; aTaskID : cardinal); reintroduce;
destructor Destroy; override;
end;
implementation implementation
uses uses
@ -283,4 +295,36 @@ begin
inherited Destroy; inherited Destroy;
end; end;
// TCefGenericTask
procedure TCefGenericTask.Execute;
begin
try
try
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnExecuteTaskOnCefThread(FTaskID);
except
on e : exception do
if CustomExceptionHandler('TCefGenericTask.Execute', e) then raise;
end;
finally
FEvents := nil;
end;
end;
constructor TCefGenericTask.Create(const aEvents : IChromiumEvents; aTaskID : cardinal);
begin
inherited Create;
FEvents := Pointer(aEvents);
FTaskID := aTaskID;
end;
destructor TCefGenericTask.Destroy;
begin
FEvents := nil;
inherited Destroy;
end;
end. end.

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [ "UpdateLazPackages" : [
{ {
"ForceNotify" : true, "ForceNotify" : true,
"InternalVersion" : 46, "InternalVersion" : 47,
"Name" : "cef4delphi_lazarus.lpk", "Name" : "cef4delphi_lazarus.lpk",
"Version" : "77.1.14.0" "Version" : "77.1.14.0"
} }