1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-04-07 06:50:04 +02:00

Added more time handling functions

This commit is contained in:
salvadordf 2022-06-14 11:27:45 +02:00
parent 337cabaa18
commit 67d3e5e528
4 changed files with 118 additions and 2 deletions

View File

@ -345,6 +345,7 @@ type
function Load_cef_textfield_capi_h : boolean;
function Load_cef_window_capi_h : boolean;
function Load_cef_types_linux_h : boolean;
function Load_cef_time_h : boolean;
procedure ShutDown;
procedure FreeLibcefLibrary;
@ -2549,7 +2550,8 @@ begin
Load_cef_scroll_view_capi_h and
Load_cef_textfield_capi_h and
Load_cef_window_capi_h and
Load_cef_types_linux_h then
Load_cef_types_linux_h and
Load_cef_time_h then
begin
FStatus := asLoaded;
FLibLoaded := True;
@ -3185,6 +3187,22 @@ begin
{$ENDIF}
end;
function TCefApplicationCore.Load_cef_time_h : boolean;
begin
{$IFDEF FPC}Pointer({$ENDIF}cef_time_to_timet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_to_timet');
{$IFDEF FPC}Pointer({$ENDIF}cef_time_from_timet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_from_timet');
{$IFDEF FPC}Pointer({$ENDIF}cef_time_to_doublet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_to_doublet');
{$IFDEF FPC}Pointer({$ENDIF}cef_time_from_doublet{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_from_doublet');
{$IFDEF FPC}Pointer({$ENDIF}cef_time_now{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_now');
{$IFDEF FPC}Pointer({$ENDIF}cef_time_delta{$IFDEF FPC}){$ENDIF} := GetProcAddress(FLibHandle, 'cef_time_delta');
Result := assigned(cef_time_to_timet) and
assigned(cef_time_from_timet) and
assigned(cef_time_to_doublet) and
assigned(cef_time_from_doublet) and
assigned(cef_time_now) and
assigned(cef_time_delta);
end;
// TCEFDirectoryDeleterThread

View File

@ -347,6 +347,14 @@ var
cef_get_current_platform_thread_id : function : TCefPlatformThreadId; cdecl;
cef_get_current_platform_thread_handle : function : TCefPlatformThreadHandle; cdecl;
// /include/internal/cef_time.h
cef_time_to_timet : function(const cef_time: PCefTime; out time_: Int64): integer; cdecl;
cef_time_from_timet : function(time_: int64; out cef_time: TCefTime): integer; cdecl;
cef_time_to_doublet : function(const cef_time: PCefTime; out time_: double): integer; cdecl;
cef_time_from_doublet : function(time: double; out cef_time: TCefTime): integer; cdecl;
cef_time_now : function(out cef_time: TCefTime): integer; cdecl;
cef_time_delta : function(const cef_time1, cef_time2: PCefTime; out delta: int64): integer; cdecl;
// /include/internal/cef_trace_event_internal.h
cef_trace_event_instant : procedure(const category, name, arg1_name: PAnsiChar; arg1_val: uint64; const arg2_name: PAnsiChar; arg2_val: UInt64; copy: Integer); cdecl;
cef_trace_event_begin : procedure(const category, name, arg1_name: PAnsiChar; arg1_val: UInt64; const arg2_name: PAnsiChar; arg2_val: UInt64; copy: Integer); cdecl;

View File

@ -129,6 +129,15 @@ function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
function FixCefTime(const dt : TCefTime): TCefTime;
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
function DateTimeToCefTime(dt: TDateTime): TCefTime;
function CefTimeToDouble(const dt: TCefTime): double;
function DoubleToCefTime(const dt: double): TCefTime;
function CefTimeToUnixTime(const dt: TCefTime): int64;
function UnixTimeToCefTime(const dt: int64): TCefTime;
function CefTimeNow: TCefTime;
function DoubleTimeNow: double;
function CefTimeDelta(const cef_time1, cef_time2: TCefTime): int64;
function GetTimeIntervalMilliseconds(const from_: TCefTime): integer;
procedure InitializeCefTime(var aTime : TCefTime);
function cef_string_wide_copy(const src: PWideChar; src_len: NativeUInt; output: PCefStringWide): Integer;
function cef_string_utf8_copy(const src: PAnsiChar; src_len: NativeUInt; output: PCefStringUtf8): Integer;
@ -617,6 +626,87 @@ begin
Result.millisecond := TempMSec;
end;
function CefTimeToDouble(const dt: TCefTime): double;
begin
Result := 0;
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
cef_time_to_doublet(@dt, Result);
end;
function DoubleToCefTime(const dt: double): TCefTime;
begin
FillChar(Result, SizeOf(TCefTime), #0);
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
cef_time_from_doublet(dt, Result);
end;
function CefTimeToUnixTime(const dt: TCefTime): int64;
begin
Result := 0;
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
cef_time_to_timet(@dt, Result);
end;
function UnixTimeToCefTime(const dt: int64): TCefTime;
begin
FillChar(Result, SizeOf(TCefTime), #0);
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
cef_time_from_timet(dt, Result);
end;
function CefTimeNow: TCefTime;
begin
FillChar(Result, SizeOf(TCefTime), #0);
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
cef_time_now(Result);
end;
function DoubleTimeNow: double;
var
TempTime : TCefTime;
begin
Result := 0;
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
begin
FillChar(TempTime, SizeOf(TCefTime), #0);
if (cef_time_now(TempTime) <> 0) then
cef_time_to_doublet(@TempTime, Result);
end;
end;
function CefTimeDelta(const cef_time1, cef_time2: TCefTime): int64;
begin
Result := 0;
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then
cef_time_delta(@cef_time1, @cef_time2, Result);
end;
function GetTimeIntervalMilliseconds(const from_: TCefTime): integer;
var
TempFrom : double;
TempDelay : integer;
begin
Result := -1;
TempFrom := CefTimeToDouble(from_);
if (TempFrom = 0) then exit;
TempDelay := ceil((TempFrom - DoubleTimeNow) * 1000);
Result := max(0, TempDelay);
end;
procedure InitializeCefTime(var aTime : TCefTime);
begin
aTime.year := 0;
aTime.month := 0;
aTime.day_of_week := 0;
aTime.day_of_month := 0;
aTime.hour := 0;
aTime.minute := 0;
aTime.second := 0;
aTime.millisecond := 0;
end;
function cef_string_wide_copy(const src: PWideChar; src_len: NativeUInt; output: PCefStringWide): Integer;
begin
if (GlobalCEFApp <> nil) and GlobalCEFApp.LibLoaded then

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 400,
"InternalVersion" : 401,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "102.0.9.0"
}