From f0c83d6fb05826e7f9b814daf602b458bde6f2d4 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Tue, 16 Aug 2022 14:22:47 -0700 Subject: [PATCH] fix: Frameless window shows frame while opening (#35189) * fix: Frameless window shows frame while opening * Clarify comments * Inline setter * Edit comment --- patches/chromium/.patches | 1 + .../feat_add_set_can_resize_mutator.patch | 27 +++++++++++++++++++ shell/browser/native_window_views.cc | 17 ++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 patches/chromium/feat_add_set_can_resize_mutator.patch diff --git a/patches/chromium/.patches b/patches/chromium/.patches index ea04e58a07500..c9e516ffc0929 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -116,3 +116,4 @@ chore_add_electron_deps_to_gitignores.patch chore_allow_chromium_to_handle_synthetic_mouse_events_for_touch.patch add_maximized_parameter_to_linuxui_getwindowframeprovider.patch add_electron_deps_to_license_credits_file.patch +feat_add_set_can_resize_mutator.patch diff --git a/patches/chromium/feat_add_set_can_resize_mutator.patch b/patches/chromium/feat_add_set_can_resize_mutator.patch new file mode 100644 index 0000000000000..5b2adba9ecd49 --- /dev/null +++ b/patches/chromium/feat_add_set_can_resize_mutator.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> +Date: Tue, 2 Aug 2022 09:30:36 -0700 +Subject: feat: Add set_can_resize mutator + +Adds a set_can_resize mutator to WidgetDelegate that +doesn't emit the OnSizeConstraintsChanged event. +This way, we can call set_can_resize from Electron before +the widget is initialized to set the value earlier, +and in turn, avoid showing a frame at startup +for frameless applications. + +diff --git a/ui/views/widget/widget_delegate.h b/ui/views/widget/widget_delegate.h +index 431d19f2543a9011de76b941982603ff98afa041..32e07e0c9686e6942a40c4d4775a03068cfd33b5 100644 +--- a/ui/views/widget/widget_delegate.h ++++ b/ui/views/widget/widget_delegate.h +@@ -323,6 +323,10 @@ class VIEWS_EXPORT WidgetDelegate { + // be cycled through with keyboard focus. + virtual void GetAccessiblePanes(std::vector* panes) {} + ++ // A setter for the can_resize parameter that doesn't ++ // emit any events. ++ void set_can_resize(bool can_resize) { params_.can_resize = can_resize; } ++ + // Setters for data parameters of the WidgetDelegate. If you use these + // setters, there is no need to override the corresponding virtual getters. + void SetAccessibleRole(ax::mojom::Role role); diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index bf60cc85f0736..2fea92b1ed57a 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -281,7 +281,24 @@ NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, new ElectronDesktopWindowTreeHostLinux(this, native_widget); #endif + // Ref https://github.com/electron/electron/issues/30760 + // Set the can_resize param before initializing the widget. + // When resizable_ is true, this causes the WS_THICKFRAME style + // to be passed into CreateWindowEx and SetWindowLong calls in + // WindowImpl::Init and HwndMessageHandler::SizeConstraintsChanged + // respectively. As a result, the Windows 7 frame doesn't show, + // but it isn't clear why this is the case. + // When resizable_ is false, WS_THICKFRAME is not passed into the + // SetWindowLong call, so the Windows 7 frame still shows. + // One workaround would be to call set_can_resize(true) here, + // and then move the SetCanResize(resizable_) call after the + // SetWindowLong call around line 365, but that's a much larger change. + set_can_resize(true); widget()->Init(std::move(params)); + + // When the workaround above is not needed anymore, only this + // call should be necessary. + // With the workaround in place, this call doesn't do anything. SetCanResize(resizable_); bool fullscreen = false;