Skip to content

Truly independent web browser

LibWeb: Fix focus when controls stop being focusable

Andreas Kling9d6337d50e41
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 6e8477aa9d9..51c62ff01e5 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -7051,7 +7051,12 @@ bool Element::meets_focusable_area_rendering_requirements() const
if (!is_connected())
return false;
- return const_cast<Element&>(*this).document().update_style_for_element(AbstractElement { *this }, Document::StyleUpdateMode::StopAtDisplayNone);
+ if (!const_cast<Element&>(*this).document().update_style_for_element(AbstractElement { *this }, Document::StyleUpdateMode::StopAtDisplayNone))
+ return false;
+
+ // NB: Elements whose boxes are not visible cannot be focused.
+ auto const* values = style_group<CSS::ComputedValues::InheritedBoxValues>();
+ return values && values->visibility_value() == CSS::Visibility::Visible;
}
// https://drafts.csswg.org/css-view-transitions-1/#document-scoped-view-transition-name
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 6a396ef89da..a33af2e59b2 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -84,6 +84,7 @@
#include <LibWeb/HTML/HTMLTextAreaElement.h>
#include <LibWeb/HTML/LocalNavigable.h>
#include <LibWeb/HTML/NavigableContainer.h>
+#include <LibWeb/HTML/Navigation.h>
#include <LibWeb/HTML/Parser/HTMLParser.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/SimilarOriginWindowAgent.h>
@@ -1768,6 +1769,10 @@ void Node::remove(bool suppress_observers)
removal_style_record_pins.pin_style_records_after_removal(*this, was_connected);
+ // NB: A subtree holding the focused or hovered node takes :focus-within and :hover out of its old ancestor
+ // chain. Republish that chain before the removing steps clear the focused area.
+ CSS::Invalidation::invalidate_style_after_subtree_place_changed(*this, parent);
+
// 11. Run the removing steps with node, true, and parent.
// 12. Let isParentConnected be parent’s connected.
// 13. If node is custom and isParentConnected is true, then enqueue a custom element callback reaction with node,
@@ -1777,10 +1782,6 @@ void Node::remove(bool suppress_observers)
removal_style_record_pins.release_dom_style_records();
- // A subtree holding the focused or hovered node takes `:focus-within` and `:hover` out of the
- // chain it hung off. Nothing about any element in that chain moved, so it has to be told.
- CSS::Invalidation::invalidate_style_after_subtree_place_changed(*this, parent);
-
// 15. Add transient registered observers given node and parent.
add_transient_registered_observers(*parent);
@@ -2881,6 +2882,17 @@ void Node::removed_from(IsSubtreeRoot, Node* old_parent, Node&)
m_is_connected = false;
m_in_editable_subtree = false;
+
+ // https://html.spec.whatwg.org/multipage/infrastructure.html#dom-trees:concept-node-remove-ext
+ // 1. Let document be removedNode's node document.
+ auto& document = this->document();
+
+ // 2. If document's focused area is removedNode, then set document's focused area to document's viewport, and set
+ // document's relevant global object's navigation API's focus changed during ongoing navigation to false.
+ if (document.focused_area().ptr() == this) {
+ document.set_focused_area(nullptr);
+ HTML::relevant_window(document).navigation()->set_focus_changed_during_ongoing_navigation(false);
+ }
}
// https://dom.spec.whatwg.org/#concept-node-move-ext
@@ -3166,6 +3178,10 @@ void Node::remove_all_children(bool suppress_observers)
removal_style_record_pins.pin_style_records_after_removal(*child, was_connected);
+ // NB: Republish the old chain before the removing steps clear the focused area.
+ if (a_child_holds_a_propagating_state_source)
+ CSS::Invalidation::invalidate_style_after_subtree_place_changed(*child, this);
+
// 11. Run the removing steps with node, true, and parent.
// 12. Let isParentConnected be parent’s connected.
// 13. If node is custom and isParentConnected is true, then enqueue a custom element callback reaction with
@@ -3175,9 +3191,6 @@ void Node::remove_all_children(bool suppress_observers)
removal_style_record_pins.release_dom_style_records();
- if (a_child_holds_a_propagating_state_source)
- CSS::Invalidation::invalidate_style_after_subtree_place_changed(*child, this);
-
// 15. Add transient registered observers given node and parent.
child->add_transient_registered_observers(*this);
diff --git a/Libraries/LibWeb/Editing/EditCommand.cpp b/Libraries/LibWeb/Editing/EditCommand.cpp
index e708ea543ae..8a6c900edeb 100644
--- a/Libraries/LibWeb/Editing/EditCommand.cpp
+++ b/Libraries/LibWeb/Editing/EditCommand.cpp
@@ -17,6 +17,7 @@
#include <LibWeb/Editing/EditingHistory.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLElement.h>
+#include <LibWeb/HTML/HTMLTextAreaElement.h>
#include <LibWeb/WebIDL/DOMException.h>
namespace Web::Editing {
@@ -156,6 +157,9 @@ bool ReplaceDataCommand::replay(Utf16String const& from, Utf16String const& to)
if (control) {
MUST(control->set_range_text(to, m_offset, m_offset + length, Bindings::SelectionMode::Preserve));
+ // NB: History edits also create a pending change, while its input event is dispatched once by EditingHistory.
+ if (auto* textarea = dynamic_cast<HTML::HTMLTextAreaElement*>(control))
+ textarea->record_user_edit(current_data);
return true;
}
return !m_node->replace_data(m_offset, length, to).is_error();
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index 656f99a4e81..f0bf76edae6 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -29,6 +29,7 @@
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/EventLoop/FrameCompletion.h>
#include <LibWeb/HTML/EventLoop/RenderingSchedulerCounters.h>
+#include <LibWeb/HTML/Focus.h>
#include <LibWeb/HTML/FormAssociatedElement.h>
#include <LibWeb/HTML/HTMLMediaElement.h>
#include <LibWeb/HTML/ListOfAvailableImages.h>
@@ -213,8 +214,11 @@ void EventLoop::process()
// FIXME: 4. If oldestTask's document is not null, then record task start time given taskStartTime and oldestTask's document.
// AD-HOC: While a task runs, the render clock's lanes tick the animations the last rendering update planned for.
- if (oldest_task->source() != Task::Source::Rendering)
+ // A task that runs beside a rendering update in flight comes after the whole of it.
+ if (oldest_task->source() != Task::Source::Rendering) {
note_clock_lanes(ClockAnimations::Run);
+ note_script_ran_beside_rendering_update_in_flight();
+ }
// 5. Set the event loop's currently running task to oldestTask.
m_currently_running_task = oldest_task.ptr();
@@ -579,6 +583,23 @@ struct EventLoop::RenderingUpdateInFlight {
// ends before them, and they run as its frame is taken in, beside the tasks after it or in the next rendering update,
// which may begin beside the frame.
bool ended() const { return held_tasks == HeldTasks::None && docs.size() == 1; }
+ // Whether script of `document` ran beside the update.
+ bool ran_script_of_beside(DOM::Document const& document) const
+ {
+ if (!script_ran_beside)
+ return false;
+ if (held_for_testing)
+ return true;
+ switch (least_held_tasks) {
+ case HeldTasks::None:
+ return true;
+ case HeldTasks::OfLastDocument:
+ return &document != docs.last().ptr();
+ case HeldTasks::All:
+ return false;
+ }
+ VERIFY_NOT_REACHED();
+ }
Vector<GC::Root<DOM::Document>> docs;
double frame_timestamp { 0 };
@@ -591,6 +612,10 @@ struct EventLoop::RenderingUpdateInFlight {
// Whether the first round of the doc's layout flew: after the transaction, once the event loop took it in, or in its
// place, where the update had no style to change.
bool layout_flew { false };
+ // The fewest tasks the update held back at any time while it flew.
+ HeldTasks least_held_tasks { HeldTasks::None };
+ // Whether a task, or a step of the next rendering update that runs script, ran beside the update.
+ bool script_ran_beside { false };
};
// The end of a rendering update, once its last step has run.
@@ -660,6 +685,9 @@ static HeldTasks tasks_rendering_update_holds(Vector<GC::Root<DOM::Document>> co
{
if (any_of(docs, [](auto const& document) { return document->has_intersection_observation_targets(); }))
return HeldTasks::All;
+ // The focus fixup of every doc whose focused area is not its viewport reads that area as the update leaves it.
+ if (any_of(docs.span().slice(0, docs.size() - 1), [](auto const& document) { return focus_fixup_rule_may_apply(*document); }))
+ return HeldTasks::All;
// The lanes of a doc the update took in present nothing until it seals their plan, which its tasks would hold up.
auto lanes_wait = [&](DOM::Document const& document) {
auto* arena = document.layout_node_arena_if_created();
@@ -668,7 +696,7 @@ static HeldTasks tasks_rendering_update_holds(Vector<GC::Root<DOM::Document>> co
if (any_of(docs.span().slice(0, docs.size() - 1), [&](auto const& document) { return lanes_wait(*document); }))
return HeldTasks::All;
auto& document = *docs.last();
- if (document.has_resize_observers())
+ if (document.has_resize_observers() || focus_fixup_rule_may_apply(document))
return HeldTasks::OfLastDocument;
if (lanes_wait(document))
return HeldTasks::OfLastDocument;
@@ -964,7 +992,9 @@ void EventLoop::update_the_rendering()
// FIXME: 15. Let unsafeStyleAndLayoutStartTime be the unsafe shared current time.
- // AD-HOC: The rest of the last rendering update runs before anything of this one's style and layout.
+ // AD-HOC: The rest of the last rendering update runs before anything of this one's style and layout, and after
+ // the steps of this one that ran script.
+ note_script_ran_beside_rendering_update_in_flight();
finish_ended_rendering_update_in_flight();
// AD-HOC: A doc the update took the lanes of in, which was not renderable or which script left unrenderable since,
@@ -1001,7 +1031,7 @@ void EventLoop::update_the_rendering()
m_running_rendering_task = false;
auto layout_held_for_testing = style_taken_in == StyleTakenIn::Yes && exchange(m_holds_next_layout_for_testing, false) ? LayoutHeldForTesting::Yes : LayoutHeldForTesting::No;
auto held_tasks = tasks_rendering_update_holds(docs, style_taken_in, layout_held_for_testing);
- m_rendering_update_in_flight = make<RenderingUpdateInFlight>(move(docs), frame_timestamp, m_rendering_update_serial, exchange(m_holds_next_frame_for_testing, false), held_tasks, style_taken_in == StyleTakenIn::Yes);
+ m_rendering_update_in_flight = make<RenderingUpdateInFlight>(move(docs), frame_timestamp, m_rendering_update_serial, exchange(m_holds_next_frame_for_testing, false), held_tasks, style_taken_in == StyleTakenIn::Yes, held_tasks);
// The next rendering opportunity is asked for now, so that the next update can begin as soon as
// this one has run, or has ended.
finish_rendering_update(update_start_time);
@@ -1186,7 +1216,7 @@ static void update_style_and_layout_for_rendering(DOM::Document& document, u64 u
}
// Steps 17 to 23 of updating the rendering, once step 16 has laid out every doc of docs.
-void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM::Document>> const& docs, double frame_timestamp, u64 update_serial, TakenLayout taken_layout)
+void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM::Document>> const& docs, double frame_timestamp, u64 update_serial, TakenLayout taken_layout, RenderingUpdateInFlight const* update_in_flight)
{
auto relative_frame_timestamp_for = [&](DOM::Document const& document) {
return max(0.0, HighResolutionTime::relative_high_resolution_time(frame_timestamp, relevant_global_object(document)));
@@ -1212,7 +1242,20 @@ void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM:
}
}
- // FIXME: 17. For each doc of docs, if the focused area of doc is not a focusable area, then run the focusing steps for doc's viewport, and set doc's relevant global object's navigation API's focus changed during ongoing navigation to false.
+ // 17. For each doc of docs, if the focused area of doc is not a focusable area, then run the focusing steps for doc's viewport, and set doc's relevant global object's navigation API's focus changed during ongoing navigation to false.
+ for (auto& document : docs) {
+ if (!document->is_fully_active())
+ continue;
+ // AD-HOC: Script that ran beside a rendering update in flight comes after the whole of it. The update holds the
+ // tasks of a doc whose focused area is not its viewport, so that script found the viewport focused, which
+ // needs no fixup: the next rendering update fixes up what the script focused.
+ if (update_in_flight && update_in_flight->ran_script_of_beside(*document)) {
+ if (focus_fixup_rule_applies(*document))
+ document->page().client().request_frame();
+ continue;
+ }
+ run_focus_fixup_rule(*document);
+ }
// 18. For each doc of docs, perform pending transition operations for doc. [CSSVIEWTRANSITIONS]
for (auto& document : docs) {
@@ -1363,7 +1406,7 @@ void EventLoop::resume_rendering_update_in_flight()
TemporaryChange running { m_running_rendering_task, true };
// The style and layout of the doc whose transaction flew take it in, waiting for it to land.
update_style_and_layout_for_rendering(update->document(), update->serial);
- update_the_rendering_after_style_and_layout(update->docs, update->frame_timestamp, update->serial);
+ update_the_rendering_after_style_and_layout(update->docs, update->frame_timestamp, update->serial, TakenLayout::UpToDate, update.ptr());
}
// What the steps asked for, an animation frame of a promise they resolved for one, asks for the next rendering
// opportunity now, unless a rendering update runs, whose end asks for it.
@@ -1396,12 +1439,18 @@ bool EventLoop::finish_ended_rendering_update_as_its_layout_flew()
update = m_rendering_update_in_flight.release_nonnull();
if (auto navigable = document.navigable())
navigable->clamp_viewport_scroll_offset();
- update_the_rendering_after_style_and_layout(update->docs, update->frame_timestamp, update->serial, TakenLayout::AsItFlew);
+ update_the_rendering_after_style_and_layout(update->docs, update->frame_timestamp, update->serial, TakenLayout::AsItFlew, update.ptr());
}
update_whether_font_face_sets_are_pending_on_the_environment(update->docs, TakenLayout::AsItFlew);
return true;
}
+void EventLoop::note_script_ran_beside_rendering_update_in_flight()
+{
+ if (m_rendering_update_in_flight)
+ m_rendering_update_in_flight->script_ran_beside = true;
+}
+
u64 EventLoop::first_rendering_update_to_gather_resize_observations_of(DOM::Document const& document) const
{
if (m_rendering_update_in_flight && &m_rendering_update_in_flight->document() == &document)
@@ -1502,6 +1551,7 @@ bool EventLoop::let_layout_of_rendering_update_fly()
return false;
update.layout_flew = true;
update.held_tasks = tasks_rendering_update_holds(update.docs, StyleTakenIn::Yes, exchange(m_holds_next_layout_for_testing, false) ? LayoutHeldForTesting::Yes : LayoutHeldForTesting::No);
+ update.least_held_tasks = min(update.least_held_tasks, update.held_tasks);
return true;
}
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
index 27f6013d1f9..2a1ef701d60 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h
@@ -220,12 +220,15 @@ private:
UpToDate,
AsItFlew,
};
- void update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM::Document>> const& docs, double frame_timestamp, u64 update_serial, TakenLayout = TakenLayout::UpToDate);
+ struct RenderingUpdateInFlight;
+ // `update_in_flight` is the rendering update whose steps go on, if it flew.
+ void update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM::Document>> const& docs, double frame_timestamp, u64 update_serial, TakenLayout = TakenLayout::UpToDate, RenderingUpdateInFlight const* update_in_flight = nullptr);
void update_whether_font_face_sets_are_pending_on_the_environment(Vector<GC::Root<DOM::Document>> const& docs, TakenLayout);
void finish_rendering_update(double update_start_time);
void resume_rendering_update_in_flight();
void finish_ended_rendering_update_in_flight();
bool finish_ended_rendering_update_as_its_layout_flew();
+ void note_script_ran_beside_rendering_update_in_flight();
// Goes on with the rendering update in flight where it has landed, and presents the recordings that have landed.
void take_finished_frames_in();
bool let_layout_of_rendering_update_fly();
@@ -291,7 +294,6 @@ private:
bool m_holds_next_frame_for_testing { false };
bool m_holds_next_layout_for_testing { false };
- struct RenderingUpdateInFlight;
OwnPtr<RenderingUpdateInFlight> m_rendering_update_in_flight;
// The serial number of the last rendering update that began: the lanes an update takes in wait for its own plan,
// not for that of an update before it.
diff --git a/Libraries/LibWeb/HTML/Focus.cpp b/Libraries/LibWeb/HTML/Focus.cpp
index 615d17fc9ac..685b2e6f682 100644
--- a/Libraries/LibWeb/HTML/Focus.cpp
+++ b/Libraries/LibWeb/HTML/Focus.cpp
@@ -30,6 +30,7 @@
#include <LibWeb/HTML/Numbers.h>
#include <LibWeb/HTML/RemoteNavigable.h>
#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Page/Page.h>
@@ -403,6 +404,35 @@ static bool is_focusable_area(DOM::Node& node)
return node.is_focusable();
}
+// NB: Whether the document has a focused area that the focus fixup rule may find not focusable. The viewport is
+// focusable, and a container stands for its child navigable's viewport in the parent's focus chain. The child
+// document handles its own focused area; an inert container does not make that document inert.
+bool focus_fixup_rule_may_apply(DOM::Document const& document)
+{
+ auto focused_area = document.focused_area();
+ if (!focused_area)
+ return false;
+ auto const* container = as_if<NavigableContainer>(focused_area.ptr());
+ return !container || !container->content_navigable();
+}
+
+// https://html.spec.whatwg.org/multipage/interaction.html#focus-fixup-rule
+bool focus_fixup_rule_applies(DOM::Document& document)
+{
+ return focus_fixup_rule_may_apply(document) && !is_focusable_area(*document.focused_area());
+}
+
+// https://html.spec.whatwg.org/multipage/interaction.html#focus-fixup-rule
+void run_focus_fixup_rule(DOM::Document& document)
+{
+ if (!focus_fixup_rule_applies(document))
+ return;
+
+ TemporaryExecutionContext execution_context { document.relevant_settings_object() };
+ run_focusing_steps(&document);
+ relevant_window(document).navigation()->set_focus_changed_during_ongoing_navigation(false);
+}
+
// https://html.spec.whatwg.org/multipage/interaction.html#get-the-focusable-area
static GC::Ptr<DOM::Node> get_focusable_area(DOM::Node& focus_target, FocusTrigger focus_trigger);
diff --git a/Libraries/LibWeb/HTML/Focus.h b/Libraries/LibWeb/HTML/Focus.h
index 08ae0f873ab..642d08b1742 100644
--- a/Libraries/LibWeb/HTML/Focus.h
+++ b/Libraries/LibWeb/HTML/Focus.h
@@ -27,6 +27,9 @@ WEB_API void run_focusing_steps(GC::Ptr<DOM::Node> new_focus_target, GC::Ptr<DOM
WEB_API void run_unfocusing_steps(GC::Ptr<DOM::Node> old_focus_target);
GC::Ptr<DOM::Node> focus_delegate(DOM::Node& focus_target, FocusTrigger = FocusTrigger::Other);
void run_popover_focusing_steps(HTMLElement& subject);
+bool focus_fixup_rule_may_apply(DOM::Document const&);
+bool focus_fixup_rule_applies(DOM::Document&);
+void run_focus_fixup_rule(DOM::Document&);
// https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-direction
enum class SequentialFocusDirection : u8 {
diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
index 87ef0783c98..a64eaacccf0 100644
--- a/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
+++ b/Libraries/LibWeb/HTML/FormAssociatedElement.cpp
@@ -1339,7 +1339,7 @@ void FormAssociatedTextControlElement::handle_insert(Utf16FlyString const& input
if (first_is_one_of(input_type, UIEvents::InputTypes::insertText, UIEvents::InputTypes::insertCompositionText, UIEvents::InputTypes::insertFromPaste, UIEvents::InputTypes::insertReplacementText))
data_for_input_event = Utf16String::from_utf16(data_for_insertion);
- did_edit_text_node(input_type, data_for_input_event);
+ did_edit_text_node(input_type, data_for_input_event, old_value);
html_element.document().spell_check_controller().did_user_edit(html_element);
html_element.document().writing_suggestion_controller().did_user_edit(html_element);
reveal_cursor_after_edit();
@@ -1429,7 +1429,7 @@ void FormAssociatedTextControlElement::handle_delete(Utf16FlyString const& input
}
history->end_recording();
- did_edit_text_node(input_type, {});
+ did_edit_text_node(input_type, {}, old_value);
html_element.document().spell_check_controller().did_user_edit(html_element);
html_element.document().writing_suggestion_controller().did_user_edit(html_element);
reveal_cursor_after_edit();
diff --git a/Libraries/LibWeb/HTML/FormAssociatedElement.h b/Libraries/LibWeb/HTML/FormAssociatedElement.h
index 3e6a32926ad..d96a45c75b8 100644
--- a/Libraries/LibWeb/HTML/FormAssociatedElement.h
+++ b/Libraries/LibWeb/HTML/FormAssociatedElement.h
@@ -278,7 +278,7 @@ public:
virtual HTMLElement& text_control_to_html_element() = 0;
HTMLElement const& text_control_to_html_element() const { return const_cast<FormAssociatedTextControlElement&>(*this).text_control_to_html_element(); }
- virtual void did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data) = 0;
+ virtual void did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data, Utf16View previous_value) = 0;
virtual GC::Ptr<DOM::Text> form_associated_element_to_text_node() = 0;
virtual GC::Ptr<DOM::Text const> form_associated_element_to_text_node() const { return const_cast<FormAssociatedTextControlElement&>(*this).form_associated_element_to_text_node(); }
diff --git a/Libraries/LibWeb/HTML/HTMLElement.cpp b/Libraries/LibWeb/HTML/HTMLElement.cpp
index bcc3a4845e0..e4f08100425 100644
--- a/Libraries/LibWeb/HTML/HTMLElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLElement.cpp
@@ -2584,9 +2584,7 @@ void HTMLElement::removed_from(IsSubtreeRoot is_subtree_root, Node* old_ancestor
{
Element::removed_from(is_subtree_root, old_ancestor, old_root);
- // FIXME: 1. Let document be removedNode's node document.
- // FIXME: 2. If document's focused area is removedNode, then set document's focused area to document's viewport,
- // and set document's relevant global object's navigation API's focus changed during ongoing navigation to false.
+ // NB: Node::removed_from() performs steps 1 and 2, which fix up focus for all namespaces.
// 3. If removedNode is an element whose namespace is the HTML namespace, and this standard defines HTML element
// removing steps for removedNode's local name, then run the corresponding HTML element removing steps given
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
index 7d12d0b725d..51abe5621ea 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp
@@ -580,7 +580,7 @@ WebIDL::ExceptionOr<void> HTMLInputElement::run_input_activation_behavior(DOM::E
return {};
}
-void HTMLInputElement::did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data)
+void HTMLInputElement::did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data, Utf16View)
{
m_dirty_value = true;
m_has_uncommitted_changes = true;
@@ -1561,6 +1561,10 @@ void HTMLInputElement::create_range_input_shadow_tree()
void HTMLInputElement::user_interaction_did_change_input_value(Utf16FlyString const& input_type, Optional<Utf16String> const& data)
{
+ // NB: Range interactions bypass text editing; keep their pending change for focus loss.
+ if (type_state() == TypeAttributeState::Range)
+ m_has_uncommitted_changes = true;
+
// https://html.spec.whatwg.org/multipage/input.html#common-input-element-events
// For input elements without a defined input activation behavior, but to which these events apply,
// Although HTML specifies queuing this event, Blink, WebKit, and Gecko dispatch it
@@ -1625,7 +1629,13 @@ void HTMLInputElement::did_lose_focus()
if (m_placeholder_text_node)
m_placeholder_text_node->set_needs_repaint(InvalidateDisplayList::PaintCommands);
- commit_pending_changes();
+ // NB: Removal discards pending changes, as does switching to a type to which change does not apply.
+ if (!is_connected() || !change_event_applies()) {
+ m_has_uncommitted_changes = false;
+ return;
+ }
+ if (m_has_uncommitted_changes)
+ commit_pending_changes();
}
void HTMLInputElement::form_associated_element_attribute_changed(Utf16FlyString const& name, Optional<Utf16String> const& old_value, Optional<Utf16String> const& value, Optional<Utf16FlyString> const& namespace_)
diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h
index de436c58dfb..80ca019e082 100644
--- a/Libraries/LibWeb/HTML/HTMLInputElement.h
+++ b/Libraries/LibWeb/HTML/HTMLInputElement.h
@@ -270,7 +270,7 @@ public:
// ^FormAssociatedTextControlElement
virtual HTMLElement& text_control_to_html_element() override { return *this; }
- virtual void did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data) override;
+ virtual void did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data, Utf16View previous_value) override;
virtual GC::Ptr<DOM::Text> form_associated_element_to_text_node() override { return m_text_node; }
virtual GC::Ptr<DOM::Element> text_control_scroll_container() override { return m_inner_text_element; }
diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
index d6947823c3b..ff6b154eccc 100644
--- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.cpp
@@ -83,6 +83,13 @@ void HTMLTextAreaElement::did_lose_focus()
if (m_placeholder_text_node)
m_placeholder_text_node->set_needs_repaint(InvalidateDisplayList::PaintCommands);
+ // NB: Consume the pending edit before dispatch, including removal, so reentrant focus changes cannot commit it again.
+ if (!m_value_before_first_user_edit.has_value())
+ return;
+ auto value_before_first_user_edit = m_value_before_first_user_edit.release_value();
+ if (!is_connected() || value_before_first_user_edit == api_value())
+ return;
+
// The change event fires when the value is committed, if that makes sense for the control,
// or else when the control loses focus
auto change_event = DOM::Event::create(
@@ -105,6 +112,7 @@ void HTMLTextAreaElement::reset_algorithm()
// The reset algorithm for textarea elements is to set the user validity to false, the dirty value flag back to false,
m_user_validity = false;
m_dirty_value = false;
+ m_value_before_first_user_edit.clear();
// and the raw value to its child text content.
set_raw_value(child_text_content());
@@ -124,7 +132,11 @@ void HTMLTextAreaElement::clear_algorithm()
m_dirty_value = false;
// and set the raw value of element to an empty string.
+ if (!m_value_before_first_user_edit.has_value())
+ m_value_before_first_user_edit = api_value();
set_raw_value({});
+ if (*m_value_before_first_user_edit == api_value())
+ m_value_before_first_user_edit.clear();
// Unlike their associated reset algorithms, changes made to form controls as part of these algorithms do count as
// changes caused by the user (and thus, e.g. do cause input events to fire).
@@ -486,10 +498,23 @@ void HTMLTextAreaElement::form_associated_element_attribute_changed(Utf16FlyStri
CSS::Invalidation::invalidate_style_after_validity_change(*this);
}
-void HTMLTextAreaElement::did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data)
+void HTMLTextAreaElement::record_user_edit(Utf16View previous_value)
+{
+ // NB: set_range_text() already updated the raw value, so callers supply the pre-edit value.
+ if (!m_value_before_first_user_edit.has_value())
+ m_value_before_first_user_edit = Utf16String::from_utf16(previous_value);
+ if (*m_value_before_first_user_edit == api_value())
+ m_value_before_first_user_edit.clear();
+}
+
+void HTMLTextAreaElement::did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data, Utf16View previous_value)
{
VERIFY(m_text_node);
set_raw_value(m_text_node->data());
+ record_user_edit(previous_value);
+
+ // A textarea element's dirty value flag must be set to true whenever the user interacts with the control in a way that changes the raw value.
+ m_dirty_value = true;
// AD-HOC: Editing the value may change which validity pseudo-classes match.
CSS::Invalidation::invalidate_style_after_validity_change(*this);
@@ -507,9 +532,6 @@ void HTMLTextAreaElement::did_edit_text_node(Utf16FlyString const& input_type, O
auto input_event = UIEvents::InputEvent::create_from_platform_event(HTML::EventNames::input, input_event_init, {}, HighResolutionTime::current_high_resolution_time(relevant_global_object(*this)));
dispatch_event(input_event);
- // A textarea element's dirty value flag must be set to true whenever the user interacts with the control in a way that changes the raw value.
- m_dirty_value = true;
-
update_placeholder_visibility();
}
diff --git a/Libraries/LibWeb/HTML/HTMLTextAreaElement.h b/Libraries/LibWeb/HTML/HTMLTextAreaElement.h
index 41b06ec9e20..cd37b388309 100644
--- a/Libraries/LibWeb/HTML/HTMLTextAreaElement.h
+++ b/Libraries/LibWeb/HTML/HTMLTextAreaElement.h
@@ -130,7 +130,8 @@ public:
// ^FormAssociatedTextControlElement
virtual HTMLElement& text_control_to_html_element() override { return *this; }
- virtual void did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data) override;
+ virtual void did_edit_text_node(Utf16FlyString const& input_type, Optional<Utf16String> const& data, Utf16View previous_value) override;
+ void record_user_edit(Utf16View previous_value);
virtual GC::Ptr<DOM::Text> form_associated_element_to_text_node() override { return m_text_node; }
virtual GC::Ptr<DOM::Element> text_control_scroll_container() override { return this; }
@@ -182,6 +183,9 @@ private:
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-api-value
mutable Optional<Utf16String> m_api_value;
+
+ // NB: A missing value means that no uncommitted user edit remains.
+ Optional<Utf16String> m_value_before_first_user_edit;
};
}
diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/layout-flight-focus-fixup.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/layout-flight-focus-fixup.txt
new file mode 100644
index 00000000000..7d8f662a1f9
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/layout-flight-focus-fixup.txt
@@ -0,0 +1,5 @@
+state in the next task: laying-out
+update finished, active element: button
+animation frame, active element: button
+blur
+active element: BODY
diff --git a/Tests/LibWeb/Text/expected/css/child-state-pseudo-invalidation.txt b/Tests/LibWeb/Text/expected/css/child-state-pseudo-invalidation.txt
index 075ed748608..d31723f4aa9 100644
--- a/Tests/LibWeb/Text/expected/css/child-state-pseudo-invalidation.txt
+++ b/Tests/LibWeb/Text/expected/css/child-state-pseudo-invalidation.txt
@@ -1,7 +1,7 @@
focus old before append: rgb(0, 128, 0)
focus new before append: rgb(0, 0, 0)
focus old after append: rgb(0, 0, 0)
-focus new after append: rgb(0, 128, 0)
+focus new after append: rgb(0, 0, 0)
focus new after remove: rgb(0, 0, 0)
focus move old before moveBefore: rgb(0, 128, 0)
focus move new before moveBefore: rgb(0, 0, 0)
@@ -10,11 +10,11 @@ focus move new after moveBefore: rgb(0, 128, 0)
focus fragment old before append: rgb(0, 128, 0)
focus fragment new before append: rgb(0, 0, 0)
focus fragment old after append: rgb(0, 0, 0)
-focus fragment new after append: rgb(0, 128, 0)
+focus fragment new after append: rgb(0, 0, 0)
focus pseudo old before append: focus
focus pseudo new before append: none
focus pseudo old after append: none
-focus pseudo new after append: focus
+focus pseudo new after append: none
focus pseudo new after remove: none
focus pseudo move old before moveBefore: focus
focus pseudo move new before moveBefore: none
@@ -25,13 +25,13 @@ focus pseudo move new after moveBefore back: none
focus pseudo fragment old before append: focus
focus pseudo fragment new before append: none
focus pseudo fragment old after append: none
-focus pseudo fragment new after append: focus
-focus pseudo fragment old after moveBefore back: focus
+focus pseudo fragment new after append: none
+focus pseudo fragment old after moveBefore back: none
focus pseudo fragment new after moveBefore back: none
shadow focus pseudo old before append: shadow focus
shadow focus pseudo new before append: none
shadow focus pseudo old after append: none
-shadow focus pseudo new after append: shadow focus
+shadow focus pseudo new after append: none
shadow focus pseudo new after remove: none
shadow focus pseudo move old before moveBefore: shadow focus
shadow focus pseudo move new before moveBefore: none
@@ -42,8 +42,8 @@ shadow focus pseudo move new after moveBefore back: none
shadow focus pseudo fragment old before append: shadow focus
shadow focus pseudo fragment new before append: none
shadow focus pseudo fragment old after append: none
-shadow focus pseudo fragment new after append: shadow focus
-shadow focus pseudo fragment old after moveBefore back: shadow focus
+shadow focus pseudo fragment new after append: none
+shadow focus pseudo fragment old after moveBefore back: none
shadow focus pseudo fragment new after moveBefore back: none
hover old before append: rgb(255, 0, 0)
hover new before append: rgb(255, 255, 255)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-display-none-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-display-none-001.txt
index 405a00c83a8..9397f2e4486 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-display-none-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-display-none-001.txt
@@ -2,6 +2,6 @@ Harness status: OK
Found 2 tests
-2 Fail
-Fail Test ':focus' after 'display:none' on input
-Fail Test ':focus' after 'display:none' on input's parent
\ No newline at end of file
+2 Pass
+Pass Test ':focus' after 'display:none' on input
+Pass Test ':focus' after 'display:none' on input's parent
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-009.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-009.txt
index 45545f65ac0..009b280d095 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-009.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-009.txt
@@ -2,17 +2,16 @@ Harness status: OK
Found 12 tests
-9 Pass
-3 Fail
+12 Pass
Pass Initial State
Pass Focus 'target1'
Pass Focus 'target2'
Pass Focus 'target1' again
Pass Focus 'target2' again
Pass Focus 'target1' once again
-Fail Detach 'container1' from the document
-Fail Try to focus 'target1'
+Pass Detach 'container1' from the document
+Pass Try to focus 'target1'
Pass Focus 'target2' once again
Pass Attach 'container1' in 'container2'
Pass Focus 'target1' for the last time
-Fail Move 'target1' in 'container2'
\ No newline at end of file
+Pass Move 'target1' in 'container2'
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-display-none-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-display-none-001.txt
index 0ed07b8421f..f9ad7fbcca5 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-display-none-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/selectors/focus-within-display-none-001.txt
@@ -2,6 +2,6 @@ Harness status: OK
Found 2 tests
-2 Fail
-Fail Test ':focus-within' after 'display:none' on input
-Fail Test ':focus-within' after 'display:none' on input's parent
\ No newline at end of file
+2 Pass
+Pass Test ':focus-within' after 'display:none' on input
+Pass Test ':focus-within' after 'display:none' on input's parent
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-preserve.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-preserve.txt
index 7cff4eca7c5..faa3c557ac8 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-preserve.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-preserve.txt
@@ -2,10 +2,9 @@ Harness status: OK
Found 5 tests
-2 Pass
-3 Fail
+5 Pass
Pass moveBefore() preserves focus when the focused element remains focusable
Pass moveBefore() preserves focus and a backward selection in a text input
-Fail Focus is fixed up after moveBefore() moves the focused element into an inert subtree
-Fail Focus is fixed up after moveBefore() moves the focused element into a hidden parent
-Fail Focus is fixed up after moveBefore() moves an ancestor of the focused element into a hidden parent
\ No newline at end of file
+Pass Focus is fixed up after moveBefore() moves the focused element into an inert subtree
+Pass Focus is fixed up after moveBefore() moves the focused element into a hidden parent
+Pass Focus is fixed up after moveBefore() moves an ancestor of the focused element into a hidden parent
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-within.txt b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-within.txt
index 37eff9dffdc..83f13ddcd23 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-within.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/dom/nodes/moveBefore/focus-within.txt
@@ -2,10 +2,9 @@ Harness status: OK
Found 5 tests
-3 Pass
-2 Fail
+5 Pass
Pass focus-within should be updated when reparenting focused element directly
Pass focus-within should be updated when reparenting an element that has focus within
Pass focus-within should remain the same when moving to the same parent
-Fail :focus-within should be eventually up to date when moving to an inert subtree
-Fail :focus-within should be eventually up to date when moving to a subtree that would become inert via style
\ No newline at end of file
+Pass :focus-within should be eventually up to date when moving to an inert subtree
+Pass :focus-within should be eventually up to date when moving to a subtree that would become inert via style
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/active-element.txt b/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/active-element.txt
index 078fb02dc23..a6c63d21439 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/active-element.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/active-element.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 3 tests
-1 Pass
-2 Fail
+3 Pass
Pass activeElement initially starts as the document body
-Fail activeElement gets set to a focused element and reset to the body when the focused element disappears
-Fail re-adding the formerly active element to the document does not make it active again
\ No newline at end of file
+Pass activeElement gets set to a focused element and reset to the body when the focused element disappears
+Pass re-adding the formerly active element to the document does not make it active again
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/focused-area-removal.txt b/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/focused-area-removal.txt
index 49720149b96..8d5181631cc 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/focused-area-removal.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/editing/focus/focus-management/focused-area-removal.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail removing the activeElement keeps focus on its document
\ No newline at end of file
+1 Pass
+Pass removing the activeElement keeps focus on its document
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.txt b/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.txt
index bd4b7f219e6..fb20de56a70 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/interaction/focus/processing-model/focus-fixup-rule-one-no-dialogs.txt
@@ -2,114 +2,114 @@ Harness status: OK
Found 110 tests
-110 Fail
-Fail #button1
-Fail #button2
-Fail #button3
-Fail #button4
-Fail #button5
-Fail #div
-Fail #editable
-Fail #button6
-Fail Textarea untouched: change events after becoming hidden
-Fail Textarea untouched: change events after becoming disabled
-Fail Textarea untouched: change events after becoming inert
-Fail Textarea programmatic value: change events after becoming hidden
-Fail Textarea programmatic value: change events after becoming disabled
-Fail Textarea programmatic value: change events after becoming inert
-Fail Textarea programmatic defaultValue: change events after becoming hidden
-Fail Textarea programmatic defaultValue: change events after becoming disabled
-Fail Textarea programmatic defaultValue: change events after becoming inert
-Fail Textarea user edit: change events after becoming hidden
-Fail Textarea user edit: change events after becoming disabled
-Fail Textarea user edit: change events after becoming inert
-Fail Textarea reverted user edit: change events after becoming hidden
-Fail Textarea reverted user edit: change events after becoming disabled
-Fail Textarea reverted user edit: change events after becoming inert
-Fail Textarea programmatic value followed by user edit: change events after becoming hidden
-Fail Textarea programmatic value followed by user edit: change events after becoming disabled
-Fail Textarea programmatic value followed by user edit: change events after becoming inert
-Fail Textarea user edit with an input handler changing defaultValue: change events after becoming hidden
-Fail Textarea user edit with an input handler changing defaultValue: change events after becoming disabled
-Fail Textarea user edit with an input handler changing defaultValue: change events after becoming inert
-Fail Textarea user edit followed by form reset: change events after becoming hidden
-Fail Textarea user edit followed by form reset: change events after becoming disabled
-Fail Textarea user edit followed by form reset: change events after becoming inert
-Fail Textarea removal discards its pending change before reinsertion
-Fail Cloning an edited textarea does not copy its pending change
-Fail Untouched input type=text: no change after becoming hidden
-Fail Untouched input type=text: no change after becoming disabled
-Fail Untouched input type=text: no change after becoming inert
-Fail Untouched input type=search: no change after becoming hidden
-Fail Untouched input type=search: no change after becoming disabled
-Fail Untouched input type=search: no change after becoming inert
-Fail Untouched input type=tel: no change after becoming hidden
-Fail Untouched input type=tel: no change after becoming disabled
-Fail Untouched input type=tel: no change after becoming inert
-Fail Untouched input type=url: no change after becoming hidden
-Fail Untouched input type=url: no change after becoming disabled
-Fail Untouched input type=url: no change after becoming inert
-Fail Untouched input type=email: no change after becoming hidden
-Fail Untouched input type=email: no change after becoming disabled
-Fail Untouched input type=email: no change after becoming inert
-Fail Untouched input type=password: no change after becoming hidden
-Fail Untouched input type=password: no change after becoming disabled
-Fail Untouched input type=password: no change after becoming inert
-Fail Untouched input type=date: no change after becoming hidden
-Fail Untouched input type=date: no change after becoming disabled
-Fail Untouched input type=date: no change after becoming inert
-Fail Untouched input type=month: no change after becoming hidden
-Fail Untouched input type=month: no change after becoming disabled
-Fail Untouched input type=month: no change after becoming inert
-Fail Untouched input type=week: no change after becoming hidden
-Fail Untouched input type=week: no change after becoming disabled
-Fail Untouched input type=week: no change after becoming inert
-Fail Untouched input type=time: no change after becoming hidden
-Fail Untouched input type=time: no change after becoming disabled
-Fail Untouched input type=time: no change after becoming inert
-Fail Untouched input type=datetime-local: no change after becoming hidden
-Fail Untouched input type=datetime-local: no change after becoming disabled
-Fail Untouched input type=datetime-local: no change after becoming inert
-Fail Untouched input type=number: no change after becoming hidden
-Fail Untouched input type=number: no change after becoming disabled
-Fail Untouched input type=number: no change after becoming inert
-Fail Untouched input type=range: no change after becoming hidden
-Fail Untouched input type=range: no change after becoming disabled
-Fail Untouched input type=range: no change after becoming inert
-Fail Untouched input type=color: no change after becoming hidden
-Fail Untouched input type=color: no change after becoming disabled
-Fail Untouched input type=color: no change after becoming inert
-Fail Untouched input type=checkbox: no change after becoming hidden
-Fail Untouched input type=checkbox: no change after becoming disabled
-Fail Untouched input type=checkbox: no change after becoming inert
-Fail Untouched input type=radio: no change after becoming hidden
-Fail Untouched input type=radio: no change after becoming disabled
-Fail Untouched input type=radio: no change after becoming inert
-Fail Untouched input type=file: no change after becoming hidden
-Fail Untouched input type=file: no change after becoming disabled
-Fail Untouched input type=file: no change after becoming inert
-Fail Untouched input type=submit: no change after becoming hidden
-Fail Untouched input type=submit: no change after becoming disabled
-Fail Untouched input type=submit: no change after becoming inert
-Fail Untouched input type=image: no change after becoming hidden
-Fail Untouched input type=image: no change after becoming disabled
-Fail Untouched input type=image: no change after becoming inert
-Fail Untouched input type=reset: no change after becoming hidden
-Fail Untouched input type=reset: no change after becoming disabled
-Fail Untouched input type=reset: no change after becoming inert
-Fail Untouched input type=button: no change after becoming hidden
-Fail Untouched input type=button: no change after becoming disabled
-Fail Untouched input type=button: no change after becoming inert
-Fail Programmatic text input value: no change after becoming hidden
-Fail User-edited text input: one change after becoming hidden
-Fail User-edited range input: one change after becoming hidden
-Fail Programmatic text input value: no change after becoming disabled
-Fail User-edited text input: one change after becoming disabled
-Fail User-edited range input: one change after becoming disabled
-Fail Programmatic text input value: no change after becoming inert
-Fail User-edited text input: one change after becoming inert
-Fail User-edited range input: one change after becoming inert
-Fail Text input removal discards its pending change before reinsertion
-Fail Changing an edited input to hidden discards its pending change
-Fail Textarea undo after a committed edit creates a new pending change
-Fail Textarea redo after a committed edit creates a new pending change
\ No newline at end of file
+110 Pass
+Pass #button1
+Pass #button2
+Pass #button3
+Pass #button4
+Pass #button5
+Pass #div
+Pass #editable
+Pass #button6
+Pass Textarea untouched: change events after becoming hidden
+Pass Textarea untouched: change events after becoming disabled
+Pass Textarea untouched: change events after becoming inert
+Pass Textarea programmatic value: change events after becoming hidden
+Pass Textarea programmatic value: change events after becoming disabled
+Pass Textarea programmatic value: change events after becoming inert
+Pass Textarea programmatic defaultValue: change events after becoming hidden
+Pass Textarea programmatic defaultValue: change events after becoming disabled
+Pass Textarea programmatic defaultValue: change events after becoming inert
+Pass Textarea user edit: change events after becoming hidden
+Pass Textarea user edit: change events after becoming disabled
+Pass Textarea user edit: change events after becoming inert
+Pass Textarea reverted user edit: change events after becoming hidden
+Pass Textarea reverted user edit: change events after becoming disabled
+Pass Textarea reverted user edit: change events after becoming inert
+Pass Textarea programmatic value followed by user edit: change events after becoming hidden
+Pass Textarea programmatic value followed by user edit: change events after becoming disabled
+Pass Textarea programmatic value followed by user edit: change events after becoming inert
+Pass Textarea user edit with an input handler changing defaultValue: change events after becoming hidden
+Pass Textarea user edit with an input handler changing defaultValue: change events after becoming disabled
+Pass Textarea user edit with an input handler changing defaultValue: change events after becoming inert
+Pass Textarea user edit followed by form reset: change events after becoming hidden
+Pass Textarea user edit followed by form reset: change events after becoming disabled
+Pass Textarea user edit followed by form reset: change events after becoming inert
+Pass Textarea removal discards its pending change before reinsertion
+Pass Cloning an edited textarea does not copy its pending change
+Pass Untouched input type=text: no change after becoming hidden
+Pass Untouched input type=text: no change after becoming disabled
+Pass Untouched input type=text: no change after becoming inert
+Pass Untouched input type=search: no change after becoming hidden
+Pass Untouched input type=search: no change after becoming disabled
+Pass Untouched input type=search: no change after becoming inert
+Pass Untouched input type=tel: no change after becoming hidden
+Pass Untouched input type=tel: no change after becoming disabled
+Pass Untouched input type=tel: no change after becoming inert
+Pass Untouched input type=url: no change after becoming hidden
+Pass Untouched input type=url: no change after becoming disabled
+Pass Untouched input type=url: no change after becoming inert
+Pass Untouched input type=email: no change after becoming hidden
+Pass Untouched input type=email: no change after becoming disabled
+Pass Untouched input type=email: no change after becoming inert
+Pass Untouched input type=password: no change after becoming hidden
+Pass Untouched input type=password: no change after becoming disabled
+Pass Untouched input type=password: no change after becoming inert
+Pass Untouched input type=date: no change after becoming hidden
+Pass Untouched input type=date: no change after becoming disabled
+Pass Untouched input type=date: no change after becoming inert
+Pass Untouched input type=month: no change after becoming hidden
+Pass Untouched input type=month: no change after becoming disabled
+Pass Untouched input type=month: no change after becoming inert
+Pass Untouched input type=week: no change after becoming hidden
+Pass Untouched input type=week: no change after becoming disabled
+Pass Untouched input type=week: no change after becoming inert
+Pass Untouched input type=time: no change after becoming hidden
+Pass Untouched input type=time: no change after becoming disabled
+Pass Untouched input type=time: no change after becoming inert
+Pass Untouched input type=datetime-local: no change after becoming hidden
+Pass Untouched input type=datetime-local: no change after becoming disabled
+Pass Untouched input type=datetime-local: no change after becoming inert
+Pass Untouched input type=number: no change after becoming hidden
+Pass Untouched input type=number: no change after becoming disabled
+Pass Untouched input type=number: no change after becoming inert
+Pass Untouched input type=range: no change after becoming hidden
+Pass Untouched input type=range: no change after becoming disabled
+Pass Untouched input type=range: no change after becoming inert
+Pass Untouched input type=color: no change after becoming hidden
+Pass Untouched input type=color: no change after becoming disabled
+Pass Untouched input type=color: no change after becoming inert
+Pass Untouched input type=checkbox: no change after becoming hidden
+Pass Untouched input type=checkbox: no change after becoming disabled
+Pass Untouched input type=checkbox: no change after becoming inert
+Pass Untouched input type=radio: no change after becoming hidden
+Pass Untouched input type=radio: no change after becoming disabled
+Pass Untouched input type=radio: no change after becoming inert
+Pass Untouched input type=file: no change after becoming hidden
+Pass Untouched input type=file: no change after becoming disabled
+Pass Untouched input type=file: no change after becoming inert
+Pass Untouched input type=submit: no change after becoming hidden
+Pass Untouched input type=submit: no change after becoming disabled
+Pass Untouched input type=submit: no change after becoming inert
+Pass Untouched input type=image: no change after becoming hidden
+Pass Untouched input type=image: no change after becoming disabled
+Pass Untouched input type=image: no change after becoming inert
+Pass Untouched input type=reset: no change after becoming hidden
+Pass Untouched input type=reset: no change after becoming disabled
+Pass Untouched input type=reset: no change after becoming inert
+Pass Untouched input type=button: no change after becoming hidden
+Pass Untouched input type=button: no change after becoming disabled
+Pass Untouched input type=button: no change after becoming inert
+Pass Programmatic text input value: no change after becoming hidden
+Pass User-edited text input: one change after becoming hidden
+Pass User-edited range input: one change after becoming hidden
+Pass Programmatic text input value: no change after becoming disabled
+Pass User-edited text input: one change after becoming disabled
+Pass User-edited range input: one change after becoming disabled
+Pass Programmatic text input value: no change after becoming inert
+Pass User-edited text input: one change after becoming inert
+Pass User-edited range input: one change after becoming inert
+Pass Text input removal discards its pending change before reinsertion
+Pass Changing an edited input to hidden discards its pending change
+Pass Textarea undo after a committed edit creates a new pending change
+Pass Textarea redo after a committed edit creates a new pending change
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/inert/dynamic-inert-on-focused-element.txt b/Tests/LibWeb/Text/expected/wpt-import/inert/dynamic-inert-on-focused-element.txt
index 271e35e1d66..37717baf05c 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/inert/dynamic-inert-on-focused-element.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/inert/dynamic-inert-on-focused-element.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 6 tests
-6 Fail
-Fail <input> that gets 'inert' attribute
-Fail <input> whose parent gets 'inert' attribute
-Fail <button> that gets 'inert' attribute
-Fail <div> that gets 'inert' attribute
-Fail <div> whose parent gets 'inert' attribute
-Fail <div> whose grandparent gets 'inert' attribute
\ No newline at end of file
+6 Pass
+Pass <input> that gets 'inert' attribute
+Pass <input> whose parent gets 'inert' attribute
+Pass <button> that gets 'inert' attribute
+Pass <div> that gets 'inert' attribute
+Pass <div> whose parent gets 'inert' attribute
+Pass <div> whose grandparent gets 'inert' attribute
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/ShadowRoot-interface.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/ShadowRoot-interface.txt
index 24fb3fe962f..cef15b75274 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/ShadowRoot-interface.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/ShadowRoot-interface.txt
@@ -2,13 +2,12 @@ Harness status: OK
Found 12 tests
-10 Pass
-2 Fail
+12 Pass
Pass Check the existence of ShadowRoot interface
Pass ShadowRoot must inherit from DocumentFragment
Pass ShadowRoot must not be a constructor
-Fail ShadowRoot.activeElement must return the focused element of the context object when shadow root is open.
-Fail ShadowRoot.activeElement must return the focused element of the context object when shadow root is closed.
+Pass ShadowRoot.activeElement must return the focused element of the context object when shadow root is open.
+Pass ShadowRoot.activeElement must return the focused element of the context object when shadow root is closed.
Pass ShadowRoot.host must return the shadow host of the context object.
Pass ShadowRoot.innerHTML must return the result of the HTML fragment serialization algorithm when shadow root is open.
Pass ShadowRoot.innerHTML must return the result of the HTML fragment serialization algorithm when shadow root is closed.
diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/layout-flight-focus-fixup.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/layout-flight-focus-fixup.html
new file mode 100644
index 00000000000..b5b7657fb80
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/layout-flight-focus-fixup.html
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script src="frame-in-flight.js"></script>
+<style>
+ #box { width: 100px; height: 10px; color: rgb(0, 0, 255); }
+ #box.wide { width: 200px; color: rgb(0, 128, 0); }
+</style>
+<div id="box"></div>
+<button id="button">button</button>
+<script>
+ // A task beside a rendering update whose layout flies comes after the whole of the update: the rest of it does not
+ // fix up a control the task focused and then disabled. The next rendering update does, after its animation frame
+ // callbacks.
+ asyncTest(async done => {
+ const events = [];
+ button.addEventListener("blur", () => events.push("blur"));
+ await twoFramesLanded();
+ requestAnimationFrame(() => {
+ internals.holdNextFrame("layout");
+ internals.setManualRenderingOpportunities(true);
+ box.classList.add("wide");
+ });
+ await nextFrame();
+ while (internals.frameSchedulerState() !== "laying-out")
+ await nextTask();
+ await nextTask();
+ println(`state in the next task: ${internals.frameSchedulerState()}`);
+ button.focus();
+ button.disabled = true;
+ requestAnimationFrame(() => events.push(`animation frame, active element: ${document.activeElement.id}`));
+ internals.releaseHeldFrame();
+ while (internals.frameSchedulerState() !== "idle")
+ await nextTask();
+ events.push(`update finished, active element: ${document.activeElement.id}`);
+ internals.setManualRenderingOpportunities(false);
+ await twoFrames();
+ for (const event of events)
+ println(event);
+ println(`active element: ${document.activeElement.tagName}`);
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/css/style-invalidation/has-structural-feature-filter.html b/Tests/LibWeb/Text/input/css/style-invalidation/has-structural-feature-filter.html
index 78995a4c9a7..9cde6698aa8 100644
--- a/Tests/LibWeb/Text/input/css/style-invalidation/has-structural-feature-filter.html
+++ b/Tests/LibWeb/Text/input/css/style-invalidation/has-structural-feature-filter.html
@@ -490,6 +490,7 @@
}
}
+ // Reparent focused controls with moveBefore; appendChild removes them and clears their focus.
const unprobeablePseudoCases = [
{
name: "child :focus insertion with unrelated metadata",
@@ -500,7 +501,7 @@
input.focus({ preventScroll: true });
return { input };
},
- mutate: ({ anchor, input }) => anchor.appendChild(input),
+ mutate: ({ anchor, input }) => anchor.moveBefore(input, null),
},
{
name: "descendant :focus insertion through wrapper with unrelated metadata",
@@ -513,7 +514,7 @@
input.focus({ preventScroll: true });
return { wrapper };
},
- mutate: ({ anchor, wrapper }) => anchor.appendChild(wrapper),
+ mutate: ({ anchor, wrapper }) => anchor.moveBefore(wrapper, null),
},
{
name: "child :focus-within insertion with unrelated metadata",
@@ -526,7 +527,7 @@
input.focus({ preventScroll: true });
return { wrapper };
},
- mutate: ({ anchor, wrapper }) => anchor.appendChild(wrapper),
+ mutate: ({ anchor, wrapper }) => anchor.moveBefore(wrapper, null),
},
{
name: "child :focus-visible insertion with unrelated metadata",
@@ -537,7 +538,7 @@
input.focus({ preventScroll: true });
return { input };
},
- mutate: ({ anchor, input }) => anchor.appendChild(input),
+ mutate: ({ anchor, input }) => anchor.moveBefore(input, null),
},
{
name: "child :default checkbox insertion with unrelated metadata",
@@ -594,7 +595,7 @@
input.focus({ preventScroll: true });
return { input };
},
- mutate: ({ anchor, input }) => anchor.appendChild(input),
+ mutate: ({ anchor, input }) => anchor.moveBefore(input, null),
},
{
name: "child :where(:invalid) insertion with unrelated metadata",