1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:08:12 +00:00

LibWeb: Move mouse event and label logic from layout to painting tree

Input events have nothing to do with layout, so let's not send them to
layout nodes.

The job of Paintable starts to become clear. It represents a paintable
item that can be rendered into the viewport, which means it can also
be targeted by the mouse cursor.
This commit is contained in:
Andreas Kling 2022-03-10 22:46:35 +01:00
parent ed84fbce47
commit cb0c5390ff
35 changed files with 560 additions and 429 deletions

View file

@ -241,41 +241,6 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_
m_text_for_rendering = builder.to_string();
}
bool TextNode::wants_mouse_events() const
{
return first_ancestor_of_type<Label>();
}
void TextNode::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
{
auto* label = first_ancestor_of_type<Label>();
if (!label)
return;
label->handle_mousedown_on_label({}, position, button);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(this);
}
void TextNode::handle_mouseup(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
{
auto* label = first_ancestor_of_type<Label>();
if (!label)
return;
// NOTE: Changing the state of the DOM node may run arbitrary JS, which could disappear this node.
NonnullRefPtr protect = *this;
label->handle_mouseup_on_label({}, position, button);
browsing_context().event_handler().set_mouse_event_tracking_layout_node(nullptr);
}
void TextNode::handle_mousemove(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
{
auto* label = first_ancestor_of_type<Label>();
if (!label)
return;
label->handle_mousemove_on_label({}, position, button);
}
TextNode::ChunkIterator::ChunkIterator(StringView text, LayoutMode layout_mode, bool wrap_lines, bool respect_linebreaks)
: m_layout_mode(layout_mode)
, m_wrap_lines(wrap_lines)