Skip to content

Commit 0c50170

Browse files
committed
A: CEF TTask
1 parent 67d1815 commit 0c50170

7 files changed

+177
-2
lines changed

src/CEF_Events_Declaration.inc

+3
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,6 @@ procedure MenuButtonComponent_OnMenuButtonPressed(const Sender: TObject; const m
220220
{==TCEFTextfieldComponent==}
221221
procedure TextfieldComponent_OnTextfieldKeyEvent(const Sender: TObject; const textfield: ICefTextfield; const event: TCefKeyEvent; var aResult : boolean);
222222
procedure TextfieldComponent_OnAfterUserAction(const Sender: TObject; const textfield: ICefTextfield);
223+
224+
// TTask
225+
procedure Task_OnExecute();

src/CEF_Events_Implement.inc

+6
Original file line numberDiff line numberDiff line change
@@ -1158,3 +1158,9 @@ procedure TLCLEvent.TextfieldComponent_OnAfterUserAction(const Sender: TObject;
11581158
begin
11591159
SendEvent([textfield]);
11601160
end;
1161+
1162+
// TTask
1163+
procedure TLCLEvent.Task_OnExecute();
1164+
begin
1165+
SendEvent([]);
1166+
end;

src/CEF_LCL_Component.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ uCEFExtension,
3232
uCEF_LCL_Entity, uCEF_LCL_Application, uCEF_LCL_Event, uCEF_LCL_V8AccessorRef, uCEF_LCL_V8HandlerRef, uCEF_LCL_V8InterceptorRef, uCEF_LCL_PdfPrintCallbackRef, uCEF_LCL_ClientRef, uCEF_LCL_ClientHandlersRef, uCEF_LCL_ResourceRequestHandlerRef,
3333
uCEF_LCL_V8ArrayBufferReleaseCallbackRef, uCEF_LCL_ValueConvert, uCEF_LCL_CompletionCallbackRef, uCEF_LCL_ExtensionHandlerRef, uCEF_LCL_AccessibilityHandlerRef, uCEF_LCL_CookieCallbacksRef, uCEF_LCL_RequestContextRef, uCEF_LCL_SchemeHandlerFactoryRef, uCEF_LCL_ResponseFilterRef,
3434
uCEF_LCL_DomVisitorRef, uCEF_LCL_WinAPICallbackRef, uCEF_LCL_TString, uCEF_LCL_RunFileDialogCallbackRef, uCEF_LCL_DownloadImageCallbackRef, uCEF_LCL_MenuModelDelegateRef, uCEF_LCL_ViewDelegateRef, uCEF_LCL_BrowserViewDelegateRef, uCEF_LCL_ButtonDelegateRef,
35-
uCEF_LCL_MenuButtonDelegateRef, uCEF_LCL_PanelDelegateRef, uCEF_LCL_TextfieldDelegateRef,uCEF_LCL_WindowDelegateRef,
35+
uCEF_LCL_MenuButtonDelegateRef, uCEF_LCL_PanelDelegateRef, uCEF_LCL_TextfieldDelegateRef,uCEF_LCL_WindowDelegateRef, uCEF_LCL_Task,

src/CEF_LCL_Export.inc

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
{$I CEF_LCL_StreamReader.inc}
106106
{$I CEF_LCL_StreamWriter.inc}
107107
{$I CEF_LCL_StringMultiMap.inc}
108+
{$I CEF_LCL_Task.inc}
108109
{$I CEF_LCL_Textfield.inc}
109110
{$I CEF_LCL_TextfieldComponent.inc}
110111
{$I CEF_LCL_TextfieldDelegate.inc}

src/CEF_LCL_MiscFunctions.inc

+26-1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,28 @@ begin
170170
handleExceptionEnd
171171
end;
172172

173+
174+
function Misc_CefPostTask(aThreadId : TCefThreadId; const aTask: ICefTask) : LongBool; extdecl;
175+
begin
176+
handleExceptionBegin
177+
Result := CefPostTask(aThreadId, aTask);
178+
handleExceptionEnd
179+
end;
180+
181+
function Misc_CefPostDelayedTask(aThreadId : TCefThreadId; const aTask : ICefTask; var aDelayMs : Int64) : LongBool; extdecl;
182+
begin
183+
handleExceptionBegin
184+
Result := CefPostDelayedTask(aThreadId, aTask, aDelayMs);
185+
handleExceptionEnd
186+
end;
187+
188+
function Misc_CefCurrentlyOn(aThreadId : TCefThreadId) : LongBool; extdecl;
189+
begin
190+
handleExceptionBegin
191+
Result := CefCurrentlyOn(aThreadId);
192+
handleExceptionEnd
193+
end;
194+
173195
exports
174196
Misc_WindowInfoAsChild,
175197
Misc_WindowInfoAsPopUp,
@@ -192,4 +214,7 @@ exports
192214
Misc_InitializeWindowHandle,
193215
Misc_ValidCefWindowHandle,
194216
Misc_GetScreenDPI,
195-
Misc_GetDeviceScaleFactor;
217+
Misc_GetDeviceScaleFactor,
218+
Misc_CefPostTask,
219+
Misc_CefPostDelayedTask,
220+
Misc_CefCurrentlyOn;

src/CEF_LCL_Task.inc

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
//constructor
3+
function Task_Create(): TTask; extdecl;
4+
begin
5+
handleExceptionBegin
6+
Result := TTask.Create();
7+
handleExceptionEnd
8+
end;
9+
10+
//function
11+
function Task_OnlyPostTask(AObj: TTask; threadId: TCefThreadId): LongBool; extdecl;
12+
begin
13+
handleExceptionBegin
14+
Result := AObj.OnlyPostTask(threadId);
15+
handleExceptionEnd
16+
end;
17+
18+
//function
19+
function Task_OnlyPostDelayedTask(AObj: TTask; threadId: TCefThreadId; var delay: int64): LongBool; extdecl;
20+
begin
21+
handleExceptionBegin
22+
Result := AObj.OnlyPostDelayedTask(threadId, delay);
23+
handleExceptionEnd
24+
end;
25+
26+
//property event
27+
procedure Task_SetOnExecute(AObj: TTask; AEventData: Pointer); extdecl;
28+
begin
29+
{$DEFINE EventMethodName := Task_OnExecute}
30+
{$DEFINE EventName := OnExecute}
31+
EventMethodCode
32+
end;
33+
34+
35+
exports
36+
Task_Create,
37+
Task_OnlyPostTask,
38+
Task_OnlyPostDelayedTask,
39+
Task_SetOnExecute;

src/uCEF_LCL_Task.pas

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//----------------------------------------
2+
// Copyright © yanghy. All Rights Reserved.
3+
4+
// Licensed under Lazarus.modifiedLGPL
5+
//----------------------------------------
6+
7+
unit uCEF_LCL_Task;
8+
9+
{$mode objfpc}{$H+}
10+
{$I cef.inc}
11+
12+
interface
13+
14+
uses
15+
Classes, SysUtils, uCEFInterfaces, uCEFTypes,
16+
uCEFTask,
17+
uCEFMiscFunctions;
18+
19+
type
20+
21+
// TTask
22+
TTaskExecute = procedure() of object;
23+
24+
/// <summary>
25+
/// Implement this interface for asynchronous task execution. If the task is
26+
/// posted successfully and if the associated message loop is still running then
27+
/// the execute() function will be called on the target thread. If the task
28+
/// fails to post then the task object may be destroyed on the source thread
29+
/// instead of the target thread. For this reason be cautious when performing
30+
/// work in the task object destructor.
31+
/// </summary>
32+
/// <remarks>
33+
/// <para><see cref="uCEFTypes|TCefTask">Implements TCefTask</see></para>
34+
/// <para><see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_task_capi.h">CEF source file: /include/capi/cef_task_capi.h (cef_task_t)</see></para>
35+
/// </remarks>
36+
TTask = class(TCefTaskOwn)
37+
protected
38+
FOnly: boolean;
39+
FOnExecute: TTaskExecute;
40+
/// <summary>
41+
/// Method that will be executed on the target thread.
42+
/// </summary>
43+
procedure Execute; override;
44+
public
45+
constructor Create; override;
46+
destructor Destroy; override;
47+
function OnlyPostTask(threadId: TCefThreadId): Boolean;
48+
function OnlyPostDelayedTask(threadId: TCefThreadId; Delay: int64): Boolean;
49+
published
50+
/// <summary>
51+
/// Method that will be executed on the target thread.
52+
/// </summary>
53+
property OnExecute: TTaskExecute read FOnExecute write FOnExecute;
54+
end;
55+
56+
implementation
57+
58+
constructor TTask.Create();
59+
begin
60+
inherited Create;
61+
FOnExecute := nil;
62+
FOnly := True;
63+
end;
64+
65+
destructor TTask.Destroy;
66+
begin
67+
inherited Destroy;
68+
FOnExecute := nil;
69+
end;
70+
71+
function TTask.OnlyPostTask(threadId: TCefThreadId): Boolean;
72+
begin
73+
Result := False;
74+
if FOnly and assigned(FOnExecute) then
75+
begin
76+
CefPostTask(threadId, self);
77+
FOnly := False;
78+
Result := True;
79+
end;
80+
end;
81+
82+
function TTask.OnlyPostDelayedTask(threadId: TCefThreadId; Delay: int64): Boolean;
83+
begin
84+
Result := False;
85+
if FOnly and assigned(FOnExecute) then
86+
begin
87+
CefPostDelayedTask(threadId, self, Delay);
88+
FOnly := False;
89+
Result := True;
90+
end;
91+
end;
92+
93+
procedure TTask.Execute;
94+
begin
95+
if assigned(FOnExecute) then
96+
begin
97+
FOnExecute();
98+
end;
99+
end;
100+
101+
end.

0 commit comments

Comments
 (0)