LibWeb: Allow label activation via any descendant of the label node

Previously we were only forwarding the activation to the labelled
control if the user clicked on an immediate child of <label>.
This commit is contained in:
Andreas Kling 2022-02-15 18:48:30 +01:00
parent f318045a8f
commit e91b2c57c1
Notes: sideshowbarker 2024-07-17 18:44:19 +09:00

View file

@ -207,34 +207,37 @@ void TextNode::compute_text_for_rendering(bool collapse, bool previous_is_empty_
bool TextNode::wants_mouse_events() const
{
return parent() && is<Label>(parent());
return first_ancestor_of_type<Label>();
}
void TextNode::handle_mousedown(Badge<EventHandler>, const Gfx::IntPoint& position, unsigned button, unsigned)
{
if (!parent() || !is<Label>(*parent()))
auto* label = first_ancestor_of_type<Label>();
if (!label)
return;
verify_cast<Label>(*parent()).handle_mousedown_on_label({}, position, button);
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)
{
if (!parent() || !is<Label>(*parent()))
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;
verify_cast<Label>(*parent()).handle_mouseup_on_label({}, position, button);
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)
{
if (!parent() || !is<Label>(*parent()))
auto* label = first_ancestor_of_type<Label>();
if (!label)
return;
verify_cast<Label>(*parent()).handle_mousemove_on_label({}, position, button);
label->handle_mousemove_on_label({}, position, button);
}
TextNode::ChunkIterator::ChunkIterator(StringView text, LayoutMode layout_mode, bool wrap_lines, bool respect_linebreaks)