1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-01-13 10:22:04 +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:
Salvador Diaz Fau 2020-09-30 12:43:48 +02:00
parent 048a812b11
commit 6e936cf07c
5 changed files with 66 additions and 88 deletions

View File

@ -327,10 +327,6 @@ object MiniBrowserFrm: TMiniBrowserFrm
Caption = 'Print to PDF file...'
OnClick = PrintinPDF1Click
end
object PrinttoPDFstream1: TMenuItem
Caption = 'Print to PDF stream...'
OnClick = PrinttoPDFstream1Click
end
object N3: TMenuItem
Caption = '-'
end

View File

@ -138,7 +138,6 @@ type
akescreenshot1: TMenuItem;
Useragent1: TMenuItem;
ClearallstorageforcurrentURL1: TMenuItem;
PrinttoPDFstream1: TMenuItem;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
@ -207,13 +206,10 @@ type
procedure akescreenshot1Click(Sender: TObject);
procedure Useragent1Click(Sender: TObject);
procedure ClearallstorageforcurrentURL1Click(Sender: TObject);
procedure PrinttoPDFstream1Click(Sender: TObject);
protected
FDevToolsMsgID : integer;
FPrintToPDFMsgID : integer;
FScreenshotMsgID : integer;
FDevToolsMsgID : integer;
FScreenshotMsgID : integer;
FDevToolsMsgValue : ustring;
FResponse : TStringList;
@ -224,7 +220,6 @@ type
FClosing : boolean; // Set to True in the CloseQuery event.
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; overload;
@ -587,59 +582,6 @@ begin
showmessage('There was a problem generating the PDF file.');
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);
begin
if (aMessage.lParam <> 0) then
@ -1181,10 +1123,10 @@ procedure TMiniBrowserFrm.Chromium1DevToolsMethodResult( Sender : TObje
success : Boolean;
const result : ICefValue);
var
TempDict : ICefDictionaryValue;
TempValue : ICefValue;
TempResult : WPARAM;
TempCode : integer;
TempDict : ICefDictionaryValue;
TempValue : ICefValue;
TempResult : WPARAM;
TempCode : integer;
TempMessage : string;
begin
FDevToolsMsgValue := '';
@ -1249,16 +1191,10 @@ begin
SaveDialog1.Filter := 'PNG files (*.png)|*.PNG';
end
else
if (aMessage.LParam = FPrintToPDFMsgID) then
begin
SaveDialog1.DefaultExt := 'pdf';
SaveDialog1.Filter := 'PDF files (*.pdf)|*.PDF';
end
else
begin
SaveDialog1.DefaultExt := '';
SaveDialog1.Filter := 'All files (*.*)|*.*';
end;
begin
SaveDialog1.DefaultExt := '';
SaveDialog1.Filter := 'All files (*.*)|*.*';
end;
if SaveDialog1.Execute then
try

View File

@ -336,6 +336,7 @@ type
function GetZoomStep : byte;
function GetIsPopUp : boolean;
function GetWindowHandle : TCefWindowHandle;
function GetOpenerWindowHandle : TCefWindowHandle;
function GetWindowlessFrameRate : integer;
function GetFrameIsFocused : boolean;
function GetInitialized : boolean;
@ -353,6 +354,7 @@ type
function GetBrowserById(aID : integer) : ICefBrowser;
function GetBrowserCount : integer;
function GetBrowserIdByIndex(aIndex : integer) : integer;
function GetMouseCursorChangeDisabled : boolean;
procedure SetDoNotTrack(aValue : boolean);
procedure SetSendReferrer(aValue : boolean);
@ -395,6 +397,7 @@ type
procedure SetQuicAllowed(aValue : boolean);
procedure SetJavascriptEnabled(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 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 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 ExecuteDevToolsMethod(message_id: integer; const method: ustring; const params: ICefDictionaryValue): Integer;
function AddDevToolsMessageObserver(const observer: ICefDevToolsMessageObserver): ICefRegistration;
@ -797,6 +801,9 @@ type
procedure IMEFinishComposingText(keep_selection : boolean);
procedure IMECancelComposition;
procedure ReplaceMisspelling(const aWord : ustring);
procedure AddWordToDictionary(const aWord : ustring);
// ICefMediaRouter methods
function AddObserver(const observer: ICefMediaObserver): ICefRegistration;
function GetSource(const urn: ustring): ICefMediaSource;
@ -845,6 +852,7 @@ type
property CanGoForward : boolean read GetCanGoForward;
property IsPopUp : boolean read GetIsPopUp;
property WindowHandle : TCefWindowHandle read GetWindowHandle;
property OpenerWindowHandle : TCefWindowHandle read GetOpenerWindowHandle;
{$IFDEF MSWINDOWS}
property BrowserHandle : THandle read FBrowserCompHWND;
property WidgetHandle : THandle read FWidgetCompHWND;
@ -886,6 +894,7 @@ type
property QuicAllowed : boolean read FQuicAllowed write SetQuicAllowed;
property JavascriptEnabled : boolean read FJavascriptEnabled write SetJavascriptEnabled;
property LoadImagesAutomatically : boolean read FLoadImagesAutomatically write SetLoadImagesAutomatically;
property MouseCursorChangeDisabled : boolean read GetMouseCursorChangeDisabled write SetMouseCursorChangeDisabled;
property WebRTCIPHandlingPolicy : TCefWebRTCHandlingPolicy read FWebRTCIPHandlingPolicy write SetWebRTCIPHandlingPolicy;
property WebRTCMultipleRoutes : TCefState read FWebRTCMultipleRoutes write SetWebRTCMultipleRoutes;
@ -1205,7 +1214,7 @@ begin
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
// it may cause side effects. Read these links for more information :
// https://www.briskbard.com/forum/viewtopic.php?f=10&t=723
@ -2534,10 +2543,18 @@ end;
function TChromiumCore.GetWindowHandle : TCefWindowHandle;
begin
InitializeWindowHandle(Result);
if Initialized then
Result := Browser.Host.WindowHandle
else
Result := 0;
Result := Browser.Host.WindowHandle;
end;
function TChromiumCore.GetOpenerWindowHandle : TCefWindowHandle;
begin
InitializeWindowHandle(Result);
if Initialized then
Result := Browser.Host.OpenerWindowHandle;
end;
function TChromiumCore.GetFrameIsFocused : boolean;
@ -2665,6 +2682,11 @@ begin
Result := Initialized and Browser.host.RequestContext.IsGlobal;
end;
function TChromiumCore.GetMouseCursorChangeDisabled : boolean;
begin
Result := Initialized and Browser.host.IsMouseCursorChangeDisabled;
end;
function TChromiumCore.GetAudioMuted : boolean;
begin
Result := Initialized and Browser.host.IsAudioMuted;
@ -2672,7 +2694,7 @@ end;
function TChromiumCore.GetParentFormHandle : TCefWindowHandle;
begin
Result := 0;
InitializeWindowHandle(Result);
end;
procedure TChromiumCore.SetMultiBrowserMode(aValue : boolean);
@ -2716,6 +2738,12 @@ begin
end;
end;
procedure TChromiumCore.SetMouseCursorChangeDisabled(aValue : boolean);
begin
if Initialized then
Browser.Host.SetMouseCursorChangeDisabled(aValue);
end;
procedure TChromiumCore.SetAudioMuted(aValue : boolean);
begin
if Initialized then
@ -3941,7 +3969,7 @@ begin
UpdatePreference(aBrowser, 'webrtc.nonproxied_udp_enabled', (FWebRTCNonProxiedUDP = STATE_ENABLED));
UpdatePreference(aBrowser, 'net.network_prediction_options', integer(FNetworkPredictions));
UpdatePreference(aBrowser, 'net.quic_allowed', FQuicAllowed);
UpdatePreference(aBrowser, 'net.quic_allowed', FQuicAllowed);
UpdatePreference(aBrowser, 'webkit.webprefs.javascript_enabled', FJavascriptEnabled);
UpdatePreference(aBrowser, 'webkit.webprefs.loads_images_automatically', FLoadImagesAutomatically);
@ -4779,12 +4807,18 @@ begin
end;
end;
procedure TChromiumCore.CloseDevTools;
begin
if Initialized then
Browser.Host.CloseDevTools;
end;
procedure TChromiumCore.CloseDevTools(const aDevToolsWnd : TCefWindowHandle);
begin
if Initialized then
begin
{$IFDEF MSWINDOWS}
if (aDevToolsWnd <> 0) then
if ValidCefWindowHandle(aDevToolsWnd) then
SetParent(GetWindow(aDevToolsWnd, GW_CHILD), 0);
{$ENDIF}
@ -6342,6 +6376,18 @@ begin
Browser.Host.IMECancelComposition;
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
function TChromiumCore.AddObserver(const observer: ICefMediaObserver): ICefRegistration;
var

View File

@ -1438,7 +1438,7 @@ begin
try
if FileExists(aDLLFile) then
begin
TempStream := TFileStream.Create(aDLLFile, fmOpenRead);
TempStream := TFileStream.Create(aDLLFile, fmOpenRead or fmShareDenyWrite);
TempStream.seek(0, soFromBeginning);
TempStream.ReadBuffer(TempHeader, SizeOf(TempHeader));

View File

@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 187,
"InternalVersion" : 188,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "85.3.11.0"
}