Skip to content

Commit

Permalink
Set dpi_ correctly during main window creation
Browse files Browse the repository at this point in the history
For some Chrome windows the dpi_ setting cannot be set during window
creation because the window location is not yet known. For other windows
the dpi_ setting _must_ be set during window creation. This change
handles both cases by setting dpi_ if the window size/location is being
specified. This then handles both the task manager and main window
cases.

Bug: 1282804
Change-Id: Ic85dfb1646e9d063af324cc79736b660cea1acdc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3378579
Reviewed-by: Robert Liao <robliao@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#957715}
  • Loading branch information
randomascii authored and Chromium LUCI CQ committed Jan 11, 2022
1 parent ab1d42d commit 1aa9b09
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ui/views/win/hwnd_message_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {
GetMonitorAndRects(bounds.ToRECT(), &last_monitor_, &last_monitor_rect_,
&last_work_area_);

initial_bounds_valid_ = !bounds.IsEmpty();
// Create the window.
WindowImpl::Init(parent, bounds);

Expand Down Expand Up @@ -1646,6 +1647,12 @@ LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {
std::make_unique<ui::SessionChangeObserver>(base::BindRepeating(
&HWNDMessageHandler::OnSessionChange, base::Unretained(this)));

// If the window was initialized with a specific size/location then we know
// the DPI and thus must initialize dpi_ now. See https://crbug.com/1282804
// for details.
if (initial_bounds_valid_)
dpi_ = display::win::ScreenWin::GetDPIForHWND(hwnd());

// TODO(beng): move more of NWW::OnCreate here.
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions ui/views/win/hwnd_message_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,10 @@ class VIEWS_EXPORT HWNDMessageHandler : public gfx::WindowImpl,
// The current DPI.
int dpi_;

// This is true if the window is created with a specific size/location, as
// opposed to having them set after window creation.
bool initial_bounds_valid_ = false;

// Whether EnableNonClientDpiScaling was called successfully with this window.
// This flag exists because EnableNonClientDpiScaling must be called during
// WM_NCCREATE and EnableChildWindowDpiMessage is called after window
Expand Down

0 comments on commit 1aa9b09

Please sign in to comment.