From 702bed0b5a18e1f23a7d8070d9ff8102bd816611 Mon Sep 17 00:00:00 2001 From: mlaurencin Date: Thu, 10 Mar 2022 15:31:06 -0800 Subject: [PATCH 1/2] chore: cherry-pick 1aa9b09 from chromium --- patches/chromium/.patches | 1 + ...orrectly_during_main_window_creation.patch | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 patches/chromium/set_dpi_correctly_during_main_window_creation.patch diff --git a/patches/chromium/.patches b/patches/chromium/.patches index 13d518ee2d0d6..154a131c13715 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -116,3 +116,4 @@ cherry-pick-f5101995acd2.patch fix_don_t_restore_maximized_windows_when_calling_showinactive.patch build_disable_partition_alloc_on_mac.patch fix_non-client_mouse_tracking_and_message_bubbling_on_windows.patch +set_dpi_correctly_during_main_window_creation.patch diff --git a/patches/chromium/set_dpi_correctly_during_main_window_creation.patch b/patches/chromium/set_dpi_correctly_during_main_window_creation.patch new file mode 100644 index 0000000000000..7b478b14505b8 --- /dev/null +++ b/patches/chromium/set_dpi_correctly_during_main_window_creation.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Bruce Dawson +Date: Tue, 11 Jan 2022 21:22:18 +0000 +Subject: Set dpi_ correctly during main window creation + +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 +Commit-Queue: Bruce Dawson +Cr-Commit-Position: refs/heads/main@{#957715} + +diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc +index 6507557bf5a47492343602607e0dbb7d8f88246d..ee7581aed9a96eb9e75ecb8c06c4c0e4ebc3c508 100644 +--- a/ui/views/win/hwnd_message_handler.cc ++++ b/ui/views/win/hwnd_message_handler.cc +@@ -444,6 +444,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); + +@@ -1665,6 +1666,12 @@ LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { + std::make_unique(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; + } +diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h +index f6691252bd593e83fdda4fac73498df9d1cf3af6..9d45f97b930831a703efab2bbdf10afb61140c7f 100644 +--- a/ui/views/win/hwnd_message_handler.h ++++ b/ui/views/win/hwnd_message_handler.h +@@ -645,6 +645,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 From e5290a82332afed72498c41ad1c67834140a3a95 Mon Sep 17 00:00:00 2001 From: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Date: Tue, 22 Mar 2022 00:32:44 +0000 Subject: [PATCH 2/2] chore: update patches --- .../set_dpi_correctly_during_main_window_creation.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/chromium/set_dpi_correctly_during_main_window_creation.patch b/patches/chromium/set_dpi_correctly_during_main_window_creation.patch index 7b478b14505b8..808b6539e7d60 100644 --- a/patches/chromium/set_dpi_correctly_during_main_window_creation.patch +++ b/patches/chromium/set_dpi_correctly_during_main_window_creation.patch @@ -18,7 +18,7 @@ Commit-Queue: Bruce Dawson Cr-Commit-Position: refs/heads/main@{#957715} diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc -index 6507557bf5a47492343602607e0dbb7d8f88246d..ee7581aed9a96eb9e75ecb8c06c4c0e4ebc3c508 100644 +index 783fde724396ee0dce8bbb25834e00c0da0d924b..896ba821b1bbbf44f1464b3efb4f251d42980c8a 100644 --- a/ui/views/win/hwnd_message_handler.cc +++ b/ui/views/win/hwnd_message_handler.cc @@ -444,6 +444,7 @@ void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) {