Skip to content

Truly independent web browser

LibWeb: Stop only mouse presses at disabled form controls

sideshowbarker7dff93ec7dde
diff --git a/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Libraries/LibWeb/DOM/EventDispatcher.cpp
index 67538dd71f7..987ad3a2a0b 100644
--- a/Libraries/LibWeb/DOM/EventDispatcher.cpp
+++ b/Libraries/LibWeb/DOM/EventDispatcher.cpp
@@ -288,6 +288,21 @@ bool EventDispatcher::dispatch(GC::Ref<EventTarget> target, Event& event, bool l
// events are always dispatched. This saves us from going through the path building and dispatch
// phases for events that will be dropped on the floor anyway.
bool is_activation_event = is<UIEvents::MouseEvent>(event) && event.type() == HTML::EventNames::click;
+
+ // AD-HOC: The spec only has a disabled form control prevent the click events queued on the user interaction task
+ // source from being dispatched on it:
+ // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute
+ // But no mousedown, mouseup, click, or dblclick from the user reaches a disabled form control, or anything
+ // above it: The path of such an event ends below the control, so a press on the control's own box
+ // dispatches nothing. Every other event (pointer events, mouseover, mousemove, wheel, ...) reaches it as
+ // usual. See https://github.com/whatwg/html/issues/2368.
+ bool const path_ends_below_disabled_form_control = event.is_trusted() && is<UIEvents::MouseEvent>(event)
+ && (event.type() == UIEvents::EventNames::mousedown || event.type() == UIEvents::EventNames::mouseup
+ || event.type() == UIEvents::EventNames::click || event.type() == UIEvents::EventNames::dblclick);
+ auto is_disabled_form_control = [](EventTarget const& event_target) {
+ auto const* element = as_if<Element>(event_target);
+ return element && element->is_disabled_form_control();
+ };
bool should_dispatch = is_activation_event;
if (!should_dispatch) {
auto const* node = as_if<Node>(*target);
@@ -324,6 +339,9 @@ bool EventDispatcher::dispatch(GC::Ref<EventTarget> target, Event& event, bool l
}
}
+ if (path_ends_below_disabled_form_control && is_disabled_form_control(*target))
+ should_dispatch = false;
+
// 6. If target is not relatedTarget or target is event’s relatedTarget, then:
if (should_dispatch && (related_target != target || event.related_target() == target)) {
// 1. Let touchTargets be a new list.
@@ -361,6 +379,9 @@ bool EventDispatcher::dispatch(GC::Ref<EventTarget> target, Event& event, bool l
// 9. While parent is non-null:
while (parent) {
+ if (path_ends_below_disabled_form_control && is_disabled_form_control(*parent))
+ break;
+
// 1. If slottable is non-null:
if (slottable != nullptr) {
// 1. Assert: parent is a slot.
diff --git a/Libraries/LibWeb/Page/EventHandler.cpp b/Libraries/LibWeb/Page/EventHandler.cpp
index e5c03c4d607..7b1d77cd6ed 100644
--- a/Libraries/LibWeb/Page/EventHandler.cpp
+++ b/Libraries/LibWeb/Page/EventHandler.cpp
@@ -378,16 +378,9 @@ static bool parent_element_for_event_dispatch(Layout::Node& target_layout_node,
layout_node = generator_layout_node;
}
- // An event aimed at a disabled form control is not dispatched, and neither is one aimed at
- // anything under one, including the contents of its shadow tree.
// NB: The document outlives every live row of its arena.
VERIFY(arena.document());
auto& document = *arena.document();
- for (GC::Ptr<DOM::Node> ancestor = identity.resolve(document); ancestor; ancestor = ancestor->parent_or_shadow_host()) {
- if (auto const* form_associated_element = as_if<HTML::FormAssociatedElement>(*ancestor); form_associated_element && !form_associated_element->enabled())
- return false;
- }
-
while (layout_node && identity && !identity_names_element(identity)) {
auto row_identity = layout_node->is_anonymous() ? DOM::NodeIdentity {} : layout_node->dom_node_identity();
if (row_identity && row_identity != identity) {
@@ -402,6 +395,23 @@ static bool parent_element_for_event_dispatch(Layout::Node& target_layout_node,
return node && layout_node;
}
+// A click goes no further than the first disabled form control on its path, so it activates a link inside that control,
+// but not a link the control is in. The walk follows the flat tree, as the click's path and the link lookup do.
+static GC::Ptr<DOM::Element const> link_reached_by_click(DOM::Node const& click_target)
+{
+ auto const* link = click_target.enclosing_link_element();
+ if (!link)
+ return nullptr;
+ auto const& link_element = link->hyperlink_element_utils_element();
+ for (DOM::Node const* ancestor = &click_target; ancestor; ancestor = ancestor->flat_tree_parent()) {
+ if (ancestor == &link_element)
+ return link_element;
+ if (auto const* element = as_if<DOM::Element>(*ancestor); element && element->is_disabled_form_control())
+ return nullptr;
+ }
+ return nullptr;
+}
+
EventResult EventHandler::handle_mousedown(CSSPixelPoint visual_viewport_position, CSSPixelPoint screen_position, u32 button, u32 buttons, u32 modifiers, int click_count, Optional<Web::ScrollbarDraggedByCompositor> const& scrollbar_dragged_by_compositor, Optional<RemoteInputEventTarget>* remote_target)
{
if (should_ignore_device_input_event())
@@ -922,6 +932,9 @@ EventResult EventHandler::handle_mouseup(CSSPixelPoint visual_viewport_position,
if (auto* click_layout_node = click_target->layout_node(read))
coordinates = compute_mouse_event_coordinates(visual_viewport_position, viewport_position, *click_layout_node);
+ // NB: The link a click can activate is decided before its listeners run, as the click's path is.
+ auto const link = link_reached_by_click(*click_target);
+
// https://www.w3.org/TR/pointerevents3/#event-dispatch
// Dispatch event to target following the [UIEVENTS] spec.
if (fire_click_events(*click_target, coordinates, screen_position, button, buttons, modifiers, click_count)
@@ -937,7 +950,8 @@ EventResult EventHandler::handle_mouseup(CSSPixelPoint visual_viewport_position,
// some way to be able to communicate with browsing contexts in remote WebContent processes, and
// then step 8 of this algorithm needs to be implemented in LocalNavigable::choose_a_navigable:
// https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable
- run_activation_behavior(*click_target, button, modifiers);
+ if (link)
+ run_activation_behavior(*link, button, modifiers);
}
}
@@ -3977,9 +3991,9 @@ void EventHandler::finish_selection_from_preserved_mousedown(DOM::Document& docu
}
#endif
-void EventHandler::run_activation_behavior(GC::Ref<DOM::Node> node, unsigned button, unsigned modifiers)
+void EventHandler::run_activation_behavior(DOM::Node const& node, unsigned button, unsigned modifiers)
{
- if (auto const* link = node->enclosing_link_element()) {
+ if (auto const* link = node.enclosing_link_element()) {
GC::Ref<DOM::Document> document = *m_navigable->active_document();
auto href = link->href();
@@ -4230,6 +4244,13 @@ void EventHandler::maybe_show_context_menu(GC::Ref<DOM::Node> node, MouseEventCo
static bool is_middle_click_paste_target(DOM::Node const& node)
{
+ // NB: A disabled input or textarea takes no paste, not even into the editable text inside it.
+ auto const* text_control = node.find_in_shadow_including_ancestry([](DOM::Node const& node) {
+ return is<HTML::HTMLInputElement>(node) || is<HTML::HTMLTextAreaElement>(node);
+ });
+ if (text_control && as<DOM::Element>(*text_control).is_disabled_form_control())
+ return false;
+
if (node.is_editable_or_editing_host())
return true;
@@ -5492,6 +5513,8 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSS
for (auto* ancestor = mouse_target.ptr(); ancestor; ancestor = ancestor->parent_or_shadow_host())
touch_hover_ancestors.append(*ancestor);
}
+ // NB: The link a click can activate is decided before its listeners run, as the click's path is.
+ auto const link = link_reached_by_click(*click_target);
auto click = create_pointer_event(pointer, *click_target, UIEvents::EventNames::click, click_coordinates, screen_position, 0);
auto allowed = click_target->dispatch_event(click);
if (m_navigable->active_document() != document)
@@ -5505,8 +5528,8 @@ EventResult EventHandler::handle_pointer_event(Web::MouseEvent const& input, CSS
break;
}
}
- if (allowed)
- run_activation_behavior(*click_target, to_underlying(input.button), pointer.modifiers);
+ if (allowed && link)
+ run_activation_behavior(*link, to_underlying(input.button), pointer.modifiers);
}
}
}
diff --git a/Libraries/LibWeb/Page/EventHandler.h b/Libraries/LibWeb/Page/EventHandler.h
index 029d71e80e5..8e08711bc34 100644
--- a/Libraries/LibWeb/Page/EventHandler.h
+++ b/Libraries/LibWeb/Page/EventHandler.h
@@ -271,7 +271,7 @@ private:
GC::Ptr<DOM::Node> focus_candidate_for_position(Layout::BegunRead const& read, CSSPixelPoint) const;
void run_mousedown_default_actions(Layout::BegunRead const& read, DOM::Document&, CSSPixelPoint visual_viewport_position, unsigned button, unsigned modifiers, int click_count);
- void run_activation_behavior(GC::Ref<DOM::Node>, unsigned button, unsigned modifiers);
+ void run_activation_behavior(DOM::Node const&, unsigned button, unsigned modifiers);
void maybe_show_context_menu(GC::Ref<DOM::Node>, MouseEventCoordinates const&, CSSPixelPoint screen_position, CSSPixelPoint viewport_position, unsigned buttons, unsigned modifiers);
bool maybe_request_paste_for_middle_click(Layout::BegunRead const& read, DOM::Document&, CSSPixelPoint visual_viewport_position);
diff --git a/Tests/LibWeb/Text/expected/UIEvents/context-menu-focus.txt b/Tests/LibWeb/Text/expected/UIEvents/context-menu-focus.txt
index b6a12d1fa87..82ecc510988 100644
--- a/Tests/LibWeb/Text/expected/UIEvents/context-menu-focus.txt
+++ b/Tests/LibWeb/Text/expected/UIEvents/context-menu-focus.txt
@@ -4,7 +4,8 @@ contextmenu: focused=textarea
right-click #textarea: focused=textarea, menu=true
contextmenu: focused=editable
right-click #editable: focused=editable, menu=true
-right-click #disabled: focused=other, menu=false
+contextmenu: focused=body
+right-click #disabled: focused=body, menu=true
contextmenu: focused=body
right-click #plain: focused=body, menu=true
mousedown: focused=other
diff --git a/Tests/LibWeb/Text/expected/UIEvents/mouse-events-at-disabled-form-controls.txt b/Tests/LibWeb/Text/expected/UIEvents/mouse-events-at-disabled-form-controls.txt
new file mode 100644
index 00000000000..2d433ab7ec7
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/UIEvents/mouse-events-at-disabled-form-controls.txt
@@ -0,0 +1,93 @@
+moving over #button, and clicking and double-clicking it:
+ mouseover captured at document, target button
+ mouseover at button
+ mouseover bubbled to body
+ mouseenter captured at document, target button
+ mouseenter at button
+ mousemove captured at document, target button
+ mousemove at button
+ mousemove bubbled to body
+ pointerdown captured at document, target button
+ pointerdown at button
+ pointerdown bubbled to body
+ pointerup captured at document, target button
+ pointerup at button
+ pointerup bubbled to body
+ mouseleave captured at document, target button
+ mouseleave at button
+moving over #span, and clicking and double-clicking it:
+ mouseover captured at document, target span
+ mouseover at span
+ mouseover bubbled to body
+ mouseenter captured at document, target button
+ mouseenter at button
+ mouseenter captured at document, target span
+ mouseenter at span
+ mousemove captured at document, target span
+ mousemove at span
+ mousemove bubbled to body
+ pointerdown captured at document, target span
+ pointerdown at span
+ pointerdown bubbled to body
+ mousedown at span
+ pointerup captured at document, target span
+ pointerup at span
+ pointerup bubbled to body
+ mouseup at span
+ click at span
+ dblclick at span
+ mouseleave captured at document, target span
+ mouseleave at span
+ mouseleave captured at document, target button
+ mouseleave at button
+moving over #input, and clicking and double-clicking it:
+ mouseover captured at document, target input
+ mouseover at input
+ mouseover bubbled to body
+ mouseenter captured at document, target input
+ mouseenter at input
+ mousemove captured at document, target input
+ mousemove at input
+ mousemove bubbled to body
+ pointerdown captured at document, target input
+ pointerdown at input
+ pointerdown bubbled to body
+ pointerup captured at document, target input
+ pointerup at input
+ pointerup bubbled to body
+ mouseleave captured at document, target input
+ mouseleave at input
+moving over #div-in-fieldset, and clicking and double-clicking it:
+ mouseover captured at document, target div-in-fieldset
+ mouseover at div-in-fieldset
+ mouseover bubbled to body
+ mouseenter captured at document, target div-in-fieldset
+ mouseenter at div-in-fieldset
+ mousemove captured at document, target div-in-fieldset
+ mousemove at div-in-fieldset
+ mousemove bubbled to body
+ pointerdown captured at document, target div-in-fieldset
+ pointerdown at div-in-fieldset
+ pointerdown bubbled to body
+ mousedown captured at document, target div-in-fieldset
+ mousedown at div-in-fieldset
+ mousedown bubbled to body
+ pointerup captured at document, target div-in-fieldset
+ pointerup at div-in-fieldset
+ pointerup bubbled to body
+ mouseup captured at document, target div-in-fieldset
+ mouseup at div-in-fieldset
+ mouseup bubbled to body
+ click captured at document, target div-in-fieldset
+ click at div-in-fieldset
+ click bubbled to body
+ dblclick captured at document, target div-in-fieldset
+ dblclick at div-in-fieldset
+ dblclick bubbled to body
+ mouseleave captured at document, target div-in-fieldset
+ mouseleave at div-in-fieldset
+a wheel over #button:
+ wheel captured at document, target button
+ wheel at button
+ wheel bubbled to body
+the page scrolled: true
diff --git a/Tests/LibWeb/Text/expected/UIEvents/press-in-disabled-form-control.txt b/Tests/LibWeb/Text/expected/UIEvents/press-in-disabled-form-control.txt
new file mode 100644
index 00000000000..b4ff33b4435
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/UIEvents/press-in-disabled-form-control.txt
@@ -0,0 +1,14 @@
+left-click on #disabled-input: focused body
+right-click on #disabled-input: focused body
+left-click on #disabled-button: focused body
+right-click on #disabled-button: focused body
+a click on #disabled-button keeps the page's selection: "some plain text here"
+a click on #link-in-button:
+ location.hash is "#from-link-in-button"
+a click on #button-in-link:
+ location.hash is ""
+a click on #slotted:
+ location.hash is ""
+a click on #submit-in-control:
+ the form was submitted
+ location.hash is ""
diff --git a/Tests/LibWeb/Text/expected/css/cursor-over-disabled-form-control.txt b/Tests/LibWeb/Text/expected/css/cursor-over-disabled-form-control.txt
new file mode 100644
index 00000000000..1c46e66125f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/cursor-over-disabled-form-control.txt
@@ -0,0 +1,5 @@
+cursor over #disabled-button: Disallowed
+cursor over #disabled-input: Disallowed
+cursor over #button-in-disabled-fieldset: Disallowed
+cursor over #disabled-by-its-click before its click: Arrow
+cursor over #disabled-by-its-click after its click: Disallowed
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-checkbox-click.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-checkbox-click.txt
new file mode 100644
index 00000000000..54efcbacaef
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-checkbox-click.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Disabled checkbox does not change state when clicked
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch-additional.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch-additional.tentative.txt
new file mode 100644
index 00000000000..d6b1462ac44
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch-additional.tentative.txt
@@ -0,0 +1,13 @@
+Harness status: OK
+
+Found 8 tests
+
+8 Pass
+Pass Testing dblclick events when clicking child of disabled button.
+Pass Testing dblclick events when clicking child of disabled my-control.
+Pass Testing dblclick events when clicking disabled button.
+Pass Testing dblclick events when clicking disabled my-control.
+Pass Testing auxclick events when clicking child of disabled button.
+Pass Testing auxclick events when clicking child of disabled my-control.
+Pass Testing auxclick events when clicking disabled button.
+Pass Testing auxclick events when clicking disabled my-control.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch.tentative.txt
new file mode 100644
index 00000000000..da8f5e43462
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch.tentative.txt
@@ -0,0 +1,25 @@
+Harness status: OK
+
+Found 20 tests
+
+20 Pass
+Pass Testing mousedown events when clicking child of disabled button.
+Pass Testing mousedown events when clicking child of disabled my-control.
+Pass Testing mousedown events when clicking disabled button.
+Pass Testing mousedown events when clicking disabled my-control.
+Pass Testing mouseup events when clicking child of disabled button.
+Pass Testing mouseup events when clicking child of disabled my-control.
+Pass Testing mouseup events when clicking disabled button.
+Pass Testing mouseup events when clicking disabled my-control.
+Pass Testing pointerdown events when clicking child of disabled button.
+Pass Testing pointerdown events when clicking child of disabled my-control.
+Pass Testing pointerdown events when clicking disabled button.
+Pass Testing pointerdown events when clicking disabled my-control.
+Pass Testing pointerup events when clicking child of disabled button.
+Pass Testing pointerup events when clicking child of disabled my-control.
+Pass Testing pointerup events when clicking disabled button.
+Pass Testing pointerup events when clicking disabled my-control.
+Pass Testing click events when clicking child of disabled button.
+Pass Testing click events when clicking child of disabled my-control.
+Pass Testing click events when clicking disabled button.
+Pass Testing click events when clicking disabled my-control.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/event-propagate-disabled.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/event-propagate-disabled.tentative.txt
new file mode 100644
index 00000000000..4251455e731
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/event-propagate-disabled.tentative.txt
@@ -0,0 +1,286 @@
+Harness status: OK
+
+Found 256 tests
+
+255 Pass
+1 Fail
+Pass Trusted click on <input>, observed from <input>
+Pass Trusted click on <input>, observed from <body>
+Pass Dispatch new MouseEvent() on <input>, observed from <input>
+Pass Dispatch new MouseEvent() on <input>, observed from <body>
+Pass Dispatch new PointerEvent() on <input>, observed from <input>
+Pass Dispatch new PointerEvent() on <input>, observed from <body>
+Pass click() on <input>, observed from <input>
+Pass click() on <input>, observed from <body>
+Pass Trusted click on <select disabled=""></select>, observed from <select>
+Pass Trusted click on <select disabled=""></select>, observed from <body>
+Pass Dispatch new MouseEvent() on <select disabled=""></select>, observed from <select>
+Pass Dispatch new MouseEvent() on <select disabled=""></select>, observed from <body>
+Pass Dispatch new PointerEvent() on <select disabled=""></select>, observed from <select>
+Pass Dispatch new PointerEvent() on <select disabled=""></select>, observed from <body>
+Pass click() on <select disabled=""></select>, observed from <select>
+Pass click() on <select disabled=""></select>, observed from <body>
+Pass Trusted click on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <select>
+Pass Trusted click on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <body>
+Pass Dispatch new MouseEvent() on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <select>
+Pass Dispatch new MouseEvent() on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <body>
+Pass Dispatch new PointerEvent() on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <select>
+Pass Dispatch new PointerEvent() on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <body>
+Pass click() on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <select>
+Pass click() on <select disabled="">
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>, observed from <body>
+Pass Trusted click on <fieldset disabled="">Text</fieldset>, observed from <fieldset>
+Pass Trusted click on <fieldset disabled="">Text</fieldset>, observed from <body>
+Pass Dispatch new MouseEvent() on <fieldset disabled="">Text</fieldset>, observed from <fieldset>
+Pass Dispatch new MouseEvent() on <fieldset disabled="">Text</fieldset>, observed from <body>
+Pass Dispatch new PointerEvent() on <fieldset disabled="">Text</fieldset>, observed from <fieldset>
+Pass Dispatch new PointerEvent() on <fieldset disabled="">Text</fieldset>, observed from <body>
+Pass click() on <fieldset disabled="">Text</fieldset>, observed from <fieldset>
+Pass click() on <fieldset disabled="">Text</fieldset>, observed from <body>
+Pass Trusted click on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <span>
+Pass Trusted click on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <fieldset>
+Pass Trusted click on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <body>
+Pass Dispatch new MouseEvent() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <span>
+Pass Dispatch new MouseEvent() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <fieldset>
+Pass Dispatch new MouseEvent() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <body>
+Pass Dispatch new PointerEvent() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <span>
+Pass Dispatch new PointerEvent() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <fieldset>
+Pass Dispatch new PointerEvent() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <body>
+Pass click() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <span>
+Pass click() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <fieldset>
+Pass click() on <fieldset disabled=""><span class="target">Span</span></fieldset>, observed from <body>
+Pass Trusted click on <button disabled="">Text</button>, observed from <button>
+Pass Trusted click on <button disabled="">Text</button>, observed from <body>
+Pass Dispatch new MouseEvent() on <button disabled="">Text</button>, observed from <button>
+Pass Dispatch new MouseEvent() on <button disabled="">Text</button>, observed from <body>
+Pass Dispatch new PointerEvent() on <button disabled="">Text</button>, observed from <button>
+Pass Dispatch new PointerEvent() on <button disabled="">Text</button>, observed from <body>
+Pass click() on <button disabled="">Text</button>, observed from <button>
+Pass click() on <button disabled="">Text</button>, observed from <body>
+Pass Trusted click on <button disabled=""><span class="target">Span</span></button>, observed from <span>
+Pass Trusted click on <button disabled=""><span class="target">Span</span></button>, observed from <button>
+Pass Trusted click on <button disabled=""><span class="target">Span</span></button>, observed from <body>
+Pass Dispatch new MouseEvent() on <button disabled=""><span class="target">Span</span></button>, observed from <span>
+Pass Dispatch new MouseEvent() on <button disabled=""><span class="target">Span</span></button>, observed from <button>
+Pass Dispatch new MouseEvent() on <button disabled=""><span class="target">Span</span></button>, observed from <body>
+Pass Dispatch new PointerEvent() on <button disabled=""><span class="target">Span</span></button>, observed from <span>
+Pass Dispatch new PointerEvent() on <button disabled=""><span class="target">Span</span></button>, observed from <button>
+Pass Dispatch new PointerEvent() on <button disabled=""><span class="target">Span</span></button>, observed from <body>
+Pass click() on <button disabled=""><span class="target">Span</span></button>, observed from <span>
+Pass click() on <button disabled=""><span class="target">Span</span></button>, observed from <button>
+Pass click() on <button disabled=""><span class="target">Span</span></button>, observed from <body>
+Pass Trusted click on <textarea disabled=""></textarea>, observed from <textarea>
+Pass Trusted click on <textarea disabled=""></textarea>, observed from <body>
+Pass Dispatch new MouseEvent() on <textarea disabled=""></textarea>, observed from <textarea>
+Pass Dispatch new MouseEvent() on <textarea disabled=""></textarea>, observed from <body>
+Pass Dispatch new PointerEvent() on <textarea disabled=""></textarea>, observed from <textarea>
+Pass Dispatch new PointerEvent() on <textarea disabled=""></textarea>, observed from <body>
+Pass click() on <textarea disabled=""></textarea>, observed from <textarea>
+Pass click() on <textarea disabled=""></textarea>, observed from <body>
+Pass Trusted click on <input disabled="" type="button">, observed from <input>
+Pass Trusted click on <input disabled="" type="button">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="button">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="button">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="button">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="button">, observed from <body>
+Pass click() on <input disabled="" type="button">, observed from <input>
+Pass click() on <input disabled="" type="button">, observed from <body>
+Pass Trusted click on <input disabled="" type="checkbox">, observed from <input>
+Pass Trusted click on <input disabled="" type="checkbox">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="checkbox">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="checkbox">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="checkbox">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="checkbox">, observed from <body>
+Pass click() on <input disabled="" type="checkbox">, observed from <input>
+Pass click() on <input disabled="" type="checkbox">, observed from <body>
+Pass Trusted click on <input disabled="" type="color" value="#000000">, observed from <input>
+Pass Trusted click on <input disabled="" type="color" value="#000000">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="color" value="#000000">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="color" value="#000000">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="color" value="#000000">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="color" value="#000000">, observed from <body>
+Pass click() on <input disabled="" type="color" value="#000000">, observed from <input>
+Pass click() on <input disabled="" type="color" value="#000000">, observed from <body>
+Pass Trusted click on <input disabled="" type="date">, observed from <input>
+Pass Trusted click on <input disabled="" type="date">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="date">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="date">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="date">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="date">, observed from <body>
+Pass click() on <input disabled="" type="date">, observed from <input>
+Pass click() on <input disabled="" type="date">, observed from <body>
+Pass Trusted click on <input disabled="" type="datetime-local">, observed from <input>
+Pass Trusted click on <input disabled="" type="datetime-local">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="datetime-local">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="datetime-local">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="datetime-local">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="datetime-local">, observed from <body>
+Pass click() on <input disabled="" type="datetime-local">, observed from <input>
+Pass click() on <input disabled="" type="datetime-local">, observed from <body>
+Pass Trusted click on <input disabled="" type="email">, observed from <input>
+Pass Trusted click on <input disabled="" type="email">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="email">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="email">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="email">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="email">, observed from <body>
+Pass click() on <input disabled="" type="email">, observed from <input>
+Pass click() on <input disabled="" type="email">, observed from <body>
+Pass Trusted click on <input disabled="" type="file">, observed from <input>
+Pass Trusted click on <input disabled="" type="file">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="file">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="file">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="file">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="file">, observed from <body>
+Pass click() on <input disabled="" type="file">, observed from <input>
+Pass click() on <input disabled="" type="file">, observed from <body>
+Pass Trusted click on <input disabled="" type="image">, observed from <input>
+Fail Trusted click on <input disabled="" type="image">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="image">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="image">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="image">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="image">, observed from <body>
+Pass click() on <input disabled="" type="image">, observed from <input>
+Pass click() on <input disabled="" type="image">, observed from <body>
+Pass Trusted click on <input disabled="" type="month">, observed from <input>
+Pass Trusted click on <input disabled="" type="month">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="month">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="month">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="month">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="month">, observed from <body>
+Pass click() on <input disabled="" type="month">, observed from <input>
+Pass click() on <input disabled="" type="month">, observed from <body>
+Pass Trusted click on <input disabled="" type="number">, observed from <input>
+Pass Trusted click on <input disabled="" type="number">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="number">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="number">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="number">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="number">, observed from <body>
+Pass click() on <input disabled="" type="number">, observed from <input>
+Pass click() on <input disabled="" type="number">, observed from <body>
+Pass Trusted click on <input disabled="" type="password">, observed from <input>
+Pass Trusted click on <input disabled="" type="password">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="password">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="password">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="password">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="password">, observed from <body>
+Pass click() on <input disabled="" type="password">, observed from <input>
+Pass click() on <input disabled="" type="password">, observed from <body>
+Pass Trusted click on <input disabled="" type="radio">, observed from <input>
+Pass Trusted click on <input disabled="" type="radio">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="radio">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="radio">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="radio">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="radio">, observed from <body>
+Pass click() on <input disabled="" type="radio">, observed from <input>
+Pass click() on <input disabled="" type="radio">, observed from <body>
+Pass Trusted click on <input disabled="" type="range" value="0">, observed from <input>
+Pass Trusted click on <input disabled="" type="range" value="0">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="range" value="0">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="range" value="0">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="range" value="0">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="range" value="0">, observed from <body>
+Pass click() on <input disabled="" type="range" value="0">, observed from <input>
+Pass click() on <input disabled="" type="range" value="0">, observed from <body>
+Pass Trusted click on <input disabled="" type="range" value="50">, observed from <input>
+Pass Trusted click on <input disabled="" type="range" value="50">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="range" value="50">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="range" value="50">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="range" value="50">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="range" value="50">, observed from <body>
+Pass click() on <input disabled="" type="range" value="50">, observed from <input>
+Pass click() on <input disabled="" type="range" value="50">, observed from <body>
+Pass Trusted click on <input disabled="" type="reset">, observed from <input>
+Pass Trusted click on <input disabled="" type="reset">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="reset">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="reset">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="reset">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="reset">, observed from <body>
+Pass click() on <input disabled="" type="reset">, observed from <input>
+Pass click() on <input disabled="" type="reset">, observed from <body>
+Pass Trusted click on <input disabled="" type="search">, observed from <input>
+Pass Trusted click on <input disabled="" type="search">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="search">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="search">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="search">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="search">, observed from <body>
+Pass click() on <input disabled="" type="search">, observed from <input>
+Pass click() on <input disabled="" type="search">, observed from <body>
+Pass Trusted click on <input disabled="" type="submit">, observed from <input>
+Pass Trusted click on <input disabled="" type="submit">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="submit">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="submit">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="submit">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="submit">, observed from <body>
+Pass click() on <input disabled="" type="submit">, observed from <input>
+Pass click() on <input disabled="" type="submit">, observed from <body>
+Pass Trusted click on <input disabled="" type="tel">, observed from <input>
+Pass Trusted click on <input disabled="" type="tel">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="tel">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="tel">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="tel">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="tel">, observed from <body>
+Pass click() on <input disabled="" type="tel">, observed from <input>
+Pass click() on <input disabled="" type="tel">, observed from <body>
+Pass Trusted click on <input disabled="" type="text">, observed from <input>
+Pass Trusted click on <input disabled="" type="text">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="text">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="text">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="text">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="text">, observed from <body>
+Pass click() on <input disabled="" type="text">, observed from <input>
+Pass click() on <input disabled="" type="text">, observed from <body>
+Pass Trusted click on <input disabled="" type="time">, observed from <input>
+Pass Trusted click on <input disabled="" type="time">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="time">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="time">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="time">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="time">, observed from <body>
+Pass click() on <input disabled="" type="time">, observed from <input>
+Pass click() on <input disabled="" type="time">, observed from <body>
+Pass Trusted click on <input disabled="" type="url">, observed from <input>
+Pass Trusted click on <input disabled="" type="url">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="url">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="url">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="url">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="url">, observed from <body>
+Pass click() on <input disabled="" type="url">, observed from <input>
+Pass click() on <input disabled="" type="url">, observed from <body>
+Pass Trusted click on <input disabled="" type="week">, observed from <input>
+Pass Trusted click on <input disabled="" type="week">, observed from <body>
+Pass Dispatch new MouseEvent() on <input disabled="" type="week">, observed from <input>
+Pass Dispatch new MouseEvent() on <input disabled="" type="week">, observed from <body>
+Pass Dispatch new PointerEvent() on <input disabled="" type="week">, observed from <input>
+Pass Dispatch new PointerEvent() on <input disabled="" type="week">, observed from <body>
+Pass click() on <input disabled="" type="week">, observed from <input>
+Pass click() on <input disabled="" type="week">, observed from <body>
+Pass Trusted click on <my-control disabled="">Text</my-control>, observed from <my-control>
+Pass Trusted click on <my-control disabled="">Text</my-control>, observed from <body>
+Pass Dispatch new MouseEvent() on <my-control disabled="">Text</my-control>, observed from <my-control>
+Pass Dispatch new MouseEvent() on <my-control disabled="">Text</my-control>, observed from <body>
+Pass Dispatch new PointerEvent() on <my-control disabled="">Text</my-control>, observed from <my-control>
+Pass Dispatch new PointerEvent() on <my-control disabled="">Text</my-control>, observed from <body>
+Pass click() on <my-control disabled="">Text</my-control>, observed from <my-control>
+Pass click() on <my-control disabled="">Text</my-control>, observed from <body>
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/fieldset-event-propagation.tentative.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/fieldset-event-propagation.tentative.txt
new file mode 100644
index 00000000000..62a5433f78c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/disabled-elements/fieldset-event-propagation.tentative.txt
@@ -0,0 +1,9 @@
+Harness status: OK
+
+Found 4 tests
+
+4 Pass
+Pass Disabled fieldset elements should not prevent click event propagation from native click
+Pass Disabled fieldset elements should not block click events from native click.
+Pass Disabled fieldset elements should not prevent click event propagation from click()
+Pass Disabled fieldset elements should not block click events from click().
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/UIEvents/mouse-events-at-disabled-form-controls.html b/Tests/LibWeb/Text/input/UIEvents/mouse-events-at-disabled-form-controls.html
new file mode 100644
index 00000000000..d0e66b9d180
--- /dev/null
+++ b/Tests/LibWeb/Text/input/UIEvents/mouse-events-at-disabled-form-controls.html
@@ -0,0 +1,70 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; height: 3000px; }
+ button, input, div, fieldset { display: block; box-sizing: border-box; width: 200px; height: 40px; margin: 0 0 20px; padding: 0; }
+ fieldset { height: auto; border: none; }
+</style>
+<form id="form" onsubmit="event.preventDefault(); println('form submitted')">
+ <button id="button" disabled><span id="span">span</span></button>
+</form>
+<input id="input" disabled value="text">
+<fieldset id="fieldset" disabled><div id="div-in-fieldset">div</div></fieldset>
+<div id="outside">outside</div>
+<script>
+ const types = ["pointerdown", "pointerup", "mouseover", "mouseenter", "mousedown", "mousemove", "mouseup", "click", "dblclick", "mouseleave", "wheel"];
+ let log = [];
+ const name = target => target.id || target.nodeName.toLowerCase();
+ for (const target of [document, document.body, ...document.querySelectorAll("[id]")]) {
+ if (target.id === "outside")
+ continue;
+ for (const type of types) {
+ target.addEventListener(type, event => {
+ if (event.target.id === "outside" || event.target.id === "form" || event.target.id === "fieldset")
+ return;
+ if (target === document && event.eventPhase === Event.CAPTURING_PHASE)
+ log.push(`${type} captured at document, target ${name(event.target)}`);
+ else if (target === document.body && event.eventPhase === Event.BUBBLING_PHASE)
+ log.push(`${type} bubbled to body`);
+ else if (event.eventPhase === Event.AT_TARGET && target !== document && target !== document.body)
+ log.push(`${type} at ${name(target)}`);
+ }, target === document);
+ }
+ }
+ const center = element => {
+ const rect = element.getBoundingClientRect();
+ return [rect.left + 10, rect.top + 10];
+ };
+ const flush = (label, type) => {
+ println(`${label}:`);
+ // Keep only the first of each event, so the log doesn't depend on how many moves the pointer makes.
+ for (const line of [...new Set(log)].filter(line => !type || line.startsWith(type)))
+ println(` ${line}`);
+ log = [];
+ };
+
+ // A disabled form control gets every event but mousedown, mouseup, click, and dblclick, and those don't reach
+ // anything above it either. A disabled fieldset's own content gets them all.
+ asyncTest(async done => {
+ const outside = center(document.getElementById("outside"));
+ for (const id of ["button", "span", "input", "div-in-fieldset"]) {
+ await internals.mouseMove(...outside);
+ log = [];
+ const [x, y] = center(document.getElementById(id));
+ await internals.mouseMove(x, y);
+ await internals.click(x, y);
+ await internals.click(x, y, 2);
+ await internals.mouseMove(...outside);
+ flush(`moving over #${id}, and clicking and double-clicking it`);
+ }
+
+ const [x, y] = center(document.getElementById("button"));
+ await internals.mouseMove(x, y);
+ log = [];
+ await internals.wheel(x, y, 0, 120);
+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ flush("a wheel over #button", "wheel");
+ println(`the page scrolled: ${window.scrollY > 0}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/UIEvents/press-in-disabled-form-control.html b/Tests/LibWeb/Text/input/UIEvents/press-in-disabled-form-control.html
new file mode 100644
index 00000000000..70a900f913b
--- /dev/null
+++ b/Tests/LibWeb/Text/input/UIEvents/press-in-disabled-form-control.html
@@ -0,0 +1,55 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; font: 16px monospace; }
+ input, button, div, a, my-control { display: block; box-sizing: border-box; width: 300px; height: 30px; margin: 0 0 20px; font: 16px monospace; }
+</style>
+<input id="other">
+<input id="disabled-input" disabled value="disabled input text here">
+<button id="disabled-button" disabled>disabled button</button>
+<div id="plain">some plain text here</div>
+<button id="button-holding-link" disabled><a id="link-in-button" href="#from-link-in-button">link</a></button>
+<a href="#from-link-around-button"><button id="button-in-link" disabled>button in link</button></a>
+<a href="#from-link-around-host"><div id="host"><span id="slotted">slotted</span></div></a>
+<form id="form"><my-control id="control" disabled><button id="submit-in-control">submit</button></my-control></form>
+<script>
+ document.getElementById("host").attachShadow({ mode: "open" }).innerHTML = "<button disabled><slot></slot></button>";
+ customElements.define("my-control", class extends HTMLElement {
+ static get formAssociated() { return true; }
+ });
+ document.getElementById("form").addEventListener("submit", event => {
+ event.preventDefault();
+ println(" the form was submitted");
+ });
+ document.addEventListener("contextmenu", event => event.preventDefault());
+ const center = id => {
+ const rect = document.getElementById(id).getBoundingClientRect();
+ return [rect.left + 20, rect.top + rect.height / 2];
+ };
+ const focused = () => document.activeElement.id || document.activeElement.nodeName.toLowerCase();
+
+ // A press in a disabled form control runs its default actions like a press anywhere else, and a click in one
+ // activates whatever it hits below the control, but nothing the control is in.
+ asyncTest(async done => {
+ for (const id of ["disabled-input", "disabled-button"]) {
+ for (const [label, button] of [["left", 0], ["right", 2]]) {
+ document.getElementById("other").focus();
+ await internals.click(...center(id), 1, button);
+ println(`${label}-click on #${id}: focused ${focused()}`);
+ }
+ }
+
+ getSelection().selectAllChildren(document.getElementById("plain"));
+ await internals.click(...center("disabled-button"));
+ println(`a click on #disabled-button keeps the page's selection: ${JSON.stringify(getSelection().toString())}`);
+
+ for (const id of ["link-in-button", "button-in-link", "slotted", "submit-in-control"]) {
+ location.hash = "";
+ println(`a click on #${id}:`);
+ await internals.click(...center(id));
+ await new Promise(resolve => setTimeout(resolve, 50));
+ println(` location.hash is ${JSON.stringify(location.hash)}`);
+ }
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/css/cursor-over-disabled-form-control.html b/Tests/LibWeb/Text/input/css/cursor-over-disabled-form-control.html
new file mode 100644
index 00000000000..b03fa3ec4c8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/cursor-over-disabled-form-control.html
@@ -0,0 +1,41 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style>
+ body { margin: 0; }
+ button, input { display: block; width: 200px; height: 40px; margin: 0 0 10px; }
+ :disabled { cursor: not-allowed; }
+</style>
+<button id="disabled-button" disabled>disabled</button>
+<input id="disabled-input" disabled>
+<fieldset id="fieldset" disabled><button id="button-in-disabled-fieldset">in a disabled fieldset</button></fieldset>
+<button id="disabled-by-its-click">disabled by its click</button>
+<script>
+ function nextRenderingUpdate() {
+ return new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));
+ }
+
+ // A disabled form control gets no mouse events, but the pointer over it still shows its cursor, also where it
+ // becomes disabled under a pointer that doesn't move.
+ asyncTest(async done => {
+ const center = element => {
+ const rect = element.getBoundingClientRect();
+ return [rect.left + 50, rect.top + 20];
+ };
+ for (const id of ["disabled-button", "disabled-input", "button-in-disabled-fieldset"]) {
+ internals.mouseMove(...center(document.getElementById(id)));
+ await nextRenderingUpdate();
+ println(`cursor over #${id}: ${internals.currentCursor()}`);
+ }
+
+ const button = document.getElementById("disabled-by-its-click");
+ button.addEventListener("click", () => { button.disabled = true; });
+ internals.mouseMove(...center(button));
+ await nextRenderingUpdate();
+ println(`cursor over #${button.id} before its click: ${internals.currentCursor()}`);
+ internals.click(...center(button));
+ await nextRenderingUpdate();
+ await nextRenderingUpdate();
+ println(`cursor over #${button.id} after its click: ${internals.currentCursor()}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-checkbox-click.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-checkbox-click.html
new file mode 100644
index 00000000000..2fd0970af3d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-checkbox-click.html
@@ -0,0 +1,26 @@
+<!doctype html>
+<link rel="author" title="Aditya Keerthi" href="https://github.com/pxlcoder">
+<link rel="help" href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute">
+<title>Test disabled checkbox does not change state when clicked</title>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/testdriver.js"></script>
+<script src="../../../resources/testdriver-actions.js"></script>
+<script src="../../../resources/testdriver-vendor.js"></script>
+
+<input type="checkbox" disabled>
+<script>
+const input = document.querySelector("input");
+
+promise_test(async function() {
+ assert_false(input.checked);
+
+ await new test_driver.Actions()
+ .pointerMove(0, 0, { origin: input })
+ .pointerDown()
+ .pointerUp()
+ .send();
+
+ assert_false(input.checked);
+}, `Disabled checkbox does not change state when clicked`);
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch-additional.tentative.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch-additional.tentative.html
new file mode 100644
index 00000000000..960900c9abd
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch-additional.tentative.html
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<meta name="timeout" content="long">
+<link rel=author href="mailto:[email protected]">
+<link rel=help href="https://github.com/whatwg/html/issues/2368">
+<link rel=help href="https://github.com/whatwg/html/issues/5886">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/testdriver.js"></script>
+<script src="../../../resources/testdriver-vendor.js"></script>
+<script src="../../../resources/testdriver-actions.js"></script>
+
+<!-- This test should be merged with disabled-event-dispatch.tentative.html after interop2023 is over. -->
+
+<div id=targetparent>
+ <button disabled>
+ hello world
+ <span style="border: 1px solid black">child</span>
+ </button>
+ <my-control disabled>
+ hello world
+ <span style="border: 1px solid black">child</span>
+ </my-control>
+</div>
+
+<script>
+customElements.define('my-control', class extends HTMLElement {
+ static get formAssociated() { return true; }
+});
+
+['dblclick', 'auxclick'].forEach(eventName => {
+ [true, false].forEach(clickChildElement => {
+ for (const target of targetparent.children) {
+ promise_test(async () => {
+ let parentReceivedEvent = false;
+ targetparent.addEventListener(eventName, () => parentReceivedEvent = true);
+
+ let targetReceivedEvent = false;
+ target.addEventListener(eventName, () => targetReceivedEvent = true);
+
+ let childReceivedEvent = false;
+ let targetchild = target.firstElementChild;
+ targetchild.addEventListener(eventName, () => childReceivedEvent = true);
+
+ const elementToClick = clickChildElement ? targetchild : target;
+ if (eventName === 'dblclick') {
+ await (new test_driver.Actions()
+ .pointerMove(1, 1, {origin: elementToClick})
+ .pointerDown()
+ .pointerUp()
+ .pointerDown()
+ .pointerUp())
+ .send();
+ } else if (eventName === 'auxclick') {
+ const actions = new test_driver.Actions();
+ await actions
+ .pointerMove(1, 1, {origin: elementToClick})
+ .pointerDown({button: actions.ButtonType.MIDDLE})
+ .pointerUp({button: actions.ButtonType.MIDDLE})
+ .send();
+ }
+
+
+ const shouldReceiveEvents = eventName.startsWith('pointer') || eventName === 'auxclick';
+ assert_equals(parentReceivedEvent, shouldReceiveEvents,
+ `parent element received ${eventName} events`);
+ assert_equals(targetReceivedEvent, shouldReceiveEvents,
+ `target element received ${eventName} events`);
+ assert_equals(childReceivedEvent, clickChildElement,
+ `child element received ${eventName} events`);
+ }, `Testing ${eventName} events when clicking ${clickChildElement ? 'child of ' : ''}disabled ${target.localName}.`);
+ }
+ });
+});
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch.tentative.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch.tentative.html
new file mode 100644
index 00000000000..b6e952dfd07
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/disabled-event-dispatch.tentative.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<meta name="timeout" content="long">
+<link rel=author href="mailto:[email protected]">
+<link rel=help href="https://github.com/whatwg/html/issues/2368">
+<link rel=help href="https://github.com/whatwg/html/issues/5886">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/testdriver.js"></script>
+<script src="../../../resources/testdriver-vendor.js"></script>
+<script src="../../../resources/testdriver-actions.js"></script>
+
+<div id=targetparent>
+ <button disabled>
+ hello world
+ <span style="border: 1px solid black">child</span>
+ </button>
+ <my-control disabled>
+ hello world
+ <span style="border: 1px solid black">child</span>
+ </my-control>
+</div>
+
+<script>
+customElements.define('my-control', class extends HTMLElement {
+ static get formAssociated() { return true; }
+});
+
+['mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click'].forEach(eventName => {
+ [true, false].forEach(clickChildElement => {
+ for (const target of targetparent.children) {
+ promise_test(async () => {
+ let parentReceivedEvent = false;
+ targetparent.addEventListener(eventName, () => parentReceivedEvent = true);
+
+ let targetReceivedEvent = false;
+ target.addEventListener(eventName, () => targetReceivedEvent = true);
+
+ let childReceivedEvent = false;
+ let targetchild = target.firstElementChild;
+ targetchild.addEventListener(eventName, () => childReceivedEvent = true);
+
+ await test_driver.click(clickChildElement ? targetchild : target);
+
+ const parentShouldReceiveEvents = eventName.startsWith('pointer');
+ assert_equals(parentReceivedEvent, parentShouldReceiveEvents,
+ `parent element received ${eventName} events`);
+
+ const targetShouldReceiveEvents = eventName.startsWith('pointer');
+ assert_equals(targetReceivedEvent, targetShouldReceiveEvents,
+ `target element received ${eventName} events`);
+ assert_equals(childReceivedEvent, clickChildElement,
+ `child element received ${eventName} events`);
+ }, `Testing ${eventName} events when clicking ${clickChildElement ? 'child of ' : ''}disabled ${target.localName}.`);
+ }
+ });
+});
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/event-propagate-disabled.tentative.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/event-propagate-disabled.tentative.html
new file mode 100644
index 00000000000..836eea25e1f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/event-propagate-disabled.tentative.html
@@ -0,0 +1,269 @@
+<!DOCTYPE html>
+<meta charset="utf8">
+<meta name="timeout" content="long">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<title>Event propagation on disabled form elements</title>
+<link rel="author" href="mailto:[email protected]">
+<link rel="help" href="https://github.com/whatwg/html/issues/2368">
+<link rel="help" href="https://github.com/whatwg/html/issues/5886">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/testdriver.js"></script>
+<script src="../../../resources/testdriver-vendor.js"></script>
+<script src="../../../resources/testdriver-actions.js"></script>
+
+<div id="cases">
+ <input> <!-- Sanity check with non-disabled control -->
+ <select disabled></select>
+ <select disabled>
+ <!-- <option> can't be clicked as it doesn't have its own painting area -->
+ <option>foo</option>
+ </select>
+ <fieldset disabled>Text</fieldset>
+ <fieldset disabled><span class="target">Span</span></fieldset>
+ <button disabled>Text</button>
+ <button disabled><span class="target">Span</span></button>
+ <textarea disabled></textarea>
+ <input disabled type="button">
+ <input disabled type="checkbox">
+ <input disabled type="color" value="#000000">
+ <input disabled type="date">
+ <input disabled type="datetime-local">
+ <input disabled type="email">
+ <input disabled type="file">
+ <input disabled type="image">
+ <input disabled type="month">
+ <input disabled type="number">
+ <input disabled type="password">
+ <input disabled type="radio">
+ <!-- Native click will click the bar -->
+ <input disabled type="range" value="0">
+ <!-- Native click will click the slider -->
+ <input disabled type="range" value="50">
+ <input disabled type="reset">
+ <input disabled type="search">
+ <input disabled type="submit">
+ <input disabled type="tel">
+ <input disabled type="text">
+ <input disabled type="time">
+ <input disabled type="url">
+ <input disabled type="week">
+ <my-control disabled>Text</my-control>
+</div>
+
+<script>
+ customElements.define('my-control', class extends HTMLElement {
+ static get formAssociated() { return true; }
+ get disabled() { return this.hasAttribute("disabled"); }
+ });
+
+ /**
+ * @param {Element} element
+ */
+ function getEventFiringTarget(element) {
+ return element.querySelector(".target") || element;
+ }
+
+ const allEvents = ["pointermove", "mousemove", "pointerdown", "mousedown", "pointerup", "mouseup", "click"];
+
+ /**
+ * @param {*} t
+ * @param {Element} element
+ * @param {Element} observingElement
+ */
+ function setupTest(t, element, observingElement) {
+ /** @type {{type: string, composedPath: Node[]}[]} */
+ const observedEvents = [];
+ const controller = new AbortController();
+ const { signal } = controller;
+ const listenerFn = t.step_func(event => {
+ observedEvents.push({
+ type: event.type,
+ target: event.target,
+ isTrusted: event.isTrusted,
+ composedPath: event.composedPath().map(n => n.constructor.name),
+ });
+ });
+ for (const event of allEvents) {
+ observingElement.addEventListener(event, listenerFn, { signal });
+ }
+ t.add_cleanup(() => controller.abort());
+
+ const target = getEventFiringTarget(element);
+ return { target, observedEvents };
+ }
+
+ /**
+ * @param {Element} element
+ * @returns {boolean}
+ */
+ function isFormControl(element) {
+ if (["button", "input", "select", "textarea"].includes(element.localName)) {
+ return true;
+ }
+ return element.constructor.formAssociated;
+ }
+
+ function isDisabledFormControl(element) {
+ return isFormControl(element) && element.disabled;
+ }
+
+ /**
+ * @param {Element} target
+ * @param {*} observedEvent
+ */
+ function shouldNotBubble(target, observedEvent) {
+ return (
+ isDisabledFormControl(target) &&
+ observedEvent.isTrusted &&
+ ["mousedown", "mouseup", "click"].includes(observedEvent.type)
+ );
+ }
+
+ /**
+ * @param {Event} event
+ */
+ function getExpectedComposedPath(event) {
+ let target = event.target;
+ const result = [];
+ while (target) {
+ if (shouldNotBubble(target, event)) {
+ return result;
+ }
+ result.push(target.constructor.name);
+ target = target.parentNode;
+ }
+ result.push("Window");
+ return result;
+ }
+
+ /**
+ * @param {object} options
+ * @param {Element & { disabled: boolean }} options.element
+ * @param {Element} options.observingElement
+ * @param {string[]} options.expectedEvents
+ * @param {(target: Element) => (Promise<void> | void)} options.clickerFn
+ * @param {string} options.title
+ */
+ function promise_event_test({ element, observingElement, expectedEvents, nonDisabledExpectedEvents, clickerFn, title }) {
+ promise_test(async t => {
+ const { target, observedEvents } = setupTest(t, element, observingElement);
+
+ await t.step_func(clickerFn)(target);
+ await new Promise(resolve => t.step_timeout(resolve, 0));
+
+ const expected = isDisabledFormControl(element) ? expectedEvents : nonDisabledExpectedEvents;
+
+ t.step_wait_func_done(() => observedEvents.length > 0,
+ () => assert_array_equals(observedEvents.map(e => e.type), expected, "Observed events"),
+ undefined, 1000, 10);
+ ;
+
+ for (const observed of observedEvents) {
+ assert_equals(observed.target, target, `${observed.type}.target`)
+ assert_array_equals(
+ observed.composedPath,
+ getExpectedComposedPath(observed),
+ `${observed.type}.composedPath`
+ );
+ }
+
+ }, `${title} on ${element.outerHTML}, observed from <${observingElement.localName}>`);
+ }
+
+ /**
+ * @param {object} options
+ * @param {Element & { disabled: boolean }} options.element
+ * @param {string[]} options.expectedEvents
+ * @param {(target: Element) => (Promise<void> | void)} options.clickerFn
+ * @param {string} options.title
+ */
+ function promise_event_test_hierarchy({ element, expectedEvents, nonDisabledExpectedEvents, clickerFn, title }) {
+ const targets = [element, document.body];
+ if (element.querySelector(".target")) {
+ targets.unshift(element.querySelector(".target"));
+ }
+ for (const observingElement of targets) {
+ promise_event_test({ element, observingElement, expectedEvents, nonDisabledExpectedEvents, clickerFn, title });
+ }
+ }
+
+ function trusted_click(target) {
+ // To workaround type=file clicking issue
+ // https://github.com/w3c/webdriver/issues/1666
+ return new test_driver.Actions()
+ .pointerMove(0, 0, { origin: target })
+ .pointerDown()
+ .pointerUp()
+ .send();
+ }
+
+ const mouseEvents = ["mousemove", "mousedown", "mouseup", "click"];
+ const pointerEvents = ["pointermove", "pointerdown", "pointerup"];
+
+ // Events except mousedown/up/click
+ const allowedEvents = ["pointermove", "mousemove", "pointerdown", "pointerup"];
+
+ const elements = document.getElementById("cases").children;
+ for (const element of elements) {
+ // Observe on a child element of the control, if exists
+ const target = element.querySelector(".target");
+ if (target) {
+ promise_event_test({
+ element,
+ observingElement: target,
+ expectedEvents: allEvents,
+ nonDisabledExpectedEvents: allEvents,
+ clickerFn: trusted_click,
+ title: "Trusted click"
+ });
+ }
+
+ // Observe on the control itself
+ promise_event_test({
+ element,
+ observingElement: element,
+ expectedEvents: allowedEvents,
+ nonDisabledExpectedEvents: allEvents,
+ clickerFn: trusted_click,
+ title: "Trusted click"
+ });
+
+ // Observe on document.body
+ promise_event_test({
+ element,
+ observingElement: document.body,
+ expectedEvents: allowedEvents,
+ nonDisabledExpectedEvents: allEvents,
+ clickerFn: trusted_click,
+ title: "Trusted click"
+ });
+
+ const eventFirePair = [
+ [MouseEvent, mouseEvents],
+ [PointerEvent, pointerEvents]
+ ];
+
+ for (const [eventInterface, events] of eventFirePair) {
+ promise_event_test_hierarchy({
+ element,
+ expectedEvents: events,
+ nonDisabledExpectedEvents: events,
+ clickerFn: target => {
+ for (const event of events) {
+ target.dispatchEvent(new eventInterface(event, { bubbles: true }))
+ }
+ },
+ title: `Dispatch new ${eventInterface.name}()`
+ })
+ }
+
+ promise_event_test_hierarchy({
+ element,
+ expectedEvents: getEventFiringTarget(element) === element ? [] : ["click"],
+ nonDisabledExpectedEvents: ["click"],
+ clickerFn: target => target.click(),
+ title: `click()`
+ })
+ }
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/fieldset-event-propagation.tentative.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/fieldset-event-propagation.tentative.html
new file mode 100644
index 00000000000..fc4f17bc8b5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/disabled-elements/fieldset-event-propagation.tentative.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:[email protected]">
+<link rel=help href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-disabled">
+<link rel=help href="https://github.com/whatwg/html/issues/5886#issuecomment-1460425364">
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<script src="../../../resources/testdriver.js"></script>
+<script src="../../../resources/testdriver-vendor.js"></script>
+<script src="../../../resources/testdriver-actions.js"></script>
+
+<div id=target1parent>
+ <fieldset disabled id=target1fieldset>
+ <div id=target1child>hello world</div>
+ </fieldset>
+</div>
+
+<div id=target2parent>
+ <fieldset disabled id=target2fieldset>hello world</fieldset>
+</div>
+
+<script>
+ const clickers = {
+ "native click": target => test_driver.click(target),
+ "click()": target => target.click(),
+ };
+
+ for (const [clickerName, clicker] of Object.entries(clickers)) {
+ promise_test(async () => {
+ let target1parentClicked = false;
+ let target1childClicked = false;
+ let target1fieldsetClicked = false;
+ target1parent.onclick = () => target1parentClicked = true;
+ target1child.onclick = () => target1childClicked = true;
+ target1fieldset.onclick = () => target1fieldsetClicked = true;
+
+ await clicker(target1child);
+
+ assert_true(target1parentClicked, 'The parent of the fieldset should receive a click event.');
+ assert_true(target1childClicked, 'The child of the fieldset should receive a click event.');
+ assert_true(target1fieldsetClicked, 'The fieldset element should receive a click event.');
+ }, `Disabled fieldset elements should not prevent click event propagation from ${clickerName}`);
+
+ promise_test(async () => {
+ let target2parentClicked = false;
+ let target2fieldsetClicked = false;
+ target2parent.onclick = () => target2parentClicked = true;
+ target2fieldset.onclick = () => target2fieldsetClicked = true;
+
+ await clicker(target2fieldset);
+
+ assert_true(target2parentClicked, 'The parent of the fieldset should receive a click event.');
+ assert_true(target2fieldsetClicked, 'The fieldset element should receive a click event.');
+ }, `Disabled fieldset elements should not block click events from ${clickerName}.`);
+ }
+</script>