Skip to content

Commit

Permalink
fix: fix aspect ratio when max width/height is set
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
CezaryKulakowski committed May 11, 2021
1 parent aea8d53 commit bb5f6aa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions patches/chromium/.patches
Expand Up @@ -103,6 +103,7 @@ web_contents.patch
disable_unload_metrics.patch
fix_add_check_for_sandbox_then_result.patch
extend_apply_webpreferences.patch
fix_aspect_ratio_with_max_size.patch
fix_expose_decrementcapturercount_in_web_contents_impl.patch
add_setter_for_browsermainloop_result_code.patch
revert_roll_clang_llvmorg-13-init-7051-gdad5caa5-2.patch
38 changes: 38 additions & 0 deletions 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 <cezary@openfin.co>
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 92eb76ff7a5406ff022b5a88988ef78451c90c1c..f916276cc7339c9c9793b44d044529540ca87284 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -3570,6 +3570,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);
}

0 comments on commit bb5f6aa

Please sign in to comment.