From 4237899b45584899280dc964dd2adaf9e8ea096d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20D=C3=ADaz=20Fau?= Date: Sat, 8 Jun 2024 09:18:00 +0200 Subject: [PATCH] Fixed high DPI issue in Delphi_VCL\WindowlessBrowser --- .../WindowlessBrowser/uWindowlessBrowser.pas | 10 ++++++---- update_WebView4Delphi.json | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/demos/Delphi_VCL/WindowlessBrowser/uWindowlessBrowser.pas b/demos/Delphi_VCL/WindowlessBrowser/uWindowlessBrowser.pas index a98a888..f838247 100644 --- a/demos/Delphi_VCL/WindowlessBrowser/uWindowlessBrowser.pas +++ b/demos/Delphi_VCL/WindowlessBrowser/uWindowlessBrowser.pas @@ -363,6 +363,7 @@ procedure TMainForm.WVBrowser1WebMessageReceived(Sender: TObject; TempValue : TJSonValue; TempPoint : TPoint; TempSize : TSize; + TempScale : single; begin TempArgs := TCoreWebView2WebMessageReceivedEventArgs.Create(aArgs); TempMsg := TempArgs.WebMessageAsJson; @@ -370,12 +371,13 @@ procedure TMainForm.WVBrowser1WebMessageReceived(Sender: TObject; // The JavaScript code returned a DOMRect in JSON format. TempObject := TJSonObject.Create; TempValue := TempObject.ParseJSONValue(TempMsg); + TempScale := WVBrowser1.ScreenScale; // Get the coordinates and size of the element - TempPoint.x := round((TempValue as TJSONObject).Get('x').JSONValue.AsType * GlobalWebView2Loader.DeviceScaleFactor); - TempPoint.y := round((TempValue as TJSONObject).Get('y').JSONValue.AsType * GlobalWebView2Loader.DeviceScaleFactor); - TempSize.cx := round((TempValue as TJSONObject).Get('width').JSONValue.AsType * GlobalWebView2Loader.DeviceScaleFactor); - TempSize.cy := round((TempValue as TJSONObject).Get('height').JSONValue.AsType * GlobalWebView2Loader.DeviceScaleFactor); + TempPoint.x := round((TempValue as TJSONObject).Get('x').JSONValue.AsType * TempScale); + TempPoint.y := round((TempValue as TJSONObject).Get('y').JSONValue.AsType * TempScale); + TempSize.cx := round((TempValue as TJSONObject).Get('width').JSONValue.AsType * TempScale); + TempSize.cy := round((TempValue as TJSONObject).Get('height').JSONValue.AsType * TempScale); // Middle point of the element TempPoint.x := TempPoint.x + (TempSize.cx div 2); diff --git a/update_WebView4Delphi.json b/update_WebView4Delphi.json index 815ca69..b3f1cf9 100644 --- a/update_WebView4Delphi.json +++ b/update_WebView4Delphi.json @@ -2,7 +2,7 @@ "UpdateLazPackages" : [ { "ForceNotify" : true, - "InternalVersion" : 151, + "InternalVersion" : 152, "Name" : "webview4delphi.lpk", "Version" : "1.0.2535.41" }