Skip to content

Commit fe26853

Browse files
committed
WPF/OffScreen - Add missing ScreenInfo values
Change to using Rect struct Follow up to cefsharp#2474
1 parent 1d73f7c commit fe26853

4 files changed

Lines changed: 63 additions & 37 deletions

File tree

‎CefSharp.Core/Internals/RenderClientAdapter.h‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,32 @@ namespace CefSharp
5555
return false;
5656
}
5757

58-
screen_info.device_scale_factor = screenInfo.Value.ScaleFactor;
58+
screen_info.device_scale_factor = screenInfo.Value.DeviceScaleFactor;
59+
screen_info.depth = screenInfo.Value.Depth;
60+
screen_info.depth_per_component = screenInfo.Value.DepthPerComponent;
61+
screen_info.is_monochrome = screenInfo.Value.IsMonochrome ? 1 : 0;
5962

60-
//NOTE: But even if it's not null and the Available* and Width and Height properties are empty, same would happen: the screen_info available and rect structs would remain default (0,0,0,0). If so, the underlying CEF library would use
63+
//NOTE: If rect values remain (0,0,0,0) then the underlying CEF library will use
6164
// GetViewRect to populate values in the window.screen object (javascript).
62-
screen_info.rect.width = screenInfo.Value.Width;
63-
screen_info.rect.height = screenInfo.Value.Height;
64-
65-
screen_info.available_rect.x = screenInfo.Value.AvailableLeft;
66-
screen_info.available_rect.y = screenInfo.Value.AvailableTop;
67-
screen_info.available_rect.width = screenInfo.Value.AvailableWidth;
68-
screen_info.available_rect.height = screenInfo.Value.AvailableHeight;
65+
auto rect = screenInfo.Value.Rect;
66+
67+
if (rect.HasValue)
68+
{
69+
screen_info.rect.width = rect.Value.Width;
70+
screen_info.rect.height = rect.Value.Height;
71+
screen_info.rect.x = rect.Value.X;
72+
screen_info.rect.y = rect.Value.Y;
73+
}
74+
75+
auto availableRect = screenInfo.Value.Rect;
76+
77+
if (availableRect.HasValue)
78+
{
79+
screen_info.available_rect.width = availableRect.Value.Width;
80+
screen_info.available_rect.height = availableRect.Value.Height;
81+
screen_info.available_rect.x = availableRect.Value.X;
82+
screen_info.available_rect.y = availableRect.Value.Y;
83+
}
6984

7085
return true;
7186
}

‎CefSharp.OffScreen/DefaultRenderHandler.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ public void Dispose()
7777
browser = null;
7878
}
7979

80-
public virtual ScreenInfo? GetScreenInfo()
81-
{
82-
var screenInfo = new ScreenInfo(scaleFactor: 1.0F);
80+
public virtual ScreenInfo? GetScreenInfo()
81+
{
82+
var screenInfo = new ScreenInfo { DeviceScaleFactor = 1.0F };
8383

8484
return screenInfo;
8585
}

‎CefSharp.Wpf/ChromiumWebBrowser.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ protected virtual void Dispose(bool isDisposing)
649649
/// <returns>ScreenInfo containing the current DPI scale factor</returns>
650650
protected virtual ScreenInfo? GetScreenInfo()
651651
{
652-
var screenInfo = new ScreenInfo(scaleFactor: (float)DpiScaleFactor);
652+
var screenInfo = new ScreenInfo { DeviceScaleFactor = (float)DpiScaleFactor };
653653

654654
return screenInfo;
655655
}

‎CefSharp/Structs/ScreenInfo.cs‎

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,54 @@
44

55
namespace CefSharp.Structs
66
{
7+
/// <summary>
8+
/// Class representing the virtual screen information for use when window
9+
/// rendering is disabled.
10+
/// </summary>
11+
/// <remarks>
12+
/// See also https://cs.chromium.org/chromium/src/content/public/common/screen_info.h?q=content::ScreenInfo&sq=package:chromium&g=0&l=19
13+
/// </remarks>
714
public struct ScreenInfo
815
{
9-
public float ScaleFactor { get; private set; }
10-
11-
public ScreenInfo(float scaleFactor) : this()
12-
{
13-
ScaleFactor = scaleFactor;
14-
}
15-
1616
/// <summary>
17-
/// Height of the monitor nearest to the window hosting the browser
17+
/// Device scale factor. Specifies the ratio between physical and logical pixels.
1818
/// </summary>
19-
public int Height { get; set; }
20-
19+
public float DeviceScaleFactor { get; set; }
2120
/// <summary>
22-
/// Width of the monitor nearest to the window hosting the browser
21+
/// The screen depth in bits per pixel.
2322
/// </summary>
24-
public int Width { get; set; }
25-
23+
public int Depth { get; set; }
2624
/// <summary>
27-
/// Available Left location of the monitor nearest to the window hosting the browser. iF toolbar is on the left - this would be a non-zero value
25+
/// The bits per color component. This assumes that the colors are balanced equally.
2826
/// </summary>
29-
public int AvailableLeft { get; set; }
30-
27+
public int DepthPerComponent { get; set; }
3128
/// <summary>
32-
/// Available Top location of the monitor nearest to the window hosting the browser. iF toolbar is on top - this would be a non-zero value
29+
/// This can be true for black and white printers.
3330
/// </summary>
34-
public int AvailableTop { get; set; }
35-
31+
public bool IsMonochrome { get; set; }
3632
/// <summary>
37-
/// Available Wdith of the monitor nearest to the window hosting the browser. iF toolbar is on the left or on the right - this would be different from the <see cref="Width">Width</see> property
33+
/// This is set from the rcMonitor member of MONITORINFOEX, to whit:
34+
/// "A RECT structure that specifies the display monitor rectangle,
35+
/// expressed in virtual-screen coordinates. Note that if the monitor
36+
/// is not the primary display monitor, some of the rectangle's
37+
/// coordinates may be negative values."
38+
/// The Rect and AvailableRect properties are used to determine the
39+
/// available surface for rendering popup views.
3840
/// </summary>
39-
public int AvailableWidth { get; set; }
40-
41+
public Rect? Rect { get; set; }
4142
/// <summary>
42-
/// Available Heiht of the monitor nearest to the window hosting the browser. iF toolbar is on top or on the bottom - this would be different from the <see cref="Height">Height</see> property
43+
/// This is set from the rcWork member of MONITORINFOEX, to whit:
44+
/// "A RECT structure that specifies the work area rectangle of the
45+
/// display monitor that can be used by applications, expressed in
46+
/// virtual-screen coordinates. Windows uses this rectangle to
47+
/// maximize an application on the monitor. The rest of the area in
48+
/// rcMonitor contains system windows such as the task bar and side
49+
/// bars. Note that if the monitor is not the primary display monitor,
50+
/// some of the rectangle's coordinates may be negative values".
51+
///
52+
/// The Rect and AvailableRect properties are used to determine the
53+
/// available surface for rendering popup views.
4354
/// </summary>
44-
public int AvailableHeight { get; set; }
55+
public Rect? AvailableRect { get; set; }
4556
}
4657
}

0 commit comments

Comments
 (0)