Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: aspect ratio when max width/height is set (#31956)
* 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 <cezary@openfin.co> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
- Loading branch information
1 parent
098a118
commit 6226507
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 18acd3724d486f7acdaa6aeedcd8ff3681729746..dc4e4755116935c527c34e98a27ce19de0e7b7bc 100644 | ||
--- a/ui/views/win/hwnd_message_handler.cc | ||
+++ b/ui/views/win/hwnd_message_handler.cc | ||
@@ -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); | ||
+ // 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters