fix_aspect_ratio_with_max_size.patch 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Cezary Kulakowski <[email protected]>
  3. Date: Tue, 11 May 2021 11:14:06 +0200
  4. Subject: fix: fix aspect ratio when max width/height is set
  5. Add the native frame border size to the minimum and maximum size if
  6. the view reports its size as the client size. It allows to enlarge
  7. window to proper values when aspect ratio and max width/height are
  8. set. It also fixes DCHECK which was triggered when user tried to
  9. enlarge window above dimensions set during creation of the
  10. BrowserWindow.
  11. diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
  12. index ebce632954ae08535eec9565ca4a908f38410daa..5c4719e1f2084f9d1b99f12b614396f68a3903aa 100644
  13. --- a/ui/views/win/hwnd_message_handler.cc
  14. +++ b/ui/views/win/hwnd_message_handler.cc
  15. @@ -3745,15 +3745,30 @@ void HWNDMessageHandler::SizeWindowToAspectRatio(UINT param,
  16. delegate_->GetMinMaxSize(&min_window_size, &max_window_size);
  17. min_window_size = delegate_->DIPToScreenSize(min_window_size);
  18. max_window_size = delegate_->DIPToScreenSize(max_window_size);
  19. + // Add the native frame border size to the minimum and maximum size if the
  20. + // view reports its size as the client size.
  21. + if (delegate_->WidgetSizeIsClientSize()) {
  22. + RECT client_rect, rect;
  23. + GetClientRect(hwnd(), &client_rect);
  24. + GetWindowRect(hwnd(), &rect);
  25. + CR_DEFLATE_RECT(&rect, &client_rect);
  26. + min_window_size.Enlarge(rect.right - rect.left,
  27. + rect.bottom - rect.top);
  28. + // Either axis may be zero, so enlarge them independently.
  29. + if (max_window_size.width())
  30. + max_window_size.Enlarge(rect.right - rect.left, 0);
  31. + if (max_window_size.height())
  32. + max_window_size.Enlarge(0, rect.bottom - rect.top);
  33. + }
  34. std::optional<gfx::Size> max_size_param;
  35. if (!max_window_size.IsEmpty()) {
  36. max_size_param = max_window_size;
  37. }
  38. - gfx::SizeRectToAspectRatioWithExcludedMargin(
  39. + gfx::SizeRectToAspectRatio(
  40. GetWindowResizeEdge(param), aspect_ratio_.value(), min_window_size,
  41. - max_size_param, excluded_margin_, *window_rect);
  42. + max_size_param, window_rect);
  43. }
  44. POINT HWNDMessageHandler::GetCursorPos() const {