Skip to content

Commit

Permalink
Fixed high DPI issue in Delphi_VCL\WindowlessBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadordf committed Jun 8, 2024
1 parent f675443 commit 4237899
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions demos/Delphi_VCL/WindowlessBrowser/uWindowlessBrowser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,21 @@ procedure TMainForm.WVBrowser1WebMessageReceived(Sender: TObject;
TempValue : TJSonValue;
TempPoint : TPoint;
TempSize : TSize;
TempScale : single;
begin
TempArgs := TCoreWebView2WebMessageReceivedEventArgs.Create(aArgs);
TempMsg := TempArgs.WebMessageAsJson;

// 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<double> * GlobalWebView2Loader.DeviceScaleFactor);
TempPoint.y := round((TempValue as TJSONObject).Get('y').JSONValue.AsType<double> * GlobalWebView2Loader.DeviceScaleFactor);
TempSize.cx := round((TempValue as TJSONObject).Get('width').JSONValue.AsType<double> * GlobalWebView2Loader.DeviceScaleFactor);
TempSize.cy := round((TempValue as TJSONObject).Get('height').JSONValue.AsType<double> * GlobalWebView2Loader.DeviceScaleFactor);
TempPoint.x := round((TempValue as TJSONObject).Get('x').JSONValue.AsType<double> * TempScale);
TempPoint.y := round((TempValue as TJSONObject).Get('y').JSONValue.AsType<double> * TempScale);
TempSize.cx := round((TempValue as TJSONObject).Get('width').JSONValue.AsType<double> * TempScale);
TempSize.cy := round((TempValue as TJSONObject).Get('height').JSONValue.AsType<double> * TempScale);

// Middle point of the element
TempPoint.x := TempPoint.x + (TempSize.cx div 2);
Expand Down
2 changes: 1 addition & 1 deletion update_WebView4Delphi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"UpdateLazPackages" : [
{
"ForceNotify" : true,
"InternalVersion" : 151,
"InternalVersion" : 152,
"Name" : "webview4delphi.lpk",
"Version" : "1.0.2535.41"
}
Expand Down

0 comments on commit 4237899

Please sign in to comment.