From 5462e954b71d210b68690091192d9b4a6b94913a Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 24 Nov 2021 17:07:37 -0500 Subject: [PATCH] fix: aspect ratio when max width/height is set (#31955) * 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. * chore: update patches Co-authored-by: Cezary Kulakowski Co-authored-by: John Kleinschmidt Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> --- patches/chromium/.patches | 1 + .../fix_aspect_ratio_with_max_size.patch | 38 +++++++++++++++++++ spec-main/api-browser-window-spec.ts | 11 ++++++ 3 files changed, 50 insertions(+) create mode 100644 patches/chromium/fix_aspect_ratio_with_max_size.patch diff --git a/patches/chromium/.patches b/patches/chromium/.patches index 5bf3cc6345908..78ecb9626d95d 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -126,3 +126,4 @@ introduce_crossthreadcopier_skbitmap.patch allow_null_skbitmap_to_be_transferred_across_threads.patch use_weakptrs_for_the_threadediconloader_s_background_tasks.patch cherry-pick-a5f54612590d.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..a76b7ca31a5db --- /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 41fa3c23b9a5d8596f2fb44d0957ab6e1f60a95a..e4c25788cf40e2b748cb25f004e448c0ea5f622c 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 a23a95614a081..746788b6cd5ab 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -953,6 +953,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)', () => {