Skip to content

Truly independent web browser

LibWeb: Implement the CSS Custom Highlight API interfaces

Andreas Klinga0d4f4f31da6
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 80e148e55a7..dbcc1d94935 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -173,6 +173,8 @@ set(SOURCES
CSS/FontFaceSet.cpp
CSS/FontFaceSetLoadEvent.cpp
CSS/Frequency.cpp
+ CSS/Highlight.cpp
+ CSS/HighlightRegistry.cpp
CSS/HypotheticalElement.cpp
CSS/Invalidation/AdoptedStyleSheetInvalidator.cpp
CSS/Invalidation/AttributeInvalidator.cpp
diff --git a/Libraries/LibWeb/CSS/BindingsGlue.h b/Libraries/LibWeb/CSS/BindingsGlue.h
index 3354233ab90..5711782695a 100644
--- a/Libraries/LibWeb/CSS/BindingsGlue.h
+++ b/Libraries/LibWeb/CSS/BindingsGlue.h
@@ -29,6 +29,8 @@ class CSSFontFeatureValuesMap;
class FontFace;
class FontFaceState;
class FontFaceSet;
+class Highlight;
+class HighlightRegistry;
}
@@ -55,4 +57,18 @@ WEB_API void did_add_font_face(CSS::FontFaceSet const&, NonnullRefPtr<CSS::FontF
WEB_API void did_remove_font_face(CSS::FontFaceSet const&, NonnullRefPtr<CSS::FontFaceState>);
WEB_API void did_reorder_font_faces(CSS::FontFaceSet const&, Vector<NonnullRefPtr<CSS::FontFaceState>> const&);
+WEB_API GC::Ref<JS::Set> setlike_entries(JS::Realm&, WrapperWorld const&, CSS::Highlight const&);
+WEB_API bool setlike_has(CSS::Highlight const&, JS::Value);
+WEB_API void setlike_add(CSS::Highlight&, JS::Value);
+WEB_API bool setlike_remove(CSS::Highlight&, JS::Value);
+WEB_API void setlike_clear(CSS::Highlight&);
+WEB_API void setlike_on_set_modified_from_js(CSS::Highlight&);
+
+WEB_API GC::Ref<JS::Map> map_entries(JS::Realm&, CSS::HighlightRegistry&);
+WEB_API Optional<JS::Value> map_get(JS::Realm&, CSS::HighlightRegistry&, Utf16View key);
+WEB_API bool map_has(CSS::HighlightRegistry&, Utf16View key);
+WEB_API bool map_remove(CSS::HighlightRegistry&, Utf16View key);
+WEB_API void map_clear(CSS::HighlightRegistry&);
+WEB_API WebIDL::ExceptionOr<void> set(JS::Realm&, CSS::HighlightRegistry&, Utf16String const& key, JS::Value);
+
}
diff --git a/Libraries/LibWeb/CSS/CSS.cpp b/Libraries/LibWeb/CSS/CSS.cpp
index a05844d5abf..b8efd6267af 100644
--- a/Libraries/LibWeb/CSS/CSS.cpp
+++ b/Libraries/LibWeb/CSS/CSS.cpp
@@ -10,12 +10,15 @@
#include <LibWeb/CSS/CSS.h>
#include <LibWeb/CSS/CSSUnitValue.h>
#include <LibWeb/CSS/CustomPropertyRegistration.h>
+#include <LibWeb/CSS/HighlightRegistry.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/Parser/SyntaxParsing.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/PropertyNameAndID.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/DOM/Document.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Window.h>
namespace Web::CSS {
@@ -150,4 +153,13 @@ WebIDL::ExceptionOr<void> register_property(DOM::Document& document, PropertyDef
return {};
}
+// https://drafts.csswg.org/css-highlight-api-1/#dom-css-highlights
+GC::Ref<HighlightRegistry> highlights(JS::VM&)
+{
+ // The highlight registry is accessed via the highlights attribute of the CSS namespace, and represents all the
+ // custom highlights registered for the current global object’s associated Document.
+ auto& window = HTML::relevant_window(HTML::current_global_object());
+ return window.associated_document().highlight_registry();
+}
+
}
diff --git a/Libraries/LibWeb/CSS/CSS.h b/Libraries/LibWeb/CSS/CSS.h
index 93769309e42..b7fa1c0b6ca 100644
--- a/Libraries/LibWeb/CSS/CSS.h
+++ b/Libraries/LibWeb/CSS/CSS.h
@@ -30,6 +30,8 @@ WEB_API WebIDL::ExceptionOr<bool> supports(JS::VM&, Utf16View condition_text);
WEB_API WebIDL::ExceptionOr<void> register_property(DOM::Document&, PropertyDefinition const&);
+WEB_API GC::Ref<HighlightRegistry> highlights(JS::VM&);
+
// NB: Numeric factory functions (https://drafts.css-houdini.org/css-typed-om-1/#numeric-factory) are generated,
// see GenerateCSSNumericFactoryMethods.cpp
diff --git a/Libraries/LibWeb/CSS/CSS.idl b/Libraries/LibWeb/CSS/CSS.idl
index 6473aaa54a1..eb268bac268 100644
--- a/Libraries/LibWeb/CSS/CSS.idl
+++ b/Libraries/LibWeb/CSS/CSS.idl
@@ -24,6 +24,11 @@ partial namespace CSS {
[ImplementedInBindings] undefined registerProperty(PropertyDefinition definition);
};
+// https://drafts.csswg.org/css-highlight-api-1/#registration
+partial namespace CSS {
+ readonly attribute HighlightRegistry highlights;
+};
+
// https://drafts.css-houdini.org/css-typed-om-1/#numeric-factory
// NB: Extensions to the CSS namepace are generated by generate_libweb_css_numeric_factory_methods.py.
diff --git a/Libraries/LibWeb/CSS/Highlight.cpp b/Libraries/LibWeb/CSS/Highlight.cpp
new file mode 100644
index 00000000000..458fb8b8513
--- /dev/null
+++ b/Libraries/LibWeb/CSS/Highlight.cpp
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibGC/Heap.h>
+#include <LibJS/Runtime/Set.h>
+#include <LibWeb/Bindings/Highlight.h>
+#include <LibWeb/Bindings/WrapperWorld.h>
+#include <LibWeb/CSS/BindingsGlue.h>
+#include <LibWeb/CSS/Highlight.h>
+#include <LibWeb/DOM/AbstractRange.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
+
+namespace Web::CSS {
+
+GC_DEFINE_ALLOCATOR(Highlight);
+
+// https://drafts.csswg.org/css-highlight-api-1/#dom-highlight-highlight
+GC::Ref<Highlight> Highlight::construct_impl(GC::RootVector<GC::Ref<DOM::AbstractRange>> const& initial_ranges)
+{
+ // 1. Let highlight be the new Highlight object.
+ auto highlight = GC::Heap::the().allocate<Highlight>();
+
+ // 2. Set highlight’s priority to 0.
+ highlight->m_priority = 0;
+
+ // 3. Set highlight’s type to highlight.
+ highlight->m_type = HighlightType::Highlight;
+
+ // 4. For each range of initialRanges, let rangeArg be the result of converting range to an ECMAScript value,
+ // then run the steps for a built-in setlike add function, with highlight as the this value, and rangeArg as
+ // the argument.
+ // NB: highlight has no wrapper yet, so there are no set entries in any world to update.
+ for (auto range : initial_ranges)
+ highlight->add_range(range);
+
+ // 5. Return highlight.
+ return highlight;
+}
+
+Highlight::Highlight() = default;
+
+void Highlight::visit_edges(GC::Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ for (auto range : m_ranges)
+ visitor.visit(range);
+}
+
+bool Highlight::has_range(DOM::AbstractRange& range) const
+{
+ return m_ranges.contains(GC::Ref { range });
+}
+
+void Highlight::add_range(GC::Ref<DOM::AbstractRange> range)
+{
+ m_ranges.set(range, AK::HashSetExistingEntryBehavior::Keep);
+}
+
+bool Highlight::remove_range(DOM::AbstractRange& range)
+{
+ return m_ranges.remove(GC::Ref { range });
+}
+
+void Highlight::clear_ranges()
+{
+ m_ranges.clear();
+}
+
+}
+
+namespace Web::Bindings {
+
+static WrapperWorldWeakValueCacheMap<CSS::Highlight const, JS::Set>& highlight_set_caches()
+{
+ static NeverDestroyed<WrapperWorldWeakValueCacheMap<CSS::Highlight const, JS::Set>> caches;
+ return *caches;
+}
+
+static WrapperWorldWeakValueCache<JS::Set>& highlight_set_cache_for(CSS::Highlight const& highlight)
+{
+ return highlight_set_caches().cache_for(highlight);
+}
+
+static DOM::AbstractRange& range_from_set_value(JS::Value value)
+{
+ auto* range = Bindings::impl_from<DOM::AbstractRange>(&value.as_object());
+ VERIFY(range);
+ return *range;
+}
+
+static JS::Value wrap_range(JS::Realm& realm, DOM::AbstractRange& range)
+{
+ return Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, GC::Ref { range });
+}
+
+GC::Ref<JS::Set> setlike_entries(JS::Realm& realm, WrapperWorld const& wrapper_world, CSS::Highlight const& highlight)
+{
+ auto& cache = highlight_set_cache_for(highlight);
+ if (auto set_entries = cache.get(wrapper_world))
+ return *set_entries;
+
+ auto set_entries = GC::make_root(JS::Set::create(realm));
+ for (auto range : highlight.ranges())
+ set_entries->set_add(wrap_range(realm, *range));
+ cache.set(wrapper_world, set_entries.ptr());
+ return GC::Ref { *set_entries };
+}
+
+bool setlike_has(CSS::Highlight const& highlight, JS::Value value)
+{
+ return highlight.has_range(range_from_set_value(value));
+}
+
+void setlike_add(CSS::Highlight& highlight, JS::Value value)
+{
+ auto& range = range_from_set_value(value);
+ highlight.add_range(range);
+ highlight_set_cache_for(highlight).for_each([&](auto& set_entries) {
+ set_entries.set_add(wrap_range(HTML::relevant_realm(set_entries), range));
+ });
+}
+
+bool setlike_remove(CSS::Highlight& highlight, JS::Value value)
+{
+ auto& range = range_from_set_value(value);
+ auto removed = highlight.remove_range(range);
+ if (removed) {
+ highlight_set_cache_for(highlight).for_each([&](auto& set_entries) {
+ set_entries.set_remove(wrap_range(HTML::relevant_realm(set_entries), range));
+ });
+ }
+ return removed;
+}
+
+void setlike_clear(CSS::Highlight& highlight)
+{
+ highlight.clear_ranges();
+ highlight_set_cache_for(highlight).for_each([&](auto& set_entries) {
+ set_entries.set_clear();
+ });
+}
+
+void setlike_on_set_modified_from_js(CSS::Highlight&)
+{
+ // FIXME: https://drafts.csswg.org/css-highlight-api-1/#repaint
+ // The addition or removal of a range in a registered custom highlight must cause the user agent to
+ // reevaluate the rendering, and to repaint if appropriate. We do not paint custom highlights yet.
+}
+
+}
diff --git a/Libraries/LibWeb/CSS/Highlight.h b/Libraries/LibWeb/CSS/Highlight.h
new file mode 100644
index 00000000000..830b24af7db
--- /dev/null
+++ b/Libraries/LibWeb/CSS/Highlight.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/HashTable.h>
+#include <LibGC/RootVector.h>
+#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Export.h>
+#include <LibWeb/Forward.h>
+#include <LibWebCommon/Bindings/Highlight.h>
+#include <LibWebCommon/WebIDL/Types.h>
+
+namespace Web::CSS {
+
+using HighlightType = Bindings::HighlightType;
+
+// https://drafts.csswg.org/css-highlight-api-1/#highlight
+class WEB_API Highlight final : public Bindings::GCAllocatedWrappable {
+ WEB_WRAPPABLE(Highlight, Bindings::GCAllocatedWrappable);
+ GC_DECLARE_ALLOCATOR(Highlight);
+
+public:
+ static GC::Ref<Highlight> construct_impl(GC::RootVector<GC::Ref<DOM::AbstractRange>> const& initial_ranges);
+ virtual ~Highlight() override = default;
+
+ WebIDL::Long priority() const { return m_priority; }
+ void set_priority(WebIDL::Long priority) { m_priority = priority; }
+
+ HighlightType type() const { return m_type; }
+ void set_type(HighlightType type) { m_type = type; }
+
+ // The set entries of this setlike object, in insertion order.
+ OrderedHashTable<GC::Ref<DOM::AbstractRange>> const& ranges() const { return m_ranges; }
+ bool has_range(DOM::AbstractRange&) const;
+ void add_range(GC::Ref<DOM::AbstractRange>);
+ bool remove_range(DOM::AbstractRange&);
+ void clear_ranges();
+
+private:
+ Highlight();
+
+ virtual void visit_edges(GC::Cell::Visitor&) override;
+
+ OrderedHashTable<GC::Ref<DOM::AbstractRange>> m_ranges;
+ WebIDL::Long m_priority { 0 };
+ HighlightType m_type { HighlightType::Highlight };
+};
+
+}
diff --git a/Libraries/LibWeb/CSS/Highlight.idl b/Libraries/LibWeb/CSS/Highlight.idl
new file mode 100644
index 00000000000..bc6ddab0d9b
--- /dev/null
+++ b/Libraries/LibWeb/CSS/Highlight.idl
@@ -0,0 +1,15 @@
+// https://drafts.csswg.org/css-highlight-api-1/#enumdef-highlighttype
+enum HighlightType {
+ "highlight",
+ "spelling-error",
+ "grammar-error"
+};
+
+// https://drafts.csswg.org/css-highlight-api-1/#highlight
+[Exposed=Window]
+interface Highlight {
+ constructor(AbstractRange... initialRanges);
+ setlike<AbstractRange>;
+ attribute long priority;
+ attribute HighlightType type;
+};
diff --git a/Libraries/LibWeb/CSS/HighlightRegistry.cpp b/Libraries/LibWeb/CSS/HighlightRegistry.cpp
new file mode 100644
index 00000000000..bff5ed0c444
--- /dev/null
+++ b/Libraries/LibWeb/CSS/HighlightRegistry.cpp
@@ -0,0 +1,283 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/QuickSort.h>
+#include <LibGC/Heap.h>
+#include <LibJS/Runtime/Map.h>
+#include <LibJS/Runtime/PrimitiveString.h>
+#include <LibWeb/Bindings/Highlight.h>
+#include <LibWeb/Bindings/HighlightRegistry.h>
+#include <LibWeb/Bindings/WrapperWorld.h>
+#include <LibWeb/CSS/BindingsGlue.h>
+#include <LibWeb/CSS/Highlight.h>
+#include <LibWeb/CSS/HighlightRegistry.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/DOM/Range.h>
+#include <LibWeb/DOM/ShadowRoot.h>
+#include <LibWeb/DOM/StaticRange.h>
+#include <LibWeb/DOM/Utils.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/Layout/RenderDocument.h>
+#include <LibWeb/Painting/HitTestResult.h>
+
+namespace Web::CSS {
+
+GC_DEFINE_ALLOCATOR(HighlightRegistry);
+
+GC::Ref<HighlightRegistry> HighlightRegistry::create(DOM::Document& document)
+{
+ return GC::Heap::the().allocate<HighlightRegistry>(document);
+}
+
+HighlightRegistry::HighlightRegistry(DOM::Document& document)
+ : m_document(document)
+{
+}
+
+void HighlightRegistry::visit_edges(GC::Cell::Visitor& visitor)
+{
+ Base::visit_edges(visitor);
+ visitor.visit(m_document);
+ for (auto& entry : m_highlights)
+ visitor.visit(entry.value);
+}
+
+GC::Ptr<Highlight> HighlightRegistry::get_highlight(Utf16View name) const
+{
+ auto highlight = m_highlights.get(Utf16String::from_utf16(name));
+ if (!highlight.has_value())
+ return {};
+ return *highlight;
+}
+
+bool HighlightRegistry::has_highlight(Utf16View name) const
+{
+ return m_highlights.contains(Utf16String::from_utf16(name));
+}
+
+void HighlightRegistry::set_highlight(Utf16String name, GC::Ref<Highlight> highlight)
+{
+ // FIXME: https://drafts.csswg.org/css-highlight-api-1/#repaint
+ // The addition or removal of a custom highlight in the highlight registry must cause the user agent to
+ // reevaluate the rendering, and to repaint if appropriate. We do not paint custom highlights yet.
+ m_highlights.set(move(name), highlight);
+}
+
+bool HighlightRegistry::remove_highlight(Utf16View name)
+{
+ return m_highlights.remove(Utf16String::from_utf16(name));
+}
+
+void HighlightRegistry::clear_highlights()
+{
+ m_highlights.clear();
+}
+
+static bool shadow_root_is_contained_by_options(DOM::ShadowRoot const& shadow_root, Bindings::HighlightsFromPointOptions const& options)
+{
+ for (auto const& allowed_shadow_root : options.shadow_roots) {
+ if (allowed_shadow_root.ptr() == &shadow_root)
+ return true;
+ }
+ return false;
+}
+
+// https://drafts.csswg.org/css-highlight-api-1/#dom-highlightregistry-highlightsfrompoint
+GC::ConservativeVector<Bindings::HighlightHitResult> HighlightRegistry::highlights_from_point(float x, float y, Bindings::HighlightsFromPointOptions const& options)
+{
+ auto& document = *m_document;
+
+ // 1. If any of the following are true, return the empty sequence:
+ // * x is negative
+ // * y is negative
+ // * x is greater than the viewport width excluding the size of a rendered scroll bar (if any)
+ // * y is greater than the viewport height excluding the size of a rendered scroll bar (if any)
+ // FIXME: This should account for the size of the scroll bar.
+ auto viewport_rect = document.viewport_rect();
+ CSSPixelPoint position { x, y };
+ if (x < 0 || y < 0 || position.x() > viewport_rect.width() || position.y() > viewport_rect.height())
+ return {};
+
+ // * The topmost box in the viewport in paint order that would be a target for hit testing at coordinates x,y
+ // when applying the transforms that apply to the descendants of the viewport, has an element associated to
+ // it that's in a shadow tree whose shadow root is not contained by options.shadowRoots.
+ {
+ document.update_layout(DOM::UpdateLayoutReason::HighlightRegistryHighlightsFromPoint);
+ Layout::ForcedReadScope read { document };
+ GC::Ptr<DOM::Element> hit_element;
+ (void)document.hit_test_all(read, position, [&](Painting::HitTestResult result) {
+ auto* node = result.dom_node();
+ if (!node)
+ return TraversalDecision::Continue;
+ hit_element = is<DOM::Element>(*node) ? static_cast<DOM::Element*>(node) : node->parent_element();
+ return TraversalDecision::Break;
+ });
+ if (hit_element) {
+ // AD-HOC: If the element is inside a UA internal shadow root, retarget to the host, as elementFromPoint()
+ // does. UA internal shadow roots can never be passed in options.shadowRoots.
+ hit_element = DOM::retarget_from_ua_internal_shadow_root(*hit_element);
+ if (auto* shadow_root = as_if<DOM::ShadowRoot>(hit_element->root()); shadow_root && !shadow_root_is_contained_by_options(*shadow_root, options))
+ return {};
+ }
+ }
+
+ // 2. Otherwise, let results be an empty sequence.
+ struct ResultWithRegistrationIndex {
+ Bindings::HighlightHitResult result;
+ WebIDL::Long priority;
+ size_t registration_index;
+ };
+ GC::ConservativeVector<ResultWithRegistrationIndex> results;
+
+ // 3. For each Highlight highlight in this HighlightRegistry:
+ size_t registration_index = 0;
+ for (auto const& entry : m_highlights) {
+ auto highlight = entry.value;
+
+ // 1. Let result be a new HighlightHitResult with highlight set to highlight.
+ Bindings::HighlightHitResult result;
+ result.highlight = highlight;
+ GC::RootVector<GC::Ref<DOM::AbstractRange>> ranges;
+
+ // 2. For each AbstractRange abstractRange in highlight:
+ for (auto abstract_range : highlight->ranges()) {
+ // 1. If abstractRange is an invalid StaticRange, then continue.
+ if (auto* static_range = as_if<DOM::StaticRange>(*abstract_range); static_range && !static_range->is_valid())
+ continue;
+
+ // 2. Let range be a new Range whose start node and end node are set to abstractRange’s start node and end
+ // node respectively, and start offset and end offset are set to abstractRange’s start offset and end
+ // offset respectively.
+ // OPTIMIZATION: A live Range already has these boundary points, so we use it instead of creating a new live
+ // Range that every DOM mutation would have to update until it is collected.
+ GC::Ptr<DOM::Range> range = as_if<DOM::Range>(*abstract_range);
+ if (!range)
+ range = DOM::Range::create(abstract_range->start_container(), abstract_range->start_offset(), abstract_range->end_container(), abstract_range->end_offset());
+
+ // 3. If the coordinates x,y fall inside at least one of the DOMRects returned by calling getClientRects()
+ // on range, then append abstractRange to result.ranges.
+ // NB: A rect is treated as half-open, so that the empty rect of a collapsed range is never hit.
+ auto client_rects = range->client_rects();
+ auto is_hit = any_of(client_rects, [&](Gfx::DoubleRect const& rect) {
+ return x >= rect.left() && x < rect.right() && y >= rect.top() && y < rect.bottom();
+ });
+ if (is_hit)
+ ranges.append(abstract_range);
+ }
+
+ // 3. If result.ranges is not empty, append result to results.
+ if (!ranges.is_empty()) {
+ result.ranges = move(ranges);
+ results.append({ move(result), highlight->priority(), registration_index });
+ }
+ ++registration_index;
+ }
+
+ // 4. Sort results by descending order of priority of its HighlightHitResults' highlight attributes.
+ // NB: When two or more custom highlights have the same numerical priority, the one most recently registered has
+ // the higher effective priority.
+ quick_sort(results, [](auto const& a, auto const& b) {
+ if (a.priority != b.priority)
+ return a.priority > b.priority;
+ return a.registration_index > b.registration_index;
+ });
+
+ // 5. Return results.
+ GC::ConservativeVector<Bindings::HighlightHitResult> sorted_results;
+ sorted_results.ensure_capacity(results.size());
+ for (auto& result : results)
+ sorted_results.unchecked_append(move(result.result));
+ return sorted_results;
+}
+
+}
+
+namespace Web::Bindings {
+
+static WrapperWorldWeakValueCacheMap<CSS::HighlightRegistry, JS::Map>& highlight_registry_caches()
+{
+ static NeverDestroyed<WrapperWorldWeakValueCacheMap<CSS::HighlightRegistry, JS::Map>> caches;
+ return *caches;
+}
+
+static WrapperWorldWeakValueCache<JS::Map>& entries_cache_for(CSS::HighlightRegistry& registry)
+{
+ return highlight_registry_caches().cache_for(registry);
+}
+
+static void set_map_entry(JS::Map& map_entries, Utf16View name, CSS::Highlight& highlight)
+{
+ auto& map_realm = HTML::relevant_realm(map_entries);
+ auto key = GC::make_root(JS::PrimitiveString::create(map_realm.vm(), name));
+ JS::Value value = Bindings::wrap(Bindings::host_defined_wrapper_world(map_realm), map_realm, GC::Ref { highlight });
+ map_entries.map_set(JS::Value { key.ptr() }, value);
+}
+
+static void remove_map_entry(JS::Map& map_entries, Utf16View name)
+{
+ auto& map_realm = HTML::relevant_realm(map_entries);
+ auto key = GC::make_root(JS::PrimitiveString::create(map_realm.vm(), name));
+ map_entries.map_remove(JS::Value { key.ptr() });
+}
+
+GC::Ref<JS::Map> map_entries(JS::Realm& realm, CSS::HighlightRegistry& registry)
+{
+ auto& wrapper_world = host_defined_wrapper_world(realm);
+ auto& cache = entries_cache_for(registry);
+ if (auto map_entries = cache.get(wrapper_world))
+ return *map_entries;
+
+ auto map_entries = GC::make_root(JS::Map::create(realm));
+ for (auto const& entry : registry.highlights())
+ set_map_entry(*map_entries, entry.key, *entry.value);
+ cache.set(wrapper_world, map_entries.ptr());
+ return GC::Ref { *map_entries };
+}
+
+Optional<JS::Value> map_get(JS::Realm& realm, CSS::HighlightRegistry& registry, Utf16View key)
+{
+ auto highlight = registry.get_highlight(key);
+ if (!highlight)
+ return {};
+ return JS::Value { Bindings::wrap(host_defined_wrapper_world(realm), realm, GC::Ref { *highlight }) };
+}
+
+bool map_has(CSS::HighlightRegistry& registry, Utf16View key)
+{
+ return registry.has_highlight(key);
+}
+
+bool map_remove(CSS::HighlightRegistry& registry, Utf16View key)
+{
+ auto removed = registry.remove_highlight(key);
+ if (removed) {
+ entries_cache_for(registry).for_each([&](auto& map_entries) {
+ remove_map_entry(map_entries, key);
+ });
+ }
+ return removed;
+}
+
+void map_clear(CSS::HighlightRegistry& registry)
+{
+ registry.clear_highlights();
+ entries_cache_for(registry).for_each([&](auto& map_entries) {
+ map_entries.map_clear();
+ });
+}
+
+WebIDL::ExceptionOr<void> set(JS::Realm&, CSS::HighlightRegistry& registry, Utf16String const& key, JS::Value value)
+{
+ auto* highlight = Bindings::impl_from<CSS::Highlight>(&value.as_object());
+ VERIFY(highlight);
+ registry.set_highlight(key, *highlight);
+ entries_cache_for(registry).for_each([&](auto& map_entries) {
+ set_map_entry(map_entries, key, *highlight);
+ });
+ return {};
+}
+
+}
diff --git a/Libraries/LibWeb/CSS/HighlightRegistry.h b/Libraries/LibWeb/CSS/HighlightRegistry.h
new file mode 100644
index 00000000000..eb9d1be636e
--- /dev/null
+++ b/Libraries/LibWeb/CSS/HighlightRegistry.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/HashMap.h>
+#include <AK/Utf16String.h>
+#include <LibGC/ConservativeVector.h>
+#include <LibWeb/Bindings/HighlightRegistry.h>
+#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWeb/Export.h>
+#include <LibWeb/Forward.h>
+
+namespace Web::CSS {
+
+// https://drafts.csswg.org/css-highlight-api-1/#highlightregistry
+class WEB_API HighlightRegistry final : public Bindings::GCAllocatedWrappable {
+ WEB_WRAPPABLE(HighlightRegistry, Bindings::GCAllocatedWrappable);
+ GC_DECLARE_ALLOCATOR(HighlightRegistry);
+
+public:
+ [[nodiscard]] static GC::Ref<HighlightRegistry> create(DOM::Document&);
+ virtual ~HighlightRegistry() override = default;
+
+ // The map entries of this maplike object, in insertion order.
+ OrderedHashMap<Utf16String, GC::Ref<Highlight>> const& highlights() const { return m_highlights; }
+ GC::Ptr<Highlight> get_highlight(Utf16View name) const;
+ bool has_highlight(Utf16View name) const;
+ void set_highlight(Utf16String name, GC::Ref<Highlight>);
+ bool remove_highlight(Utf16View name);
+ void clear_highlights();
+
+ GC::ConservativeVector<Bindings::HighlightHitResult> highlights_from_point(float x, float y, Bindings::HighlightsFromPointOptions const&);
+
+private:
+ explicit HighlightRegistry(DOM::Document&);
+
+ virtual void visit_edges(GC::Cell::Visitor&) override;
+
+ GC::Ref<DOM::Document> m_document;
+ OrderedHashMap<Utf16String, GC::Ref<Highlight>> m_highlights;
+};
+
+}
diff --git a/Libraries/LibWeb/CSS/HighlightRegistry.idl b/Libraries/LibWeb/CSS/HighlightRegistry.idl
new file mode 100644
index 00000000000..1a9bb066f11
--- /dev/null
+++ b/Libraries/LibWeb/CSS/HighlightRegistry.idl
@@ -0,0 +1,19 @@
+// https://drafts.csswg.org/css-highlight-api-1/#highlightregistry
+[Exposed=Window]
+interface HighlightRegistry {
+ maplike<DOMString, Highlight>;
+};
+
+// https://drafts.csswg.org/css-highlight-api-1/#interactions
+partial interface HighlightRegistry {
+ sequence<HighlightHitResult> highlightsFromPoint(float x, float y, optional HighlightsFromPointOptions options = {});
+};
+
+dictionary HighlightHitResult {
+ Highlight highlight;
+ sequence<AbstractRange> ranges;
+};
+
+dictionary HighlightsFromPointOptions {
+ sequence<ShadowRoot> shadowRoots = [];
+};
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index ad6d7bfbe28..bf4787e4b73 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -59,6 +59,7 @@
#include <LibWeb/CSS/CustomPropertyRegistration.h>
#include <LibWeb/CSS/FontComputer.h>
#include <LibWeb/CSS/FontFaceSet.h>
+#include <LibWeb/CSS/HighlightRegistry.h>
#include <LibWeb/CSS/HypotheticalElement.h>
#include <LibWeb/CSS/Invalidation/AdoptedStyleSheetInvalidator.h>
#include <LibWeb/CSS/Invalidation/ElementStateInvalidator.h>
@@ -986,6 +987,7 @@ void Document::visit_edges(Cell::Visitor& visitor)
visitor.visit(m_scripts);
visitor.visit(m_all);
visitor.visit(m_fonts);
+ visitor.visit(m_highlight_registry);
visitor.visit(m_selection);
visitor.visit(m_find_in_page_active_match);
visitor.visit(m_find_in_page_highlighted_matches);
@@ -3590,6 +3592,13 @@ GC::Ref<CSS::FontFaceSet> Document::fonts()
return m_fonts;
}
+GC::Ref<CSS::HighlightRegistry> Document::highlight_registry()
+{
+ if (!m_highlight_registry)
+ m_highlight_registry = CSS::HighlightRegistry::create(*this);
+ return *m_highlight_registry;
+}
+
// https://html.spec.whatwg.org/multipage/obsolete.html#dom-document-clear
void Document::clear()
{
@@ -9509,17 +9518,6 @@ WebIDL::ExceptionOr<void> Document::set_design_mode(Utf16View design_mode)
return {};
}
-static Element* retarget_from_ua_internal_shadow_root(Element& element)
-{
- auto* result = &element;
- while (auto shadow_root = result->containing_shadow_root()) {
- if (!shadow_root->is_user_agent_internal())
- break;
- result = shadow_root->host();
- }
- return result;
-}
-
// https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint
Element const* Document::element_from_point(double x, double y)
{
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 2464778afd6..edb802e364a 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -182,6 +182,7 @@ enum class InvalidateLayoutTreeReason {
X(HTMLInputElementHeight, true) \
X(HTMLInputElementWidth, true) \
X(HTMLLabelElementActivationBehavior, false) \
+ X(HighlightRegistryHighlightsFromPoint, false) \
X(InspectAccessibilityTree, false) \
X(InspectDOMTree, false) \
X(InspectDevToolsLayoutData, false) \
@@ -656,6 +657,7 @@ public:
// https://drafts.csswg.org/css-font-loading/#font-source
GC::Ref<CSS::FontFaceSet> fonts();
+ GC::Ref<CSS::HighlightRegistry> highlight_registry();
void clear();
void capture_events();
@@ -2095,6 +2097,9 @@ private:
// https://drafts.csswg.org/css-font-loading/#font-source
GC::Ref<CSS::FontFaceSet> m_fonts;
+ // https://drafts.csswg.org/css-highlight-api-1/#highlight-registry
+ GC::Ptr<CSS::HighlightRegistry> m_highlight_registry;
+
// https://html.spec.whatwg.org/multipage/document-lifecycle.html#completely-loaded-time
Optional<AK::UnixDateTime> m_completely_loaded_time;
bool m_completely_loaded_deferred { false };
diff --git a/Libraries/LibWeb/DOM/StaticRange.cpp b/Libraries/LibWeb/DOM/StaticRange.cpp
index b90c8144f56..1bf4b233087 100644
--- a/Libraries/LibWeb/DOM/StaticRange.cpp
+++ b/Libraries/LibWeb/DOM/StaticRange.cpp
@@ -10,6 +10,7 @@
#include <LibWeb/Bindings/StaticRange.h>
#include <LibWeb/DOM/Attr.h>
#include <LibWeb/DOM/DocumentType.h>
+#include <LibWeb/DOM/Range.h>
#include <LibWeb/DOM/StaticRange.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
@@ -38,4 +39,25 @@ WebIDL::ExceptionOr<GC::Ref<StaticRange>> StaticRange::create(Bindings::StaticRa
return GC::Heap::the().allocate<StaticRange>(*init.start_container, init.start_offset, *init.end_container, init.end_offset);
}
+// https://dom.spec.whatwg.org/#staticrange-valid
+bool StaticRange::is_valid() const
+{
+ // A StaticRange is valid if all of the following are true:
+
+ // - Its start and end are in the same node tree.
+ if (&start_container()->root() != &end_container()->root())
+ return false;
+
+ // - Its start offset is between 0 and its start node’s length, inclusive.
+ if (start_offset() > start_container()->length())
+ return false;
+
+ // - Its end offset is between 0 and its end node’s length, inclusive.
+ if (end_offset() > end_container()->length())
+ return false;
+
+ // - Its start is before or equal to its end.
+ return position_of_boundary_point_relative_to_other_boundary_point(start(), end()) != RelativeBoundaryPointPosition::After;
+}
+
}
diff --git a/Libraries/LibWeb/DOM/StaticRange.h b/Libraries/LibWeb/DOM/StaticRange.h
index a81da850f90..724f391682b 100644
--- a/Libraries/LibWeb/DOM/StaticRange.h
+++ b/Libraries/LibWeb/DOM/StaticRange.h
@@ -26,6 +26,8 @@ public:
StaticRange(Node& start_container, u32 start_offset, Node& end_container, u32 end_offset);
virtual ~StaticRange() override;
+
+ bool is_valid() const;
};
}
diff --git a/Libraries/LibWeb/DOM/Utils.cpp b/Libraries/LibWeb/DOM/Utils.cpp
index 0582a365a6b..372913a1000 100644
--- a/Libraries/LibWeb/DOM/Utils.cpp
+++ b/Libraries/LibWeb/DOM/Utils.cpp
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <LibWeb/DOM/Element.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/DOM/Node.h>
#include <LibWeb/DOM/ShadowRoot.h>
@@ -38,4 +39,15 @@ EventTarget* retarget(EventTarget* a, EventTarget* b)
}
}
+Element* retarget_from_ua_internal_shadow_root(Element& element)
+{
+ auto* result = &element;
+ while (auto shadow_root = result->containing_shadow_root()) {
+ if (!shadow_root->is_user_agent_internal())
+ break;
+ result = shadow_root->host();
+ }
+ return result;
+}
+
}
diff --git a/Libraries/LibWeb/DOM/Utils.h b/Libraries/LibWeb/DOM/Utils.h
index 416e532c6e2..68612b14037 100644
--- a/Libraries/LibWeb/DOM/Utils.h
+++ b/Libraries/LibWeb/DOM/Utils.h
@@ -8,9 +8,11 @@
#pragma once
#include <LibWeb/DOM/EventTarget.h>
+#include <LibWeb/Forward.h>
namespace Web::DOM {
EventTarget* retarget(EventTarget* a, EventTarget* b);
+Element* retarget_from_ua_internal_shadow_root(Element&);
}
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 12e5f8ba39e..4a36c14d397 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -322,6 +322,8 @@ class Frequency;
class FrequencyPercentage;
class FrequencyStyleValue;
class FunctionStyleValue;
+class Highlight;
+class HighlightRegistry;
class HueRotateFilterStyleValue;
class ImageSetStyleValue;
class ImageStyleValue;
diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake
index c1ac03b7886..ee8a032e389 100644
--- a/Libraries/LibWeb/idl_files.cmake
+++ b/Libraries/LibWeb/idl_files.cmake
@@ -95,6 +95,8 @@ libweb_js_bindings(CSS/FontFaceSet)
libweb_js_bindings(CSS/FontFaceSetLoadEvent)
libweb_js_bindings(CSS/GeneratedCSSNumericFactoryMethods)
libweb_js_bindings(CSS/GeneratedCSSStyleProperties)
+libweb_js_bindings(CSS/Highlight)
+libweb_js_bindings(CSS/HighlightRegistry)
libweb_js_bindings(CSS/LinkStyle)
libweb_js_bindings(CSS/MediaList)
libweb_js_bindings(CSS/MediaQueryList)
diff --git a/Meta/Linters/check_libweb_realm_mentions.py b/Meta/Linters/check_libweb_realm_mentions.py
index 415c4eb9aa7..64e4c522d33 100755
--- a/Meta/Linters/check_libweb_realm_mentions.py
+++ b/Meta/Linters/check_libweb_realm_mentions.py
@@ -36,7 +36,7 @@ CHECKED_SUFFIXES = {
# the same change. If it goes up, justify the architecture change here.
ALLOWED_REALM_MENTIONS = {
"Animations": (5, 14, "animation callbacks/events and CSS value materialization still pass spec-selected realms"),
- "CSS": (7, 19, "CSS Typed OM, parser-facing reification, and style-value JS materialization"),
+ "CSS": (9, 24, "CSS Typed OM, parser-facing reification, style-value JS materialization, and setlike/maplike glue"),
"Clipboard": (4, 16, "clipboard item/data callbacks still materialize JS values in caller-selected realms"),
"ContentSecurityPolicy": (4, 14, "CSP violation/report objects and callbacks still materialize JS-facing values"),
"CookieStore": (2, 19, "cookie-store async callbacks and promise/value materialization still thread realms"),
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index e9517099595..49e8b551406 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -399,6 +399,7 @@ Text/input/wpt-import/css/css-animations/idlharness.html
Text/input/wpt-import/css/css-conditional/idlharness.html
Text/input/wpt-import/css/css-counter-styles/idlharness.html
Text/input/wpt-import/css/css-fonts/idlharness.html
+Text/input/wpt-import/css/css-highlight-api/idlharness.window.html
Text/input/wpt-import/css/css-transitions/idlharness.html
Text/input/wpt-import/css/css-typed-om/idlharness.html
Text/input/wpt-import/css/cssom-view/idlharness.html
diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt
index fc76e13f556..2e992c8b053 100644
--- a/Tests/LibWeb/Text/expected/all-window-properties.txt
+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt
@@ -273,6 +273,8 @@ HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
Headers
+Highlight
+HighlightRegistry
History
IDBCursor
IDBCursorWithValue
diff --git a/Tests/LibWeb/Text/expected/css/highlights-from-point-form-control.txt b/Tests/LibWeb/Text/expected/css/highlights-from-point-form-control.txt
new file mode 100644
index 00000000000..fd2d5d9c0b0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/highlights-from-point-form-control.txt
@@ -0,0 +1,6 @@
+input: elementFromPoint is the control: true
+input: results: 1
+input: highlight matches: true, ranges: 1
+textarea: elementFromPoint is the control: true
+textarea: results: 1
+textarea: highlight matches: true, ranges: 1
diff --git a/Tests/LibWeb/Text/expected/namespace-objects-default-property-attributes.txt b/Tests/LibWeb/Text/expected/namespace-objects-default-property-attributes.txt
index 987fe8116d2..6249bbe2b63 100644
--- a/Tests/LibWeb/Text/expected/namespace-objects-default-property-attributes.txt
+++ b/Tests/LibWeb/Text/expected/namespace-objects-default-property-attributes.txt
@@ -1,4 +1,7 @@
== CSS property descriptors
+highlights writable: undefined
+highlights configurable: true
+highlights enumerable: true
escape writable: true
escape configurable: true
escape enumerable: true
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txt
index c8fb3019255..1ca6b90f8a3 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration-with-modifications.txt
@@ -2,10 +2,10 @@ Harness status: OK
Found 6 tests
-6 Fail
-Fail Highlight iteration includes ranges added after starting the iteration (Set-like behavior)
-Fail Highlight iteration includes ranges added after starting the iteration when there were already ranges (Set-like behavior)
-Fail Highlight iteration skips ranges deleted before being visited (Set-like behavior)
-Fail Highlight iteration skips ranges deleted before being visited even when other ranges remain (Set-like behavior)
-Fail Highlight iteration is not modified when a range that was already visited is deleted and there are still ranges to visit
-Fail Highlight iteration skips all ranges when .clear() is called before visiting them (Set-like behavior)
\ No newline at end of file
+6 Pass
+Pass Highlight iteration includes ranges added after starting the iteration (Set-like behavior)
+Pass Highlight iteration includes ranges added after starting the iteration when there were already ranges (Set-like behavior)
+Pass Highlight iteration skips ranges deleted before being visited (Set-like behavior)
+Pass Highlight iteration skips ranges deleted before being visited even when other ranges remain (Set-like behavior)
+Pass Highlight iteration is not modified when a range that was already visited is deleted and there are still ranges to visit
+Pass Highlight iteration skips all ranges when .clear() is called before visiting them (Set-like behavior)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txt
index 6bc0845be58..4221df83935 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-iteration.txt
@@ -2,29 +2,29 @@ Harness status: OK
Found 25 tests
-25 Fail
-Fail Highlight can be iterated when it's empty initializing the iterator with customHighlight[Symbol.iterator]()
-Fail Highlight can be iterated when it's empty initializing the iterator with customHighlight.values()
-Fail Highlight can be iterated when it's empty initializing the iterator with customHighlight.keys()
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding a range by passing it to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding two ranges by passing them to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding a range by passing it to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding two ranges by passing them to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding a range by passing it to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding two ranges by passing them to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding a range by passing it to the add function
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding two ranges by passing them to the add function
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding a range by passing it to the add function
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding two ranges by passing them to the add function
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding a range by passing it to the add function
-Fail Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding two ranges by passing them to the add function
-Fail Highlight can be iterated when it's empty initializing the iterator with .entries()
-Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the constructor
-Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the add function
-Fail Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the add function
-Fail Highlight can be iterated through when it's empty using forEach.
-Fail Highlight can be iterated through using forEach when it has one range that was added by passing it to the constructor
-Fail Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the constructor
-Fail Highlight can be iterated through using forEach when it has one range that was added by passing it to the add function
-Fail Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the add function
\ No newline at end of file
+25 Pass
+Pass Highlight can be iterated when it's empty initializing the iterator with customHighlight[Symbol.iterator]()
+Pass Highlight can be iterated when it's empty initializing the iterator with customHighlight.values()
+Pass Highlight can be iterated when it's empty initializing the iterator with customHighlight.keys()
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding a range by passing it to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding two ranges by passing them to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding a range by passing it to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding two ranges by passing them to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding a range by passing it to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding two ranges by passing them to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding a range by passing it to the add function
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight[Symbol.iterator]() and adding two ranges by passing them to the add function
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding a range by passing it to the add function
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.values() and adding two ranges by passing them to the add function
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding a range by passing it to the add function
+Pass Highlight can be iterated over all of its ranges initializing the iterator with customHighlight.keys() and adding two ranges by passing them to the add function
+Pass Highlight can be iterated when it's empty initializing the iterator with .entries()
+Pass Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the constructor
+Pass Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding a range by passing it to the add function
+Pass Highlight can be iterated over all of its ranges initializing the iterator with .entries() and adding two ranges by passing them to the add function
+Pass Highlight can be iterated through when it's empty using forEach.
+Pass Highlight can be iterated through using forEach when it has one range that was added by passing it to the constructor
+Pass Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the constructor
+Pass Highlight can be iterated through using forEach when it has one range that was added by passing it to the add function
+Pass Highlight can be iterated through using forEach when it has two ranges that were added by passing them to the add function
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txt
index 22618176b2a..4905f0fb535 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-multiple-type-attribute.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Highlight type has a limited set of types
\ No newline at end of file
+1 Pass
+Pass Highlight type has a limited set of types
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txt
index c777dcc5092..1db470cb0b6 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike-tampered-Set-prototype.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Highlight is a setlike interface that works as expected even if Set.prototype is tampered.
\ No newline at end of file
+1 Pass
+Pass Highlight is a setlike interface that works as expected even if Set.prototype is tampered.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txt
index a111d661bf9..2191ec3152d 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/Highlight-setlike.txt
@@ -2,33 +2,33 @@ Harness status: OK
Found 29 tests
-29 Fail
-Fail Highlight initializes empty (if no ranges are provided) and with priority 0.
-Fail Highlight add and has methods work as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight add method is chainable (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight delete method works as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight clear method works as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])
-Fail Highlight add and has methods work as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight add method is chainable (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight delete method works as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight clear method works as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
-Fail Highlight add and has methods work as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight add method is chainable (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight delete method works as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight clear method works as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
-Fail Highlight add and has methods work as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
-Fail Highlight add method is chainable (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
-Fail Highlight delete method works as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
-Fail Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
-Fail Highlight constructor works as expected when called with one range (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
-Fail Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
-Fail Highlight clear method works as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
\ No newline at end of file
+29 Pass
+Pass Highlight initializes empty (if no ranges are provided) and with priority 0.
+Pass Highlight add and has methods work as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight add method is chainable (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight delete method works as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight constructor works as expected when called with one range (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight clear method works as expected (using the following combination of ranges [[object Range], [object Range], [object Range]])
+Pass Highlight add and has methods work as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight add method is chainable (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight delete method works as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight constructor works as expected when called with one range (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight clear method works as expected (using the following combination of ranges [[object StaticRange], [object StaticRange], [object StaticRange]])
+Pass Highlight add and has methods work as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight add method is chainable (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight delete method works as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight constructor works as expected when called with one range (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight clear method works as expected (using the following combination of ranges [[object Range], [object StaticRange], [object Range]])
+Pass Highlight add and has methods work as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
+Pass Highlight add method is chainable (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
+Pass Highlight delete method works as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
+Pass Highlight constructor behaves like a set when using equal ranges (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
+Pass Highlight constructor works as expected when called with one range (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
+Pass Highlight constructor works as expected when called with two ranges (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
+Pass Highlight clear method works as expected (using the following combination of ranges [[object StaticRange], [object Range], [object StaticRange]])
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txt
index 3a1f804d49b..652992b41ac 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint-ranges.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail CSS.highlights.highlightsFromPoint() returns HighlightHitResults with the Highlights and their corresponding Ranges and StaticRanges present at the given point in the right order on multi-line text.
\ No newline at end of file
+1 Pass
+Pass CSS.highlights.highlightsFromPoint() returns HighlightHitResults with the Highlights and their corresponding Ranges and StaticRanges present at the given point in the right order on multi-line text.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txt
index fa4b6a08990..3e84bb05dac 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-highlightsFromPoint.txt
@@ -2,13 +2,12 @@ Harness status: OK
Found 8 tests
-1 Pass
-7 Fail
+8 Pass
Pass CSS.highlights.highlightsFromPoint() should throw when called with incorrect parameters.
-Fail CSS.highlights.highlightsFromPoint() should return an empty array when called with a point outside the document.
-Fail CSS.highlights.highlightsFromPoint() returns the Highlights with their corresponding ranges present at the given point in the right order.
-Fail CSS.highlights.highlightsFromPoint() returns empty array when called on a display:none iframe document.
-Fail CSS.highlights.highlightsFromPoint() returns empty array for coordinates outside the viewport.
-Fail CSS.highlights.highlightsFromPoint() does not return highlights with only collapsed ranges.
-Fail CSS.highlights.highlightsFromPoint() skips invalid StaticRanges.
-Fail CSS.highlights.highlightsFromPoint() returns all overlapping ranges within the same highlight.
\ No newline at end of file
+Pass CSS.highlights.highlightsFromPoint() should return an empty array when called with a point outside the document.
+Pass CSS.highlights.highlightsFromPoint() returns the Highlights with their corresponding ranges present at the given point in the right order.
+Pass CSS.highlights.highlightsFromPoint() returns empty array when called on a display:none iframe document.
+Pass CSS.highlights.highlightsFromPoint() returns empty array for coordinates outside the viewport.
+Pass CSS.highlights.highlightsFromPoint() does not return highlights with only collapsed ranges.
+Pass CSS.highlights.highlightsFromPoint() skips invalid StaticRanges.
+Pass CSS.highlights.highlightsFromPoint() returns all overlapping ranges within the same highlight.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txt
index 6055c864758..b1e535fda19 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration-with-modifications.txt
@@ -1,3 +1,13 @@
-Harness status: Error
+Harness status: OK
-Found 0 tests
+Found 8 tests
+
+8 Pass
+Pass HighlightRegistry iteration includes Highlights added after starting the iteration (Map-like behavior)
+Pass HighlightRegistry iteration includes Highlights added after starting the iteration when there were already Highlights (Map-like behavior)
+Pass HighlightRegistry iteration skips Highlights deleted before being visited (Map-like behavior)
+Pass HighlightRegistry iteration skips Highlights deleted before being visited even when other Highlights remain (Map-like behavior)
+Pass HighlightRegistry iteration is not modified when a Highlight that was already visited is deleted and there are still Highlights to visit
+Pass HighlightRegistry iteration skips all Highlights when .clear() is called before visiting them (Map-like behavior)
+Pass HighlightRegistry iteration doesn't visit a highlight name again when it is overwritten with .set() after being visited (Map-like behavior)
+Pass HighlightRegistry iteration terminates when every visited highlight name is overwritten with .set() (Map-like behavior)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txt
index 6055c864758..d60c14975a7 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-iteration.txt
@@ -1,3 +1,20 @@
-Harness status: Error
+Harness status: OK
-Found 0 tests
+Found 15 tests
+
+15 Pass
+Pass HighlightRegistry can be iterated when it's empty initializing the iterator with CSS.highlights.keys()
+Pass HighlightRegistry can be iterated over all of its highlight names after adding one of them initializing the iterator with CSS.highlights.keys()
+Pass HighlightRegistry can be iterated over all of its highlight names after adding two of them initializing the iterator with CSS.highlights.keys()
+Pass HighlightRegistry can be iterated when it's empty initializing the iterator with CSS.highlights.values()
+Pass HighlightRegistry can be iterated over all of its Highlights after adding one of them initializing the iterator with CSS.highlights.values()
+Pass HighlightRegistry can be iterated over all of its Highlights after adding two of them initializing the iterator with CSS.highlights.values()
+Pass HighlightRegistry can be iterated when it's empty initializing the iterator with CSS.highlights[Symbol.iterator]()
+Pass HighlightRegistry can be iterated over all of its Highlights after adding one of them initializing the iterator with CSS.highlights[Symbol.iterator]()
+Pass HighlightRegistry can be iterated over all of its Highlights after adding two of them initializing the iterator with CSS.highlights[Symbol.iterator]()
+Pass HighlightRegistry can be iterated when it's empty initializing the iterator with CSS.highlights.entries()
+Pass HighlightRegistry can be iterated over all of its Highlights after adding one of them initializing the iterator with CSS.highlights.entries()
+Pass HighlightRegistry can be iterated over all of its Highlights after adding two of them initializing the iterator with CSS.highlights.entries()
+Pass HighlightRegistry can be iterated through when it's empty using forEach.
+Pass HighlightRegistry can be iterated through when it has one Highlight using forEach.
+Pass HighlightRegistry can be iterated through when it has two Highlights using forEach.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txt
index 11f8b2e2f2e..76726a546d6 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike-tampered-Map-prototype.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered.
\ No newline at end of file
+1 Pass
+Pass HighlightRegistry is a maplike interface that works as expected even if Map.prototype is tampered.
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txt
index df03b953805..d673a0418d4 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/HighlightRegistry-maplike.txt
@@ -2,7 +2,7 @@ Harness status: OK
Found 3 tests
-3 Fail
-Fail HighlightRegistry initializes as it should.
-Fail HighlightRegistry has a maplike interface.
-Fail HighlightRegistry.set() with an existing name preserves the insertion order (Map-like behavior)
\ No newline at end of file
+3 Pass
+Pass HighlightRegistry initializes as it should.
+Pass HighlightRegistry has a maplike interface.
+Pass HighlightRegistry.set() with an existing name preserves the insertion order (Map-like behavior)
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txt
index fa6495ae3ab..333bcfe4852 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-priority.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail Highlight priority attribute is mutable
\ No newline at end of file
+1 Pass
+Pass Highlight priority attribute is mutable
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txt
index 6055c864758..4c238641884 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-from-font-computed.txt
@@ -1,3 +1,8 @@
-Harness status: Error
+Harness status: OK
-Found 0 tests
+Found 3 tests
+
+3 Fail
+Fail getComputedStyle() for root element
+Fail getComputedStyle() for root highlight applied to div
+Fail getComputedStyle() for div specific highlight
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txt
index c9e0f148032..62db71d4dbe 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/idlharness.window.txt
@@ -1,6 +1,38 @@
Harness status: OK
-Found 1 tests
+Found 33 tests
-1 Fail
-Fail idl_test setup
\ No newline at end of file
+33 Pass
+Pass idl_test setup
+Pass idl_test validation
+Pass Partial namespace CSS: original namespace defined
+Pass Partial namespace CSS: member names are unique
+Pass Partial interface HighlightRegistry: original interface defined
+Pass Partial interface HighlightRegistry: member names are unique
+Pass Highlight interface: existence and properties of interface object
+Pass Highlight interface object length
+Pass Highlight interface object name
+Pass Highlight interface: existence and properties of interface prototype object
+Pass Highlight interface: existence and properties of interface prototype object's "constructor" property
+Pass Highlight interface: existence and properties of interface prototype object's @@unscopables property
+Pass Highlight interface: setlike<AbstractRange>
+Pass Highlight interface: attribute priority
+Pass Highlight interface: attribute type
+Pass Highlight must be primary interface of new Highlight(new Range())
+Pass Stringification of new Highlight(new Range())
+Pass Highlight interface: new Highlight(new Range()) must inherit property "priority" with the proper type
+Pass Highlight interface: new Highlight(new Range()) must inherit property "type" with the proper type
+Pass HighlightRegistry interface: existence and properties of interface object
+Pass HighlightRegistry interface object length
+Pass HighlightRegistry interface object name
+Pass HighlightRegistry interface: existence and properties of interface prototype object
+Pass HighlightRegistry interface: existence and properties of interface prototype object's "constructor" property
+Pass HighlightRegistry interface: existence and properties of interface prototype object's @@unscopables property
+Pass HighlightRegistry interface: maplike<DOMString, Highlight>
+Pass HighlightRegistry interface: operation highlightsFromPoint(float, float, optional HighlightsFromPointOptions)
+Pass HighlightRegistry must be primary interface of CSS.highlights
+Pass Stringification of CSS.highlights
+Pass HighlightRegistry interface: CSS.highlights must inherit property "highlightsFromPoint(float, float, optional HighlightsFromPointOptions)" with the proper type
+Pass HighlightRegistry interface: calling highlightsFromPoint(float, float, optional HighlightsFromPointOptions) on CSS.highlights with too few arguments must throw TypeError
+Pass CSS namespace: operation escape(CSSOMString)
+Pass CSS namespace: attribute highlights
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/css/highlights-from-point-form-control.html b/Tests/LibWeb/Text/input/css/highlights-from-point-form-control.html
new file mode 100644
index 00000000000..05d219c40b2
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/highlights-from-point-form-control.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ body {
+ font: 16px Arial, sans-serif;
+ margin: 0;
+ }
+</style>
+<input id="input" value="hello world"><textarea id="textarea">hello world</textarea>
+<script>
+ test(() => {
+ const range = document.createRange();
+ range.selectNode(input);
+ const textareaRange = document.createRange();
+ textareaRange.selectNode(textarea);
+ const highlight = new Highlight(range, textareaRange);
+ CSS.highlights.set("example", highlight);
+
+ for (const element of [input, textarea]) {
+ const rect = element.getBoundingClientRect();
+ const x = rect.left + rect.width / 2;
+ const y = rect.top + rect.height / 2;
+ println(`${element.localName}: elementFromPoint is the control: ${document.elementFromPoint(x, y) === element}`);
+ const results = CSS.highlights.highlightsFromPoint(x, y);
+ println(`${element.localName}: results: ${results.length}`);
+ if (results.length)
+ println(`${element.localName}: highlight matches: ${results[0].highlight === highlight}, ranges: ${results[0].ranges.length}`);
+ }
+ });
+</script>