chore_modify_chromium_handling_of_mouse_events.patch 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: deepak1556 <[email protected]>
  3. Date: Fri, 29 Jul 2022 00:29:35 +0900
  4. Subject: chore: modify chromium handling of mouse events
  5. This patch does the following:
  6. 1. When Windows Control Overlay is enabled, it allows chromium to handle synthetic mouse events generated for touch
  7. actions in the non-client caption area.
  8. 2. It calls HandleMouseEvent on the delegate earlier in HandleMouseEventInternal, so that Electron can selectively disable
  9. draggable regions to allow events to propagate to the underlying renderer.
  10. diff --git a/ui/events/event.h b/ui/events/event.h
  11. index 39b5a8fdd165efd74b00256552b51b5413107958..bfc4ef4f50efff4a77f2aef64335bb7e34c69f34 100644
  12. --- a/ui/events/event.h
  13. +++ b/ui/events/event.h
  14. @@ -587,6 +587,9 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
  15. const PointerDetails& pointer_details() const { return pointer_details_; }
  16. + bool is_system_menu() const { return is_system_menu_; }
  17. + void set_is_system_menu(bool is_menu) { is_system_menu_ = is_menu; }
  18. +
  19. // Event:
  20. std::string ToString() const override;
  21. std::unique_ptr<Event> Clone() const override;
  22. @@ -619,6 +622,8 @@ class EVENTS_EXPORT MouseEvent : public LocatedEvent {
  23. // Structure for holding pointer details for implementing PointerEvents API.
  24. PointerDetails pointer_details_;
  25. +
  26. + bool is_system_menu_ = false;
  27. };
  28. class ScrollEvent;
  29. 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
  30. index 55c426aee12da4d4d1f62dc7d489133e8d21dc49..40c88bf14d2d4fe841e29b32414361688ae438e5 100644
  31. --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
  32. +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc
  33. @@ -1362,6 +1362,10 @@ void DesktopWindowTreeHostWin::HandleHeadlessWindowBoundsChanged(
  34. window()->SetProperty(aura::client::kHeadlessBoundsKey, bounds);
  35. }
  36. +bool DesktopWindowTreeHostWin::HandleMouseEventForCaption(UINT message) const {
  37. + return false;
  38. +}
  39. +
  40. DesktopNativeCursorManager*
  41. DesktopWindowTreeHostWin::GetSingletonDesktopNativeCursorManager() {
  42. return new DesktopNativeCursorManagerWin();
  43. diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
  44. index 4865d79c95c34d8cead96d3bb8063a0e2bd6076b..ebfa09ed15dca98b75a013e3dcbb566ce84d7cb7 100644
  45. --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
  46. +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h
  47. @@ -267,6 +267,7 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin : public DesktopWindowTreeHost,
  48. void HandleWindowSizeUnchanged() override;
  49. void HandleWindowScaleFactorChanged(float window_scale_factor) override;
  50. void HandleHeadlessWindowBoundsChanged(const gfx::Rect& bounds) override;
  51. + bool HandleMouseEventForCaption(UINT message) const override;
  52. // Overridden from WidgetObserver.
  53. void OnWidgetThemeChanged(Widget* widget) override;
  54. diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
  55. index 3a60e310d1c4048f0e37e085c97b8dfc093aefda..8fe48c9bef144218e34434d563883b15733d03bc 100644
  56. --- a/ui/views/win/hwnd_message_handler.cc
  57. +++ b/ui/views/win/hwnd_message_handler.cc
  58. @@ -3156,15 +3156,19 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
  59. }
  60. // We must let Windows handle the caption buttons if it's drawing them, or
  61. // they won't work.
  62. + bool simulate_mouse_event_for_caption = false;
  63. if (delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN &&
  64. (hittest == HTCLOSE || hittest == HTMINBUTTON ||
  65. hittest == HTMAXBUTTON)) {
  66. - SetMsgHandled(FALSE);
  67. + simulate_mouse_event_for_caption =
  68. + delegate_->HandleMouseEventForCaption(message);
  69. + if (!simulate_mouse_event_for_caption)
  70. + SetMsgHandled(FALSE);
  71. }
  72. // Let resize events fall through. Ignore everything else, as we're either
  73. // letting Windows handle it above or we've already handled the equivalent
  74. // touch message.
  75. - if (!IsHitTestOnResizeHandle(hittest)) {
  76. + if (!IsHitTestOnResizeHandle(hittest) && !simulate_mouse_event_for_caption) {
  77. return 0;
  78. }
  79. }
  80. @@ -3187,6 +3191,7 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
  81. // handle alt-space, or in the frame itself.
  82. is_right_mouse_pressed_on_caption_ = false;
  83. ReleaseCapture();
  84. +
  85. // |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu()
  86. // expect screen coordinates.
  87. POINT screen_point = CR_POINT_INITIALIZER_FROM_LPARAM(l_param);
  88. @@ -3194,7 +3199,17 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message,
  89. w_param = static_cast<WPARAM>(SendMessage(
  90. hwnd(), WM_NCHITTEST, 0, MAKELPARAM(screen_point.x, screen_point.y)));
  91. if (w_param == HTCAPTION || w_param == HTSYSMENU) {
  92. - ShowSystemMenuAtScreenPixelLocation(hwnd(), gfx::Point(screen_point));
  93. + LONG message_time = GetMessageTime();
  94. + CHROME_MSG msg = {hwnd(),
  95. + message,
  96. + w_param,
  97. + l_param,
  98. + static_cast<DWORD>(message_time),
  99. + {CR_GET_X_LPARAM(l_param), CR_GET_Y_LPARAM(l_param)}};
  100. + ui::MouseEvent event(msg);
  101. + event.set_is_system_menu(true);
  102. + if (!delegate_->HandleMouseEvent(&event))
  103. + ShowSystemMenuAtScreenPixelLocation(hwnd(), gfx::Point(screen_point));
  104. return 0;
  105. }
  106. } else if (message == WM_NCLBUTTONDOWN &&
  107. diff --git a/ui/views/win/hwnd_message_handler_delegate.h b/ui/views/win/hwnd_message_handler_delegate.h
  108. index de8fd5657e6885f74a5970bdd49647a6f1616387..4af87792edc7a147468077b834582510550e35e6 100644
  109. --- a/ui/views/win/hwnd_message_handler_delegate.h
  110. +++ b/ui/views/win/hwnd_message_handler_delegate.h
  111. @@ -255,6 +255,10 @@ class VIEWS_EXPORT HWNDMessageHandlerDelegate {
  112. // Called when the headless window bounds has changed.
  113. virtual void HandleHeadlessWindowBoundsChanged(const gfx::Rect& bounds) = 0;
  114. + // Called when synthetic mouse event is generated for touch event on
  115. + // caption buttons.
  116. + virtual bool HandleMouseEventForCaption(UINT message) const = 0;
  117. +
  118. protected:
  119. virtual ~HWNDMessageHandlerDelegate() = default;
  120. };