Skip to content

Commit

Permalink
Issue #273 fixed
Browse files Browse the repository at this point in the history
- Added TFMXChromium.ScreenScale property
  • Loading branch information
salvadordf committed Apr 9, 2020
1 parent c9b2af2 commit 846aedd
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 55 deletions.
25 changes: 3 additions & 22 deletions demos/Delphi_FMX/FMXTabbedBrowser/uBrowserFrame.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@ object BrowserFrame: TBrowserFrame
Size.Width = 1000.000000000000000000
Size.Height = 733.000000000000000000
Size.PlatformDefault = False
object StatusBar: TStatusBar
Padding.Left = 5.000000000000000000
Padding.Right = 5.000000000000000000
Position.X = 1.000000000000000000
Position.Y = 710.000000000000000000
ShowSizeGrip = False
Size.Width = 998.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 2
object StatusLbl: TLabel
Align = Client
Size.Width = 988.000000000000000000
Size.Height = 22.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
end
end
object AddressLay: TLayout
Align = Top
Padding.Left = 5.000000000000000000
Expand All @@ -35,7 +17,7 @@ object BrowserFrame: TBrowserFrame
Size.Width = 998.000000000000000000
Size.Height = 35.000000000000000000
Size.PlatformDefault = False
TabOrder = 4
TabOrder = 3
object GoBtn: TSpeedButton
Align = Right
Margins.Left = 5.000000000000000000
Expand Down Expand Up @@ -112,17 +94,16 @@ object BrowserFrame: TBrowserFrame
object WindowParentLay: TLayout
Align = Client
Size.Width = 998.000000000000000000
Size.Height = 674.000000000000000000
Size.Height = 696.000000000000000000
Size.PlatformDefault = False
TabOrder = 5
TabOrder = 4
OnResize = WindowParentLayResize
end
object FMXChromium1: TFMXChromium
OnLoadError = FMXChromium1LoadError
OnLoadingStateChange = FMXChromium1LoadingStateChange
OnAddressChange = FMXChromium1AddressChange
OnTitleChange = FMXChromium1TitleChange
OnStatusMessage = FMXChromium1StatusMessage
OnBeforePopup = FMXChromium1BeforePopup
OnAfterCreated = FMXChromium1AfterCreated
OnBeforeClose = FMXChromium1BeforeClose
Expand Down
24 changes: 7 additions & 17 deletions demos/Delphi_FMX/FMXTabbedBrowser/uBrowserFrame.pas
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ interface

TBrowserFrame = class(TFrame)
FMXChromium1: TFMXChromium;
StatusBar: TStatusBar;
StatusLbl: TLabel;
AddressLay: TLayout;
GoBtn: TSpeedButton;
NavButtonLay: TLayout;
Expand All @@ -81,7 +79,6 @@ TBrowserFrame = class(TFrame)
procedure FMXChromium1AddressChange(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const url: ustring);
procedure FMXChromium1LoadError(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; errorCode: Integer; const errorText, failedUrl: ustring);
procedure FMXChromium1LoadingStateChange(Sender: TObject; const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean);
procedure FMXChromium1StatusMessage(Sender: TObject; const browser: ICefBrowser; const value: ustring);
procedure FMXChromium1TitleChange(Sender: TObject; const browser: ICefBrowser; const title: ustring);

protected
Expand Down Expand Up @@ -144,12 +141,14 @@ constructor TBrowserFrame.Create(AOwner : TComponent);
function TBrowserFrame.GetFMXWindowParentRect : System.Types.TRect;
var
TempRect : TRectF;
TempScale : single;
begin
TempRect := WindowParentLay.AbsoluteRect;
Result.Left := round(TempRect.Left);
Result.Top := round(TempRect.Top);
Result.Right := round(TempRect.Right);
Result.Bottom := round(TempREct.Bottom);
TempScale := FMXChromium1.ScreenScale;
TempRect := WindowParentLay.AbsoluteRect;
Result.Left := round(TempRect.Left * TempScale);
Result.Top := round(TempRect.Top * TempScale);
Result.Right := round(TempRect.Right * TempScale) - 1;
Result.Bottom := round(TempREct.Bottom * TempScale) - 1;
end;

procedure TBrowserFrame.ReloadBtnClick(Sender: TObject);
Expand Down Expand Up @@ -297,15 +296,6 @@ procedure TBrowserFrame.FMXChromium1OpenUrlFromTab(Sender: TObject;
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
end;

procedure TBrowserFrame.FMXChromium1StatusMessage(Sender: TObject;
const browser: ICefBrowser; const value: ustring);
begin
TThread.Queue(nil, procedure
begin
StatusLbl.Text := value;
end);
end;

procedure TBrowserFrame.FMXChromium1TitleChange(Sender: TObject;
const browser: ICefBrowser; const title: ustring);
begin
Expand Down
10 changes: 5 additions & 5 deletions demos/Delphi_FMX/FMXTabbedBrowser/uMainForm.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ object MainForm: TMainForm
Left = 0
Top = 0
Caption = 'Initializing. Please, wait...'
ClientHeight = 716
ClientWidth = 979
ClientHeight = 700
ClientWidth = 1032
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
Expand All @@ -19,7 +19,7 @@ object MainForm: TMainForm
Padding.Left = 5.000000000000000000
Padding.Right = 5.000000000000000000
Size.Width = 32.000000000000000000
Size.Height = 716.000000000000000000
Size.Height = 700.000000000000000000
Size.PlatformDefault = False
TabOrder = 0
object AddTabBtn: TSpeedButton
Expand Down Expand Up @@ -51,8 +51,8 @@ object MainForm: TMainForm
end
object BrowserTabCtrl: TTabControl
Align = Client
Size.Width = 947.000000000000000000
Size.Height = 716.000000000000000000
Size.Width = 1000.000000000000000000
Size.Height = 700.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
TabPosition = PlatformDefault
Expand Down
7 changes: 5 additions & 2 deletions demos/Delphi_FMX/FMXToolBoxBrowser/uChildForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,14 @@ procedure TChildForm.CreateFMXWindowParent;
end;

function TChildForm.GetFMXWindowParentRect : System.Types.TRect;
var
TempScale : single;
begin
TempScale := FMXChromium1.ScreenScale;
Result.Left := 0;
Result.Top := 0;
Result.Right := ClientWidth - 1;
Result.Bottom := ClientHeight - 1;
Result.Right := round(ClientWidth * TempScale) - 1;
Result.Bottom := round(ClientHeight * TempScale) - 1;
end;

procedure TChildForm.ResizeChild;
Expand Down
8 changes: 4 additions & 4 deletions demos/Delphi_FMX/SimpleFMXBrowser/uSimpleFMXBrowser.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ object SimpleFMXBrowserFrm: TSimpleFMXBrowserFrm
Top = 0
Caption = 'Initializing browser. Please wait...'
ClientHeight = 600
ClientWidth = 917
ClientWidth = 1000
Position = ScreenCenter
FormFactor.Width = 320
FormFactor.Height = 480
Expand All @@ -20,7 +20,7 @@ object SimpleFMXBrowserFrm: TSimpleFMXBrowserFrm
Padding.Top = 5.000000000000000000
Padding.Right = 5.000000000000000000
Padding.Bottom = 5.000000000000000000
Size.Width = 917.000000000000000000
Size.Width = 1000.000000000000000000
Size.Height = 35.000000000000000000
Size.PlatformDefault = False
TabOrder = 1
Expand All @@ -29,14 +29,14 @@ object SimpleFMXBrowserFrm: TSimpleFMXBrowserFrm
Align = Client
TabOrder = 0
Text = 'https://www.google.com'
Size.Width = 825.000000000000000000
Size.Width = 908.000000000000000000
Size.Height = 25.000000000000000000
Size.PlatformDefault = False
end
object Layout1: TLayout
Align = Right
Padding.Left = 5.000000000000000000
Position.X = 830.000000000000000000
Position.X = 913.000000000000000000
Position.Y = 5.000000000000000000
Size.Width = 82.000000000000000000
Size.Height = 25.000000000000000000
Expand Down
9 changes: 6 additions & 3 deletions demos/Delphi_FMX/SimpleFMXBrowser/uSimpleFMXBrowser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,14 @@ procedure TSimpleFMXBrowserFrm.FormResize(Sender: TObject);
end;

function TSimpleFMXBrowserFrm.GetFMXWindowParentRect : System.Types.TRect;
var
TempScale : single;
begin
TempScale := FMXChromium1.ScreenScale;
Result.Left := 0;
Result.Top := round(AddressPnl.Height);
Result.Right := ClientWidth - 1;
Result.Bottom := ClientHeight - 1;
Result.Top := round(AddressPnl.Height * TempScale);
Result.Right := round(ClientWidth * TempScale) - 1;
Result.Bottom := round(ClientHeight * TempScale) - 1;
end;

procedure TSimpleFMXBrowserFrm.ResizeChild;
Expand Down
27 changes: 26 additions & 1 deletion source/uCEFFMXChromium.pas
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ TFMXChromium = class(TChromiumCore, IChromiumEvents)
protected
function GetParentFormHandle : TCefWindowHandle; override;
function GetParentForm : TCustomForm;
function GetScreenScale : Single;
procedure InitializeDevToolsWindowInfo; virtual;

public
procedure ShowDevTools(inspectElementAt: TPoint);
procedure CloseDevTools;
Expand All @@ -73,6 +75,8 @@ TFMXChromium = class(TChromiumCore, IChromiumEvents)
function CreateBrowser(const aWindowName : ustring = ''; const aContext : ICefRequestContext = nil; const aExtraInfo : ICefDictionaryValue = nil) : boolean; overload; virtual;
function SaveAsBitmapStream(var aStream : TStream; const aRect : System.Types.TRect) : boolean;
function TakeSnapshot(var aBitmap : TBitmap; const aRect : System.Types.TRect) : boolean;

property ScreenScale : single read GetScreenScale;
end;

// *********************************************************
Expand Down Expand Up @@ -105,7 +109,9 @@ TFMXChromium = class(TChromiumCore, IChromiumEvents)
implementation

uses
System.SysUtils, System.Math;
{$IFDEF MSWINDOWS}FMX.Helpers.Win,{$ENDIF}
System.SysUtils, System.Math,
uCEFApplicationCore;

function TFMXChromium.CreateBrowser(const aWindowName : ustring;
const aContext : ICefRequestContext;
Expand Down Expand Up @@ -150,6 +156,25 @@ function TFMXChromium.GetParentForm : TCustomForm;
TempComp := TempComp.owner;
end;

function TFMXChromium.GetScreenScale : Single;
{$IFDEF MSWINDOWS}
var
TempHandle : TCefWindowHandle;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
TempHandle := GetParentFormHandle;

if (TempHandle <> 0) then
Result := GetWndScale(TempHandle)
else
{$ENDIF}
if (GlobalCEFApp <> nil) then
Result := GlobalCEFApp.DeviceScaleFactor
else
Result := 1;
end;

function TFMXChromium.GetParentFormHandle : TCefWindowHandle;
{$IFDEF MSWINDOWS}
var
Expand Down
2 changes: 1 addition & 1 deletion update_CEF4Delphi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 115,
"InternalVersion" : 116,
"Name" : "cef4delphi_lazarus.lpk",
"Version" : "80.1.15.0"
}
Expand Down

0 comments on commit 846aedd

Please sign in to comment.