You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-12 22:07:39 +02:00
Fixed issue #303
- Added TChromiumCore.ReplaceMisspelling - Added TChromiumCore.AddWordToDictionary - Added TChromiumCore.OpenerWindowHandle - Added TChromiumCore.MouseCursorChangeDisabled - Removed the 'Print to PDF stream...' menu option from the MiniBrowser demo because it's only available in headless chrome.
This commit is contained in:
@ -327,10 +327,6 @@ object MiniBrowserFrm: TMiniBrowserFrm
|
|||||||
Caption = 'Print to PDF file...'
|
Caption = 'Print to PDF file...'
|
||||||
OnClick = PrintinPDF1Click
|
OnClick = PrintinPDF1Click
|
||||||
end
|
end
|
||||||
object PrinttoPDFstream1: TMenuItem
|
|
||||||
Caption = 'Print to PDF stream...'
|
|
||||||
OnClick = PrinttoPDFstream1Click
|
|
||||||
end
|
|
||||||
object N3: TMenuItem
|
object N3: TMenuItem
|
||||||
Caption = '-'
|
Caption = '-'
|
||||||
end
|
end
|
||||||
|
@ -138,7 +138,6 @@ type
|
|||||||
akescreenshot1: TMenuItem;
|
akescreenshot1: TMenuItem;
|
||||||
Useragent1: TMenuItem;
|
Useragent1: TMenuItem;
|
||||||
ClearallstorageforcurrentURL1: TMenuItem;
|
ClearallstorageforcurrentURL1: TMenuItem;
|
||||||
PrinttoPDFstream1: TMenuItem;
|
|
||||||
|
|
||||||
procedure FormShow(Sender: TObject);
|
procedure FormShow(Sender: TObject);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
@ -207,13 +206,10 @@ type
|
|||||||
procedure akescreenshot1Click(Sender: TObject);
|
procedure akescreenshot1Click(Sender: TObject);
|
||||||
procedure Useragent1Click(Sender: TObject);
|
procedure Useragent1Click(Sender: TObject);
|
||||||
procedure ClearallstorageforcurrentURL1Click(Sender: TObject);
|
procedure ClearallstorageforcurrentURL1Click(Sender: TObject);
|
||||||
procedure PrinttoPDFstream1Click(Sender: TObject);
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
FDevToolsMsgID : integer;
|
FDevToolsMsgID : integer;
|
||||||
FPrintToPDFMsgID : integer;
|
|
||||||
FScreenshotMsgID : integer;
|
FScreenshotMsgID : integer;
|
||||||
|
|
||||||
FDevToolsMsgValue : ustring;
|
FDevToolsMsgValue : ustring;
|
||||||
|
|
||||||
FResponse : TStringList;
|
FResponse : TStringList;
|
||||||
@ -224,7 +220,6 @@ type
|
|||||||
FClosing : boolean; // Set to True in the CloseQuery event.
|
FClosing : boolean; // Set to True in the CloseQuery event.
|
||||||
|
|
||||||
procedure AddURL(const aURL : string);
|
procedure AddURL(const aURL : string);
|
||||||
procedure PrintToPDFStream(aUseChromiumPDFSettings : boolean = False; const aPageRanges : string = ''; const aHeaderTemplate : string = ''; const aFooterTemplate : string = ''; aIgnoreInvalidPageRanges : boolean = False; aPreferCSSPageSize : boolean = False);
|
|
||||||
|
|
||||||
procedure ShowDevTools(aPoint : TPoint); overload;
|
procedure ShowDevTools(aPoint : TPoint); overload;
|
||||||
procedure ShowDevTools; overload;
|
procedure ShowDevTools; overload;
|
||||||
@ -587,59 +582,6 @@ begin
|
|||||||
showmessage('There was a problem generating the PDF file.');
|
showmessage('There was a problem generating the PDF file.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// This procedure uses the "Page.printToPDF" method from the DevTools :
|
|
||||||
// https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF
|
|
||||||
procedure TMiniBrowserFrm.PrintToPDFStream( aUseChromiumPDFSettings : boolean;
|
|
||||||
const aPageRanges, aHeaderTemplate, aFooterTemplate : string;
|
|
||||||
aIgnoreInvalidPageRanges, aPreferCSSPageSize : boolean);
|
|
||||||
var
|
|
||||||
TempParams : ICefDictionaryValue;
|
|
||||||
begin
|
|
||||||
try
|
|
||||||
TempParams := TCefDictionaryValueRef.New;
|
|
||||||
|
|
||||||
if aUseChromiumPDFSettings then
|
|
||||||
begin
|
|
||||||
TempParams.SetBool('landscape', Chromium1.PDFPrintOptions.landscape);
|
|
||||||
TempParams.SetBool('displayHeaderFooter', Chromium1.PDFPrintOptions.header_footer_enabled);
|
|
||||||
TempParams.SetBool('printBackground', Chromium1.PDFPrintOptions.backgrounds_enabled);
|
|
||||||
TempParams.SetDouble('scale', Chromium1.PDFPrintOptions.scale_factor / 100); // integer percent to double
|
|
||||||
TempParams.SetDouble('paperWidth', Chromium1.PDFPrintOptions.page_width * 0.000039370); // microns to inches
|
|
||||||
TempParams.SetDouble('paperHeight', Chromium1.PDFPrintOptions.page_height * 0.000039370); // microns to inches
|
|
||||||
TempParams.SetDouble('marginTop', Chromium1.PDFPrintOptions.margin_top / 72); // points to inches
|
|
||||||
TempParams.SetDouble('marginBottom', Chromium1.PDFPrintOptions.margin_bottom / 72); // points to inches
|
|
||||||
TempParams.SetDouble('marginLeft', Chromium1.PDFPrintOptions.margin_left / 72); // points to inches
|
|
||||||
TempParams.SetDouble('marginRight', Chromium1.PDFPrintOptions.margin_right / 72); // points to inches
|
|
||||||
end;
|
|
||||||
|
|
||||||
if (length(aPageRanges) > 0) then
|
|
||||||
begin
|
|
||||||
TempParams.SetString('pageRanges', aPageRanges);
|
|
||||||
TempParams.SetBool('ignoreInvalidPageRanges', aIgnoreInvalidPageRanges);
|
|
||||||
end;
|
|
||||||
|
|
||||||
if (length(aHeaderTemplate) > 0) then
|
|
||||||
TempParams.SetString('headerTemplate', aHeaderTemplate);
|
|
||||||
|
|
||||||
if (length(aFooterTemplate) > 0) then
|
|
||||||
TempParams.SetString('footerTemplate', aFooterTemplate);
|
|
||||||
|
|
||||||
TempParams.SetBool('preferCSSPageSize', aPreferCSSPageSize);
|
|
||||||
TempParams.SetString('transferMode', 'ReturnAsBase64');
|
|
||||||
|
|
||||||
inc(FDevToolsMsgID);
|
|
||||||
FPrintToPDFMsgID := FDevToolsMsgID;
|
|
||||||
Chromium1.ExecuteDevToolsMethod(FPrintToPDFMsgID, 'Page.printToPDF', TempParams);
|
|
||||||
finally
|
|
||||||
TempParams := nil;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TMiniBrowserFrm.PrinttoPDFstream1Click(Sender: TObject);
|
|
||||||
begin
|
|
||||||
PrintToPDFStream;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TMiniBrowserFrm.PreferencesAvailableMsg(var aMessage : TMessage);
|
procedure TMiniBrowserFrm.PreferencesAvailableMsg(var aMessage : TMessage);
|
||||||
begin
|
begin
|
||||||
if (aMessage.lParam <> 0) then
|
if (aMessage.lParam <> 0) then
|
||||||
@ -1248,12 +1190,6 @@ begin
|
|||||||
SaveDialog1.DefaultExt := 'png';
|
SaveDialog1.DefaultExt := 'png';
|
||||||
SaveDialog1.Filter := 'PNG files (*.png)|*.PNG';
|
SaveDialog1.Filter := 'PNG files (*.png)|*.PNG';
|
||||||
end
|
end
|
||||||
else
|
|
||||||
if (aMessage.LParam = FPrintToPDFMsgID) then
|
|
||||||
begin
|
|
||||||
SaveDialog1.DefaultExt := 'pdf';
|
|
||||||
SaveDialog1.Filter := 'PDF files (*.pdf)|*.PDF';
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
SaveDialog1.DefaultExt := '';
|
SaveDialog1.DefaultExt := '';
|
||||||
|
@ -336,6 +336,7 @@ type
|
|||||||
function GetZoomStep : byte;
|
function GetZoomStep : byte;
|
||||||
function GetIsPopUp : boolean;
|
function GetIsPopUp : boolean;
|
||||||
function GetWindowHandle : TCefWindowHandle;
|
function GetWindowHandle : TCefWindowHandle;
|
||||||
|
function GetOpenerWindowHandle : TCefWindowHandle;
|
||||||
function GetWindowlessFrameRate : integer;
|
function GetWindowlessFrameRate : integer;
|
||||||
function GetFrameIsFocused : boolean;
|
function GetFrameIsFocused : boolean;
|
||||||
function GetInitialized : boolean;
|
function GetInitialized : boolean;
|
||||||
@ -353,6 +354,7 @@ type
|
|||||||
function GetBrowserById(aID : integer) : ICefBrowser;
|
function GetBrowserById(aID : integer) : ICefBrowser;
|
||||||
function GetBrowserCount : integer;
|
function GetBrowserCount : integer;
|
||||||
function GetBrowserIdByIndex(aIndex : integer) : integer;
|
function GetBrowserIdByIndex(aIndex : integer) : integer;
|
||||||
|
function GetMouseCursorChangeDisabled : boolean;
|
||||||
|
|
||||||
procedure SetDoNotTrack(aValue : boolean);
|
procedure SetDoNotTrack(aValue : boolean);
|
||||||
procedure SetSendReferrer(aValue : boolean);
|
procedure SetSendReferrer(aValue : boolean);
|
||||||
@ -395,6 +397,7 @@ type
|
|||||||
procedure SetQuicAllowed(aValue : boolean);
|
procedure SetQuicAllowed(aValue : boolean);
|
||||||
procedure SetJavascriptEnabled(aValue : boolean);
|
procedure SetJavascriptEnabled(aValue : boolean);
|
||||||
procedure SetLoadImagesAutomatically(aValue : boolean);
|
procedure SetLoadImagesAutomatically(aValue : boolean);
|
||||||
|
procedure SetMouseCursorChangeDisabled(aValue : boolean);
|
||||||
|
|
||||||
function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aExtraInfo : ICefDictionaryValue; const aContext : ICefRequestContext): boolean;
|
function CreateBrowserHost(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aExtraInfo : ICefDictionaryValue; const aContext : ICefRequestContext): boolean;
|
||||||
function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aExtraInfo : ICefDictionaryValue; const aContext : ICefRequestContext): Boolean;
|
function CreateBrowserHostSync(aWindowInfo : PCefWindowInfo; const aURL : ustring; const aSettings : PCefBrowserSettings; const aExtraInfo : ICefDictionaryValue; const aContext : ICefRequestContext): Boolean;
|
||||||
@ -732,7 +735,8 @@ type
|
|||||||
procedure UpdateSupportedSchemes(const aSchemes : TStrings; aIncludeDefaults : boolean = True);
|
procedure UpdateSupportedSchemes(const aSchemes : TStrings; aIncludeDefaults : boolean = True);
|
||||||
|
|
||||||
procedure ShowDevTools(const inspectElementAt: TPoint; aWindowInfo: PCefWindowInfo);
|
procedure ShowDevTools(const inspectElementAt: TPoint; aWindowInfo: PCefWindowInfo);
|
||||||
procedure CloseDevTools(const aDevToolsWnd : TCefWindowHandle = 0);
|
procedure CloseDevTools; overload;
|
||||||
|
procedure CloseDevTools(const aDevToolsWnd : TCefWindowHandle); overload;
|
||||||
function SendDevToolsMessage(const message_: ustring): boolean;
|
function SendDevToolsMessage(const message_: ustring): boolean;
|
||||||
function ExecuteDevToolsMethod(message_id: integer; const method: ustring; const params: ICefDictionaryValue): Integer;
|
function ExecuteDevToolsMethod(message_id: integer; const method: ustring; const params: ICefDictionaryValue): Integer;
|
||||||
function AddDevToolsMessageObserver(const observer: ICefDevToolsMessageObserver): ICefRegistration;
|
function AddDevToolsMessageObserver(const observer: ICefDevToolsMessageObserver): ICefRegistration;
|
||||||
@ -797,6 +801,9 @@ type
|
|||||||
procedure IMEFinishComposingText(keep_selection : boolean);
|
procedure IMEFinishComposingText(keep_selection : boolean);
|
||||||
procedure IMECancelComposition;
|
procedure IMECancelComposition;
|
||||||
|
|
||||||
|
procedure ReplaceMisspelling(const aWord : ustring);
|
||||||
|
procedure AddWordToDictionary(const aWord : ustring);
|
||||||
|
|
||||||
// ICefMediaRouter methods
|
// ICefMediaRouter methods
|
||||||
function AddObserver(const observer: ICefMediaObserver): ICefRegistration;
|
function AddObserver(const observer: ICefMediaObserver): ICefRegistration;
|
||||||
function GetSource(const urn: ustring): ICefMediaSource;
|
function GetSource(const urn: ustring): ICefMediaSource;
|
||||||
@ -845,6 +852,7 @@ type
|
|||||||
property CanGoForward : boolean read GetCanGoForward;
|
property CanGoForward : boolean read GetCanGoForward;
|
||||||
property IsPopUp : boolean read GetIsPopUp;
|
property IsPopUp : boolean read GetIsPopUp;
|
||||||
property WindowHandle : TCefWindowHandle read GetWindowHandle;
|
property WindowHandle : TCefWindowHandle read GetWindowHandle;
|
||||||
|
property OpenerWindowHandle : TCefWindowHandle read GetOpenerWindowHandle;
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
property BrowserHandle : THandle read FBrowserCompHWND;
|
property BrowserHandle : THandle read FBrowserCompHWND;
|
||||||
property WidgetHandle : THandle read FWidgetCompHWND;
|
property WidgetHandle : THandle read FWidgetCompHWND;
|
||||||
@ -886,6 +894,7 @@ type
|
|||||||
property QuicAllowed : boolean read FQuicAllowed write SetQuicAllowed;
|
property QuicAllowed : boolean read FQuicAllowed write SetQuicAllowed;
|
||||||
property JavascriptEnabled : boolean read FJavascriptEnabled write SetJavascriptEnabled;
|
property JavascriptEnabled : boolean read FJavascriptEnabled write SetJavascriptEnabled;
|
||||||
property LoadImagesAutomatically : boolean read FLoadImagesAutomatically write SetLoadImagesAutomatically;
|
property LoadImagesAutomatically : boolean read FLoadImagesAutomatically write SetLoadImagesAutomatically;
|
||||||
|
property MouseCursorChangeDisabled : boolean read GetMouseCursorChangeDisabled write SetMouseCursorChangeDisabled;
|
||||||
|
|
||||||
property WebRTCIPHandlingPolicy : TCefWebRTCHandlingPolicy read FWebRTCIPHandlingPolicy write SetWebRTCIPHandlingPolicy;
|
property WebRTCIPHandlingPolicy : TCefWebRTCHandlingPolicy read FWebRTCIPHandlingPolicy write SetWebRTCIPHandlingPolicy;
|
||||||
property WebRTCMultipleRoutes : TCefState read FWebRTCMultipleRoutes write SetWebRTCMultipleRoutes;
|
property WebRTCMultipleRoutes : TCefState read FWebRTCMultipleRoutes write SetWebRTCMultipleRoutes;
|
||||||
@ -1205,7 +1214,7 @@ begin
|
|||||||
FHyperlinkAuditing := True;
|
FHyperlinkAuditing := True;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Somo focus issues in CEF seem to be fixed when you use WS_EX_NOACTIVATE in
|
// Some focus issues in CEF seem to be fixed when you use WS_EX_NOACTIVATE in
|
||||||
// FDefaultWindowInfoExStyle to initialize the browser with that ExStyle but
|
// FDefaultWindowInfoExStyle to initialize the browser with that ExStyle but
|
||||||
// it may cause side effects. Read these links for more information :
|
// it may cause side effects. Read these links for more information :
|
||||||
// https://www.briskbard.com/forum/viewtopic.php?f=10&t=723
|
// https://www.briskbard.com/forum/viewtopic.php?f=10&t=723
|
||||||
@ -2534,10 +2543,18 @@ end;
|
|||||||
|
|
||||||
function TChromiumCore.GetWindowHandle : TCefWindowHandle;
|
function TChromiumCore.GetWindowHandle : TCefWindowHandle;
|
||||||
begin
|
begin
|
||||||
|
InitializeWindowHandle(Result);
|
||||||
|
|
||||||
if Initialized then
|
if Initialized then
|
||||||
Result := Browser.Host.WindowHandle
|
Result := Browser.Host.WindowHandle;
|
||||||
else
|
end;
|
||||||
Result := 0;
|
|
||||||
|
function TChromiumCore.GetOpenerWindowHandle : TCefWindowHandle;
|
||||||
|
begin
|
||||||
|
InitializeWindowHandle(Result);
|
||||||
|
|
||||||
|
if Initialized then
|
||||||
|
Result := Browser.Host.OpenerWindowHandle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TChromiumCore.GetFrameIsFocused : boolean;
|
function TChromiumCore.GetFrameIsFocused : boolean;
|
||||||
@ -2665,6 +2682,11 @@ begin
|
|||||||
Result := Initialized and Browser.host.RequestContext.IsGlobal;
|
Result := Initialized and Browser.host.RequestContext.IsGlobal;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TChromiumCore.GetMouseCursorChangeDisabled : boolean;
|
||||||
|
begin
|
||||||
|
Result := Initialized and Browser.host.IsMouseCursorChangeDisabled;
|
||||||
|
end;
|
||||||
|
|
||||||
function TChromiumCore.GetAudioMuted : boolean;
|
function TChromiumCore.GetAudioMuted : boolean;
|
||||||
begin
|
begin
|
||||||
Result := Initialized and Browser.host.IsAudioMuted;
|
Result := Initialized and Browser.host.IsAudioMuted;
|
||||||
@ -2672,7 +2694,7 @@ end;
|
|||||||
|
|
||||||
function TChromiumCore.GetParentFormHandle : TCefWindowHandle;
|
function TChromiumCore.GetParentFormHandle : TCefWindowHandle;
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
InitializeWindowHandle(Result);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TChromiumCore.SetMultiBrowserMode(aValue : boolean);
|
procedure TChromiumCore.SetMultiBrowserMode(aValue : boolean);
|
||||||
@ -2716,6 +2738,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChromiumCore.SetMouseCursorChangeDisabled(aValue : boolean);
|
||||||
|
begin
|
||||||
|
if Initialized then
|
||||||
|
Browser.Host.SetMouseCursorChangeDisabled(aValue);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChromiumCore.SetAudioMuted(aValue : boolean);
|
procedure TChromiumCore.SetAudioMuted(aValue : boolean);
|
||||||
begin
|
begin
|
||||||
if Initialized then
|
if Initialized then
|
||||||
@ -4779,12 +4807,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChromiumCore.CloseDevTools;
|
||||||
|
begin
|
||||||
|
if Initialized then
|
||||||
|
Browser.Host.CloseDevTools;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TChromiumCore.CloseDevTools(const aDevToolsWnd : TCefWindowHandle);
|
procedure TChromiumCore.CloseDevTools(const aDevToolsWnd : TCefWindowHandle);
|
||||||
begin
|
begin
|
||||||
if Initialized then
|
if Initialized then
|
||||||
begin
|
begin
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
if (aDevToolsWnd <> 0) then
|
if ValidCefWindowHandle(aDevToolsWnd) then
|
||||||
SetParent(GetWindow(aDevToolsWnd, GW_CHILD), 0);
|
SetParent(GetWindow(aDevToolsWnd, GW_CHILD), 0);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
@ -6342,6 +6376,18 @@ begin
|
|||||||
Browser.Host.IMECancelComposition;
|
Browser.Host.IMECancelComposition;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TChromiumCore.ReplaceMisspelling(const aWord : ustring);
|
||||||
|
begin
|
||||||
|
if Initialized then
|
||||||
|
Browser.Host.ReplaceMisspelling(aWord);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TChromiumCore.AddWordToDictionary(const aWord : ustring);
|
||||||
|
begin
|
||||||
|
if Initialized then
|
||||||
|
Browser.Host.AddWordToDictionary(aWord);
|
||||||
|
end;
|
||||||
|
|
||||||
// ICefMediaRouter methods
|
// ICefMediaRouter methods
|
||||||
function TChromiumCore.AddObserver(const observer: ICefMediaObserver): ICefRegistration;
|
function TChromiumCore.AddObserver(const observer: ICefMediaObserver): ICefRegistration;
|
||||||
var
|
var
|
||||||
|
@ -1438,7 +1438,7 @@ begin
|
|||||||
try
|
try
|
||||||
if FileExists(aDLLFile) then
|
if FileExists(aDLLFile) then
|
||||||
begin
|
begin
|
||||||
TempStream := TFileStream.Create(aDLLFile, fmOpenRead);
|
TempStream := TFileStream.Create(aDLLFile, fmOpenRead or fmShareDenyWrite);
|
||||||
TempStream.seek(0, soFromBeginning);
|
TempStream.seek(0, soFromBeginning);
|
||||||
TempStream.ReadBuffer(TempHeader, SizeOf(TempHeader));
|
TempStream.ReadBuffer(TempHeader, SizeOf(TempHeader));
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 187,
|
"InternalVersion" : 188,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "85.3.11.0"
|
"Version" : "85.3.11.0"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user