From 7d9143bcffc135b159b2e86fe866f0f2f35cc62d Mon Sep 17 00:00:00 2001 From: Cezary Kulakowski Date: Tue, 11 May 2021 15:17:15 +0200 Subject: [PATCH 1/2] fix: fix aspect ratio when max width/height is set Add the native frame border size to the minimum and maximum size if the view reports its size as the client size. It allows to enlarge window to proper values when aspect ratio and max width/height are set. It also fixes DCHECK which was triggered when user tried to enlarge window above dimensions set during creation of the BrowserWindow. --- patches/chromium/.patches | 3 ++ .../fix_aspect_ratio_with_max_size.patch | 38 +++++++++++++++++++ spec-main/api-browser-window-spec.ts | 11 ++++++ 3 files changed, 52 insertions(+) create mode 100644 patches/chromium/fix_aspect_ratio_with_max_size.patch diff --git a/patches/chromium/.patches b/patches/chromium/.patches index cac1e6ce514be..336d3ff10ef58 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -114,3 +114,6 @@ cherry-pick-2e7c9b33453b.patch move_networkstateobserver_from_document_to_window.patch cherry-pick-0894af410c4e.patch cherry-pick-91dd4f79ab5b.patch +load_v8_snapshot_in_browser_process.patch +fix_patch_out_permissions_checks_in_exclusive_access.patch +fix_aspect_ratio_with_max_size.patch diff --git a/patches/chromium/fix_aspect_ratio_with_max_size.patch b/patches/chromium/fix_aspect_ratio_with_max_size.patch new file mode 100644 index 0000000000000..4e3f76c81bad0 --- /dev/null +++ b/patches/chromium/fix_aspect_ratio_with_max_size.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Cezary Kulakowski +Date: Tue, 11 May 2021 11:14:06 +0200 +Subject: fix: fix aspect ratio when max width/height is set + +Add the native frame border size to the minimum and maximum size if +the view reports its size as the client size. It allows to enlarge +window to proper values when aspect ratio and max width/height are +set. It also fixes DCHECK which was triggered when user tried to +enlarge window above dimensions set during creation of the +BrowserWindow. + +diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc +index a235cab941ec583a8dc9cb5e4105c2d7baae02df..f7c1232b0893c366aeeb77e6df0bbd275b6f7bd4 100644 +--- a/ui/views/win/hwnd_message_handler.cc ++++ b/ui/views/win/hwnd_message_handler.cc +@@ -3569,6 +3569,21 @@ void HWNDMessageHandler::SizeWindowToAspectRatio(UINT param, + delegate_->GetMinMaxSize(&min_window_size, &max_window_size); + min_window_size = delegate_->DIPToScreenSize(min_window_size); + max_window_size = delegate_->DIPToScreenSize(max_window_size); ++ // Add the native frame border size to the minimum and maximum size if the ++ // view reports its size as the client size. ++ if (delegate_->WidgetSizeIsClientSize()) { ++ RECT client_rect, rect; ++ GetClientRect(hwnd(), &client_rect); ++ GetWindowRect(hwnd(), &rect); ++ CR_DEFLATE_RECT(&rect, &client_rect); ++ min_window_size.Enlarge(rect.right - rect.left, ++ rect.bottom - rect.top); ++ // Either axis may be zero, so enlarge them independently. ++ if (max_window_size.width()) ++ max_window_size.Enlarge(rect.right - rect.left, 0); ++ if (max_window_size.height()) ++ max_window_size.Enlarge(0, rect.bottom - rect.top); ++ } + gfx::SizeRectToAspectRatio(GetWindowResizeEdge(param), aspect_ratio_.value(), + min_window_size, max_window_size, window_rect); + } diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index f45eb55fd8093..83ed22f397de6 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -952,6 +952,17 @@ describe('BrowserWindow module', () => { await resize; expectBoundsEqual(w.getSize(), size); }); + + it('doesn\'t change bounds when maximum size is set', () => { + w.setMenu(null); + w.setMaximumSize(400, 400); + // Without https://github.com/electron/electron/pull/29101 + // following call would shrink the window to 384x361. + // There would be also DCHECK in resize_utils.cc on + // debug build. + w.setAspectRatio(1.0); + expectBoundsEqual(w.getSize(), [400, 400]); + }); }); describe('BrowserWindow.setPosition(x, y)', () => { From 58dc3e74b68392095f20f29c60985f8267e1a570 Mon Sep 17 00:00:00 2001 From: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Date: Mon, 22 Nov 2021 21:51:12 +0000 Subject: [PATCH 2/2] chore: update patches --- patches/chromium/fix_aspect_ratio_with_max_size.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patches/chromium/fix_aspect_ratio_with_max_size.patch b/patches/chromium/fix_aspect_ratio_with_max_size.patch index 4e3f76c81bad0..26b539cb37ef2 100644 --- a/patches/chromium/fix_aspect_ratio_with_max_size.patch +++ b/patches/chromium/fix_aspect_ratio_with_max_size.patch @@ -11,10 +11,10 @@ enlarge window above dimensions set during creation of the BrowserWindow. diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc -index a235cab941ec583a8dc9cb5e4105c2d7baae02df..f7c1232b0893c366aeeb77e6df0bbd275b6f7bd4 100644 +index 18acd3724d486f7acdaa6aeedcd8ff3681729746..dc4e4755116935c527c34e98a27ce19de0e7b7bc 100644 --- a/ui/views/win/hwnd_message_handler.cc +++ b/ui/views/win/hwnd_message_handler.cc -@@ -3569,6 +3569,21 @@ void HWNDMessageHandler::SizeWindowToAspectRatio(UINT param, +@@ -3565,6 +3565,21 @@ void HWNDMessageHandler::SizeWindowToAspectRatio(UINT param, delegate_->GetMinMaxSize(&min_window_size, &max_window_size); min_window_size = delegate_->DIPToScreenSize(min_window_size); max_window_size = delegate_->DIPToScreenSize(max_window_size);