Browse Source

fix: `system-context-menu` should only fire in draggable regions (36-x-y) (#46002)

fix: `system-context-menu` should only fire in draggable regions (#45893)

fix: system-context-menu should only fire in draggable regions

Co-authored-by: Shelley Vohr <[email protected]>
Charles Kerr 1 month ago
parent
commit
1fc3a60655

+ 1 - 1
patches/chromium/.patches

@@ -83,7 +83,7 @@ feat_filter_out_non-shareable_windows_in_the_current_application_in.patch
 disable_freezing_flags_after_init_in_node.patch
 short-circuit_permissions_checks_in_mediastreamdevicescontroller.patch
 chore_add_electron_deps_to_gitignores.patch
-chore_allow_chromium_to_handle_synthetic_mouse_events_for_touch.patch
+chore_modify_chromium_handling_of_mouse_events.patch
 add_electron_deps_to_license_credits_file.patch
 fix_crash_loading_non-standard_schemes_in_iframes.patch
 create_browser_v8_snapshot_file_name_fuse.patch

+ 57 - 3
patches/chromium/chore_allow_chromium_to_handle_synthetic_mouse_events_for_touch.patch → patches/chromium/chore_modify_chromium_handling_of_mouse_events.patch

@@ -1,11 +1,38 @@
 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
 From: deepak1556 <[email protected]>
 Date: Fri, 29 Jul 2022 00:29:35 +0900
-Subject: chore: allow chromium to handle synthetic mouse events for touch
+Subject: chore: modify chromium handling of mouse events
 
-With WCO, allow chromium to handle synthetic mouse events generated for touch
+This patch does the following:
+
+1. When Windows Control Overlay is enabled, it allows chromium to handle synthetic mouse events generated for touch
 actions in the non-client caption area.
+2. It calls HandleMouseEvent on the delegate earlier in HandleMouseEventInternal, so that Electron can selectively disable
+draggable regions to allow events to propagate to the underlying renderer.
 
+diff --git a/ui/events/event.h b/ui/events/event.h
+index 39b5a8fdd165efd74b00256552b51b5413107958..bfc4ef4f50efff4a77f2aef64335bb7e34c69f34 100644
+--- a/ui/events/event.h
++++ b/ui/events/event.h
+@@ -587,6 +587,9 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
+ 
+   const PointerDetails& pointer_details() const { return pointer_details_; }
+ 
++  bool is_system_menu() const { return is_system_menu_; }
++  void set_is_system_menu(bool is_menu) { is_system_menu_ = is_menu; }
++
+   // Event:
+   std::string ToString() const override;
+   std::unique_ptr<Event> Clone() const override;
+@@ -619,6 +622,8 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
+ 
+   // Structure for holding pointer details for implementing PointerEvents API.
+   PointerDetails pointer_details_;
++
++  bool is_system_menu_ = false;
+ };
+ 
+ class ScrollEvent;
 diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
 index 55c426aee12da4d4d1f62dc7d489133e8d21dc49..40c88bf14d2d4fe841e29b32414361688ae438e5 100644
 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
@@ -34,7 +61,7 @@ index 4865d79c95c34d8cead96d3bb8063a0e2bd6076b..ebfa09ed15dca98b75a013e3dcbb566c
    // Overridden from WidgetObserver.
    void OnWidgetThemeChanged(Widget* widget) override;
 diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
-index 7f29d902ae0a2f980a56e77e6e25935dab3c0685..679efe5af4954d9ddca7bc5ccee6b8d6fac966a3 100644
+index 7f29d902ae0a2f980a56e77e6e25935dab3c0685..ad844f4d6d150aee3e00fd6465600bfb248d79d2 100644
 --- a/ui/views/win/hwnd_message_handler.cc
 +++ b/ui/views/win/hwnd_message_handler.cc
 @@ -3146,15 +3146,19 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
@@ -59,6 +86,33 @@ index 7f29d902ae0a2f980a56e77e6e25935dab3c0685..679efe5af4954d9ddca7bc5ccee6b8d6
        return 0;
      }
    }
+@@ -3177,6 +3181,7 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
+     // handle alt-space, or in the frame itself.
+     is_right_mouse_pressed_on_caption_ = false;
+     ReleaseCapture();
++
+     // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu()
+     // expect screen coordinates.
+     POINT screen_point = CR_POINT_INITIALIZER_FROM_LPARAM(l_param);
+@@ -3184,7 +3189,17 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
+     w_param = static_cast<WPARAM>(SendMessage(
+         hwnd(), WM_NCHITTEST, 0, MAKELPARAM(screen_point.x, screen_point.y)));
+     if (w_param == HTCAPTION || w_param == HTSYSMENU) {
+-      ShowSystemMenuAtScreenPixelLocation(hwnd(), gfx::Point(screen_point));
++      LONG message_time = GetMessageTime();
++      CHROME_MSG msg = {hwnd(),
++                        message,
++                        w_param,
++                        l_param,
++                        static_cast<DWORD>(message_time),
++                        {CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param)}};
++      ui::MouseEvent event(msg);
++      event.set_is_system_menu(true);
++      if (!delegate_->HandleMouseEvent(&event))
++        ShowSystemMenuAtScreenPixelLocation(hwnd(), gfx::Point(screen_point));
+       return 0;
+     }
+   } else if (message == WM_NCLBUTTONDOWN &&
 diff --git a/ui/views/win/hwnd_message_handler_delegate.h b/ui/views/win/hwnd_message_handler_delegate.h
 index de8fd5657e6885f74a5970bdd49647a6f1616387..4af87792edc7a147468077b834582510550e35e6 100644
 --- a/ui/views/win/hwnd_message_handler_delegate.h

+ 1 - 1
patches/chromium/fix_activate_background_material_on_windows.patch

@@ -14,7 +14,7 @@ This patch likely can't be upstreamed as-is, as Chromium doesn't have
 this use case in mind currently.
 
 diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
-index e061dc5e64fde1a9c531dbedae0c137105700ac7..3d0cc571b471bb79d845f8b0a1da168ace33bb6b 100644
+index d68fd93d4cb912b9b27d3a7cdfecc6faf638b91e..22ed43bdf4dbaccc598135807abc8383c52db50e 100644
 --- a/ui/views/win/hwnd_message_handler.cc
 +++ b/ui/views/win/hwnd_message_handler.cc
 @@ -934,13 +934,13 @@ void HWNDMessageHandler::FrameTypeChanged() {

+ 1 - 1
patches/chromium/fix_remove_caption-removing_style_call.patch

@@ -18,7 +18,7 @@ or resizing, but Electron does not seem to run into that issue
 for opaque frameless windows even with that block commented out.
 
 diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
-index 679efe5af4954d9ddca7bc5ccee6b8d6fac966a3..e061dc5e64fde1a9c531dbedae0c137105700ac7 100644
+index ad844f4d6d150aee3e00fd6465600bfb248d79d2..d68fd93d4cb912b9b27d3a7cdfecc6faf638b91e 100644
 --- a/ui/views/win/hwnd_message_handler.cc
 +++ b/ui/views/win/hwnd_message_handler.cc
 @@ -1788,7 +1788,23 @@ LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) {

+ 0 - 9
shell/browser/native_window_views_win.cc

@@ -288,15 +288,6 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
 
       return false;
     }
-    case WM_RBUTTONUP: {
-      if (!has_frame()) {
-        bool prevent_default = false;
-        NotifyWindowSystemContextMenu(GET_X_LPARAM(l_param),
-                                      GET_Y_LPARAM(l_param), &prevent_default);
-        return prevent_default;
-      }
-      return false;
-    }
     case WM_GETMINMAXINFO: {
       WINDOWPLACEMENT wp;
       wp.length = sizeof(WINDOWPLACEMENT);

+ 11 - 0
shell/browser/ui/win/electron_desktop_window_tree_host_win.cc

@@ -108,6 +108,17 @@ bool ElectronDesktopWindowTreeHostWin::HandleMouseEventForCaption(
   return native_window_view_->IsWindowControlsOverlayEnabled();
 }
 
+bool ElectronDesktopWindowTreeHostWin::HandleMouseEvent(ui::MouseEvent* event) {
+  if (event->is_system_menu() && !native_window_view_->has_frame()) {
+    bool prevent_default = false;
+    native_window_view_->NotifyWindowSystemContextMenu(event->x(), event->y(),
+                                                       &prevent_default);
+    return prevent_default;
+  }
+
+  return views::DesktopWindowTreeHostWin::HandleMouseEvent(event);
+}
+
 void ElectronDesktopWindowTreeHostWin::OnNativeThemeUpdated(
     ui::NativeTheme* observed_theme) {
   HWND hWnd = GetAcceleratedWidget();

+ 1 - 0
shell/browser/ui/win/electron_desktop_window_tree_host_win.h

@@ -40,6 +40,7 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
   bool GetClientAreaInsets(gfx::Insets* insets,
                            HMONITOR monitor) const override;
   bool HandleMouseEventForCaption(UINT message) const override;
+  bool HandleMouseEvent(ui::MouseEvent* event) override;
 
   // ui::NativeThemeObserver:
   void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;