Truly independent web browser
LibWeb: Add the ::spelling-error highlight pseudo-element
sideshowbarker89517337074a
diff --git a/Libraries/LibWeb/CSS/Default.css b/Libraries/LibWeb/CSS/Default.cssindex 40b0b27744c..50b285daaee 100644--- a/Libraries/LibWeb/CSS/Default.css+++ b/Libraries/LibWeb/CSS/Default.css@@ -2174,3 +2174,8 @@ iframe:fullscreen {symbols: \25B8;/* ▸ */}++/* https://drafts.csswg.org/css-pseudo-4/#highlight-ua-styles */+:root::spelling-error {+ text-decoration: spelling-error;+}diff --git a/Libraries/LibWeb/CSS/PseudoElements.json b/Libraries/LibWeb/CSS/PseudoElements.jsonindex c07a9fe7790..3cf8800ca2c 100644--- a/Libraries/LibWeb/CSS/PseudoElements.json+++ b/Libraries/LibWeb/CSS/PseudoElements.json@@ -181,6 +181,20 @@"is-element-backed": true,"implementation": "element-reference"},+ "spelling-error": {+ "spec": "https://drafts.csswg.org/css-pseudo-4/#selectordef-spelling-error",+ "is-highlight": true,+ "property-whitelist": [+ "color",+ "background-color",+ "#text-decoration-properties",+ "FIXME: stroke-color",+ "FIXME: fill-color",+ "stroke-width",+ "#custom-properties"+ ],+ "implementation": "synthetic"+ },"view-transition": {"spec": "https://drafts.csswg.org/css-view-transitions-1/#selectordef-view-transition","is-pseudo-root": true,diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cppindex eed216e393e..bb805902dbb 100644--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp@@ -41,6 +41,7 @@ StyleEngine::StyleEngine(StyleComputer* style_computer)StyleEngineFFI::style_engine_set_pseudo_element_style_deferred(host(), to_underlying(PseudoElement::Selection), true);StyleEngineFFI::style_engine_set_pseudo_element_style_deferred(host(), to_underlying(PseudoElement::SearchText), true);StyleEngineFFI::style_engine_set_pseudo_element_style_deferred(host(), to_underlying(PseudoElement::SearchTextCurrent), true);+ StyleEngineFFI::style_engine_set_pseudo_element_style_deferred(host(), to_underlying(PseudoElement::SpellingError), true);}}@@ -186,6 +187,7 @@ StyleRecordID StyleEngine::republish_record_environment(Layout::BegunRead const&ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(After)ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(SearchText)ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(SearchTextCurrent)+ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(SpellingError)ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(ViewTransition)ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(DetailsContent)ASSERT_DEMANDED_PSEUDO_ELEMENT_KIND(SliderTrack)diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cppindex 984500cd7f7..80f3dc17c34 100644--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp@@ -20,6 +20,8 @@#include <LibWeb/DOM/PseudoElement.h>#include <LibWeb/DOM/Range.h>#include <LibWeb/DOM/ShadowRoot.h>+#include <LibWeb/DOM/Text.h>+#include <LibWeb/Editing/SpellingMarkers.h>#include <LibWeb/HTML/FormAssociatedElement.h>#include <LibWeb/HTML/HTMLSlotElement.h>#include <LibWeb/HTML/LocalNavigable.h>@@ -962,7 +964,14 @@ namespace Web::DOM {Document::HighlightStyleObservability& Document::highlight_style_observability(CSS::PseudoElement pseudo_element){VERIFY(CSS::is_highlight_pseudo_element(pseudo_element));- return m_highlight_style_observability[pseudo_element == CSS::PseudoElement::Selection ? 0 : 1];+ switch (pseudo_element) {+ case CSS::PseudoElement::Selection:+ return m_highlight_style_observability[0];+ case CSS::PseudoElement::SpellingError:+ return m_highlight_style_observability[2];+ default:+ return m_highlight_style_observability[1];+ }}bool Document::highlight_styles_are_observable(CSS::PseudoElement pseudo_element) const@@ -1029,6 +1038,28 @@ static Vector<HighlightStyleInput, 2> search_text_style_inputs(Document& documenreturn inputs;}+static Vector<HighlightStyleInput, 2> spelling_error_style_inputs(Document& document)+{+ Vector<HighlightStyleInput, 2> inputs;+ if (!document.has_spelling_markers())+ return inputs;+ HashTable<Node*> roots;+ document.spelling_markers().for_each_marked_text([&](Text& text, auto) {+ auto* parent = text.parent();+ if (parent && roots.set(parent) == HashSetResult::InsertedNewEntry)+ inputs.append({ *parent, nullptr });+ });+ // A root inside another root's subtree adds nothing, since the outer root's walk visits all of it.+ inputs.remove_all_matching([&](auto const& input) {+ for (auto* ancestor = input.root->parent_or_shadow_host(); ancestor; ancestor = ancestor->parent_or_shadow_host()) {+ if (roots.contains(ancestor))+ return true;+ }+ return false;+ });+ return inputs;+}+void Document::update_highlight_style_observability(CSS::PseudoElement pseudo_element){// NB: Editing commands temporarily select content to restore its formatting. Style reads@@ -1038,7 +1069,16 @@ void Document::update_highlight_style_observability(CSS::PseudoElement pseudo_elif (pseudo_element == CSS::PseudoElement::Selection && m_running_editing_command_action)return;- auto inputs = pseudo_element == CSS::PseudoElement::Selection ? selection_style_inputs(*this) : search_text_style_inputs(*this);+ auto inputs = [&] {+ switch (pseudo_element) {+ case CSS::PseudoElement::Selection:+ return selection_style_inputs(*this);+ case CSS::PseudoElement::SpellingError:+ return spelling_error_style_inputs(*this);+ default:+ return search_text_style_inputs(*this);+ }+ }();auto& state = highlight_style_observability(pseudo_element);bool observable = !inputs.is_empty();if (observable == state.observable && !state.needs_update)@@ -1055,6 +1095,7 @@ void Document::update_highlight_style_observability(){update_highlight_style_observability(CSS::PseudoElement::Selection);update_highlight_style_observability(CSS::PseudoElement::SearchText);+ update_highlight_style_observability(CSS::PseudoElement::SpellingError);}void Document::drain_style_transaction_that_flew(Layout::BegunRead const& read)diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 56b579e2496..e7c5b506d79 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -1086,6 +1086,10 @@ void Document::update_highlight_states_if_needed(Layout::BegunRead const& read)recompute_search_text_paint_states(read);Node::set_needs_repaint(InvalidateDisplayList::PaintCommands);}+ if (exchange(m_spelling_error_states_are_stale, false) && has_committed_viewport_box()) {+ recompute_spelling_error_paint_states(read);+ Node::set_needs_repaint(InvalidateDisplayList::PaintCommands);+ }}void Document::set_find_in_page_highlighted_matches(Vector<GC::Ref<Range>> matches)@@ -1147,6 +1151,23 @@ bool Document::has_spelling_markers() constreturn m_spelling_markers && !m_spelling_markers->is_empty();}+void Document::note_spelling_markers_changed()+{+ set_needs_highlight_style_update(CSS::PseudoElement::SpellingError);+ // The boxes the markers paint through are found at the next read of the paint state, as for find-in-page matches.+ m_spelling_error_states_are_stale = true;+ request_frame_for_pending_repaint();+}++void Document::recompute_spelling_error_paint_states(Layout::BegunRead const& read)+{+ if (!has_spelling_markers()) {+ paint_state().reset_spelling_error_states();+ return;+ }+ paint_state().recompute_spelling_error_states(read, *this, spelling_markers());+}+void Document::remove_find_in_page_highlighted_matches_whose_text_changed(){if (m_find_in_page_highlighted_matches.is_empty())@@ -2108,6 +2129,7 @@ void Document::after_layout_commit(Layout::BegunRead const& read, LayoutTreeChancollapse_find_in_page_active_match_if_its_text_changed();remove_find_in_page_highlighted_matches_whose_text_changed();recompute_search_text_paint_states(read);+ recompute_spelling_error_paint_states(read);if (layout_tree_changed == LayoutTreeChanged::Yes) {// Broadcast the current viewport rect to any new committed boxes, so they know whetherdiff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.hindex 6abc600abe3..de2a594214c 100644--- a/Libraries/LibWeb/DOM/Document.h+++ b/Libraries/LibWeb/DOM/Document.h@@ -341,6 +341,8 @@ public:Editing::SpellingMarkers& spelling_markers();bool has_spelling_markers() const;void recompute_search_text_paint_states(Layout::BegunRead const&);+ void note_spelling_markers_changed();+ void recompute_spelling_error_paint_states(Layout::BegunRead const&);WebIDL::ExceptionOr<Utf16String> cookie();WebIDL::ExceptionOr<void> set_cookie(Utf16View);@@ -1990,6 +1992,7 @@ private:GC::Ptr<Range> m_find_in_page_active_match;bool m_selection_states_are_stale { false };bool m_search_text_states_are_stale { false };+ bool m_spelling_error_states_are_stale { false };Utf16String m_find_in_page_active_match_text;Vector<GC::Ref<Range>> m_find_in_page_highlighted_matches;OwnPtr<Editing::SpellingMarkers> m_spelling_markers;@@ -2001,7 +2004,7 @@ private:bool observable { false };bool needs_update { true };};- Array<HighlightStyleObservability, 2> m_highlight_style_observability;+ Array<HighlightStyleObservability, 3> m_highlight_style_observability;HighlightStyleObservability& highlight_style_observability(CSS::PseudoElement);void update_highlight_style_observability(CSS::PseudoElement);void update_highlight_style_observability();diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cppindex f2f34962202..665dc3afa79 100644--- a/Libraries/LibWeb/DOM/Element.cpp+++ b/Libraries/LibWeb/DOM/Element.cpp@@ -1504,7 +1504,8 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_pseudo_element_styl&& !(m_rendered_in_top_layer && may_have_style(CSS::PseudoElement::Backdrop))&& !highlight_may_have_style(CSS::PseudoElement::Selection)&& !highlight_may_have_style(CSS::PseudoElement::SearchText)- && !highlight_may_have_style(CSS::PseudoElement::SearchTextCurrent))+ && !highlight_may_have_style(CSS::PseudoElement::SearchTextCurrent)+ && !highlight_may_have_style(CSS::PseudoElement::SpellingError))return false;auto settled = CSS::StyleEngineFFI::style_engine_settle_pseudo_records_after_host_record(style_computer.style_engine().host(), &read, style_node_id().value(), had_list_marker);// What the settled pseudo-elements' container-relative lengths read of the element's containers.@@ -1652,6 +1653,7 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_pseudo_element_stylrecompute_pseudo_element_style(CSS::PseudoElement::Selection);recompute_pseudo_element_style(CSS::PseudoElement::SearchText);recompute_pseudo_element_style(CSS::PseudoElement::SearchTextCurrent);+ recompute_pseudo_element_style(CSS::PseudoElement::SpellingError);// An element that left the top layer drops the ::backdrop it held.if (m_rendered_in_top_layer || !!style_record_identity(CSS::PseudoElement::Backdrop))recompute_pseudo_element_style(CSS::PseudoElement::Backdrop);diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cppindex 38357be8396..0cbd486e49d 100644--- a/Libraries/LibWeb/DOM/Node.cpp+++ b/Libraries/LibWeb/DOM/Node.cpp@@ -508,6 +508,7 @@ void Node::bump_dom_tree_version()// NB: Inserted or moved content can enter a selection without moving its boundary points.document().set_needs_highlight_style_update(CSS::PseudoElement::Selection);document().set_needs_highlight_style_update(CSS::PseudoElement::SearchText);+ document().set_needs_highlight_style_update(CSS::PseudoElement::SpellingError);if (auto* holder = tree_version_holder(*this))holder->m_dom_tree_version = ++s_last_tree_version;}diff --git a/Libraries/LibWeb/Editing/SpellingMarkers.cpp b/Libraries/LibWeb/Editing/SpellingMarkers.cppindex c52094d4d14..5703e8d750d 100644--- a/Libraries/LibWeb/Editing/SpellingMarkers.cpp+++ b/Libraries/LibWeb/Editing/SpellingMarkers.cpp@@ -119,6 +119,7 @@ void SpellingMarkers::did_change(DOM::Text& text)if (entry.has_value() && !has_markers)m_markers.remove(text);text.set_has_spelling_markers({}, has_markers);+ m_document->note_spelling_markers_changed();}}diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cppindex 7cdbe8bb909..9bb9d0e1b7e 100644--- a/Libraries/LibWeb/Layout/Node.cpp+++ b/Libraries/LibWeb/Layout/Node.cpp@@ -589,7 +589,7 @@ void NodeWithStyle::publish_style_record_to_node_data()void NodeWithStyle::did_update_style_record(){- if (auto const* element = as_if<DOM::Element>(dom_node()); element && (element->has_style(CSS::PseudoElement::Selection) || element->has_style(CSS::PseudoElement::SearchText) || element->has_style(CSS::PseudoElement::SearchTextCurrent)))+ if (auto const* element = as_if<DOM::Element>(dom_node()); element && (element->has_style(CSS::PseudoElement::Selection) || element->has_style(CSS::PseudoElement::SearchText) || element->has_style(CSS::PseudoElement::SearchTextCurrent) || element->has_style(CSS::PseudoElement::SpellingError)))Painting::push_highlight_pseudo_styles(*element);if (style_group<CSS::ComputedValues::MiscResetValues>().scroll_snap_strictness_value() != CSS::ScrollSnapStrictness::None)@@ -695,6 +695,7 @@ static_assert(Node::encode_generated_for(CSS::last_synthetic_pseudo_element) ==static_assert(Node::encode_generated_for(CSS::PseudoElement::Selection) == RustFFI::SELECTION_PSEUDO_KIND + 1);static_assert(Node::encode_generated_for(CSS::PseudoElement::SearchText) == RustFFI::SEARCH_TEXT_PSEUDO_KIND + 1);static_assert(Node::encode_generated_for(CSS::PseudoElement::SearchTextCurrent) == RustFFI::SEARCH_TEXT_CURRENT_PSEUDO_KIND + 1);+static_assert(Node::encode_generated_for(CSS::PseudoElement::SpellingError) == RustFFI::SPELLING_ERROR_PSEUDO_KIND + 1);void Node::dom_node_style_node_changed(DOM::Node& dom_node, CSS::StyleNodeID old_style_node){diff --git a/Libraries/LibWeb/Painting/BoxViews.cpp b/Libraries/LibWeb/Painting/BoxViews.cppindex f5f953c9049..d96262d75f9 100644--- a/Libraries/LibWeb/Painting/BoxViews.cpp+++ b/Libraries/LibWeb/Painting/BoxViews.cpp@@ -724,7 +724,7 @@ DOM::NodeIdentity node_identity_of(Layout::RustFFI::FfiNodeIdentity identity)void push_highlight_pseudo_styles(DOM::Element const& element){if (auto* arena = const_cast<DOM::Document&>(element.document()).layout_node_arena_if_created())- Layout::RustFFI::render_state_sync_highlight_pseudo_styles(arena->host(), element.style_node_id().value(), element.style_record_identity(CSS::PseudoElement::Selection).value(), element.style_record_identity(CSS::PseudoElement::SearchText).value(), element.style_record_identity(CSS::PseudoElement::SearchTextCurrent).value());+ Layout::RustFFI::render_state_sync_highlight_pseudo_styles(arena->host(), element.style_node_id().value(), element.style_record_identity(CSS::PseudoElement::Selection).value(), element.style_record_identity(CSS::PseudoElement::SearchText).value(), element.style_record_identity(CSS::PseudoElement::SearchTextCurrent).value(), element.style_record_identity(CSS::PseudoElement::SpellingError).value());}class BoxViewRepaintAccess {diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.cpp b/Libraries/LibWeb/Painting/DocumentPaintState.cppindex 3e01c97ceec..d9dbe241112 100644--- a/Libraries/LibWeb/Painting/DocumentPaintState.cpp+++ b/Libraries/LibWeb/Painting/DocumentPaintState.cpp@@ -8,6 +8,7 @@#include <LibWeb/DOM/EventTarget.h>#include <LibWeb/DOM/Range.h>#include <LibWeb/DOM/Text.h>+#include <LibWeb/Editing/SpellingMarkers.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/Window.h>#include <LibWeb/Layout/TextNode.h>@@ -288,4 +289,27 @@ void DocumentPaintState::recompute_search_text_states(Layout::BegunRead const& rLayout::RustFFI::render_state_apply_search_text(m_layout_node_arena->host(), viewport_row_slot(read, document), ranges.data(), ranges.size(), entries.data(), entries.size());}+void DocumentPaintState::reset_spelling_error_states()+{+ Layout::RustFFI::render_state_clear_spelling_errors(m_layout_node_arena->host());+}++void DocumentPaintState::recompute_spelling_error_states(Layout::BegunRead const& read, DOM::Document& document, Editing::SpellingMarkers& markers)+{+ Vector<Layout::RustFFI::FfiSpellingError> errors;+ markers.for_each_marked_text([&](DOM::Text& text, ReadonlySpan<Editing::SpellingMarker> text_markers) {+ auto* layout_node = text.unsafe_layout_node(read);+ if (!layout_node)+ return;+ for (auto const& marker : text_markers) {+ errors.append({+ .layout_node = Layout::Node::slot_id(layout_node),+ .start_offset = marker.start,+ .end_offset = marker.end,+ });+ }+ });+ Layout::RustFFI::render_state_apply_spelling_errors(m_layout_node_arena->host(), viewport_row_slot(read, document), errors.data(), errors.size());+}+}diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.h b/Libraries/LibWeb/Painting/DocumentPaintState.hindex 7476bbecd7e..a4f4be3bd6f 100644--- a/Libraries/LibWeb/Painting/DocumentPaintState.h+++ b/Libraries/LibWeb/Painting/DocumentPaintState.h@@ -61,6 +61,8 @@ public:void reset_selection_states(Layout::BegunRead const& read, DOM::Document&);void recompute_search_text_states(Layout::BegunRead const& read, DOM::Document&, GC::Ptr<DOM::Range> active_match, Vector<GC::Ref<DOM::Range>> const& highlighted_matches);void reset_search_text_states();+ void recompute_spelling_error_states(Layout::BegunRead const& read, DOM::Document&, Editing::SpellingMarkers&);+ void reset_spelling_error_states();void invalidate_all_cached_paint(DOM::Document&);diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex ca82f822e87..beb5b35d1cf 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -226,7 +226,7 @@ pub struct FfiSettledPseudoRecords {}/// One record slot per synthetic pseudo-element kind in an engine record answer.-pub const PSEUDO_RECORD_SLOTS: usize = 10;+pub const PSEUDO_RECORD_SLOTS: usize = 11;#[derive(Default)]pub(crate) struct FfiStyleTransactionOutput {@@ -629,9 +629,9 @@ pub struct FfiElementArrival {/// The last pseudo-element kind C++ materializes as a synthetic pseudo-element; the kinds up to/// it are the bits a style record's pseudo-element mask carries. Mirrors the C++/// `last_synthetic_pseudo_element`.-pub const LAST_SYNTHETIC_PSEUDO_ELEMENT_KIND: u16 = 9;-pub const FIRST_ELEMENT_REFERENCE_PSEUDO_ELEMENT_KIND: u8 = 10;-pub const LAST_ELEMENT_REFERENCE_PSEUDO_ELEMENT_KIND: u8 = 15;+pub const LAST_SYNTHETIC_PSEUDO_ELEMENT_KIND: u16 = 10;+pub const FIRST_ELEMENT_REFERENCE_PSEUDO_ELEMENT_KIND: u8 = 11;+pub const LAST_ELEMENT_REFERENCE_PSEUDO_ELEMENT_KIND: u8 = 16;/// What C++ reports about a style reaction it applied, for the engine to derive the reactions of/// the element's children. Mirrors C++ `StyleReactionAppliedFact`.@@ -2539,17 +2539,18 @@ pub enum FfiDemandedPseudoElement {SearchText = 6,SearchTextCurrent = 7,Selection = 8,- ViewTransition = 9,- DetailsContent = 10,- FileSelectorButton = 11,- Placeholder = 12,- SliderFill = 13,- SliderThumb = 14,- SliderTrack = 15,- ViewTransitionGroup = 18,- ViewTransitionImagePair = 19,- ViewTransitionNew = 20,- ViewTransitionOld = 21,+ SpellingError = 9,+ ViewTransition = 10,+ DetailsContent = 11,+ FileSelectorButton = 12,+ Placeholder = 13,+ SliderFill = 14,+ SliderThumb = 15,+ SliderTrack = 16,+ ViewTransitionGroup = 19,+ ViewTransitionImagePair = 20,+ ViewTransitionNew = 21,+ ViewTransitionOld = 22,}/// The answer to a record demand: the record, or that the pseudo-element read generates no boxdiff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rsindex 6bacf21b4a0..229f6a761ff 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs@@ -4912,8 +4912,9 @@ pub(super) mod pseudo_kind {pub(in crate::css::style) const SEARCH_TEXT: u8 = 6;pub(in crate::css::style) const SEARCH_TEXT_CURRENT: u8 = 7;pub(in crate::css::style) const SELECTION: u8 = 8;- pub(in crate::css::style) const VIEW_TRANSITION: u8 = 9;- pub(in crate::css::style) const SYNTHETIC_COUNT: usize = 10;+ pub(in crate::css::style) const SPELLING_ERROR: u8 = 9;+ pub(in crate::css::style) const VIEW_TRANSITION: u8 = 10;+ pub(in crate::css::style) const SYNTHETIC_COUNT: usize = 11;/// Every kind, in the order a settlement goes through them: first the ones a style update/// settles, then the ones only a read asks for.pub(in crate::css::style) const SETTLEMENT_ORDER: [u8; SYNTHETIC_COUNT] = [@@ -4923,6 +4924,7 @@ pub(super) mod pseudo_kind {SELECTION,SEARCH_TEXT,SEARCH_TEXT_CURRENT,+ SPELLING_ERROR,BACKDROP,MARKER,FIRST_LINE,@@ -4935,7 +4937,7 @@ pub(super) mod pseudo_kind {/// https://drafts.csswg.org/css-pseudo-4/#highlight-pseudospub(in crate::css::style) const fn is_highlight(kind: u8) -> bool {- matches!(kind, SEARCH_TEXT | SEARCH_TEXT_CURRENT | SELECTION)+ matches!(kind, SEARCH_TEXT | SEARCH_TEXT_CURRENT | SELECTION | SPELLING_ERROR)}}diff --git a/Libraries/LibWeb/Rust/src/layout/host_tables.rs b/Libraries/LibWeb/Rust/src/layout/host_tables.rsindex 8573c696f1a..83a3282af16 100644--- a/Libraries/LibWeb/Rust/src/layout/host_tables.rs+++ b/Libraries/LibWeb/Rust/src/layout/host_tables.rs@@ -56,6 +56,8 @@ pub(crate) struct HostTables {pub(crate) update_layout_running: Cell<bool>,/// Whether the host gave the rows search text highlights that it has not cleared since.pub(crate) shows_search_text: Cell<bool>,+ /// Whether the host gave the rows spelling-error highlights that it has not cleared since.+ pub(crate) shows_spelling_errors: Cell<bool>,/// The rows the host gave layer image paint facts, which the arena drops with the row.pub(crate) rows_with_layer_image_paint_facts: RefCell<HashSet<NodeSlotId>>,/// The image resources the tree builds of the rounds the host was paid for owe the rows they stamped, which thediff --git a/Libraries/LibWeb/Rust/src/layout/node_data.rs b/Libraries/LibWeb/Rust/src/layout/node_data.rsindex fd61229ac79..32f4d46d70f 100644--- a/Libraries/LibWeb/Rust/src/layout/node_data.rs+++ b/Libraries/LibWeb/Rust/src/layout/node_data.rs@@ -16,7 +16,7 @@ pub const GENERATED_FOR_FIRST_LETTER: u8 = 4;pub const GENERATED_FOR_MARKER: u8 = 6;/// The last pseudo-element an element holds a box for in its own right; the ones from/// `GENERATED_FOR_AFTER` up to it are an element's synthetic pseudo-elements.-pub const GENERATED_FOR_LAST_SYNTHETIC: u8 = 10;+pub const GENERATED_FOR_LAST_SYNTHETIC: u8 = 11;/// `CSS::PseudoElement::Selection`, as the style engine numbers an element's pseudo-element/// records. It generates no box, so no row names it.pub const SELECTION_PSEUDO_KIND: u8 = 8;@@ -26,6 +26,9 @@ pub const SEARCH_TEXT_PSEUDO_KIND: u8 = 6;/// The current find-in-page match's `::search-text`, as the style engine numbers an element's/// pseudo-element records. It generates no box either.pub const SEARCH_TEXT_CURRENT_PSEUDO_KIND: u8 = 7;+/// `CSS::PseudoElement::SpellingError`, as the style engine numbers an element's pseudo-element+/// records. It generates no box either.+pub const SPELLING_ERROR_PSEUDO_KIND: u8 = 9;/// The pseudo-element a row generated for `generated_for` stands for, as the style engine numbers/// an element's pseudo-element records. `Layout::Node::encode_generated_for` is its inverse.diff --git a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs b/Libraries/LibWeb/Rust/src/painting/paint_changes.rsindex d91d4c9204e..7eef70d63c8 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs@@ -15,7 +15,7 @@ use super::host::{use super::image_map_areas::{AreaCoverage, AreaShape, PublishedImageMapArea};use super::layer_image_paint_facts::{LayerImagePaintFacts, LayerImagePaintFactsEntry};use super::paint_read::GeometryRead;-use super::paintable_data::{FfiSearchTextRange, FfiSelectionEntry, PaintableFlag};+use super::paintable_data::{FfiSearchTextRange, FfiSelectionEntry, FfiSpellingError, PaintableFlag};use super::record::damage::PaintDamage;use super::replaced_paint_facts::{ImagePaintFacts, ReplacedPaintFacts, VideoPaintFacts};use super::selection::HighlightStyleRecords;@@ -53,8 +53,16 @@ pub(crate) enum PaintChange {},/// No find-in-page match is highlighted.ClearSearchText,- /// The element's style changed: the rows that paint text under it take what `style_records`, the `::selection`- /// and `::search-text` records the host holds for it (zero for none), say highlighted text paints with.+ /// The runs the spellchecker flagged, each inside one DOM text.+ ApplySpellingErrors {+ viewport: NodeSlotId,+ errors: Box<[FfiSpellingError]>,+ },+ /// No text is flagged as misspelled.+ ClearSpellingErrors,+ /// The element's style changed: the rows that paint text under it take what `style_records`, the `::selection`,+ /// `::search-text` and `::spelling-error` records the host holds for it (zero for none), say highlighted text+ /// paints with.SyncHighlightPseudoStyles {element: StyleNodeID,style_records: HighlightStyleRecords,@@ -158,6 +166,12 @@ impl PaintChange {}}Self::ClearSearchText => super::selection::clear_search_text(&mut arena.paintable_rows_mut()),+ Self::ApplySpellingErrors { viewport, errors } => {+ if arena.paintable_row_is_populated(viewport) {+ super::selection::apply_spelling_errors(&mut arena.paintable_rows_mut(), &errors);+ }+ }+ Self::ClearSpellingErrors => super::selection::clear_spelling_errors(&mut arena.paintable_rows_mut()),Self::SyncHighlightPseudoStyles { element, style_records } => {super::selection::sync_highlight_pseudo_styles(arena, element, style_records);}@@ -300,6 +314,36 @@ pub extern "C" fn render_state_clear_search_text(host: &DocumentHost) {queue(host, PaintChange::ClearSearchText);}+/// # Safety+///+/// `host` must be a live document host, on the document's thread, and `errors` must point at `error_count` readable+/// errors.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn render_state_apply_spelling_errors(+ host: &DocumentHost,+ viewport: NodeSlotId,+ errors: *const FfiSpellingError,+ error_count: usize,+) {+ let errors = if error_count == 0 {+ Box::default()+ } else {+ // SAFETY: Guaranteed by the caller.+ unsafe { std::slice::from_raw_parts(errors, error_count) }.into()+ };+ host.host_tables().shows_spelling_errors.set(error_count != 0);+ queue(host, PaintChange::ApplySpellingErrors { viewport, errors });+}++#[unsafe(no_mangle)]+pub extern "C" fn render_state_clear_spelling_errors(host: &DocumentHost) {+ // Rows that show no spelling errors have none to clear.+ if !host.host_tables().shows_spelling_errors.replace(false) {+ return;+ }+ queue(host, PaintChange::ClearSpellingErrors);+}+#[unsafe(no_mangle)]pub extern "C" fn render_state_sync_highlight_pseudo_styles(host: &DocumentHost,@@ -307,6 +351,7 @@ pub extern "C" fn render_state_sync_highlight_pseudo_styles(selection_style_record: u64,search_text_style_record: u64,search_text_current_style_record: u64,+ spelling_error_style_record: u64,) {let Some(element) = StyleNodeID::from_raw(element) else {return;@@ -317,6 +362,7 @@ pub extern "C" fn render_state_sync_highlight_pseudo_styles(selection_style_record,search_text_style_record,search_text_current_style_record,+ spelling_error_style_record,],};queue(host, change);diff --git a/Libraries/LibWeb/Rust/src/painting/paint_state.rs b/Libraries/LibWeb/Rust/src/painting/paint_state.rsindex fb52da2fb2c..fe9aea2a844 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_state.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_state.rs@@ -7,7 +7,9 @@use crate::layout::node_data::NodeSlotId;use crate::painting::paint_read::GeometryRead;use crate::painting::record::paint::text::SelectionStyleAnswer;-use crate::painting::selection::{HighlightPseudoElement, SearchTextHighlights, SelectionRange};+use crate::painting::selection::{+ HighlightPseudoElement, SearchTextHighlights, SelectionRange, SpellingErrorHighlights,+};use std::collections::HashMap;use std::sync::Arc;@@ -42,6 +44,10 @@ pub struct PaintState {pub(crate) search_text_pseudo_styles: Arc<SelectionPseudoStyles>,/// The `::search-text:current` styles, shared as the `::selection` styles are.pub(crate) search_text_current_pseudo_styles: Arc<SelectionPseudoStyles>,+ /// The misspelled runs, shared with the frames published while they hold.+ pub(crate) spelling_errors: Arc<SpellingErrorHighlights>,+ /// The `::spelling-error` styles, shared as the `::selection` styles are.+ pub(crate) spelling_error_pseudo_styles: Arc<SelectionPseudoStyles>,}/// Each row's committed style for one highlight pseudo-element.@@ -56,6 +62,7 @@ impl PaintState {HighlightPseudoElement::Selection => &mut self.selection_pseudo_styles,HighlightPseudoElement::SearchText => &mut self.search_text_pseudo_styles,HighlightPseudoElement::SearchTextCurrent => &mut self.search_text_current_pseudo_styles,+ HighlightPseudoElement::SpellingError => &mut self.spelling_error_pseudo_styles,}}diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs b/Libraries/LibWeb/Rust/src/painting/paintable_data.rsindex db0e7726ecd..c75faadc9a3 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs@@ -112,6 +112,15 @@ pub struct FfiSearchTextRange {pub is_current: bool,}+#[derive(Clone, Copy)]+#[repr(C)]+pub struct FfiSpellingError {+ /// The DOM text's primary layout node; Rust expands its slices.+ pub layout_node: NodeSlotId,+ pub start_offset: usize,+ pub end_offset: usize,+}+pub const SELECTION_STATE_NONE: u8 = 0;pub const SELECTION_STATE_START: u8 = 1;pub const SELECTION_STATE_END: u8 = 2;diff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rsindex c27dd28479a..69facfb21b7 100644--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs@@ -27,7 +27,9 @@ use crate::painting::paintable_data::{CommittedSideData, PaintableData};use crate::painting::paintable_rows::{CommittedFragmentLinkSlot, PAINTABLE_SLOTS_PER_CHUNK};use crate::painting::record::damage::FrameDamage;use crate::painting::replaced_paint_facts::ReplacedPaintFactsTable;-use crate::painting::selection::{HighlightPseudoElement, SearchTextHighlights, SelectionRange};+use crate::painting::selection::{+ HighlightPseudoElement, SearchTextHighlights, SelectionRange, SpellingErrorHighlights,+};use crate::painting::stacking_context::entries::StackingContextEntries;use crate::painting::svg_paint_resources::SvgPaintResourceRows;use crate::painting::visual_context::VisualContextTree;@@ -151,6 +153,8 @@ pub(crate) struct PublishedPaintState {pub(crate) search_text: Arc<SearchTextHighlights>,pub(crate) search_text_pseudo_styles: Arc<SelectionPseudoStyles>,pub(crate) search_text_current_pseudo_styles: Arc<SelectionPseudoStyles>,+ pub(crate) spelling_errors: Arc<SpellingErrorHighlights>,+ pub(crate) spelling_error_pseudo_styles: Arc<SelectionPseudoStyles>,pub(crate) hit_test_list_generation: u64,/// How many items the document's hit-test list held, which the recording's list reserves.pub(crate) hit_test_item_capacity_hint: usize,@@ -162,6 +166,7 @@ impl PublishedPaintState {HighlightPseudoElement::Selection => &self.selection_pseudo_styles,HighlightPseudoElement::SearchText => &self.search_text_pseudo_styles,HighlightPseudoElement::SearchTextCurrent => &self.search_text_current_pseudo_styles,+ HighlightPseudoElement::SpellingError => &self.spelling_error_pseudo_styles,}}@@ -178,6 +183,8 @@ impl PublishedPaintState {search_text: paint_state.search_text.clone(),search_text_pseudo_styles: paint_state.search_text_pseudo_styles.clone(),search_text_current_pseudo_styles: paint_state.search_text_current_pseudo_styles.clone(),+ spelling_errors: paint_state.spelling_errors.clone(),+ spelling_error_pseudo_styles: paint_state.spelling_error_pseudo_styles.clone(),hit_test_list_generation: paint_state.hit_test_list_generation,hit_test_item_capacity_hint,}diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rsindex 48695be8428..a3d91910308 100644--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs@@ -339,6 +339,27 @@ impl<O: Observer> PaintRecorder<'_, O> {answer}+ pub(crate) fn spelling_error_style(+ &mut self,+ node: crate::layout::node_data::NodeSlotId,+ ) -> Arc<paint::text::SelectionStyleAnswer> {+ let key = node.index;+ if let Some(answer) = self.scratch.spelling_error_style_cache.get(&key) {+ return answer.clone();+ }+ let committed = self.first_non_anonymous_ancestor_row(node).and_then(|element_row| {+ self.committed_highlight_pseudo_style(HighlightPseudoElement::SpellingError, node, element_row)+ });+ // The UA stylesheet's `:root::spelling-error` rule supplies the underline; with no committed style, a+ // misspelling paints nothing of its own.+ let answer = Self::highlight_style_answer(committed, || paint::text::SelectionStyleAnswer {+ facts: crate::painting::host::FfiSelectionStyleFacts::default(),+ shadows: Vec::new(),+ });+ self.scratch.spelling_error_style_cache.insert(key, answer.clone());+ answer+ }+/// A committed style that authored neither color takes the paired default colors and keeps/// its shadows and decorations.fn highlight_style_answer(diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/text.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/text.rsindex 0caed9add02..ff0da3bc81b 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/text.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/text.rs@@ -77,9 +77,12 @@ pub(crate) struct SelectionStyleAnswer {}// https://drafts.csswg.org/css-pseudo-4/#highlight-backgrounds+// The ::selection overlay is drawn over the ::target-text overlay which is drawn over the ::spelling-error overlay+// which is drawn over the ::grammar-error overlay which is drawn over the ::highlight overlays.// The ::search-text overlay is drawn directly over or below the ::selection overlay depending on the UA, and drawn// over all other overlays.-const HIGHLIGHT_OVERLAY_ORDER: [HighlightPseudoElement; 3] = [+const HIGHLIGHT_OVERLAY_ORDER: [HighlightPseudoElement; 4] = [+ HighlightPseudoElement::SpellingError,HighlightPseudoElement::Selection,HighlightPseudoElement::SearchText,HighlightPseudoElement::SearchTextCurrent,@@ -124,6 +127,27 @@ fn highlight_offsets_for_fragment<O: Observer>(};offsets.into_iter().collect()}+ HighlightPseudoElement::SpellingError => {+ let Some(runs) = recorder.paint_state.spelling_errors.by_node.get(&fragment.layout_node) else {+ return Vec::new();+ };+ // A run that ends before the fragment starts, or starts after it ends, has no part in it.+ runs.iter()+ .filter(|&&(start, end)| {+ end >= fragment.dom_start_offset_in_node+ && start <= fragment.dom_end_offset_with_trailing_whitespace+ })+ .filter_map(|&(start, end)| {+ text_fragment::compute_selection_offsets(+ recorder.source,+ fragment,+ SELECTION_STATE_START_AND_END,+ start,+ end,+ )+ })+ .collect()+ }HighlightPseudoElement::SearchText | HighlightPseudoElement::SearchTextCurrent => {let is_current = highlight == HighlightPseudoElement::SearchTextCurrent;let highlights = &recorder.paint_state.search_text;@@ -170,6 +194,7 @@ fn highlight_style<O: Observer>(HighlightPseudoElement::SearchText | HighlightPseudoElement::SearchTextCurrent => {recorder.search_text_style(node, highlight)}+ HighlightPseudoElement::SpellingError => recorder.spelling_error_style(node),}}diff --git a/Libraries/LibWeb/Rust/src/painting/record/scratch.rs b/Libraries/LibWeb/Rust/src/painting/record/scratch.rsindex cba8e3fc8f0..30c57212e2b 100644--- a/Libraries/LibWeb/Rust/src/painting/record/scratch.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/scratch.rs@@ -40,6 +40,7 @@ pub(crate) struct RecordingScratch {pub(super) selection_style_cache: HashMap<u32, Arc<SelectionStyleAnswer>>,pub(super) search_text_style_cache: HashMap<u32, Arc<SelectionStyleAnswer>>,pub(super) search_text_current_style_cache: HashMap<u32, Arc<SelectionStyleAnswer>>,+ pub(super) spelling_error_style_cache: HashMap<u32, Arc<SelectionStyleAnswer>>,pub(super) wheel_hit_test_target_cache: HashMap<NodeSlotId, SpatialNodeIndex>,}@@ -102,6 +103,7 @@ impl RecordingScratch {self.selection_style_cache.clear();self.search_text_style_cache.clear();self.search_text_current_style_cache.clear();+ self.spelling_error_style_cache.clear();self.wheel_hit_test_target_cache.clear();}diff --git a/Libraries/LibWeb/Rust/src/painting/selection.rs b/Libraries/LibWeb/Rust/src/painting/selection.rsindex a79584a3755..24b583e5487 100644--- a/Libraries/LibWeb/Rust/src/painting/selection.rs+++ b/Libraries/LibWeb/Rust/src/painting/selection.rs@@ -9,14 +9,15 @@ use crate::css::style::tree::StyleNodeID;use crate::layout::LayoutNodeArena;use crate::layout::node_data::{NodeSlotId, SEARCH_TEXT_CURRENT_PSEUDO_KIND, SEARCH_TEXT_PSEUDO_KIND, SELECTION_PSEUDO_KIND,+ SPELLING_ERROR_PSEUDO_KIND,};use crate::painting::display_list::commands::OptionalColor;use crate::painting::fragment_ownership;use crate::painting::host::FfiSelectionStyleFacts;use crate::painting::paint_read::GeometryRead;use crate::painting::paintable_data::{- FfiSearchTextRange, FfiSelectionEntry, SELECTION_STATE_END, SELECTION_STATE_NONE, SELECTION_STATE_START,- SELECTION_STATE_START_AND_END,+ FfiSearchTextRange, FfiSelectionEntry, FfiSpellingError, SELECTION_STATE_END, SELECTION_STATE_NONE,+ SELECTION_STATE_START, SELECTION_STATE_START_AND_END,};use crate::painting::paintable_rows::PaintableRowsMut;use crate::painting::record::damage::PaintDamage;@@ -31,10 +32,16 @@ pub(crate) enum HighlightPseudoElement {Selection,SearchText,SearchTextCurrent,+ SpellingError,}impl HighlightPseudoElement {- pub(crate) const ALL: [Self; 3] = [Self::Selection, Self::SearchText, Self::SearchTextCurrent];+ pub(crate) const ALL: [Self; 4] = [+ Self::Selection,+ Self::SearchText,+ Self::SearchTextCurrent,+ Self::SpellingError,+ ];/// The pseudo-element's kind, as the style engine numbers an element's pseudo-element records.pub(crate) fn pseudo_kind(self) -> u8 {@@ -42,15 +49,16 @@ impl HighlightPseudoElement {Self::Selection => SELECTION_PSEUDO_KIND,Self::SearchText => SEARCH_TEXT_PSEUDO_KIND,Self::SearchTextCurrent => SEARCH_TEXT_CURRENT_PSEUDO_KIND,+ Self::SpellingError => SPELLING_ERROR_PSEUDO_KIND,}}}/// The committed styles of each highlight pseudo-element, for an element's rows.-pub(crate) type HighlightStyleAnswers = [Option<Arc<SelectionStyleAnswer>>; 3];+pub(crate) type HighlightStyleAnswers = [Option<Arc<SelectionStyleAnswer>>; 4];/// The records an element holds for each highlight pseudo-element, zero for none.-pub(crate) type HighlightStyleRecords = [u64; 3];+pub(crate) type HighlightStyleRecords = [u64; 4];#[derive(Debug)]pub(crate) struct SelectionRange {@@ -206,6 +214,42 @@ pub(crate) fn apply_search_text(layout_arena.paint_state().borrow_mut().search_text = Arc::new(highlights);}+#[derive(Debug, Default)]+pub(crate) struct SpellingErrorHighlights {+ /// For each text fragment row, the misspelled runs of its DOM text, as start and end offsets in order.+ pub by_node: std::collections::HashMap<NodeSlotId, Vec<(usize, usize)>>,+}++pub(crate) fn clear_spelling_errors(layout_arena: &mut PaintableRowsMut<'_>) {+ let previous = std::mem::take(&mut layout_arena.paint_state().borrow_mut().spelling_errors);+ for node in previous.by_node.keys() {+ invalidate_text_node(layout_arena, *node);+ }+}++pub(crate) fn apply_spelling_errors(layout_arena: &mut PaintableRowsMut<'_>, errors: &[FfiSpellingError]) {+ let mut highlights = SpellingErrorHighlights::default();+ for error in errors {+ for &node in layout_arena.text_fragments(error.layout_node).as_slice() {+ highlights+ .by_node+ .entry(node)+ .or_default()+ .push((error.start_offset, error.end_offset));+ }+ }+ for runs in highlights.by_node.values_mut() {+ runs.sort_unstable();+ }+ let previous = std::mem::take(&mut layout_arena.paint_state().borrow_mut().spelling_errors);+ for node in previous.by_node.keys().chain(highlights.by_node.keys()) {+ if previous.by_node.get(node) != highlights.by_node.get(node) {+ invalidate_text_node(layout_arena, *node);+ }+ }+ layout_arena.paint_state().borrow_mut().spelling_errors = Arc::new(highlights);+}+/// https://drafts.csswg.org/css-pseudo-4/#highlight-styling/// What text under `element` paints with inside a highlight pseudo-element, read from/// `style_record`, the element's record for that pseudo-element (zero for none), or `None` whendiff --git a/Tests/LibWeb/Ref/expected/spelling-error-authored-style-ref.html b/Tests/LibWeb/Ref/expected/spelling-error-authored-style-ref.htmlnew file mode 100644index 00000000000..a4f4a83cbb6--- /dev/null+++ b/Tests/LibWeb/Ref/expected/spelling-error-authored-style-ref.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<style>+p {+ font: 20px/1.5 sans-serif;+}+</style>+<p>one <span style="color: green; text-decoration: underline solid blue">txet</span> two</p>diff --git a/Tests/LibWeb/Ref/expected/spelling-error-default-underline-ref.html b/Tests/LibWeb/Ref/expected/spelling-error-default-underline-ref.htmlnew file mode 100644index 00000000000..d537f8048cb--- /dev/null+++ b/Tests/LibWeb/Ref/expected/spelling-error-default-underline-ref.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<style>+p {+ font: 20px/1.5 sans-serif;+}+</style>+<p>one <span style="text-decoration: spelling-error">txet</span> two</p>diff --git a/Tests/LibWeb/Ref/expected/spelling-error-nested-ref.html b/Tests/LibWeb/Ref/expected/spelling-error-nested-ref.htmlnew file mode 100644index 00000000000..3f021d1e59e--- /dev/null+++ b/Tests/LibWeb/Ref/expected/spelling-error-nested-ref.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<style>+div {+ font: 20px/1.5 sans-serif;+ margin-left: 20px;+}+span {+ color: green;+ text-decoration: underline solid blue;+}+</style>+<div>one <span>txet</span><div>two <span>wrod</span><div>three <span>quikc</span></div></div></div>diff --git a/Tests/LibWeb/Ref/expected/spelling-error-removed-on-edit-ref.html b/Tests/LibWeb/Ref/expected/spelling-error-removed-on-edit-ref.htmlnew file mode 100644index 00000000000..1cdba76b03e--- /dev/null+++ b/Tests/LibWeb/Ref/expected/spelling-error-removed-on-edit-ref.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<style>+p {+ font: 20px/1.5 sans-serif;+}+</style>+<p>one txxet two</p>diff --git a/Tests/LibWeb/Ref/expected/spelling-error-under-selection-ref.html b/Tests/LibWeb/Ref/expected/spelling-error-under-selection-ref.htmlnew file mode 100644index 00000000000..33fd65c4ef0--- /dev/null+++ b/Tests/LibWeb/Ref/expected/spelling-error-under-selection-ref.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<style>+p {+ font: 20px/1.5 sans-serif;+}+</style>+<p>one <span style="background-color: yellow; color: black; text-decoration: spelling-error">txet</span> two</p>diff --git a/Tests/LibWeb/Ref/input/spelling-error-authored-style.html b/Tests/LibWeb/Ref/input/spelling-error-authored-style.htmlnew file mode 100644index 00000000000..e4433ad3320--- /dev/null+++ b/Tests/LibWeb/Ref/input/spelling-error-authored-style.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<link rel="match" href="../expected/spelling-error-authored-style-ref.html">+<style>+p {+ font: 20px/1.5 sans-serif;+}+p::spelling-error {+ color: green;+ text-decoration: underline solid blue;+}+</style>+<p id="p">one txet two</p>+<script>+internals.addSpellingErrorForTesting(document.getElementById("p").firstChild, 4, 8);+</script>diff --git a/Tests/LibWeb/Ref/input/spelling-error-default-underline.html b/Tests/LibWeb/Ref/input/spelling-error-default-underline.htmlnew file mode 100644index 00000000000..4030dad2501--- /dev/null+++ b/Tests/LibWeb/Ref/input/spelling-error-default-underline.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<link rel="match" href="../expected/spelling-error-default-underline-ref.html">+<style>+p {+ font: 20px/1.5 sans-serif;+}+</style>+<p id="p">one txet two</p>+<script>+internals.addSpellingErrorForTesting(document.getElementById("p").firstChild, 4, 8);+</script>diff --git a/Tests/LibWeb/Ref/input/spelling-error-nested.html b/Tests/LibWeb/Ref/input/spelling-error-nested.htmlnew file mode 100644index 00000000000..66d26d1440b--- /dev/null+++ b/Tests/LibWeb/Ref/input/spelling-error-nested.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<link rel="match" href="../expected/spelling-error-nested-ref.html">+<style>+div {+ font: 20px/1.5 sans-serif;+ margin-left: 20px;+}+::spelling-error {+ color: green;+ text-decoration: underline solid blue;+}+</style>+<div id="outer">one txet<div id="middle">two wrod<div id="inner">three quikc</div></div></div>+<script>+internals.addSpellingErrorForTesting(document.getElementById("outer").firstChild, 4, 8);+internals.addSpellingErrorForTesting(document.getElementById("middle").firstChild, 4, 8);+internals.addSpellingErrorForTesting(document.getElementById("inner").firstChild, 6, 11);+</script>diff --git a/Tests/LibWeb/Ref/input/spelling-error-removed-on-edit.html b/Tests/LibWeb/Ref/input/spelling-error-removed-on-edit.htmlnew file mode 100644index 00000000000..a1fec1640dc--- /dev/null+++ b/Tests/LibWeb/Ref/input/spelling-error-removed-on-edit.html@@ -0,0 +1,21 @@+<!DOCTYPE html>+<html class="reftest-wait">+<link rel="match" href="../expected/spelling-error-removed-on-edit-ref.html">+<style>+p {+ font: 20px/1.5 sans-serif;+}+</style>+<p id="p">one txet two</p>+<script>+const text = document.getElementById("p").firstChild;+internals.addSpellingErrorForTesting(text, 4, 8);+requestAnimationFrame(() => {+ requestAnimationFrame(() => {+ text.insertData(6, "x");+ requestAnimationFrame(() => {+ requestAnimationFrame(() => document.documentElement.classList.remove("reftest-wait"));+ });+ });+});+</script>diff --git a/Tests/LibWeb/Ref/input/spelling-error-under-selection.html b/Tests/LibWeb/Ref/input/spelling-error-under-selection.htmlnew file mode 100644index 00000000000..4d001dfd174--- /dev/null+++ b/Tests/LibWeb/Ref/input/spelling-error-under-selection.html@@ -0,0 +1,17 @@+<!DOCTYPE html>+<link rel="match" href="../expected/spelling-error-under-selection-ref.html">+<style>+p {+ font: 20px/1.5 sans-serif;+}+p::selection {+ background-color: yellow;+ color: black;+}+</style>+<p id="p">one txet two</p>+<script>+const text = document.getElementById("p").firstChild;+internals.addSpellingErrorForTesting(text, 4, 8);+getSelection().setBaseAndExtent(text, 4, text, 8);+</script>diff --git a/Tests/LibWeb/Text/expected/css/spelling-error-computed-style.txt b/Tests/LibWeb/Text/expected/css/spelling-error-computed-style.txtnew file mode 100644index 00000000000..f4ce977008e--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/spelling-error-computed-style.txt@@ -0,0 +1,2 @@+plain: line=spelling-error color=rgb(0, 0, 0) decoration-color=rgb(0, 0, 0)+styled: line=spelling-error color=rgb(0, 128, 0) decoration-color=rgb(0, 0, 255)diff --git a/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-selector-shapes.txt b/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-selector-shapes.txtindex 5829998388d..a256d4ad91a 100644--- a/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-selector-shapes.txt+++ b/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-selector-shapes.txt@@ -12,7 +12,7 @@ p#p2.b: * :where(p, section) * > * * + * * :is(p, section) :is(:is(p)) :not(:noti: * * > * * :is(p, section) > * :not(p) :not(p, section) :not(:has(em)) :not(:is(p, li)) :is(:not(p), :not(li)) p > * ::before[pseudo 2] :first-child :last-child :only-child :nth-child(2n+1) :nth-last-child(1) :nth-child(2n+1) :nth-child(-n+2) :first-of-type :last-of-type :only-of-type :nth-last-of-type(1) :read-only :defined :lang(en) :lang(en-GB) :dir(rtl) :root *section.c: * :where(p, section) * > * * + * * :is(p, section) :not(p) :not(:has(em)) :not(:is(p, li)) :is(:not(p), :not(li)) p ~ * :has(> :not(em)) ::before[pseudo 2] p ~ section :nth-child(2n+1) :nth-child(2n+1) :first-of-type :last-of-type :only-of-type :nth-last-of-type(1) :read-only :defined :lang(en) :lang(en-GB) :dir(rtl) :has(:checked) :root * :has(:not(.c))a.a: * * > * * :is(p, section) > * :not(p) :not(p, section) :not(:has(em)) :not(:is(p, li)) :is(:not(p), :not(li)) ::before[pseudo 2] .a :first-child :nth-child(2n+1) :nth-child(2n+1) :nth-child(-n+2) :first-of-type :last-of-type :only-of-type :nth-last-of-type(1) :link :any-link :read-only :defined :lang(en) :lang(en-GB) :dir(rtl) :root * :is(.a, #root):not(.c)-input: * * > * * + * * :is(p, section) > * :not(p) :not(p, section) :not(:has(em)) :not(:is(p, li)) :is(:not(p), :not(li)) ::before[pseudo 2] section > :not(a) input::placeholder[pseudo 12] :last-child :nth-child(2) :nth-last-child(1) :nth-child(2n) :nth-child(-n+2) :first-of-type :last-of-type :only-of-type :nth-last-of-type(1) :empty :checked :disabled :optional :read-only :default :defined :lang(en) :lang(en-GB) :dir(rtl) :root *+input: * * > * * + * * :is(p, section) > * :not(p) :not(p, section) :not(:has(em)) :not(:is(p, li)) :is(:not(p), :not(li)) ::before[pseudo 2] section > :not(a) input::placeholder[pseudo 13] :last-child :nth-child(2) :nth-last-child(1) :nth-child(2n) :nth-child(-n+2) :first-of-type :last-of-type :only-of-type :nth-last-of-type(1) :empty :checked :disabled :optional :read-only :default :defined :lang(en) :lang(en-GB) :dir(rtl) :root *ul: * * > * * + * * :not(p) :not(p, section) :not(:has(em)) :not(:is(p, li)) :is(:not(p), :not(li)) p ~ * :has(> :not(em)) ::before[pseudo 2] :nth-child(2n) :first-of-type :last-of-type :only-of-type :nth-last-of-type(1) :read-only :defined :lang(en) :lang(en-GB) :dir(rtl) :root * :has(:not(.c))li.x: * * > * * :not(p) :not(p, section) :not(:has(em)) :is(:not(p), :not(li)) ::before[pseudo 2] li::marker[pseudo 5] :first-child :nth-child(2n+1) :nth-child(2n+1) :nth-child(-n+2) :first-of-type :read-only :defined :lang(en) :lang(en-GB) :dir(rtl) :root * :is(p, li):is(.a, .x) li.x:nth-child(2n+1):not(:last-child)li.y: * * > * * + * * :not(p) :not(p, section) :not(:has(em)) :is(:not(p), :not(li)) ::before[pseudo 2] li::marker[pseudo 5] :nth-child(2) :nth-child(2n) :nth-child(-n+2) :nth-of-type(2) :read-only :defined :lang(en) :lang(en-GB) :dir(rtl) :root * ul > li:nth-child(2)diff --git a/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt b/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txtindex 31f2ca07026..7237902ccaa 100644--- a/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt+++ b/Tests/LibWeb/Text/expected/css/style-engine/match-agreement-sibling-fact-batches.txt@@ -5,4 +5,4 @@ section.shadow-target: .shadow-guard ~ .shadow-target .shadow-target:nth-of-typecold node evaluations: 25candidate checks: 78-rule matches emitted: 117+rule matches emitted: 118diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-inheritance-computed-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-inheritance-computed-001.txtindex 44ce38089f3..becb3079758 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-inheritance-computed-001.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-inheritance-computed-001.txt@@ -2,16 +2,16 @@ Harness status: OKFound 12 tests-4 Pass-8 Fail+6 Pass+6 FailPass getComputedStyle() for ::selection at #child1Pass getComputedStyle() for ::selection at #child2Fail getComputedStyle() for ::target-text at #child1Fail getComputedStyle() for ::target-text at #child2Pass getComputedStyle() for ::search-text at #child1Pass getComputedStyle() for ::search-text at #child2-Fail getComputedStyle() for ::spelling-error at #child1-Fail getComputedStyle() for ::spelling-error at #child2+Pass getComputedStyle() for ::spelling-error at #child1+Pass getComputedStyle() for ::spelling-error at #child2Fail getComputedStyle() for ::grammar-error at #child1Fail getComputedStyle() for ::grammar-error at #child2Fail getComputedStyle() for ::highlight(foo) at #child1diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo.txtindex 54c637fca82..ce31c49e13d 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo.txt@@ -2,8 +2,8 @@ Harness status: OKFound 28 tests-25 Pass-3 Optional Feature Unsupported+26 Pass+2 Optional Feature UnsupportedPass Resolution of width is correct when pseudo-element argument is ignored (due to no colon)Pass Resolution of width is correct when pseudo-element argument is invalid (due to a trailing token)Pass Resolution of width is correct for ::before and ::after pseudo-elements (single-colon)@@ -24,7 +24,7 @@ Optional Feature Unsupported Unknown pseudo-element with a known identifier: graOptional Feature Unsupported Unknown pseudo-element with a known identifier: highlight(name)Pass Unknown pseudo-element with a known identifier: markerPass Unknown pseudo-element with a known identifier: placeholder-Optional Feature Unsupported Unknown pseudo-element with a known identifier: spelling-error+Pass Unknown pseudo-element with a known identifier: spelling-errorPass Unknown pseudo-element with a known identifier: view-transitionPass Unknown pseudo-element with a known identifier: view-transition-image-pair(name)Pass Unknown pseudo-element with a known identifier: view-transition-group(name)diff --git a/Tests/LibWeb/Text/input/css/spelling-error-computed-style.html b/Tests/LibWeb/Text/input/css/spelling-error-computed-style.htmlnew file mode 100644index 00000000000..4dba32b36b5--- /dev/null+++ b/Tests/LibWeb/Text/input/css/spelling-error-computed-style.html@@ -0,0 +1,15 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ #styled::spelling-error { color: green; text-decoration-color: blue; }+</style>+<p id="plain">plain</p>+<p id="styled">styled</p>+<script>+ test(() => {+ for (const id of ["plain", "styled"]) {+ const style = getComputedStyle(document.getElementById(id), "::spelling-error");+ println(`${id}: line=${style.textDecorationLine} color=${style.color} decoration-color=${style.textDecorationColor}`);+ }+ });+</script>