Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

OSR - GetViewRect

Post Reply
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

OSR - GetViewRect

Post by dilfich »

Hi!
Creating a browser

Code: Select all

  TChromMod = class(TComponent)
   private
    FChromium: TChromium;
    .....
   procedure GetViewRect(Sender : TObject; const browser : ICefBrowser; var   rect    : TCefRect);
    .....
In the demo example everything works, If you comment out

Code: Select all

procedure TForm1.chrmosrGetViewRect(      Sender  : TObject;
                                    const browser : ICefBrowser;
                                    var   rect    : TCefRect);
var
  TempScale : single;
begin
  TempScale   := Panel1.ScreenScale;
  rect.x      := 0;
  rect.y      := 0;
  //rect.width  := DeviceToLogical(Panel1.Width,  TempScale);
  //rect.height := DeviceToLogical(Panel1.Height, TempScale);
end;
https://browsersize.com/ Result - Browser window size: 800 x 600

When I create a browser myself, the GetViewRect procedure does not work correctly.

https://browsersize.com/ Result - Browser window size: 1261 x 946 (TBufferPanel = 465 x 535)

I haven't used this method for a long time, but everything used to work with the same code.
What could be the problem?
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: OSR - GetViewRect

Post by Student »

Perhaps this will help you

Code: Select all

procedure TForm1.chrmosrGetScreenInfo(Sender: TObject;
const browser: ICefBrowser; var screenInfo: TCefScreenInfo;
out Result: boolean);
var
  TempRect, TempRect2: TCefRect;
  TempScale: single;
begin
  TempScale := BufferPanel.ScreenScale;
  TempRect.x := 0;
  TempRect.y := 0;
  TempRect.width := DeviceToLogical(screen.DesktopRect.Width, TempScale);
  TempRect.height := DeviceToLogical(screen.DesktopRect.Height, TempScale);

  screenInfo.device_scale_factor := TempScale;
  screenInfo.depth := 24;

  screenInfo.depth_per_component := 0;
  screenInfo.is_monochrome := Ord(False);
  screenInfo.rect := TempRect;

  TempRect2.x := 0;
  TempRect2.y := 0;
  TempRect2.width := DeviceToLogical(screen.WorkAreaRect.Width, TempScale);
  TempRect2.height := DeviceToLogical(screen.WorkAreaRect.Height, TempScale);
  screenInfo.available_rect := TempRect2;

  Result := true;
end;
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: OSR - GetViewRect

Post by dilfich »

Thanks, but no.
GetScreenInfo works, there is no problem with this procedure, it is responsible for Screen size, and I need a Browser window size that should work in GetViewRect.
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: OSR - GetViewRect

Post by dilfich »

Even if I remove all the procedures, I leave only one Paint, it should show "Browser window size: 800 x 600" but it does not and shows "Browser window size: 1261 x 946" :?
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: OSR - GetViewRect

Post by dilfich »

Or here is an example, I indicate

Code: Select all

rect.width  := 500;
rect.height := 500;
https://browsersize.com/ Result - Browser window size: 788 x 788 :shock:
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: OSR - GetViewRect

Post by Student »

dilfich wrote: Thu Apr 06, 2023 12:19 pm Or here is an example, I indicate

Code: Select all

rect.width  := 500;
rect.height := 500;
https://browsersize.com/ Result - Browser window size: 788 x 788 :shock:
I specified rect.width := 500; rect.height := 500; in my application, and the website shows Browser window size: 500 x 500, so I am not reproducing this problem. Maybe your application is not scaled correctly for HiDPI. Check the version 107 or below, there is such a problem with you?
dilfich
Posts: 330
Joined: Thu Nov 30, 2017 1:17 am

Re: OSR - GetViewRect

Post by dilfich »

Oh, I found a problem :D

Code: Select all

Before ResourceLoad
.....
if Browser.Host.Zoom Level <> 5 the Browser.Host.ZoomLevel:= -2.5;
....
If you don't change the scale then everything works
Student
Posts: 72
Joined: Tue Aug 07, 2018 9:20 am

Re: OSR - GetViewRect

Post by Student »

Good, try to write a formula that is universal for any zoom.
Post Reply