From e1b5613142b7658d1975e30295eb1a3b3180e3ea Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 3 Apr 2021 21:48:05 -0400 Subject: LibWeb: Defer mouse events from TextNode to Label A label's format is: So, a TextNode is created as a child of the Label node, and EventHandler will send events to the TextNode. This changes TextNode to accept mouse events if its parent is a Label, and to forward those events upward. --- Userland/Libraries/LibWeb/Forward.h | 1 + Userland/Libraries/LibWeb/Layout/Label.cpp | 6 +++--- Userland/Libraries/LibWeb/Layout/Label.h | 9 ++++----- Userland/Libraries/LibWeb/Layout/TextNode.cpp | 29 +++++++++++++++++++++++++++ Userland/Libraries/LibWeb/Layout/TextNode.h | 4 ++++ 5 files changed, 41 insertions(+), 8 deletions(-) (limited to 'Userland/Libraries/LibWeb') diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index fd1452b749..de6bcbe836 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -182,6 +182,7 @@ class Node; class NodeWithStyle; class RadioButton; class ReplacedBox; +class TextNode; } namespace Web { diff --git a/Userland/Libraries/LibWeb/Layout/Label.cpp b/Userland/Libraries/LibWeb/Layout/Label.cpp index 47cc0b1219..6de2615ad4 100644 --- a/Userland/Libraries/LibWeb/Layout/Label.cpp +++ b/Userland/Libraries/LibWeb/Layout/Label.cpp @@ -45,7 +45,7 @@ Label::~Label() { } -void Label::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned) +void Label::handle_mousedown_on_label(Badge, const Gfx::IntPoint&, unsigned button) { if (button != GUI::MouseButton::Left) return; @@ -56,7 +56,7 @@ void Label::handle_mousedown(Badge, const Gfx::IntPoint&, unsigned m_tracking_mouse = true; } -void Label::handle_mouseup(Badge, const Gfx::IntPoint& position, unsigned button, unsigned) +void Label::handle_mouseup_on_label(Badge, const Gfx::IntPoint& position, unsigned button) { if (!m_tracking_mouse || button != GUI::MouseButton::Left) return; @@ -75,7 +75,7 @@ void Label::handle_mouseup(Badge, const Gfx::IntPoint& position, u m_tracking_mouse = false; } -void Label::handle_mousemove(Badge, const Gfx::IntPoint& position, unsigned, unsigned) +void Label::handle_mousemove_on_label(Badge, const Gfx::IntPoint& position, unsigned) { if (!m_tracking_mouse) return; diff --git a/Userland/Libraries/LibWeb/Layout/Label.h b/Userland/Libraries/LibWeb/Layout/Label.h index 854c8490d7..ff804d64db 100644 --- a/Userland/Libraries/LibWeb/Layout/Label.h +++ b/Userland/Libraries/LibWeb/Layout/Label.h @@ -41,12 +41,11 @@ public: const HTML::HTMLLabelElement& dom_node() const { return static_cast(*BlockBox::dom_node()); } HTML::HTMLLabelElement& dom_node() { return static_cast(*BlockBox::dom_node()); } -private: - virtual bool wants_mouse_events() const override { return true; } - virtual void handle_mousedown(Badge, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; - virtual void handle_mouseup(Badge, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; - virtual void handle_mousemove(Badge, const Gfx::IntPoint&, unsigned button, unsigned modifiers) override; + void handle_mousedown_on_label(Badge, const Gfx::IntPoint&, unsigned button); + void handle_mouseup_on_label(Badge, const Gfx::IntPoint&, unsigned button); + void handle_mousemove_on_label(Badge, const Gfx::IntPoint&, unsigned button); +private: static Label* label_for_control_node(LabelableNode&); LabelableNode* control_node(); diff --git a/Userland/Libraries/LibWeb/Layout/TextNode.cpp b/Userland/Libraries/LibWeb/Layout/TextNode.cpp index 1e1603029d..cfa20a2957 100644 --- a/Userland/Libraries/LibWeb/Layout/TextNode.cpp +++ b/Userland/Libraries/LibWeb/Layout/TextNode.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -306,4 +307,32 @@ void TextNode::split_into_lines(InlineFormattingContext& context, LayoutMode lay split_into_lines_by_rules(context, layout_mode, do_collapse, do_wrap_lines, do_wrap_breaks); } +bool TextNode::wants_mouse_events() const +{ + return parent() && is