瀏覽代碼

LibWeb: Consolidate mouse handling + only trigger event on left click

This commit moves a couple more special cases in mouse event handling to
handle_mouseup. Additionally, it gets rid of the special casing with
should_dispatch_event and only fires a click event to the EventTarget
when the left mouse button is clicked. Finally it restores the link
context menu callback that was lost during 0fc8c65.
sin-ack 3 年之前
父節點
當前提交
51df97e799
共有 1 個文件被更改,包括 7 次插入7 次删除
  1. 7 7
      Userland/Libraries/LibWeb/Page/EventHandler.cpp

+ 7 - 7
Userland/Libraries/LibWeb/Page/EventHandler.cpp

@@ -194,8 +194,6 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
             node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mouseup, offset.x(), offset.y(), position.x(), position.y()));
             node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::mouseup, offset.x(), offset.y(), position.x(), position.y()));
             handled_event = true;
             handled_event = true;
 
 
-            bool should_dispatch_event = true;
-
             // FIXME: This is ad-hoc and incorrect. The reason this exists is
             // FIXME: This is ad-hoc and incorrect. The reason this exists is
             //        because we are missing browsing context navigation:
             //        because we are missing browsing context navigation:
             //
             //
@@ -229,11 +227,16 @@ bool EventHandler::handle_mouseup(const Gfx::IntPoint& position, unsigned button
                 } else if (button == GUI::MouseButton::Middle) {
                 } else if (button == GUI::MouseButton::Middle) {
                     if (auto* page = m_browsing_context.page())
                     if (auto* page = m_browsing_context.page())
                         page->client().page_did_middle_click_link(url, link->target(), modifiers);
                         page->client().page_did_middle_click_link(url, link->target(), modifiers);
-                    should_dispatch_event = false;
+                } else if (button == GUI::MouseButton::Secondary) {
+                    if (auto* page = m_browsing_context.page())
+                        page->client().page_did_request_link_context_menu(m_browsing_context.to_top_level_position(position), url, link->target(), modifiers);
                 }
                 }
+            } else if (button == GUI::MouseButton::Secondary) {
+                if (auto* page = m_browsing_context.page())
+                    page->client().page_did_request_context_menu(m_browsing_context.to_top_level_position(position));
             }
             }
 
 
-            if (node.ptr() == m_mousedown_target && should_dispatch_event) {
+            if (node.ptr() == m_mousedown_target && button == GUI::MouseButton::Primary) {
                 node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::click, offset.x(), offset.y(), position.x(), position.y()));
                 node->dispatch_event(UIEvents::MouseEvent::create(UIEvents::EventNames::click, offset.x(), offset.y(), position.x(), position.y()));
             }
             }
         }
         }
@@ -334,9 +337,6 @@ bool EventHandler::handle_mousedown(const Gfx::IntPoint& position, unsigned butt
                 }
                 }
             }
             }
         }
         }
-    } else if (button == GUI::MouseButton::Secondary) {
-        if (auto* page = m_browsing_context.page())
-            page->client().page_did_request_context_menu(m_browsing_context.to_top_level_position(position));
     }
     }
     return true;
     return true;
 }
 }