From e18501f67fb0361a10392bc626e6c43f26f1e9cc Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Fri, 12 Jul 2024 11:06:08 +0100 Subject: [PATCH] LibWeb: Don't dispatch click events to disabled FormAssociatedElements Disabled FormAssociatedElements also no longer receive focus when clicked. --- .../Layout/expected/input-as-button-align-center.txt | 11 +++++++---- .../Layout/expected/input-as-button-shrink-to-fit.txt | 11 +++++++---- Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp | 6 ++++-- Userland/Libraries/LibWeb/Page/EventHandler.cpp | 7 +++++++ 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/Tests/LibWeb/Layout/expected/input-as-button-align-center.txt b/Tests/LibWeb/Layout/expected/input-as-button-align-center.txt index 7e65092f533..d67b780b289 100644 --- a/Tests/LibWeb/Layout/expected/input-as-button-align-center.txt +++ b/Tests/LibWeb/Layout/expected/input-as-button-align-center.txt @@ -4,9 +4,11 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (13,10) content-size 290x296 children: not-inline BlockContainer <(anonymous)> at (13,10) content-size 290x296 flex-container(column) [FFC] children: not-inline BlockContainer <(anonymous)> at (13,150) content-size 290x16 flex-item [BFC] children: inline - frag 0 from TextNode start: 0, length: 31, rect: [37,150 242.4375x16] baseline: 12.5 - "Should be located in the center" - TextNode <#text> + frag 0 from BlockContainer start: 0, length: 0, rect: [37,150 242.4375x16] baseline: 12.5 + BlockContainer at (37,150) content-size 242.4375x16 inline-block [BFC] children: inline + frag 0 from TextNode start: 0, length: 31, rect: [37,150 242.4375x16] baseline: 12.5 + "Should be located in the center" + TextNode <#text> BlockContainer <(anonymous)> at (8,308) content-size 784x0 children: inline TextNode <#text> @@ -16,5 +18,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer.btn) [8,8 300x300] PaintableWithLines (BlockContainer(anonymous)) [13,10 290x296] PaintableWithLines (BlockContainer(anonymous)) [13,150 290x16] - TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer) [37,150 242.4375x16] + TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [8,308 784x0] diff --git a/Tests/LibWeb/Layout/expected/input-as-button-shrink-to-fit.txt b/Tests/LibWeb/Layout/expected/input-as-button-shrink-to-fit.txt index 2deae4d3614..0ec67006d3f 100644 --- a/Tests/LibWeb/Layout/expected/input-as-button-shrink-to-fit.txt +++ b/Tests/LibWeb/Layout/expected/input-as-button-shrink-to-fit.txt @@ -4,9 +4,11 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline BlockContainer at (13,10) content-size 195.734375x32 children: not-inline BlockContainer <(anonymous)> at (13,10) content-size 195.734375x32 flex-container(column) [FFC] children: not-inline BlockContainer <(anonymous)> at (13,18) content-size 195.734375x16 flex-item [BFC] children: inline - frag 0 from TextNode start: 0, length: 26, rect: [13,18 195.734375x16] baseline: 12.5 - "Width should shrink to fit" - TextNode <#text> + frag 0 from BlockContainer start: 0, length: 0, rect: [13,18 195.734375x16] baseline: 12.5 + BlockContainer at (13,18) content-size 195.734375x16 inline-block [BFC] children: inline + frag 0 from TextNode start: 0, length: 26, rect: [13,18 195.734375x16] baseline: 12.5 + "Width should shrink to fit" + TextNode <#text> BlockContainer <(anonymous)> at (8,44) content-size 784x0 children: inline TextNode <#text> @@ -16,5 +18,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] PaintableWithLines (BlockContainer.btn) [8,8 205.734375x36] PaintableWithLines (BlockContainer(anonymous)) [13,10 195.734375x32] PaintableWithLines (BlockContainer(anonymous)) [13,18 195.734375x16] - TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer) [13,18 195.734375x16] + TextPaintable (TextNode<#text>) PaintableWithLines (BlockContainer(anonymous)) [8,44 784x0] diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 6d9ce3c6bbe..30313855556 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -778,9 +778,11 @@ void HTMLInputElement::create_button_input_shadow_tree() { auto shadow_root = heap().allocate(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(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() diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 40fce3600eb..cf1652adb70 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -47,6 +47,13 @@ static JS::GCPtr dom_node_for_event_dispatch(Painting::Paintable& pai static bool parent_element_for_event_dispatch(Painting::Paintable& paintable, JS::GCPtr& node, Layout::Node*& layout_node) { + auto* current_ancestor_node = node.ptr(); + do { + if (is(current_ancestor_node) && !dynamic_cast(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();