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

738 lines
26 KiB
ObjectPascal
Raw Normal View History

2017-01-27 18:29:37 +02:00
unit uCEFBrowser;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
2017-02-05 21:56:46 +02:00
{$I cef.inc}
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
{$MINENUMSIZE 4}
2017-01-27 18:29:37 +02:00
interface
uses
2017-02-05 21:56:46 +02:00
{$IFDEF DELPHI16_UP}
System.Classes, System.SysUtils,
2017-02-05 21:56:46 +02:00
{$ELSE}
Classes, SysUtils,
2017-02-05 21:56:46 +02:00
{$ENDIF}
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
2017-01-27 18:29:37 +02:00
type
TCefBrowserRef = class(TCefBaseRefCountedRef, ICefBrowser)
2017-01-27 18:29:37 +02:00
protected
2021-07-29 16:20:34 +02:00
function IsValid: boolean;
2017-01-27 18:29:37 +02:00
function GetHost: ICefBrowserHost;
function CanGoBack: Boolean;
procedure GoBack;
function CanGoForward: Boolean;
procedure GoForward;
function IsLoading: Boolean;
procedure Reload;
procedure ReloadIgnoreCache;
procedure StopLoad;
function GetIdentifier: Integer;
function IsSame(const that: ICefBrowser): Boolean;
function IsPopup: Boolean;
function HasDocument: Boolean;
function GetMainFrame: ICefFrame;
function GetFocusedFrame: ICefFrame;
2018-03-29 20:02:04 +02:00
function GetFrameByident(const identifier: Int64): ICefFrame;
2017-01-27 18:29:37 +02:00
function GetFrame(const name: ustring): ICefFrame;
function GetFrameCount: NativeUInt;
function GetFrameIdentifiers(var aFrameCount : NativeUInt; var aFrameIdentifierArray : TCefFrameIdentifierArray) : boolean;
function GetFrameNames(var aFrameNames : TStrings) : boolean;
2017-01-27 18:29:37 +02:00
public
class function UnWrap(data: Pointer): ICefBrowser;
end;
TCefBrowserHostRef = class(TCefBaseRefCountedRef, ICefBrowserHost)
2017-01-27 18:29:37 +02:00
protected
function GetBrowser: ICefBrowser;
procedure CloseBrowser(forceClose: Boolean);
function TryCloseBrowser: Boolean;
procedure SetFocus(focus: Boolean);
function GetWindowHandle: TCefWindowHandle;
function GetOpenerWindowHandle: TCefWindowHandle;
function HasView: Boolean;
2023-08-07 20:21:42 +02:00
function GetClient: ICefClient;
2017-01-27 18:29:37 +02:00
function GetRequestContext: ICefRequestContext;
function GetZoomLevel: Double;
2018-03-29 20:02:04 +02:00
procedure SetZoomLevel(const zoomLevel: Double);
2022-05-26 13:08:20 +02:00
procedure RunFileDialog(mode: TCefFileDialogMode; const title, defaultFilePath: ustring; const acceptFilters: TStrings; const callback: ICefRunFileDialogCallback);
procedure RunFileDialogProc(mode: TCefFileDialogMode; const title, defaultFilePath: ustring; const acceptFilters: TStrings; const callback: TCefRunFileDialogCallbackProc);
2017-01-27 18:29:37 +02:00
procedure StartDownload(const url: ustring);
procedure DownloadImage(const imageUrl: ustring; isFavicon: Boolean; maxImageSize: Cardinal; bypassCache: Boolean; const callback: ICefDownloadImageCallback);
procedure DownloadImageProc(const imageUrl: ustring; isFavicon: Boolean; maxImageSize: Cardinal; bypassCache: Boolean; const callback: TOnDownloadImageFinishedProc);
procedure Print;
procedure PrintToPdf(const path: ustring; settings: PCefPdfPrintSettings; const callback: ICefPdfPrintCallback);
procedure PrintToPdfProc(const path: ustring; settings: PCefPdfPrintSettings; const callback: TOnPdfPrintFinishedProc);
2022-03-03 12:16:30 +02:00
procedure Find(const searchText: ustring; forward_, matchCase, findNext: Boolean);
2017-01-27 18:29:37 +02:00
procedure StopFinding(clearSelection: Boolean);
procedure ShowDevTools(const windowInfo: PCefWindowInfo; const client: ICefClient; const settings: PCefBrowserSettings; inspectElementAt: PCefPoint);
procedure CloseDevTools;
function HasDevTools: Boolean;
2020-06-21 21:27:55 +02:00
function SendDevToolsMessage(const message_: ustring): boolean;
function ExecuteDevToolsMethod(message_id: integer; const method: ustring; const params: ICefDictionaryValue): Integer;
function AddDevToolsMessageObserver(const observer: ICefDevToolsMessageObserver): ICefRegistration;
2017-01-27 18:29:37 +02:00
procedure GetNavigationEntries(const visitor: ICefNavigationEntryVisitor; currentOnly: Boolean);
procedure GetNavigationEntriesProc(const proc: TCefNavigationEntryVisitorProc; currentOnly: Boolean);
procedure ReplaceMisspelling(const word: ustring);
procedure AddWordToDictionary(const word: ustring);
function IsWindowRenderingDisabled: Boolean;
procedure WasResized;
procedure NotifyScreenInfoChanged;
procedure WasHidden(hidden: Boolean);
procedure Invalidate(type_: TCefPaintElementType);
2018-12-12 18:13:23 +02:00
procedure SendExternalBeginFrame;
2017-01-27 18:29:37 +02:00
procedure SendKeyEvent(const event: PCefKeyEvent);
procedure SendMouseClickEvent(const event: PCefMouseEvent; type_: TCefMouseButtonType; mouseUp: Boolean; clickCount: Integer);
2017-01-27 18:29:37 +02:00
procedure SendMouseMoveEvent(const event: PCefMouseEvent; mouseLeave: Boolean);
procedure SendMouseWheelEvent(const event: PCefMouseEvent; deltaX, deltaY: Integer);
2019-03-15 18:17:14 +02:00
procedure SendTouchEvent(const event: PCefTouchEvent);
2017-01-27 18:29:37 +02:00
procedure SendCaptureLostEvent;
procedure NotifyMoveOrResizeStarted;
2018-03-29 20:02:04 +02:00
function GetWindowlessFrameRate : Integer;
2017-01-27 18:29:37 +02:00
procedure SetWindowlessFrameRate(frameRate: Integer);
procedure IMESetComposition(const text: ustring; const underlines : TCefCompositionUnderlineDynArray; const replacement_range, selection_range : PCefRange);
2017-01-27 18:29:37 +02:00
procedure IMECommitText(const text: ustring; const replacement_range : PCefRange; relative_cursor_pos : integer);
procedure IMEFinishComposingText(keep_selection : boolean);
procedure IMECancelComposition;
procedure DragTargetDragEnter(const dragData: ICefDragData; const event: PCefMouseEvent; allowedOps: TCefDragOperations);
procedure DragTargetDragOver(const event: PCefMouseEvent; allowedOps: TCefDragOperations);
procedure DragTargetDragLeave;
procedure DragTargetDrop(const event: PCefMouseEvent);
2017-01-27 18:29:37 +02:00
procedure DragSourceEndedAt(x, y: Integer; op: TCefDragOperation);
procedure DragSourceSystemDragEnded;
function GetVisibleNavigationEntry : ICefNavigationEntry;
2017-06-06 12:49:27 +02:00
procedure SetAccessibilityState(accessibilityState: TCefState);
2017-10-26 13:23:13 +02:00
procedure SetAutoResizeEnabled(enabled: boolean; const min_size, max_size: PCefSize);
function GetExtension : ICefExtension;
function IsBackgroundHost : boolean;
2019-03-15 18:17:14 +02:00
procedure SetAudioMuted(mute: boolean);
function IsAudioMuted : boolean;
2017-01-27 18:29:37 +02:00
public
class function UnWrap(data: Pointer): ICefBrowserHost;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions, uCEFDownloadImageCallBack, uCEFFrame, uCEFPDFPrintCallback,
2017-10-26 13:23:13 +02:00
uCEFRunFileDialogCallback, uCEFRequestContext, uCEFNavigationEntryVisitor, uCEFNavigationEntry,
2023-08-07 20:21:42 +02:00
uCEFExtension, uCEFStringList, uCEFRegistration, uCEFClient;
2017-01-27 18:29:37 +02:00
2018-12-12 18:13:23 +02:00
// TCefBrowserRef
2021-07-29 16:20:34 +02:00
function TCefBrowserRef.IsValid: boolean;
begin
Result := PCefBrowser(FData)^.is_valid(PCefBrowser(FData)) <> 0;
end;
2017-01-27 18:29:37 +02:00
function TCefBrowserRef.GetHost: ICefBrowserHost;
begin
Result := TCefBrowserHostRef.UnWrap(PCefBrowser(FData)^.get_host(PCefBrowser(FData)));
end;
function TCefBrowserRef.CanGoBack: Boolean;
begin
Result := PCefBrowser(FData)^.can_go_back(PCefBrowser(FData)) <> 0;
end;
function TCefBrowserRef.CanGoForward: Boolean;
begin
Result := PCefBrowser(FData)^.can_go_forward(PCefBrowser(FData)) <> 0;
end;
function TCefBrowserRef.GetFocusedFrame: ICefFrame;
begin
Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_focused_frame(PCefBrowser(FData)));
end;
2018-03-29 20:02:04 +02:00
function TCefBrowserRef.GetFrameByident(const identifier: Int64): ICefFrame;
2017-01-27 18:29:37 +02:00
begin
Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_frame_byident(PCefBrowser(FData), identifier));
end;
function TCefBrowserRef.GetFrame(const name: ustring): ICefFrame;
var
TempName : TCefString;
2017-01-27 18:29:37 +02:00
begin
TempName := CefString(name);
Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_frame(PCefBrowser(FData), @TempName));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserRef.GetFrameCount: NativeUInt;
begin
Result := PCefBrowser(FData)^.get_frame_count(PCefBrowser(FData));
end;
function TCefBrowserRef.GetFrameIdentifiers(var aFrameCount : NativeUInt; var aFrameIdentifierArray : TCefFrameIdentifierArray) : boolean;
var
i : NativeUInt;
2017-01-27 18:29:37 +02:00
begin
Result := False;
try
if (aFrameCount > 0) then
begin
SetLength(aFrameIdentifierArray, aFrameCount);
i := 0;
while (i < aFrameCount) do
begin
aFrameIdentifierArray[i] := 0;
inc(i);
end;
PCefBrowser(FData)^.get_frame_identifiers(PCefBrowser(FData), aFrameCount, aFrameIdentifierArray[0]);
Result := True;
end;
except
on e : exception do
if CustomExceptionHandler('TCefBrowserRef.GetFrameIdentifiers', e) then raise;
end;
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserRef.GetFrameNames(var aFrameNames : TStrings) : boolean;
2017-01-27 18:29:37 +02:00
var
2018-03-29 20:02:04 +02:00
TempSL : ICefStringList;
2017-01-27 18:29:37 +02:00
begin
Result := False;
2018-03-29 20:02:04 +02:00
if (aFrameNames <> nil) then
begin
TempSL := TCefStringListOwn.Create;
PCefBrowser(FData)^.get_frame_names(PCefBrowser(FData), TempSL.Handle);
TempSL.CopyToStrings(aFrameNames);
Result := True;
end;
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserRef.GetMainFrame: ICefFrame;
begin
Result := TCefFrameRef.UnWrap(PCefBrowser(FData)^.get_main_frame(PCefBrowser(FData)))
end;
procedure TCefBrowserRef.GoBack;
begin
PCefBrowser(FData)^.go_back(PCefBrowser(FData));
end;
procedure TCefBrowserRef.GoForward;
begin
PCefBrowser(FData)^.go_forward(PCefBrowser(FData));
end;
function TCefBrowserRef.IsLoading: Boolean;
begin
Result := PCefBrowser(FData)^.is_loading(PCefBrowser(FData)) <> 0;
end;
function TCefBrowserRef.HasDocument: Boolean;
begin
Result := PCefBrowser(FData)^.has_document(PCefBrowser(FData)) <> 0;
end;
function TCefBrowserRef.IsPopup: Boolean;
begin
Result := PCefBrowser(FData)^.is_popup(PCefBrowser(FData)) <> 0;
end;
function TCefBrowserRef.IsSame(const that: ICefBrowser): Boolean;
begin
Result := PCefBrowser(FData)^.is_same(PCefBrowser(FData), CefGetData(that)) <> 0;
end;
procedure TCefBrowserRef.Reload;
begin
PCefBrowser(FData)^.reload(PCefBrowser(FData));
end;
procedure TCefBrowserRef.ReloadIgnoreCache;
begin
PCefBrowser(FData)^.reload_ignore_cache(PCefBrowser(FData));
end;
procedure TCefBrowserRef.StopLoad;
begin
PCefBrowser(FData)^.stop_load(PCefBrowser(FData));
end;
function TCefBrowserRef.GetIdentifier: Integer;
begin
Result := PCefBrowser(FData)^.get_identifier(PCefBrowser(FData));
end;
class function TCefBrowserRef.UnWrap(data: Pointer): ICefBrowser;
begin
if (data <> nil) then
Result := Create(data) as ICefBrowser
else
Result := nil;
end;
2018-12-12 18:13:23 +02:00
2017-01-27 18:29:37 +02:00
// TCefBrowserHostRef
procedure TCefBrowserHostRef.CloseDevTools;
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.close_dev_tools(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DownloadImage(const imageUrl : ustring;
isFavicon : Boolean;
maxImageSize : Cardinal;
bypassCache : Boolean;
const callback : ICefDownloadImageCallback);
2017-01-27 18:29:37 +02:00
var
url: TCefString;
begin
url := CefString(imageUrl);
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.download_image(PCefBrowserHost(FData),
@url,
Ord(isFavicon),
maxImageSize,
Ord(bypassCache),
CefGetData(callback));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DownloadImageProc(const imageUrl : ustring;
isFavicon : Boolean;
maxImageSize : Cardinal;
bypassCache : Boolean;
const callback : TOnDownloadImageFinishedProc);
2017-01-27 18:29:37 +02:00
begin
DownloadImage(imageUrl, isFavicon, maxImageSize, bypassCache, TCefFastDownloadImageCallback.Create(callback));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DragSourceEndedAt(x, y: Integer; op: TCefDragOperation);
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.drag_source_ended_at(PCefBrowserHost(FData), x, y, op);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DragSourceSystemDragEnded;
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.drag_source_system_drag_ended(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.GetVisibleNavigationEntry : ICefNavigationEntry;
begin
Result := TCefNavigationEntryRef.UnWrap(PCefBrowserHost(FData)^.get_visible_navigation_entry(PCefBrowserHost(FData)));
2017-01-27 18:29:37 +02:00
end;
2017-06-06 12:49:27 +02:00
procedure TCefBrowserHostRef.SetAccessibilityState(accessibilityState: TCefState);
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.set_accessibility_state(PCefBrowserHost(FData), accessibilityState);
2017-06-06 12:49:27 +02:00
end;
2017-10-26 13:23:13 +02:00
procedure TCefBrowserHostRef.SetAutoResizeEnabled(enabled: boolean; const min_size, max_size: PCefSize);
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.set_auto_resize_enabled(PCefBrowserHost(FData), Ord(enabled), min_size, max_size);
2017-10-26 13:23:13 +02:00
end;
function TCefBrowserHostRef.GetExtension : ICefExtension;
begin
2018-12-12 18:13:23 +02:00
Result := TCefExtensionRef.UnWrap(PCefBrowserHost(FData)^.get_extension(PCefBrowserHost(FData)));
2017-10-26 13:23:13 +02:00
end;
function TCefBrowserHostRef.IsBackgroundHost : boolean;
begin
2018-12-12 18:13:23 +02:00
Result := PCefBrowserHost(FData)^.is_background_host(PCefBrowserHost(FData)) <> 0;
2017-10-26 13:23:13 +02:00
end;
2019-03-15 18:17:14 +02:00
procedure TCefBrowserHostRef.SetAudioMuted(mute: boolean);
begin
PCefBrowserHost(FData)^.set_audio_muted(PCefBrowserHost(FData), Ord(mute));
end;
function TCefBrowserHostRef.IsAudioMuted : boolean;
begin
Result := PCefBrowserHost(FData)^.is_audio_muted(PCefBrowserHost(FData)) <> 0;
end;
procedure TCefBrowserHostRef.DragTargetDragEnter(const dragData: ICefDragData; const event: PCefMouseEvent; allowedOps: TCefDragOperations);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.drag_target_drag_enter(PCefBrowserHost(FData), CefGetData(dragData), event, allowedOps);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DragTargetDragLeave;
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.drag_target_drag_leave(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DragTargetDragOver(const event: PCefMouseEvent; allowedOps: TCefDragOperations);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.drag_target_drag_over(PCefBrowserHost(FData), event, allowedOps);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.DragTargetDrop(const event: PCefMouseEvent);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.drag_target_drop(PCefBrowserHost(FData), event);
2017-01-27 18:29:37 +02:00
end;
2022-03-03 12:16:30 +02:00
procedure TCefBrowserHostRef.Find(const searchText: ustring; forward_, matchCase, findNext: Boolean);
2017-01-27 18:29:37 +02:00
var
TempText : TCefString;
2017-01-27 18:29:37 +02:00
begin
TempText := CefString(searchText);
2022-03-03 12:16:30 +02:00
PCefBrowserHost(FData)^.find(PCefBrowserHost(FData), @TempText, Ord(forward_), Ord(matchCase), Ord(findNext));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.GetBrowser: ICefBrowser;
begin
Result := TCefBrowserRef.UnWrap(PCefBrowserHost(FData)^.get_browser(PCefBrowserHost(FData)));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.Print;
begin
PCefBrowserHost(FData)^.print(FData);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.PrintToPdf(const path : ustring;
settings : PCefPdfPrintSettings;
const callback : ICefPdfPrintCallback);
2017-01-27 18:29:37 +02:00
var
str: TCefString;
begin
str := CefString(path);
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.print_to_pdf(PCefBrowserHost(FData), @str, settings, CefGetData(callback));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.PrintToPdfProc(const path : ustring;
settings : PCefPdfPrintSettings;
const callback : TOnPdfPrintFinishedProc);
2017-01-27 18:29:37 +02:00
begin
PrintToPdf(path, settings, TCefFastPdfPrintCallback.Create(callback));
end;
procedure TCefBrowserHostRef.ReplaceMisspelling(const word: ustring);
var
str: TCefString;
begin
str := CefString(word);
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.replace_misspelling(PCefBrowserHost(FData), @str);
2017-01-27 18:29:37 +02:00
end;
2018-02-26 19:40:51 +02:00
procedure TCefBrowserHostRef.RunFileDialog( mode : TCefFileDialogMode;
const title : ustring;
const defaultFilePath : ustring;
const acceptFilters : TStrings;
const callback : ICefRunFileDialogCallback);
2017-01-27 18:29:37 +02:00
var
2018-03-29 20:02:04 +02:00
TempTitle, TempPath : TCefString;
TempAcceptFilters : ICefStringList;
begin
2017-01-27 18:29:37 +02:00
try
2018-03-29 20:02:04 +02:00
TempTitle := CefString(title);
TempPath := CefString(defaultFilePath);
TempAcceptFilters := TCefStringListOwn.Create;
TempAcceptFilters.AddStrings(acceptFilters);
PCefBrowserHost(FData)^.run_file_dialog(PCefBrowserHost(FData),
mode,
@TempTitle,
@TempPath,
TempAcceptFilters.Handle,
CefGetData(callback));
2017-01-27 18:29:37 +02:00
finally
2018-03-29 20:02:04 +02:00
TempAcceptFilters := nil;
2017-01-27 18:29:37 +02:00
end;
end;
2018-02-26 19:40:51 +02:00
procedure TCefBrowserHostRef.RunFileDialogProc( mode : TCefFileDialogMode;
const title : ustring;
const defaultFilePath : ustring;
const acceptFilters : TStrings;
const callback : TCefRunFileDialogCallbackProc);
2017-01-27 18:29:37 +02:00
begin
2022-05-26 13:08:20 +02:00
RunFileDialog(mode, title, defaultFilePath, acceptFilters, TCefFastRunFileDialogCallback.Create(callback));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.AddWordToDictionary(const word: ustring);
var
str: TCefString;
begin
str := CefString(word);
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.add_word_to_dictionary(PCefBrowserHost(FData), @str);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.CloseBrowser(forceClose: Boolean);
begin
PCefBrowserHost(FData)^.close_browser(PCefBrowserHost(FData), Ord(forceClose));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.SendCaptureLostEvent;
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.send_capture_lost_event(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.SendKeyEvent(const event: PCefKeyEvent);
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.send_key_event(PCefBrowserHost(FData), event);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.SendMouseClickEvent(const event : PCefMouseEvent;
type_ : TCefMouseButtonType;
mouseUp : Boolean;
clickCount : Integer);
2017-01-27 18:29:37 +02:00
begin
PCefBrowserHost(FData)^.send_mouse_click_event(PCefBrowserHost(FData), event, type_, Ord(mouseUp), clickCount);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.SendMouseMoveEvent(const event: PCefMouseEvent; mouseLeave: Boolean);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.send_mouse_move_event(PCefBrowserHost(FData), event, Ord(mouseLeave));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.SendMouseWheelEvent(const event: PCefMouseEvent; deltaX, deltaY: Integer);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.send_mouse_wheel_event(PCefBrowserHost(FData), event, deltaX, deltaY);
2017-01-27 18:29:37 +02:00
end;
2019-03-15 18:17:14 +02:00
procedure TCefBrowserHostRef.SendTouchEvent(const event: PCefTouchEvent);
begin
PCefBrowserHost(FData)^.send_touch_event(PCefBrowserHost(FData), event);
end;
2017-01-27 18:29:37 +02:00
procedure TCefBrowserHostRef.SetFocus(focus: Boolean);
begin
PCefBrowserHost(FData)^.set_focus(PCefBrowserHost(FData), Ord(focus));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.SetWindowlessFrameRate(frameRate: Integer);
begin
PCefBrowserHost(FData)^.set_windowless_frame_rate(PCefBrowserHost(FData), frameRate);
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.GetWindowHandle: TCefWindowHandle;
begin
Result := PCefBrowserHost(FData)^.get_window_handle(PCefBrowserHost(FData))
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.GetWindowlessFrameRate: Integer;
begin
Result := PCefBrowserHost(FData)^.get_windowless_frame_rate(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.GetOpenerWindowHandle: TCefWindowHandle;
begin
Result := PCefBrowserHost(FData)^.get_opener_window_handle(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
2023-08-07 20:21:42 +02:00
function TCefBrowserHostRef.GetClient: ICefClient;
begin
Result := TCefClientRef.UnWrap(PCefBrowserHost(FData)^.get_client(PCefBrowserHost(FData)));
end;
2017-01-27 18:29:37 +02:00
function TCefBrowserHostRef.GetRequestContext: ICefRequestContext;
begin
2018-12-12 18:13:23 +02:00
Result := TCefRequestContextRef.UnWrap(PCefBrowserHost(FData)^.get_request_context(PCefBrowserHost(FData)));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.GetNavigationEntries(const visitor: ICefNavigationEntryVisitor; currentOnly: Boolean);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.get_navigation_entries(PCefBrowserHost(FData), CefGetData(visitor), Ord(currentOnly));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.GetNavigationEntriesProc(const proc: TCefNavigationEntryVisitorProc; currentOnly: Boolean);
2017-01-27 18:29:37 +02:00
begin
GetNavigationEntries(TCefFastNavigationEntryVisitor.Create(proc), currentOnly);
end;
function TCefBrowserHostRef.GetZoomLevel: Double;
begin
Result := PCefBrowserHost(FData)^.get_zoom_level(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.IMESetComposition(const text : ustring;
const underlines : TCefCompositionUnderlineDynArray;
const replacement_range : PCefRange;
const selection_range : PCefRange);
2017-01-27 18:29:37 +02:00
var
TempString : TCefString;
TempCount, i : NativeUInt;
TempUnderlines : PCefCompositionUnderline;
TempItem : PCefCompositionUnderline;
2017-01-27 18:29:37 +02:00
begin
TempCount := 0;
TempUnderlines := nil;
try
TempString := CefString(text);
if (underlines <> nil) then
begin
TempCount := length(underlines);
GetMem(TempUnderlines, TempCount * SizeOf(TCefCompositionUnderline));
TempItem := TempUnderlines;
i := 0;
while (i < TempCount) do
begin
TempItem^.range := underlines[i].range;
TempItem^.color := underlines[i].color;
TempItem^.background_color := underlines[i].background_color;
TempItem^.thick := underlines[i].thick;
2020-04-10 09:49:34 +02:00
TempItem^.style := underlines[i].style;
inc(i);
inc(TempItem);
end;
end;
PCefBrowserHost(FData)^.ime_set_composition(PCefBrowserHost(FData),
@TempString,
TempCount,
TempUnderlines,
replacement_range,
selection_range);
finally
if (TempUnderlines <> nil) then FreeMem(TempUnderlines);
end;
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.IMECommitText(const text: ustring; const replacement_range : PCefRange; relative_cursor_pos : integer);
var
TempString : TCefString;
begin
TempString := CefString(text);
PCefBrowserHost(FData)^.ime_commit_text(PCefBrowserHost(FData), @TempString, replacement_range, relative_cursor_pos);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.IMEFinishComposingText(keep_selection : boolean);
begin
PCefBrowserHost(FData)^.ime_finish_composing_text(PCefBrowserHost(FData), ord(keep_selection));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.IMECancelComposition;
begin
PCefBrowserHost(FData)^.ime_cancel_composition(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.HasDevTools: Boolean;
begin
2018-12-12 18:13:23 +02:00
Result := PCefBrowserHost(FData)^.has_dev_tools(PCefBrowserHost(FData)) <> 0;
2017-01-27 18:29:37 +02:00
end;
2020-06-21 21:27:55 +02:00
function TCefBrowserHostRef.SendDevToolsMessage(const message_: ustring): boolean;
var
TempMsg : TCefStringUtf8;
TempLen : integer;
begin
TempMsg.str := nil;
TempMsg.length := 0;
TempMsg.dtor := nil;
TempLen := length(message_);
Result := (TempLen > 0) and
(cef_string_wide_to_utf8(PWideChar(@message_[1]), TempLen, @TempMsg) <> 0) and
(PCefBrowserHost(FData)^.send_dev_tools_message(PCefBrowserHost(FData), TempMsg.str, TempMsg.length) <> 0);
end;
function TCefBrowserHostRef.ExecuteDevToolsMethod(message_id: integer; const method: ustring; const params: ICefDictionaryValue): Integer;
var
TempMethod : TCefString;
begin
TempMethod := CefString(method);
Result := PCefBrowserHost(FData)^.execute_dev_tools_method(PCefBrowserHost(FData), message_id, @TempMethod, CefGetData(params));
end;
function TCefBrowserHostRef.AddDevToolsMessageObserver(const observer: ICefDevToolsMessageObserver): ICefRegistration;
begin
Result := TCefRegistrationRef.UnWrap(PCefBrowserHost(FData)^.add_dev_tools_message_observer(PCefBrowserHost(FData),
CefGetData(observer)));
end;
2017-01-27 18:29:37 +02:00
function TCefBrowserHostRef.HasView: Boolean;
begin
2018-12-12 18:13:23 +02:00
Result := PCefBrowserHost(FData)^.has_view(PCefBrowserHost(FData)) <> 0;
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.Invalidate(type_: TCefPaintElementType);
2017-01-27 18:29:37 +02:00
begin
PCefBrowserHost(FData)^.invalidate(PCefBrowserHost(FData), type_);
2018-12-12 18:13:23 +02:00
end;
procedure TCefBrowserHostRef.SendExternalBeginFrame;
begin
PCefBrowserHost(FData)^.send_external_begin_frame(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.IsWindowRenderingDisabled: Boolean;
begin
2018-12-12 18:13:23 +02:00
Result := PCefBrowserHost(FData)^.is_window_rendering_disabled(PCefBrowserHost(FData)) <> 0;
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.NotifyMoveOrResizeStarted;
begin
PCefBrowserHost(FData)^.notify_move_or_resize_started(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.NotifyScreenInfoChanged;
begin
PCefBrowserHost(FData)^.notify_screen_info_changed(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
2018-03-29 20:02:04 +02:00
procedure TCefBrowserHostRef.SetZoomLevel(const zoomLevel: Double);
2017-01-27 18:29:37 +02:00
begin
PCefBrowserHost(FData)^.set_zoom_level(PCefBrowserHost(FData), zoomLevel);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.ShowDevTools(const windowInfo : PCefWindowInfo;
const client : ICefClient;
const settings : PCefBrowserSettings;
inspectElementAt : PCefPoint);
2017-01-27 18:29:37 +02:00
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.show_dev_tools(PCefBrowserHost(FData),
windowInfo,
CefGetData(client),
settings,
inspectElementAt);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.StartDownload(const url: ustring);
var
TempURL : TCefString;
2017-01-27 18:29:37 +02:00
begin
TempURL := CefString(url);
PCefBrowserHost(FData)^.start_download(PCefBrowserHost(FData), @TempURL);
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.StopFinding(clearSelection: Boolean);
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.stop_finding(PCefBrowserHost(FData), Ord(clearSelection));
2017-01-27 18:29:37 +02:00
end;
function TCefBrowserHostRef.TryCloseBrowser: Boolean;
begin
2018-12-12 18:13:23 +02:00
Result := PCefBrowserHost(FData)^.try_close_browser(PCefBrowserHost(FData)) <> 0;
2017-01-27 18:29:37 +02:00
end;
class function TCefBrowserHostRef.UnWrap(data: Pointer): ICefBrowserHost;
begin
if (data <> nil) then
Result := Create(data) as ICefBrowserHost
else
2017-01-27 18:29:37 +02:00
Result := nil;
end;
procedure TCefBrowserHostRef.WasHidden(hidden: Boolean);
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.was_hidden(PCefBrowserHost(FData), Ord(hidden));
2017-01-27 18:29:37 +02:00
end;
procedure TCefBrowserHostRef.WasResized;
begin
2018-12-12 18:13:23 +02:00
PCefBrowserHost(FData)^.was_resized(PCefBrowserHost(FData));
2017-01-27 18:29:37 +02:00
end;
end.