Skip to content

Commit

Permalink
LibWeb: Don't dispatch click events to disabled FormAssociatedElements
Browse files Browse the repository at this point in the history
  • Loading branch information
tcl3 committed Jul 12, 2024
1 parent 191531b commit eb58c15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,11 @@ void HTMLInputElement::create_button_input_shadow_tree()
{
auto shadow_root = heap().allocate<DOM::ShadowRoot>(realm(), document(), *this, Bindings::ShadowRootMode::Closed);
set_shadow_root(shadow_root);

auto text_container = MUST(DOM::create_element(document(), HTML::TagNames::span, Namespace::HTML));
MUST(text_container->set_attribute(HTML::AttributeNames::style, "display: inline-block; pointer-events: none;"_string));
m_text_node = heap().allocate<DOM::Text>(realm(), document(), value());
MUST(shadow_root->append_child(*m_text_node));
MUST(text_container->append_child(*m_text_node));
MUST(shadow_root->append_child(*text_container));
}

void HTMLInputElement::create_text_input_shadow_tree()
Expand Down
7 changes: 7 additions & 0 deletions Userland/Libraries/LibWeb/Page/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ static JS::GCPtr<DOM::Node> dom_node_for_event_dispatch(Painting::Paintable& pai

static bool parent_element_for_event_dispatch(Painting::Paintable& paintable, JS::GCPtr<DOM::Node>& node, Layout::Node*& layout_node)
{
auto* current_ancestor_node = node.ptr();
do {
if (is<HTML::FormAssociatedElement>(current_ancestor_node) && !dynamic_cast<HTML::FormAssociatedElement*>(current_ancestor_node)->enabled()) {
return false;
}
} while ((current_ancestor_node = current_ancestor_node->parent()));

layout_node = &paintable.layout_node();
while (layout_node && node && !node->is_element() && layout_node->parent()) {
layout_node = layout_node->parent();
Expand Down

0 comments on commit eb58c15

Please sign in to comment.