From dcf6f046d9875529400b947620b4247d56853995 Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Fri, 1 Nov 2019 12:22:07 -0400 Subject: [PATCH] feat: implement win.setAspectRatio() on Linux (#19516) --- docs/api/browser-window.md | 4 +-- patches/chromium/.patches | 1 + ...t_unset_window_aspect_ratio_on_linux.patch | 28 +++++++++++++++++++ shell/browser/native_window_views.cc | 12 ++++++++ shell/browser/native_window_views.h | 2 ++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 patches/chromium/feat_unset_window_aspect_ratio_on_linux.patch diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f74b25d08986..bf7ccafa6558 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -946,11 +946,11 @@ Returns `Boolean` - Whether the window is in simple (pre-Lion) fullscreen mode. Returns `Boolean` - Whether the window is in normal state (not maximized, not minimized, not in fullscreen mode). -#### `win.setAspectRatio(aspectRatio[, extraSize])` _macOS_ +#### `win.setAspectRatio(aspectRatio[, extraSize])` _macOS_ _Linux_ * `aspectRatio` Float - The aspect ratio to maintain for some portion of the content view. -* `extraSize` [Size](structures/size.md) (optional) - The extra size not to be included while + * `extraSize` [Size](structures/size.md) (optional) _macOS_ - The extra size not to be included while maintaining the aspect ratio. This will make a window maintain an aspect ratio. The extra size allows a diff --git a/patches/chromium/.patches b/patches/chromium/.patches index b7ed453bcc4a..d4971e6b3734 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -84,3 +84,4 @@ build_win_fix_ambiguous_reference_with_msstl.patch build_win_iwyu_for_smil_time.patch remove_usage_of_incognito_apis_in_the_spellchecker.patch chore_use_electron_resources_not_chrome_for_spellchecker.patch +feat_unset_window_aspect_ratio_on_linux.patch diff --git a/patches/chromium/feat_unset_window_aspect_ratio_on_linux.patch b/patches/chromium/feat_unset_window_aspect_ratio_on_linux.patch new file mode 100644 index 000000000000..6144747aac2c --- /dev/null +++ b/patches/chromium/feat_unset_window_aspect_ratio_on_linux.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Erick Zhao +Date: Thu, 1 Aug 2019 13:40:17 -0700 +Subject: feat: unset window aspect ratio on linux + + +diff --git a/ui/base/x/x11_window.cc b/ui/base/x/x11_window.cc +index 7df0a3a8ed268e9b2ca1bad8ac5fd35115b98f77..a895defd2b695e2d5b2b4324551adcaac487f588 100644 +--- a/ui/base/x/x11_window.cc ++++ b/ui/base/x/x11_window.cc +@@ -676,9 +676,14 @@ void XWindow::SetAspectRatio(const gfx::SizeF& aspect_ratio) { + long supplied_return; + + XGetWMNormalHints(xdisplay_, xwindow_, &size_hints, &supplied_return); +- size_hints.flags |= PAspect; +- size_hints.min_aspect.x = size_hints.max_aspect.x = aspect_ratio.width(); +- size_hints.min_aspect.y = size_hints.max_aspect.y = aspect_ratio.height(); ++ // if ratio parameter has length 0, unforce the aspect ratio ++ if (aspect_ratio.IsEmpty()) { ++ size_hints.flags &= ~PAspect; ++ } else { ++ size_hints.flags |= PAspect; ++ size_hints.min_aspect.x = size_hints.max_aspect.x = aspect_ratio.width(); ++ size_hints.min_aspect.y = size_hints.max_aspect.y = aspect_ratio.height(); ++ } + XSetWMNormalHints(xdisplay_, xwindow_, &size_hints); + } + diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 4b2fff52e1ec..dc84fefbffbf 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -709,6 +709,18 @@ bool NativeWindowViews::IsResizable() { return CanResize(); } +void NativeWindowViews::SetAspectRatio(double aspect_ratio, + const gfx::Size& extra_size) { + NativeWindow::SetAspectRatio(aspect_ratio, extra_size); +#if defined(OS_LINUX) + gfx::SizeF aspect(aspect_ratio, 1.0); + // Scale up because SetAspectRatio() truncates aspect value to int + aspect.Scale(100); + + widget()->SetAspectRatio(aspect); +#endif +} + void NativeWindowViews::SetMovable(bool movable) { movable_ = movable; } diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 078885cd4181..7b428cab2670 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -72,6 +72,8 @@ class NativeWindowViews : public NativeWindow, bool MoveAbove(const std::string& sourceId) override; void MoveTop() override; bool IsResizable() override; + void SetAspectRatio(double aspect_ratio, + const gfx::Size& extra_size) override; void SetMovable(bool movable) override; bool IsMovable() override; void SetMinimizable(bool minimizable) override;