12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: Cezary Kulakowski <[email protected]>
- 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 a802f4b710b6f8fa154d11846c061720a91e15e4..2bd015be3178ab8dea012d6b1f71d13dd0548c14 100644
- --- a/ui/views/win/hwnd_message_handler.cc
- +++ b/ui/views/win/hwnd_message_handler.cc
- @@ -3747,15 +3747,30 @@ 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);
- + }
-
- std::optional<gfx::Size> max_size_param;
- if (!max_window_size.IsEmpty()) {
- max_size_param = max_window_size;
- }
-
- - gfx::SizeRectToAspectRatioWithExcludedMargin(
- + gfx::SizeRectToAspectRatio(
- GetWindowResizeEdge(param), aspect_ratio_.value(), min_window_size,
- - max_size_param, excluded_margin_, *window_rect);
- + max_size_param, window_rect);
- }
-
- POINT HWNDMessageHandler::GetCursorPos() const {
|