Truly independent web browser
LibWeb: Return `::highlight()` styles from `getComputedStyle()`
Tim Ledbetter97c85a9f5149
diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Libraries/LibWeb/CSS/CSSStyleDeclaration.hindex 6a9a87dce20..3f6ce5a0967 100644--- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.h+++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.h@@ -58,7 +58,7 @@ public:{if (!m_owner_element)return {};- return DOM::AbstractElement { m_owner_element.as_nonnull(), m_owner_pseudo_element };+ return DOM::AbstractElement { m_owner_element.as_nonnull(), m_owner_pseudo_element, owner_highlight_name() };}void set_owner_node(Optional<DOM::AbstractElement>);@@ -66,6 +66,8 @@ public:[[nodiscard]] bool is_updating() const { return m_updating; }void set_is_updating(bool value) { m_updating = value; }+ virtual Utf16FlyString owner_highlight_name() const { return {}; }+virtual bool has_property(PropertyNameAndID const&) const { VERIFY_NOT_REACHED(); }virtual RefPtr<StyleValue const> get_property_style_value(PropertyNameAndID const&) const { VERIFY_NOT_REACHED(); }virtual WebIDL::ExceptionOr<void> set_property_style_value(PropertyNameAndID const&, NonnullRefPtr<StyleValue const>) { VERIFY_NOT_REACHED(); }diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp b/Libraries/LibWeb/CSS/CSSStyleProperties.cppindex d3fc065b8d0..a385682edec 100644--- a/Libraries/LibWeb/CSS/CSSStyleProperties.cpp+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.cpp@@ -89,6 +89,7 @@ GC::Ref<CSSStyleProperties> CSSStyleProperties::create_element_inline_style(DOM:CSSStyleProperties::CSSStyleProperties(Computed computed, Readonly readonly, RustDeclarationBlock declarations, Optional<DOM::AbstractElement> owner_node): CSSStyleDeclaration(computed, readonly), m_declarations(move(declarations))+ , m_owner_highlight_name(owner_node.has_value() ? owner_node->highlight_name() : Utf16FlyString {}){set_owner_node(move(owner_node));}@@ -474,7 +475,7 @@ static void install_engine_pseudo_element_style(Layout::BegunRead const& read, Dauto pseudo_element = *target.pseudo_element();auto& element = target.element();auto& style_engine = element.document().style_computer().style_engine();- auto answer = StyleEngineFFI::style_engine_answer_pseudo_element_record_demand(style_engine.host(), &read, element.style_node_id().value(), StyleEngine::PseudoElementRecordDemand::CssomRead, *StyleEngine::demanded_pseudo_element(pseudo_element));+ auto answer = StyleEngineFFI::style_engine_answer_pseudo_element_record_demand(style_engine.host(), &read, element.style_node_id().value(), StyleEngine::PseudoElementRecordDemand::CssomRead, *StyleEngine::demanded_pseudo_element(pseudo_element), 0);if (!answer.is_absent && answer.record.style_record == 0)return;StyleRecordID record { answer.record.style_record };@@ -745,8 +746,9 @@ Optional<StyleProperty> CSSStyleProperties::get_direct_property(PropertyNameAndI// it would have for this read alone; a read it answers with none has no value.auto& style_computer = abstract_element.document().style_computer();if (auto pseudo_element = abstract_element.pseudo_element(); pseudo_element.has_value()) {+ auto highlight_name = abstract_element.is_custom_highlight() ? style_computer.style_engine().intern_atom(abstract_element.highlight_name()) : StyleAtomID {};if (auto demanded_pseudo_element = StyleEngine::demanded_pseudo_element(*pseudo_element); demanded_pseudo_element.has_value())- transient_style = style_computer.engine_transient_pseudo_element_style(read, abstract_element.element(), *demanded_pseudo_element);+ transient_style = style_computer.engine_transient_pseudo_element_style(read, abstract_element.element(), *demanded_pseudo_element, highlight_name);}if (!transient_style)return {};diff --git a/Libraries/LibWeb/CSS/CSSStyleProperties.h b/Libraries/LibWeb/CSS/CSSStyleProperties.hindex 225e3f831bf..a05c6ef84eb 100644--- a/Libraries/LibWeb/CSS/CSSStyleProperties.h+++ b/Libraries/LibWeb/CSS/CSSStyleProperties.h@@ -56,6 +56,8 @@ public:u64 identity() const { return m_declarations.identity(); }u64 revision() const { return m_declarations.revision(); }+ virtual Utf16FlyString owner_highlight_name() const override { return m_owner_highlight_name; }+virtual bool has_property(PropertyNameAndID const&) const override;bool has_property(PropertyID) const;@@ -90,6 +92,7 @@ private:Vector<Utf16FlyString> const& computed_custom_property_names() const;RustDeclarationBlock m_declarations;+ Utf16FlyString m_owner_highlight_name;mutable Vector<Utf16FlyString> m_cached_computed_custom_property_names;mutable GC::Weak<DOM::Document> m_cached_computed_custom_property_document;mutable RefPtr<CustomPropertyData const> m_cached_computed_custom_property_data;diff --git a/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp b/Libraries/LibWeb/CSS/Parser/SelectorParsing.cppindex a201ffa704b..79b9eb77d0c 100644--- a/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp+++ b/Libraries/LibWeb/CSS/Parser/SelectorParsing.cpp@@ -27,10 +27,11 @@ Optional<Selector::PseudoElementSelector> Parser::parse_as_pseudo_element_selectif (!parsed.selector)return {};auto selector = Selector::create(parsed.selector);+ auto highlight_name = parsed.highlight_name ? Utf16FlyString::adopt_raw(parsed.highlight_name) : Utf16FlyString {};auto pseudo_element = pseudo_element_from_ffi(parsed.pseudo_element);if (!pseudo_element.has_value())return {};- return Selector::PseudoElementSelector { pseudo_element.release_value(), selector->serialize() };+ return Selector::PseudoElementSelector { pseudo_element.release_value(), selector->serialize(), move(highlight_name) };}}diff --git a/Libraries/LibWeb/CSS/PseudoElements.json b/Libraries/LibWeb/CSS/PseudoElements.jsonindex 7fb35fc2c28..836722b77a2 100644--- a/Libraries/LibWeb/CSS/PseudoElements.json+++ b/Libraries/LibWeb/CSS/PseudoElements.json@@ -99,6 +99,16 @@"spec": "https://drafts.csswg.org/css-pseudo-4/#selectordef-highlight","type": "function","function-syntax": "<highlight-name-selector>",+ "is-highlight": true,+ "property-whitelist": [+ "color",+ "background-color",+ "#text-decoration-properties",+ "FIXME: stroke-color",+ "FIXME: fill-color",+ "stroke-width",+ "#custom-properties"+ ],"accepts-animations": false},"marker": {diff --git a/Libraries/LibWeb/CSS/Selector.h b/Libraries/LibWeb/CSS/Selector.hindex 3d9e20ee1e3..8fbebe29310 100644--- a/Libraries/LibWeb/CSS/Selector.h+++ b/Libraries/LibWeb/CSS/Selector.h@@ -49,9 +49,10 @@ public:{}- PseudoElementSelector(PseudoElement type, Utf16String serialized)+ PseudoElementSelector(PseudoElement type, Utf16String serialized, Utf16FlyString highlight_name = {}): m_type(type), m_serialized(move(serialized))+ , m_highlight_name(move(highlight_name)){}@@ -67,9 +68,12 @@ public:Utf16String serialize() const;PseudoElement type() const { return m_type; }+ Utf16FlyString const& highlight_name() const { return m_highlight_name; }+private:PseudoElement m_type;Utf16String m_serialized;+ Utf16FlyString m_highlight_name;};static NonnullRefPtr<Selector> create(SelectorFFI::RustSelector*);diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cppindex 3b3fe4734e6..bc2738e4180 100644--- a/Libraries/LibWeb/CSS/StyleComputer.cpp+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp@@ -1811,9 +1811,9 @@ StyleRecordID StyleComputer::install_computed_style_inputs(Layout::BegunRead conreturn const_cast<StyleComputer&>(*this).style_engine().install_host_style_record(read, payloads, payload_source.inherited_set_values(), payload_source.reset_bits(), custom_property_environment ? custom_property_environment->identity() : 0, counter_style_environment_identity, base.record().get(), custom_property_environment ? custom_property_environment->rust_store() : nullptr);}-RefPtr<ComputedValues const> StyleComputer::engine_transient_pseudo_element_style(Layout::BegunRead const& read, DOM::Element const& element, StyleEngine::DemandedPseudoElement pseudo_element)+RefPtr<ComputedValues const> StyleComputer::engine_transient_pseudo_element_style(Layout::BegunRead const& read, DOM::Element const& element, StyleEngine::DemandedPseudoElement pseudo_element, StyleAtomID highlight_name){- auto answer = StyleEngineFFI::style_engine_answer_pseudo_element_record_demand(m_style_engine.host(), &read, element.style_node_id().value(), StyleEngine::PseudoElementRecordDemand::ReadOnly, pseudo_element);+ auto answer = StyleEngineFFI::style_engine_answer_pseudo_element_record_demand(m_style_engine.host(), &read, element.style_node_id().value(), StyleEngine::PseudoElementRecordDemand::ReadOnly, pseudo_element, highlight_name.value());InstalledStyle const style { answer.record.host_record };if (!style)return {};diff --git a/Libraries/LibWeb/CSS/StyleComputer.h b/Libraries/LibWeb/CSS/StyleComputer.hindex 54d8aa1cdce..aca0ea2486d 100644--- a/Libraries/LibWeb/CSS/StyleComputer.h+++ b/Libraries/LibWeb/CSS/StyleComputer.h@@ -60,7 +60,7 @@ public:void update_root_element_font_metrics(ComputedValues const&);// The style of a pseudo-element the element holds no style for, as the style engine derives it for one read alone;// null where the engine leaves the read to C++.- [[nodiscard]] RefPtr<ComputedValues const> engine_transient_pseudo_element_style(Layout::BegunRead const& read, DOM::Element const&, StyleEngine::DemandedPseudoElement);+ [[nodiscard]] RefPtr<ComputedValues const> engine_transient_pseudo_element_style(Layout::BegunRead const& read, DOM::Element const&, StyleEngine::DemandedPseudoElement, StyleAtomID highlight_name = {});[[nodiscard]] JsonArray collect_devtools_applied_style_rules(Layout::BegunRead const& read, DOM::AbstractElement, bool include_inherited, bool include_user_agent_styles);// The way back from a StyleEngine rule identity to what that rule contributes to the cascade.diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cppindex 0f3aac5aa67..de9b613b963 100644--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp@@ -210,8 +210,6 @@ Optional<StyleEngine::DemandedPseudoElement> StyleEngine::demanded_pseudo_elemen// The engine numbers each pseudo-element it answers as its kind: the synthetic ones, the ones an element in the// shadow tree backs, and the named view transition ones. ::part() and ::slotted() name other elements.switch (pseudo_element) {- // FIXME: Compute the styles of ::highlight() pseudo-elements for each custom highlight name.- case PseudoElement::Highlight:case PseudoElement::Part:case PseudoElement::Slotted:case PseudoElement::KnownPseudoElementCount:diff --git a/Libraries/LibWeb/DOM/AbstractElement.cpp b/Libraries/LibWeb/DOM/AbstractElement.cppindex 4481a152fb0..93571818d7f 100644--- a/Libraries/LibWeb/DOM/AbstractElement.cpp+++ b/Libraries/LibWeb/DOM/AbstractElement.cpp@@ -16,15 +16,17 @@namespace Web::DOM {-AbstractElement::AbstractElement(GC::Ref<Element> element, Optional<CSS::PseudoElement> pseudo_element)+AbstractElement::AbstractElement(GC::Ref<Element> element, Optional<CSS::PseudoElement> pseudo_element, Utf16FlyString highlight_name): m_element(element), m_pseudo_element(move(pseudo_element))+ , m_highlight_name(move(highlight_name)){}-AbstractElement::AbstractElement(Element const& element, Optional<CSS::PseudoElement> pseudo_element)+AbstractElement::AbstractElement(Element const& element, Optional<CSS::PseudoElement> pseudo_element, Utf16FlyString highlight_name): m_element(const_cast<Element&>(element)), m_pseudo_element(move(pseudo_element))+ , m_highlight_name(move(highlight_name)){}@@ -197,6 +199,11 @@ Utf16String AbstractElement::debug_description() constbuilder.append(m_element->debug_description());builder.append_ascii("::"sv);builder.append_ascii(CSS::pseudo_element_name(*m_pseudo_element));+ if (!m_highlight_name.is_empty()) {+ builder.append_code_unit('(');+ builder.append(m_highlight_name);+ builder.append_code_unit(')');+ }return builder.to_string();}return m_element->debug_description();diff --git a/Libraries/LibWeb/DOM/AbstractElement.h b/Libraries/LibWeb/DOM/AbstractElement.hindex d60d7aa2596..8d7b86876e1 100644--- a/Libraries/LibWeb/DOM/AbstractElement.h+++ b/Libraries/LibWeb/DOM/AbstractElement.h@@ -6,6 +6,7 @@#pragma once+#include <AK/Utf16FlyString.h>#include <AK/Utf16String.h>#include <LibGC/Cell.h>#include <LibWeb/CSS/PseudoElement.h>@@ -26,14 +27,16 @@ namespace Web::DOM {// FIXME: Figure out const-correctness for the Element.class WEB_API AbstractElement {public:- AbstractElement(GC::Ref<Element>, Optional<CSS::PseudoElement> = {});- AbstractElement(Element const&, Optional<CSS::PseudoElement> = {});+ AbstractElement(GC::Ref<Element>, Optional<CSS::PseudoElement> = {}, Utf16FlyString highlight_name = {});+ AbstractElement(Element const&, Optional<CSS::PseudoElement> = {}, Utf16FlyString highlight_name = {});Document& document() const;Element& element() { return m_element; }Element const& element() const { return m_element; }Optional<CSS::PseudoElement> pseudo_element() const { return m_pseudo_element; }+ Utf16FlyString const& highlight_name() const { return m_highlight_name; }+ bool is_custom_highlight() const { return m_pseudo_element == CSS::PseudoElement::Highlight && !m_highlight_name.is_empty(); }Layout::NodeWithStyle* layout_node(Layout::BegunRead const& read);Layout::NodeWithStyle const* layout_node(Layout::BegunRead const& read) const { return const_cast<AbstractElement*>(this)->layout_node(read); }@@ -89,6 +92,7 @@ public:private:GC::Ref<Element> m_element;Optional<CSS::PseudoElement> m_pseudo_element;+ Utf16FlyString m_highlight_name;};}@@ -97,6 +101,6 @@ template<>struct AK::Traits<Web::DOM::AbstractElement> : public DefaultTraits<Web::DOM::AbstractElement> {static unsigned hash(Web::DOM::AbstractElement const& key){- return pair_int_hash(ptr_hash(&key.element()), key.pseudo_element().has_value() ? to_underlying(key.pseudo_element().value()) : -1);+ return pair_int_hash(pair_int_hash(ptr_hash(&key.element()), key.pseudo_element().has_value() ? to_underlying(key.pseudo_element().value()) : -1), key.highlight_name().hash());}};diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cppindex de2485a95ff..7f6d37d8e92 100644--- a/Libraries/LibWeb/HTML/Window.cpp+++ b/Libraries/LibWeb/HTML/Window.cpp@@ -1798,7 +1798,7 @@ GC::Ref<CSS::CSSStyleProperties> Window::get_computed_style(DOM::Element& elemen// 3. Otherwise let obj be the given pseudo-element of elt.else {// TODO: Keep the function arguments of the pseudo-element if there are any.- object = { element, type.value().type() };+ object = { element, type.value().type(), type.value().highlight_name() };}// https://drafts.csswg.org/css-view-transitions-1/#update-pseudo-element-stylesdiff --git a/Libraries/LibWeb/Rust/src/css/selector_arena.rs b/Libraries/LibWeb/Rust/src/css/selector_arena.rsindex c19b07e706b..37ceaec7ada 100644--- a/Libraries/LibWeb/Rust/src/css/selector_arena.rs+++ b/Libraries/LibWeb/Rust/src/css/selector_arena.rs@@ -1188,6 +1188,31 @@ impl<'a> Selector<'a> {})}+ fn target_highlight(self) -> Option<PseudoElementSelector<'a>> {+ if self.target_pseudo_element() != Some(PseudoElementType::Highlight) {+ return None;+ }+ match self.first_compound().simple_selectors.first()? {+ SimpleSelector::PseudoElement(selector) => Some(selector),+ _ => None,+ }+ }++ #[must_use]+ pub fn target_highlight_name(self) -> StyleAtomID {+ self.target_highlight()+ .and_then(|selector| selector.identifier_identities.first().copied())+ .unwrap_or(StyleAtomID::NONE)+ }++ #[must_use]+ pub fn target_highlight_name_text(self) -> Option<&'a [u16]> {+ match self.target_highlight()?.value {+ PseudoElementValue::Identifiers(names) => names.iter().next(),+ _ => None,+ }+ }+#[must_use]pub fn styles_every_search_text_match(self) -> bool {self.target_pseudo_element() == Some(PseudoElementType::SearchText)diff --git a/Libraries/LibWeb/Rust/src/css/selector_parser.rs b/Libraries/LibWeb/Rust/src/css/selector_parser.rsindex 3bc100563b5..5b000f45130 100644--- a/Libraries/LibWeb/Rust/src/css/selector_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/selector_parser.rs@@ -26,6 +26,7 @@ use super::selector_tree::{PseudoElementValue, SelectorList, SimpleSelector, TransitionNameAndClassSelector, TransitionNameSelector,search_text_match_filter,};+use crate::css::retained_fly_string::RetainedUtf16FlyString;use crate::css::style::AtomLease;use crate::css::style::index::StyleAtomID;@@ -1501,6 +1502,7 @@ pub(crate) unsafe fn parse_selector_list_from_ffi(pub struct FfiParsedPseudoElement {pub selector: *mut RustSelector,pub pseudo_element: u8,+ pub highlight_name: usize,}/// Parses the restricted pseudo-element syntax accepted by `getComputedStyle()` and animation APIs.@@ -1509,21 +1511,24 @@ pub extern "C" fn rust_selector_parse_pseudo_element(input: FfiUtf16View,for_computed_style: bool,) -> FfiParsedPseudoElement {+ let failure = FfiParsedPseudoElement {+ selector: std::ptr::null_mut(),+ pseudo_element: u8::MAX,+ highlight_name: 0,+ };let Some(input) = input.units() else {- return FfiParsedPseudoElement {- selector: std::ptr::null_mut(),- pseudo_element: u8::MAX,- };+ return failure;};let Ok((selector, pseudo_element)) = parse_pseudo_element_selector(input, for_computed_style) else {- return FfiParsedPseudoElement {- selector: std::ptr::null_mut(),- pseudo_element: u8::MAX,- };+ return failure;};+ let highlight_name = selector.view().target_highlight_name_text().map_or(0, |name| {+ std::mem::ManuallyDrop::new(RetainedUtf16FlyString::from_utf16(name)).raw()+ });FfiParsedPseudoElement {selector: Box::into_raw(Box::new(RustSelector { selector })),pseudo_element: pseudo_element as u8,+ highlight_name,}}diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge/records.rs b/Libraries/LibWeb/Rust/src/css/style/bridge/records.rsindex 7fa9b040026..b5f01d70a03 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge/records.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge/records.rs@@ -238,6 +238,7 @@ pub enum FfiDemandedPseudoElement {SliderFill = 14,SliderThumb = 15,SliderTrack = 16,+ Highlight = 17,ViewTransitionGroup = 20,ViewTransitionImagePair = 21,ViewTransitionNew = 22,diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rsindex e17bbd0cd97..480a4d5636e 100644--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs@@ -13,6 +13,7 @@//! an animation overlay record over the record it is assigned, in a recyclable slot of its own.use super::fast_hash::FastMap as HashMap;+use super::index::StyleAtomID;use super::installed_records::{InstalledRecord, InstalledRecordID, InstalledRecords};use super::tree::StyleNodeID;use crate::css::computed_longhand_table::DEPENDS_ON_VIEWPORT_METRICS;@@ -741,11 +742,32 @@ pub struct AnimationOverlayUpdate {pub struct ComputedStyleTarget {node: StyleNodeID,pseudo_kind: u8,+ highlight_name: StyleAtomID,}impl ComputedStyleTarget {pub fn new(node: StyleNodeID, pseudo_kind: u8) -> Self {- Self { node, pseudo_kind }+ Self {+ node,+ pseudo_kind,+ highlight_name: StyleAtomID::NONE,+ }+ }++ pub(super) fn of_pseudo_element(node: StyleNodeID, target: super::pipeline::PseudoElementTarget) -> Self {+ Self {+ node,+ pseudo_kind: target.kind,+ highlight_name: target.highlight_name,+ }+ }++ #[must_use]+ pub(super) fn pseudo_element(self) -> super::pipeline::PseudoElementTarget {+ super::pipeline::PseudoElementTarget {+ kind: self.pseudo_kind,+ highlight_name: self.highlight_name,+ }}#[must_use]diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rsindex f2252dd27f7..6029d5523f8 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs@@ -857,7 +857,8 @@ pub extern "C" fn style_engine_answer_record_demand(ask_record_demand(host, read, node, RecordDemand::Element(demand))}-/// Answer a read of one of an element's pseudo-elements the host makes before the next style update.+/// Answer a read of one of an element's pseudo-elements the host makes before the next style update. `highlight_name`+/// is the atom of the custom highlight name of a `::highlight()`, and zero for any other pseudo-element.#[unsafe(no_mangle)]pub extern "C" fn style_engine_answer_pseudo_element_record_demand(host: &DocumentHost,@@ -865,8 +866,14 @@ pub extern "C" fn style_engine_answer_pseudo_element_record_demand(node: u32,demand: FfiPseudoElementRecordDemand,pseudo_element: FfiDemandedPseudoElement,+ highlight_name: u32,) -> FfiRecordDemandAnswer {- ask_record_demand(host, read, node, RecordDemand::PseudoElement(demand, pseudo_element))+ ask_record_demand(+ host,+ read,+ node,+ RecordDemand::PseudoElement(demand, pseudo_element, StyleAtomID(highlight_name)),+ )}fn ask_record_demand(diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/cascade.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/cascade.rsindex e7f9f7e825f..e5bb75eb3d3 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/cascade.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/cascade.rs@@ -176,7 +176,13 @@ impl Cascade {) -> Self {let mut cascade = Self::new();cascade.declared_only = Some(Box::new(declared));- cascade.cascade(state, index, node, &[], u8::MAX);+ cascade.cascade(+ state,+ index,+ node,+ &[],+ super::PseudoElementTarget::of_kind(super::rules::ELEMENT_PSEUDO_KIND),+ );cascade}@@ -195,7 +201,13 @@ impl Cascade {matches: &[ElementMatch],) {self.backed_kind = u8::MAX;- self.cascade(state, index, node, matches, u8::MAX);+ self.cascade(+ state,+ index,+ node,+ matches,+ super::PseudoElementTarget::of_kind(super::rules::ELEMENT_PSEUDO_KIND),+ );}/// Cascade an element standing for its shadow host's pseudo-element of `kind`, such as the@@ -210,7 +222,13 @@ impl Cascade {kind: u8,) {self.backed_kind = kind;- self.cascade(state, index, node, host_matches, kind);+ self.cascade(+ state,+ index,+ node,+ host_matches,+ super::PseudoElementTarget::of_kind(kind),+ );}/// Whether a declaration of `property` by `source` takes part in the cascade: a rule's for a@@ -221,7 +239,7 @@ impl Cascade {|| crate::css::property_metadata::pseudo_element_supports_property(self.pseudo_kind, property)}- /// Cascade the element's matches for its pseudo-element of `kind` into `winners`, as+ /// Cascade the element's matches for its pseudo-element `target` into `winners`, as/// [`Self::cascade_element`] does for the element: the element's own declarations style the/// element alone.pub(super) fn cascade_pseudo_element(@@ -230,10 +248,10 @@ impl Cascade {index: &RuleIndex,node: StyleNodeID,matches: &[ElementMatch],- kind: u8,+ target: super::PseudoElementTarget,) {self.backed_kind = u8::MAX;- self.cascade(state, index, node, matches, kind);+ self.cascade(state, index, node, matches, target);}fn cascade(@@ -242,8 +260,9 @@ impl Cascade {index: &RuleIndex,node: StyleNodeID,matches: &[ElementMatch],- pseudo_kind: u8,+ target: super::PseudoElementTarget,) {+ let pseudo_kind = target.kind;self.pseudo_kind = pseudo_kind;self.decided = [0; LONGHAND_WORDS];self.winners.clear();@@ -257,7 +276,7 @@ impl Cascade {// target's; its greatest specificity decides for the rule.let mut targeted = matches.iter()- .filter(|matched| matched.pseudo_kind == pseudo_kind)+ .filter(|matched| matched.styles(index, target)).peekable();while let Some(first) = targeted.next() {let mut specificity: Specificity = first.specificity;diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rsindex bf428a63d05..1af3831a338 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs@@ -396,7 +396,7 @@ impl RetainedState {custom_properties: super::custom_properties::CustomPropertyStores<'_>,group_cache: &mut GroupCache,absolutized: &mut crate::css::style_compute::AbsolutizedValues,- target_pseudo_kind: u8,+ target_pseudo_element: super::PseudoElementTarget,root_font: Option<RootFontInputs>,group_seeds: GroupSeeds<'_>,) -> Drive<ComputedElement> {@@ -423,6 +423,7 @@ impl RetainedState {};let parent_longhands = parent_view.as_ref().map(computed::StyleRecordView::longhands);let parent_overlay = parent_view.as_ref().and_then(|view| view.animated_overlay);+ let target_pseudo_kind = target_pseudo_element.kind;// A pseudo-element's computation reads only the facts about its element's markup language.let is_pseudo_element = target_pseudo_kind != u8::MAX;let declared_only = cascade.declared_only();@@ -835,7 +836,7 @@ impl RetainedState {return Err(Unanswered::Suspended(Suspension::RandomBaseValues));}let subject = DriveSubject {- target: computed::ComputedStyleTarget::new(node, target_pseudo_kind),+ target: computed::ComputedStyleTarget::of_pseudo_element(node, target_pseudo_element),parent: parent.map(|(parent, _)| parent),facts,};diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rsindex dac4c4788a1..b7dfa194225 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/declared_only.rs@@ -132,7 +132,7 @@ impl RetainedState {},&mut groups,&mut absolutized,- u8::MAX,+ super::PseudoElementTarget::of_kind(super::rules::ELEMENT_PSEUDO_KIND),None,initial.group_seeds(None),);diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rsindex 9cac42e04a0..4853cb1f770 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/demand.rs@@ -16,7 +16,8 @@ use super::super::publication::{DemandedEngineRecord, RecordDemand, RecordDemanduse super::super::*;use super::live::Live;use super::records::{- ChildImpact, MatchList, PseudoElementRecords, Record, RecordCells, Records, RetainedRecords, highlights_moved,+ ChildImpact, MatchList, PseudoElementRecords, PseudoElementTarget, Record, RecordCells, Records, RetainedRecords,+ highlights_moved,};use super::rule_changes::RuleIndexChanges;use super::rules::RuleIndex;@@ -291,9 +292,9 @@ impl Live {}}- /// The records of the pseudo-elements of `node` that generate a box, by kind, beside its+ /// The records of the pseudo-elements of `node` that generate a box, by target, beside its/// current record.- pub(super) fn demanded_pseudo_element_records(&self, node: StyleNodeID) -> &[(u8, Arc<Record>)] {+ pub(super) fn demanded_pseudo_element_records(&self, node: StyleNodeID) -> &[(PseudoElementTarget, Arc<Record>)] {match self.computed_on_demand(node) {true => self.demand_records().pseudo_element_records(node),false => self.records.pseudo_element_records(node),@@ -304,7 +305,7 @@ impl Live {fn demanded_highlights(&self, node: StyleNodeID) -> PseudoElementRecords {self.demanded_pseudo_element_records(node).iter()- .filter(|(kind, _)| super::HIGHLIGHT_KINDS.contains(kind))+ .filter(|(target, _)| super::super::publication::pseudo_kind::is_highlight(target.kind)).cloned().collect()}@@ -457,7 +458,7 @@ impl Live {&self,state: &RetainedState,node: StyleNodeID,- kind: u8,+ target: PseudoElementTarget,read: PseudoElementRead,inheritance_parent: Option<StyleNodeID>,) -> DemandedPseudoElement {@@ -466,7 +467,7 @@ impl Live {// has one. The passes style those only while the host shows a highlight of the kind, and// then only for the elements it shows it in, so those of the ancestors are styled for the// read too.- let styles_ancestor_highlights = super::HIGHLIGHT_KINDS.contains(&kind);+ let styles_ancestor_highlights = super::super::publication::pseudo_kind::is_highlight(target.kind);let mut cells = RecordCells::default();if styles_ancestor_highlights {cells.reserve(state.projection.element_slot_count());@@ -496,9 +497,9 @@ impl Live {.collect();for &ancestor in ancestors.iter().rev() {let mut held: PseudoElementRecords = records.pseudo_element_records(ancestor).into();- held.retain(|(held_kind, _)| *held_kind != kind);- match traversal::style_pseudo_element(&context, ancestor, kind, PseudoElementRead::Styled) {- DemandedPseudoElement::Styled(record) => held.push((kind, record)),+ held.retain(|(held_target, _)| *held_target != target);+ match traversal::style_pseudo_element(&context, ancestor, target, PseudoElementRead::Styled) {+ DemandedPseudoElement::Styled(record) => held.push((target, record)),DemandedPseudoElement::Unstyled => {}demanded @ (DemandedPseudoElement::Waiting(..) | DemandedPseudoElement::Declined) => {return demanded;@@ -507,7 +508,7 @@ impl Live {records.insert_pseudo_element_records(ancestor, held);}}- traversal::style_pseudo_element_inheriting_from(&context, node, kind, read, inheritance_parent)+ traversal::style_pseudo_element_inheriting_from(&context, node, target, read, inheritance_parent)}}@@ -545,8 +546,12 @@ impl StyleEngine {let answered = self.install_demanded_element(node, &record);RecordDemandAnswer::Record { record: answered }}- RecordDemand::PseudoElement(_, pseudo_element) => {- self.answer_pseudo_element_demand(node, &record, pseudo_element as u8, demand.is_read_only())+ RecordDemand::PseudoElement(_, pseudo_element, highlight_name) => {+ let target = PseudoElementTarget {+ kind: pseudo_element as u8,+ highlight_name,+ };+ self.answer_pseudo_element_demand(node, &record, target, demand.is_read_only())}}}@@ -822,16 +827,20 @@ impl StyleEngine {style_record: style_record.raw(),..DemandedEngineRecord::default()};- for (kind, pseudo_record) in pseudo_element_records {+ for (target, pseudo_record) in pseudo_element_records+ .iter()+ .filter(|(target, _)| !target.is_custom_highlight())+ {+ let kind = target.kind;let pseudo_environment =self.retained.pseudo_element_environment(node, pseudo_record, record, environment, minted);let pseudo_record = &self.retained.record_in_environment(pseudo_record, pseudo_environment);let pseudo_style_record = self.retained.install_record(pseudo_record, &mut installed);self.retained- .hold_demand_record(computed::ComputedStyleTarget::new(node, *kind), pseudo_style_record);+ .hold_demand_record(computed::ComputedStyleTarget::new(node, kind), pseudo_style_record);answered.pseudo_records_present |= 1 << kind;- answered.pseudo_records[usize::from(*kind)] = pseudo_style_record.raw();+ answered.pseudo_records[usize::from(kind)] = pseudo_style_record.raw();}answered}@@ -895,7 +904,7 @@ impl StyleEngine {self.install_demanded_records(node, &record, &pseudo_element_records, environment, &mut minted)}- /// Answer a read of the pseudo-element of `kind` of `node`, whose current record is `element`:+ /// Answer a read of the pseudo-element `target` of `node`, whose current record is `element`:/// the record of a pseudo-element of a kind the passes style that generates a box, and for any other/// read the style the kind computes to from the element's rules for it, whether or not it/// generates a box. A `read_only` read styles any kind; another one a kind no rule styles not,@@ -904,19 +913,20 @@ impl StyleEngine {&mut self,node: StyleNodeID,element: &Arc<Record>,- kind: u8,+ target: PseudoElementTarget,read_only: bool,) -> RecordDemandAnswer {let live = self.retained.live_style.take().expect("the engine owns the document");// The passes keep the highlight pseudo-elements current only where the host shows them.- let generated = (super::PSEUDO_ELEMENT_KINDS.contains(&kind) && !super::HIGHLIGHT_KINDS.contains(&kind))- .then(|| {- live.demanded_pseudo_element_records(node)- .iter()- .find(|(held, _)| *held == kind)- .map(|(_, record)| record.clone())- })- .flatten();+ let generated = (super::PSEUDO_ELEMENT_KINDS.contains(&target.kind)+ && !super::HIGHLIGHT_KINDS.contains(&target.kind))+ .then(|| {+ live.demanded_pseudo_element_records(node)+ .iter()+ .find(|(held, _)| *held == target)+ .map(|(_, record)| record.clone())+ })+ .flatten();let mut minted = HashMap::default();let element_environment = self.demanded_environment(&live, node, element, &mut minted);self.retained.live_style = Some(live);@@ -927,7 +937,7 @@ impl StyleEngine {true => PseudoElementRead::Any,false => PseudoElementRead::Styled,};- self.demand_pseudo_element(node, kind, read, None)+ self.demand_pseudo_element(node, target, read, None)}};let record = match demanded {@@ -947,7 +957,7 @@ impl StyleEngine {let record = self.retained.record_in_environment(&record, pseudo_environment);let style_record = self.retained.install_record(&record, &mut HashMap::default());self.retained- .hold_demand_record(computed::ComputedStyleTarget::new(node, kind), style_record);+ .hold_demand_record(computed::ComputedStyleTarget::new(node, target.kind), style_record);RecordDemandAnswer::Record {record: DemandedEngineRecord {style_record: style_record.raw(),@@ -971,7 +981,13 @@ impl StyleEngine {let DemandedElement::Styled(element_record) = live.demand_element(&self.retained, element, false) else {return None;};- let record = match live.demand_pseudo_element(&self.retained, element, kind, PseudoElementRead::Styled, None) {+ let record = match live.demand_pseudo_element(+ &self.retained,+ element,+ PseudoElementTarget::of_kind(kind),+ PseudoElementRead::Styled,+ None,+ ) {DemandedPseudoElement::Styled(record) => record,DemandedPseudoElement::Unstyled => return Some(0),DemandedPseudoElement::Waiting(..) | DemandedPseudoElement::Declined => return None,@@ -992,18 +1008,18 @@ impl StyleEngine {Some(style_record.raw())}- /// Style the pseudo-element of `kind` of `node` as [`Live::demand_pseudo_element`] does,+ /// Style the pseudo-element `target` of `node` as [`Live::demand_pseudo_element`] does,/// resolving the fonts and random base values it asks for first.fn demand_pseudo_element(&mut self,node: StyleNodeID,- kind: u8,+ target: PseudoElementTarget,read: PseudoElementRead,inheritance_parent: Option<StyleNodeID>,) -> DemandedPseudoElement {self.until_resolved(node, |engine| {let live = engine.retained.live_style.take().expect("the engine owns the document");- let demanded = live.demand_pseudo_element(&engine.retained, node, kind, read, inheritance_parent);+ let demanded = live.demand_pseudo_element(&engine.retained, node, target, read, inheritance_parent);engine.retained.live_style = Some(live);match demanded {DemandedPseudoElement::Waiting(fonts, random_bases) => Err(super::Waits { fonts, random_bases }),@@ -1024,9 +1040,12 @@ impl StyleEngine {let parent = self.retained.first_letter_inheritance_parent(node, text)?;self.retained.live_style.as_ref()?;let kind = pseudo_kind::FIRST_LETTER;- let DemandedPseudoElement::Styled(record) =- self.demand_pseudo_element(node, kind, PseudoElementRead::Styled, Some(parent))- else {+ let DemandedPseudoElement::Styled(record) = self.demand_pseudo_element(+ node,+ PseudoElementTarget::of_kind(kind),+ PseudoElementRead::Styled,+ Some(parent),+ ) else {return None;};let parent_record = self.retained.computed_group_sets.assigned_style_record(parent)?;diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rsindex 39a74d97413..d57886b944c 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs@@ -1366,7 +1366,7 @@ fn highlight_pseudo_elements_are_styled_where_the_host_shows_the_highlight() {live.records().pseudo_element_records(node).iter()- .any(|(kind, _)| *kind == SELECTION)+ .any(|(target, _)| target.kind == SELECTION)};let (mut engine, nodes) = linear_document();let sheet = add_sheet(&mut engine, TreeScopeID::DOCUMENT);diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rsindex 1bbcd681b04..4d665848817 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs@@ -19,9 +19,13 @@ pub(in crate::css::style) trait DriveRecords:{fn assigned_record_view(&self, node: StyleNodeID) -> Option<computed::StyleRecordView<'_>>;- /// The record the highlight pseudo-element of `kind` of `node` inherits from: that of the same+ /// The record the highlight pseudo-element `target` of `node` inherits from: that of the same/// pseudo-element of its nearest flat-tree ancestor holding one.- fn highlight_inheritance_parent_view(&self, node: StyleNodeID, kind: u8) -> Option<computed::StyleRecordView<'_>>;+ fn highlight_inheritance_parent_view(+ &self,+ node: StyleNodeID,+ target: super::records::PseudoElementTarget,+ ) -> Option<computed::StyleRecordView<'_>>;}impl DriveRecords for RetainedState {@@ -31,8 +35,12 @@ impl DriveRecords for RetainedState {.and_then(|record| self.computed_group_sets.style_record_view(record.raw()))}- fn highlight_inheritance_parent_view(&self, node: StyleNodeID, kind: u8) -> Option<computed::StyleRecordView<'_>> {- self.retained_highlight_inheritance_parent_style_record(node, kind)+ fn highlight_inheritance_parent_view(+ &self,+ node: StyleNodeID,+ target: super::records::PseudoElementTarget,+ ) -> Option<computed::StyleRecordView<'_>> {+ self.retained_highlight_inheritance_parent_style_record(node, target).and_then(|record| self.computed_group_sets.style_record_view(record.raw()))}}@@ -550,7 +558,7 @@ impl RetainedState {// pseudo-element of the nearest ancestor.let highlight = pseudo_kind::is_highlight(target.pseudo_kind()).then(|| {let snapshot = records- .highlight_inheritance_parent_view(target.node(), target.pseudo_kind())+ .highlight_inheritance_parent_view(target.node(), target.pseudo_element()).map(|view| {crate::css::style_compute::ParentSnapshot::from_view(view.longhands(),diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rsindex ba57dbdf27d..43decb80c55 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs@@ -420,7 +420,10 @@ impl RetainedState {.pseudo_style_record(node, kind).unwrap_or(computed::FinalStyleRecordID::NONE);let old_pseudo = old_pseudo_record.raw();- let new_pseudo_record = match pseudo_element_records.iter().find(|(held, _)| *held == kind) {+ let new_pseudo_record = match pseudo_element_records+ .iter()+ .find(|(held, _)| *held == super::PseudoElementTarget::of_kind(kind))+ {Some((_, pseudo_record)) => {// A pseudo-element's containers are its originating element's.self.note_container_unit_reads(node, pseudo_record, true);diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rsindex 6e76cb8136d..82da09a02fe 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/live.rs@@ -857,7 +857,7 @@ impl Live {} else if records.pseudo_element_records(node).iter()- .any(|(kind, record)| moved(records, ComputedStyleTarget::new(node, *kind), record))+ .any(|(target, record)| moved(records, ComputedStyleTarget::of_pseudo_element(node, *target), record)){hints.mark(node, RESTYLE_PSEUDO_ELEMENTS);}@@ -1043,7 +1043,9 @@ impl Live {.records.pseudo_element_records(node).iter()- .find_map(|(pseudo, record)| (*pseudo == kind).then_some(record))?,+ .find_map(|(pseudo, record)| {+ (*pseudo == super::PseudoElementTarget::of_kind(kind)).then_some(record)+ })?,};Some(record@@ -1065,7 +1067,9 @@ impl Live {.records.pseudo_element_records(node).iter()- .find_map(|(pseudo, record)| (*pseudo == kind).then_some(record))?,+ .find_map(|(pseudo, record)| {+ (*pseudo == super::PseudoElementTarget::of_kind(kind)).then_some(record)+ })?,};Some(&record.rare().custom_property_reads)}@@ -2328,7 +2332,7 @@ impl Live {.records.pseudo_element_records(node).iter()- .any(|(generated, _)| *generated == kind)+ .any(|(generated, _)| *generated == super::PseudoElementTarget::of_kind(kind))})});if holds_demanded {diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rsindex 3cc76699715..136ced34d74 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/matching.rs@@ -37,6 +37,11 @@ pub(super) struct ElementMatch {}impl ElementMatch {+ pub(super) fn styles(&self, index: &RuleIndex, target: super::PseudoElementTarget) -> bool {+ self.pseudo_kind == target.kind+ && (!target.is_custom_highlight() || index.highlight_name_of_entry(self.entry) == target.highlight_name)+ }+/// Whether the entry styles a pseudo-element.#[cfg(test)]pub(super) fn pseudo_element(&self) -> bool {diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rsindex 3599f5e9c34..14519c242de 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/mod.rs@@ -59,6 +59,7 @@ pub(super) use cascade::DeclaredOnly;pub(super) use live::Live;#[cfg(test)]pub(super) use records::PseudoElementStyles;+pub(super) use records::PseudoElementTarget;pub(crate) use records::Record;pub(crate) use records::{CustomDeclarations, RareSetFacts, RareStyleFacts};pub(super) use records::{RecordFacts, Sample};diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rsindex 411c24809c1..11351f03b87 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/records.rs@@ -137,6 +137,26 @@ impl RecordHeader {}}+/// The pseudo-element of a kind, or the `::highlight()` of a custom highlight name.+#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]+pub(in super::super) struct PseudoElementTarget {+ pub(in super::super) kind: u8,+ pub(in super::super) highlight_name: StyleAtomID,+}++impl PseudoElementTarget {+ pub(in super::super) const fn of_kind(kind: u8) -> Self {+ Self {+ kind,+ highlight_name: StyleAtomID::NONE,+ }+ }++ pub(in super::super) fn is_custom_highlight(self) -> bool {+ !self.highlight_name.is_none()+ }+}+/// The pseudo-elements of an element that generate a box, as a bit per kind.#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]pub(in super::super) struct PseudoElementStyles(u16);@@ -145,8 +165,13 @@ impl PseudoElementStyles {pub(in super::super) const NONE: Self = Self(0);/// The pseudo-elements `records` style, by kind.- pub(in super::super) fn of(records: &[(u8, Arc<Record>)]) -> Self {- Self(records.iter().fold(0, |mask, (kind, _)| mask | (1 << kind)))+ pub(in super::super) fn of(records: &[(PseudoElementTarget, Arc<Record>)]) -> Self {+ Self(+ records+ .iter()+ .filter(|(target, _)| !target.is_custom_highlight())+ .fold(0, |mask, (target, _)| mask | (1 << target.kind)),+ )}/// The pseudo-elements of the kinds whose bits `bits` holds, as a test names them.@@ -1268,21 +1293,26 @@ pub(super) type HeldCustomProperties = Option<Arc<crate::css::custom_properties:/// record, unless its animations sampled them.pub(super) type BorrowedCustomProperties<'a> = Option<Cow<'a, Arc<crate::css::custom_properties::CustomPropertyStore>>>;-pub(super) type PseudoElementRecords = smallvec::SmallVec<[(u8, Arc<Record>); 2]>;+pub(super) type PseudoElementRecords = smallvec::SmallVec<[(PseudoElementTarget, Arc<Record>); 2]>;/// https://drafts.csswg.org/css-pseudo-4/#highlight-cascade/// Whether the highlight pseudo-elements of `new` hold other styles than those of `old`, which the/// highlight pseudo-elements of an element's children inherit from.-pub(super) fn highlights_moved(new: &[(u8, Arc<Record>)], old: &[(u8, Arc<Record>)]) -> bool {- let of_kind = |records: &'_ [(u8, Arc<Record>)], kind: u8| {+pub(super) fn highlights_moved(+ new: &[(PseudoElementTarget, Arc<Record>)],+ old: &[(PseudoElementTarget, Arc<Record>)],+) -> bool {+ let of_target = |records: &'_ [(PseudoElementTarget, Arc<Record>)], target: PseudoElementTarget| {records.iter()- .find(|(held, _)| *held == kind)+ .find(|(held, _)| *held == target).map(|(_, record)| record.clone())};- super::HIGHLIGHT_KINDS- .iter()- .any(|&kind| match (of_kind(new, kind), of_kind(old, kind)) {+ new.iter()+ .chain(old)+ .map(|&(target, _)| target)+ .filter(|target| super::super::publication::pseudo_kind::is_highlight(target.kind))+ .any(|target| match (of_target(new, target), of_target(old, target)) {(None, None) => false,(Some(new), Some(old)) => !Arc::ptr_eq(&new, &old) && !new.holds_the_same_as(&old),_ => true,@@ -1324,7 +1354,7 @@ impl RetainedSlot {self.held.is_none() && self.rare.is_none()}- fn pseudo_element_records(&self) -> &[(u8, Arc<Record>)] {+ fn pseudo_element_records(&self) -> &[(PseudoElementTarget, Arc<Record>)] {self.rare.as_ref().map_or(&[], |rare| rare.pseudo_element_records.as_slice())@@ -1460,7 +1490,7 @@ impl RetainedRecords {self.held(node)?.matches.as_ref()}- pub(super) fn pseudo_element_records(&self, node: StyleNodeID) -> &[(u8, Arc<Record>)] {+ pub(super) fn pseudo_element_records(&self, node: StyleNodeID) -> &[(PseudoElementTarget, Arc<Record>)] {self.slot(node.element_slot()).map_or(&[], RetainedSlot::pseudo_element_records)}@@ -1991,8 +2021,8 @@ impl<'a> Records<'a> {self.get_shared(node).map(|record| &**record)}- /// The records of the pseudo-elements of `node` that generate a box, by kind.- pub(super) fn pseudo_element_records(&self, node: StyleNodeID) -> &'a [(u8, Arc<Record>)] {+ /// The records of the pseudo-elements of `node` that generate a box, by target.+ pub(super) fn pseudo_element_records(&self, node: StyleNodeID) -> &'a [(PseudoElementTarget, Arc<Record>)] {match self.cells.pseudo_element_records(node.element_slot()) {Some(records) => records.as_slice(),None if self.computed(node) => &[],@@ -2326,10 +2356,14 @@ impl Record {}impl<'a> Records<'a> {- /// The record the highlight pseudo-element of `kind` of `node` inherits from: that of the same+ /// The record the highlight pseudo-element `target` of `node` inherits from: that of the same/// pseudo-element of its nearest flat-tree ancestor holding one, here or, for an ancestor these/// records hold nothing for, as it is installed.- pub(super) fn highlight_inheritance_parent(&self, node: StyleNodeID, kind: u8) -> Option<HighlightParent<'a>> {+ pub(super) fn highlight_inheritance_parent(+ &self,+ node: StyleNodeID,+ target: PseudoElementTarget,+ ) -> Option<HighlightParent<'a>> {let mut ancestor = self.state.projection.inheritance_parent(node);while let Some(current) = ancestor {match self.get(current) {@@ -2337,13 +2371,13 @@ impl<'a> Records<'a> {if let Some((_, record)) = self.pseudo_element_records(current).iter()- .find(|(held, _)| *held == kind)+ .find(|(held, _)| *held == target){return Some(HighlightParent::Record(record));}}None => {- if let Some(record) = self.state.computed_group_sets.pseudo_style_record(current, kind) {+ if let Some(record) = self.state.installed_pseudo_style_record(current, target) {return Some(HighlightParent::Installed(record));}}@@ -2373,8 +2407,12 @@ impl DriveRecords for Records<'_> {Some(record.view())}- fn highlight_inheritance_parent_view(&self, node: StyleNodeID, kind: u8) -> Option<computed::StyleRecordView<'_>> {- match self.highlight_inheritance_parent(node, kind)? {+ fn highlight_inheritance_parent_view(+ &self,+ node: StyleNodeID,+ target: PseudoElementTarget,+ ) -> Option<computed::StyleRecordView<'_>> {+ match self.highlight_inheritance_parent(node, target)? {HighlightParent::Record(record) => Some(record.view()),HighlightParent::Installed(record) => self.state.computed_group_sets.style_record_view(record.raw()),}diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rsindex fd221ef3846..8cbc74eafe3 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/rules.rs@@ -2284,6 +2284,10 @@ impl RuleIndex {.resolve(self.entries.view(entry as usize).selector())}+ pub(super) fn highlight_name_of_entry(&self, entry: u32) -> StyleAtomID {+ self.selector_of_entry(entry).target_highlight_name()+ }+/// The arena holding the selector of entry `entry`.pub(super) fn arena_of_entry(&self, entry: u32) -> &crate::css::selector::SelectorListRef {let space = self.space_of_entry(entry);diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/self_check.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/self_check.rsindex 9e870dd19dd..5532a2aa138 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/self_check.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/self_check.rs@@ -129,6 +129,13 @@ pub(super) fn pseudo_element_name(kind: u8) -> String {}}+pub(super) fn pseudo_element_target_name(target: super::PseudoElementTarget) -> String {+ match target.is_custom_highlight() {+ true => format!("::highlight() of atom {}", target.highlight_name.0),+ false => pseudo_element_name(target.kind),+ }+}+fn payloads_equal(group: usize,first: &crate::css::computed_values::GroupPointer,@@ -397,27 +404,31 @@ pub(super) fn differences_by_element(}compared += 1;let (live, cold) = (live.pseudo_element_records(node), cold.pseudo_element_records(node));- let kinds = |records: &[(u8, Arc<Record>)]| records.iter().map(|(kind, _)| *kind).collect::<Vec<_>>();- if kinds(live) != kinds(cold) {- let names = |kinds: Vec<u8>| kinds.into_iter().map(pseudo_element_name).collect::<Vec<_>>();+ let targets = |records: &[(super::PseudoElementTarget, Arc<Record>)]| {+ records.iter().map(|(target, _)| *target).collect::<Vec<_>>()+ };+ if targets(live) != targets(cold) {+ let names = |targets: Vec<super::PseudoElementTarget>| {+ targets.into_iter().map(pseudo_element_target_name).collect::<Vec<_>>()+ };failures.push((node,format!("live holds the pseudo-elements {:?}, cold computed {:?}",- names(kinds(live)),- names(kinds(cold))+ names(targets(live)),+ names(targets(cold))),));continue;}- for ((kind, live), (_, cold)) in live.iter().zip(cold) {+ for ((target, live), (_, cold)) in live.iter().zip(cold) {let differences = record_differences(live, cold);if !differences.is_empty() {failures.push((node,format!("{}: live differs from cold in {}",- pseudo_element_name(*kind),+ pseudo_element_target_name(*target),differences.join(", ")),));@@ -462,9 +473,9 @@ pub(super) fn installed_differences());}}- for (kind, held) in live.pseudo_element_records(node) {- let Some(record) = installed- .pseudo_style_record(node, *kind)+ for (target, held) in live.pseudo_element_records(node) {+ let Some(record) = state+ .installed_pseudo_style_record(node, *target).and_then(|record| installed.installed_base_record(record))else {continue;@@ -473,7 +484,7 @@ pub(super) fn installed_differences(if !differences.is_empty() {failures.push(format!("{} of {}: the installed record differs from live in {}",- pseudo_element_name(*kind),+ pseudo_element_target_name(*target),describe(node),differences.join(", ")));diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/sharing.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/sharing.rsindex a994ddda9b6..30e1e2d73d2 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/sharing.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/sharing.rs@@ -122,7 +122,7 @@ pub(super) fn key_of(super::HIGHLIGHT_KINDS.map(|kind| {parent_records.iter()- .find(|(held, _)| *held == kind)+ .find(|(held, _)| *held == super::PseudoElementTarget::of_kind(kind)).map_or(0, |(_, record)| Arc::as_ptr(record) as usize)})},diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rsindex f90e6bf879f..8140f25fd2d 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs@@ -550,9 +550,9 @@ struct Scratch<'a> {backing_elements_moved: bool,/// What `LIBWEB_STYLE_AUDIT_CACHES` found of what the pass reused, where it is set.cache_audit: Option<Box<cache_audit::CacheAudit>>,- /// The kinds of the pseudo-elements of the element styled last whose records came from the+ /// The pseudo-elements of the element styled last whose records came from the/// matched declarations cache, kept for the audit alone.- pseudo_element_cache_hits: SmallVec<[u8; 2]>,+ pseudo_element_cache_hits: SmallVec<[super::PseudoElementTarget; 2]>,}impl<'a> Scratch<'a> {@@ -1235,14 +1235,21 @@ impl<'a> Scratch<'a> {if kinds & (1 << kind) == 0 {continue;}- match self.compute_pseudo_element(context, node, &element, &inherited, kind, PseudoElementRead::Generating)- {+ let target = super::PseudoElementTarget::of_kind(kind);+ match self.compute_pseudo_element(+ context,+ node,+ &element,+ &inherited,+ target,+ PseudoElementRead::Generating,+ ) {PseudoElementOutcome::Computed {record,element_dependent: dependent,} => {element_dependent |= dependent;- pseudo_element_records.push((kind, record));+ pseudo_element_records.push((target, record));}PseudoElementOutcome::Declined => self.statistics.pseudo_elements_declined += 1,// A pseudo-element waiting on a font or a random base value is styled again with@@ -1255,7 +1262,7 @@ impl<'a> Scratch<'a> {Some((pseudo_element_records, element_dependent))}- /// Compute the style of the pseudo-element of `kind` of `node`, whose record is `element`, from the+ /// Compute the style of the pseudo-element `target` of `node`, whose record is `element`, from the/// rules it matched for it, cascaded over what it inherits, `inherited`. Which pseudo-elements/// are styled is what `read` says.fn compute_pseudo_element(@@ -1264,17 +1271,18 @@ impl<'a> Scratch<'a> {node: StyleNodeID,element: &std::sync::Arc<Record>,inherited: &PseudoElementInheritance<'_>,- kind: u8,+ target: super::PseudoElementTarget,read: PseudoElementRead,) -> PseudoElementOutcome {let state = context.state;+ let kind = target.kind;let matches: &[ElementMatch] = match self.gated {true => &self.applied,false => &self.matches,};- let has_rules = matches.iter().any(|matched| matched.pseudo_kind == kind);+ let has_rules = matches.iter().any(|matched| matched.styles(context.index, target));let generating = read == PseudoElementRead::Generating;- let highlight = super::HIGHLIGHT_KINDS.contains(&kind);+ let highlight = super::super::publication::pseudo_kind::is_highlight(kind);// A pass styles the highlight pseudo-elements of the elements the host shows a highlight// of their kind in, and a read of their styles those of any other.if generating && highlight && !state.highlight_observers.observes(node, kind) {@@ -1291,7 +1299,7 @@ impl<'a> Scratch<'a> {// https://drafts.csswg.org/css-pseudo-4/#highlight-cascade// A highlight pseudo-element no rule styles still inherits the one of an ancestor.let highlight_parent = highlight- .then(|| context.records.highlight_inheritance_parent(node, kind))+ .then(|| context.records.highlight_inheritance_parent(node, target)).flatten();if !read.styles(kind, has_rules || highlight_parent.is_some(), element) {return PseudoElementOutcome::Unstyled;@@ -1308,7 +1316,7 @@ impl<'a> Scratch<'a> {.map(|(record, _)| record.clone())}) {if self.cache_audit.is_some() {- self.pseudo_element_cache_hits.push(kind);+ self.pseudo_element_cache_hits.push(target);}return PseudoElementOutcome::Computed {record,@@ -1323,7 +1331,7 @@ impl<'a> Scratch<'a> {return PseudoElementOutcome::Waiting;}self.cascade- .cascade_pseudo_element(state, context.index, node, matches, kind);+ .cascade_pseudo_element(state, context.index, node, matches, target);// A pseudo-element's own custom properties resolve over what its element hands down,// as a child's do.let subject = SubstitutionSubject::new(context, node, Some(kind));@@ -1382,7 +1390,7 @@ impl<'a> Scratch<'a> {},&mut self.groups,&mut self.absolutized,- kind,+ target,context.root_font(),group_seeds,);@@ -1419,7 +1427,7 @@ impl<'a> Scratch<'a> {},&mut self.groups,&mut self.absolutized,- kind,+ target,context.root_font(),group_seeds,);@@ -1469,7 +1477,7 @@ impl<'a> Scratch<'a> {&& Self::reads_nothing_of_the_element(&computed);let value_of = |property| computed.groups.value(property);let counter_style_environment_identity = state.values_counter_style_environment_identity(- super::super::computed::ComputedStyleTarget::new(node, kind),+ super::super::computed::ComputedStyleTarget::of_pseudo_element(node, target),|property| {computed.value_facts@@ -1802,7 +1810,7 @@ impl<'a> Scratch<'a> {},&mut self.groups,&mut self.absolutized,- u8::MAX,+ super::PseudoElementTarget::of_kind(super::rules::ELEMENT_PSEUDO_KIND),context.root_font(),group_seeds,);@@ -1842,7 +1850,7 @@ impl<'a> Scratch<'a> {},&mut self.groups,&mut self.absolutized,- u8::MAX,+ super::PseudoElementTarget::of_kind(super::rules::ELEMENT_PSEUDO_KIND),context.root_font(),group_seeds,);@@ -2988,7 +2996,7 @@ pub(super) enum DemandedPseudoElement {Declined,}-/// Style the pseudo-element of `kind` of `node` for a read of its style, whether or not it+/// Style the pseudo-element `target` of `node` for a read of its style, whether or not it/// generates a box, from the rules the element matches for it, over the record `context` holds for/// `node`, which it inherits from. Which pseudo-elements are styled is what `read` says./// Whether the computed values of `computed` hold `display: none`.@@ -3004,18 +3012,18 @@ fn computed_display_is_none(computed: &super::compute::ComputedElement) -> boolpub(super) fn style_pseudo_element(context: &PassContext<'_>,node: StyleNodeID,- kind: u8,+ target: super::PseudoElementTarget,read: PseudoElementRead,) -> DemandedPseudoElement {- style_pseudo_element_inheriting_from(context, node, kind, read, None)+ style_pseudo_element_inheriting_from(context, node, target, read, None)}-/// Style the pseudo-element of `kind` of `node` as [`style_pseudo_element`] does, inheriting from+/// Style the pseudo-element `target` of `node` as [`style_pseudo_element`] does, inheriting from/// `inheritance_parent` rather than from `node` where it names an element.pub(super) fn style_pseudo_element_inheriting_from(context: &PassContext<'_>,node: StyleNodeID,- kind: u8,+ target: super::PseudoElementTarget,read: PseudoElementRead,inheritance_parent: Option<StyleNodeID>,) -> DemandedPseudoElement {@@ -3046,7 +3054,7 @@ pub(super) fn style_pseudo_element_inheriting_from(}None => PseudoElementInheritance::of(context, node, &element),};- let outcome = scratch.compute_pseudo_element(context, node, &element, &inherited, kind, read);+ let outcome = scratch.compute_pseudo_element(context, node, &element, &inherited, target, read);if !scratch.statistics.font_requests.is_empty() || !scratch.statistics.random_requests.is_empty() {return DemandedPseudoElement::Waiting(std::mem::take(&mut scratch.statistics.font_requests),diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal/cache_audit.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal/cache_audit.rsindex 31bab0f75d2..880765ee144 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal/cache_audit.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal/cache_audit.rs@@ -15,8 +15,8 @@//! but `0` aborts there.use super::super::super::*;-use super::super::records::{PseudoElementRecords, Record};-use super::super::self_check::{Mode, describe, pseudo_element_name, record_differences};+use super::super::records::{PseudoElementRecords, PseudoElementTarget, Record};+use super::super::self_check::{Mode, describe, pseudo_element_name, pseudo_element_target_name, record_differences};use super::{PassContext, Scratch, is_document_element};use std::sync::Arc;@@ -158,20 +158,24 @@ impl Scratch<'_> {return;};let live_pseudo_elements = context.records.pseudo_element_records(node);- let kinds = |records: &[(u8, Arc<Record>)]| records.iter().map(|(kind, _)| *kind).collect::<Vec<_>>();- if kinds(live_pseudo_elements) != kinds(cold_pseudo_elements) {- let names = |kinds: Vec<u8>| kinds.into_iter().map(pseudo_element_name).collect::<Vec<_>>();+ let targets = |records: &[(PseudoElementTarget, Arc<Record>)]| {+ records.iter().map(|(target, _)| *target).collect::<Vec<_>>()+ };+ if targets(live_pseudo_elements) != targets(cold_pseudo_elements) {+ let names = |targets: Vec<PseudoElementTarget>| {+ targets.into_iter().map(pseudo_element_target_name).collect::<Vec<_>>()+ };audit.failures.push(format!("{}, from {}: live holds the pseudo-elements {:?}, cold computes {:?}",element(),reuse.name(),- names(kinds(live_pseudo_elements)),- names(kinds(cold_pseudo_elements))+ names(targets(live_pseudo_elements)),+ names(targets(cold_pseudo_elements))));return;}- for ((kind, live), (_, cold)) in live_pseudo_elements.iter().zip(cold_pseudo_elements) {- let reuse = match self.pseudo_element_cache_hits.contains(kind) {+ for ((target, live), (_, cold)) in live_pseudo_elements.iter().zip(cold_pseudo_elements) {+ let reuse = match self.pseudo_element_cache_hits.contains(target) {true => Reuse::PseudoElementRecord,false => reuse,};@@ -180,7 +184,7 @@ impl Scratch<'_> {if !differences.is_empty() {audit.failures.push(format!("{} of {}, from {}: live differs from cold in {}",- pseudo_element_name(*kind),+ pseudo_element_target_name(*target),element(),reuse.name(),differences.join(", ")diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rsindex 15222858ab2..0202767c307 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs@@ -33,14 +33,14 @@ pub(crate) struct SubtreeGeneratedContentEffects {impl RetainedState {/// The record a highlight pseudo-element inherits from: the same pseudo-element's record on its/// nearest flat-tree ancestor holding one, as the engine has it assigned.- pub(crate) fn retained_highlight_inheritance_parent_style_record(+ pub(in crate::css::style) fn retained_highlight_inheritance_parent_style_record(&self,node: StyleNodeID,- pseudo_kind: u8,+ target: pipeline::PseudoElementTarget,) -> Option<computed::FinalStyleRecordID> {let mut ancestor = self.projection.inheritance_parent(node);while let Some(candidate) = ancestor {- if let Some(record) = self.computed_group_sets.pseudo_style_record(candidate, pseudo_kind) {+ if let Some(record) = self.installed_pseudo_style_record(candidate, target) {return Some(record);}ancestor = self.projection.inheritance_parent(candidate);@@ -48,6 +48,17 @@ impl RetainedState {None}+ pub(in crate::css::style) fn installed_pseudo_style_record(+ &self,+ node: StyleNodeID,+ target: pipeline::PseudoElementTarget,+ ) -> Option<computed::FinalStyleRecordID> {+ match target.is_custom_highlight() {+ true => None,+ false => self.computed_group_sets.pseudo_style_record(node, target.kind),+ }+ }+#[cfg(test)]pub(super) fn retained_store_supports_property(target: computed::ComputedStyleTarget, property: u16) -> bool {if property > crate::css::property_metadata::LAST_LONGHAND_PROPERTY_ID@@ -842,10 +853,15 @@ pub(super) mod pseudo_kind {pub(in crate::css::style) const SELECTION: u8 = 8;pub(in crate::css::style) const SPELLING_ERROR: u8 = 9;pub(in crate::css::style) const SYNTHETIC_COUNT: usize = 11;+ pub(in crate::css::style) const HIGHLIGHT: u8 = 17;+ const _: () = assert!(HIGHLIGHT as u16 == crate::css::selector::PseudoElementType::Highlight as u16);/// 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 | SPELLING_ERROR)+ matches!(+ kind,+ SEARCH_TEXT | SEARCH_TEXT_CURRENT | SELECTION | SPELLING_ERROR | HIGHLIGHT+ )}}@@ -876,16 +892,17 @@ mod tests {};let root_record = publish(&mut engine, root, 0);assert_eq!(- engine.retained_highlight_inheritance_parent_style_record(parent, 0),+ engine+ .retained_highlight_inheritance_parent_style_record(parent, pipeline::PseudoElementTarget::of_kind(0)),Some(root_record));assert_eq!(- engine.retained_highlight_inheritance_parent_style_record(child, 0),+ engine.retained_highlight_inheritance_parent_style_record(child, pipeline::PseudoElementTarget::of_kind(0)),Some(root_record));let slot_record = publish(&mut engine, slot, 0);assert_eq!(- engine.retained_highlight_inheritance_parent_style_record(child, 0),+ engine.retained_highlight_inheritance_parent_style_record(child, pipeline::PseudoElementTarget::of_kind(0)),Some(slot_record));}diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs b/Libraries/LibWeb/Rust/src/css/style/publication/demand.rsindex a0fe6e813e6..fbf318babca 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs@@ -14,7 +14,11 @@ use super::*;#[derive(Clone, Copy, Debug)]pub(crate) enum RecordDemand {Element(bridge::FfiRecordDemand),- PseudoElement(bridge::FfiPseudoElementRecordDemand, bridge::FfiDemandedPseudoElement),+ PseudoElement(+ bridge::FfiPseudoElementRecordDemand,+ bridge::FfiDemandedPseudoElement,+ StyleAtomID,+ ),}impl RecordDemand {@@ -25,7 +29,7 @@ impl RecordDemand {self,Self::Element(Element::ElementRead | Element::ElementReadWithoutInlineStyle | Element::ElementReadAgainstParent- ) | Self::PseudoElement(Pseudo::ReadOnly, _)+ ) | Self::PseudoElement(Pseudo::ReadOnly, _, _))}}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 4325dac7f41..3d2e6d0a752 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -13,6 +13,7 @@ use crate::css::style::bridge::{ElementBoxKind, FfiDemandedPseudoElement, FfiPseudoElementRecordDemand, answer_record_demand,element_adjustment_fact,};+use crate::css::style::index::StyleAtomID;use crate::css::style::layout_style::{AnonymousStyleKind, AnonymousStyleOverrides, DerivedStyleRecord, LayoutStyle};use crate::css::style::tree::StyleNodeID;use crate::layout::layout_node_arena::{LayoutNodeArena, OwedImageResources, StaleWalkFacts};@@ -3606,6 +3607,7 @@ fn stamp_nested_list_marker_row(let demand = RecordDemand::PseudoElement(FfiPseudoElementRecordDemand::ReadOnly,FfiDemandedPseudoElement::Marker,+ StyleAtomID::NONE,);let record = answer_record_demand(engine, generator, demand).record.style_record;(record != 0).then_some(record)diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-008.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-008.txtindex 223d0264538..1f0a58cd74b 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-008.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-008.txt@@ -2,14 +2,13 @@ Harness status: OKFound 9 tests-8 Pass-1 Fail+9 PassPass Originating element container for ::beforePass Originating element container for ::afterPass Originating element container for ::markerPass Originating element container for ::first-linePass Originating element container for ::first-letter-Fail Originating element container for ::highlight+Pass Originating element container for ::highlightPass Originating element container for outer ::first-linePass Originating element container for outer ::first-letterPass Originating element container for ::backdrop\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-013.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-013.txtindex ac90fcaec4c..af0136892ba 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-013.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-conditional/container-queries/pseudo-elements-013.txt@@ -2,7 +2,7 @@ Harness status: OKFound 3 tests-3 Fail-Fail Initial text-decoration-thickness for highlight pseudo-Fail text-decoration-thickness for highlight pseudo depending on container-Fail text-decoration-thickness for highlight pseudo depending on container only defined in a query\ No newline at end of file+3 Pass+Pass Initial text-decoration-thickness for highlight pseudo+Pass text-decoration-thickness for highlight pseudo depending on container+Pass text-decoration-thickness for highlight pseudo depending on container only defined in a query\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txtindex 512bd0fdbb7..8c01d48d19f 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-computed.txt@@ -2,10 +2,9 @@ Harness status: OKFound 12 tests-10 Pass-2 Fail-Fail getComputedStyle() for ::highlight(foo)-Fail Different getComputedStyle() for ::highlight(bar) and same element+12 Pass+Pass getComputedStyle() for ::highlight(foo)+Pass Different getComputedStyle() for ::highlight(bar) and same elementPass getComputedStyle() for ::highlight(foo): should not return a style.Pass getComputedStyle() for ::highlight(foo)) should not return a style.Pass getComputedStyle() for ::highlight(foo)( should not return a style.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.txtindex 4c238641884..76f4d31a956 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@@ -2,7 +2,7 @@ Harness status: OKFound 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+3 Pass+Pass getComputedStyle() for root element+Pass getComputedStyle() for root highlight applied to div+Pass getComputedStyle() for div specific highlight\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-inheritance.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-inheritance.txtnew file mode 100644index 00000000000..c139410fdab--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-inheritance.txt@@ -0,0 +1,12 @@+Harness status: OK++Found 6 tests++4 Pass+2 Fail+Pass getComputedStyle() for ::selection+Fail getComputedStyle() for ::target-text+Pass getComputedStyle() for ::search-text+Pass getComputedStyle() for ::spelling-error+Fail getComputedStyle() for ::grammar-error+Pass getComputedStyle() for ::highlight(foo)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-visited.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-visited.txtnew file mode 100644index 00000000000..98849abfddb--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-visited.txt@@ -0,0 +1,18 @@+Harness status: OK++Found 12 tests++6 Pass+6 Fail+Pass getComputedStyle() for ::selection at #target1+Pass getComputedStyle() for ::selection at #target2+Fail getComputedStyle() for ::target-text at #target1+Fail getComputedStyle() for ::target-text at #target2+Pass getComputedStyle() for ::search-text at #target1+Pass getComputedStyle() for ::search-text at #target2+Fail getComputedStyle() for ::spelling-error at #target1+Fail getComputedStyle() for ::spelling-error at #target2+Fail getComputedStyle() for ::grammar-error at #target1+Fail getComputedStyle() for ::grammar-error at #target2+Pass getComputedStyle() for ::highlight(foo) at #target1+Pass getComputedStyle() for ::highlight(foo) at #target2\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed.txtnew file mode 100644index 00000000000..79b1f2b8bb5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed.txt@@ -0,0 +1,18 @@+Harness status: OK++Found 12 tests++8 Pass+4 Fail+Pass getComputedStyle() for ::selection at #target1+Pass getComputedStyle() for ::selection at #target2+Fail getComputedStyle() for ::target-text at #target1+Fail getComputedStyle() for ::target-text at #target2+Pass getComputedStyle() for ::search-text at #target1+Pass getComputedStyle() for ::search-text at #target2+Pass getComputedStyle() for ::spelling-error at #target1+Pass getComputedStyle() for ::spelling-error at #target2+Fail getComputedStyle() for ::grammar-error at #target1+Fail getComputedStyle() for ::grammar-error at #target2+Pass getComputedStyle() for ::highlight(foo) at #target1+Pass getComputedStyle() for ::highlight(foo) at #target2\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-computed.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-computed.txtnew file mode 100644index 00000000000..dd70359b8eb--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-computed.txt@@ -0,0 +1,47 @@+Harness status: OK++Found 41 tests++39 Pass+2 Fail+Pass getComputedStyle() for ::selection+Pass getComputedStyle() for ::selection: should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::selection) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::selection( should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::selection(foo) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::selection() should return an empty CSSStyleDeclaration+Pass getComputedStyle() for :::selection should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::selection. should return an empty CSSStyleDeclaration+Fail getComputedStyle() for ::target-text+Pass getComputedStyle() for ::target-text: should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::target-text) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::target-text( should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::target-text(foo) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::target-text() should return an empty CSSStyleDeclaration+Pass getComputedStyle() for :::target-text should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::target-text. should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::spelling-error+Pass getComputedStyle() for ::spelling-error: should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::spelling-error) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::spelling-error( should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::spelling-error(foo) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::spelling-error() should return an empty CSSStyleDeclaration+Pass getComputedStyle() for :::spelling-error should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::spelling-error. should return an empty CSSStyleDeclaration+Fail getComputedStyle() for ::grammar-error+Pass getComputedStyle() for ::grammar-error: should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::grammar-error) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::grammar-error( should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::grammar-error(foo) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::grammar-error() should return an empty CSSStyleDeclaration+Pass getComputedStyle() for :::grammar-error should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::grammar-error. should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::highlight(foo)+Pass getComputedStyle() for ::highlight(foo): should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::highlight(foo)) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::highlight(foo)( should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::highlight(foo)(foo) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::highlight(foo)() should return an empty CSSStyleDeclaration+Pass getComputedStyle() for :::highlight(foo) should return an empty CSSStyleDeclaration+Pass getComputedStyle() for ::highlight(foo). should return an empty CSSStyleDeclaration+Pass Different getComputedStyle() for ::highlight(bar) and same element\ No newline at end of filediff --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 becb3079758..c094f249e16 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,8 +2,8 @@ Harness status: OKFound 12 tests-6 Pass-6 Fail+8 Pass+4 FailPass getComputedStyle() for ::selection at #child1Pass getComputedStyle() for ::selection at #child2Fail getComputedStyle() for ::target-text at #child1@@ -14,5 +14,5 @@ Pass getComputedStyle() for ::spelling-error at #child1Pass getComputedStyle() for ::spelling-error at #child2Fail getComputedStyle() for ::grammar-error at #child1Fail getComputedStyle() for ::grammar-error at #child2-Fail getComputedStyle() for ::highlight(foo) at #child1-Fail getComputedStyle() for ::highlight(foo) at #child2\ No newline at end of file+Pass getComputedStyle() for ::highlight(foo) at #child1+Pass getComputedStyle() for ::highlight(foo) at #child2\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-visited-computed-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-visited-computed-001.txtnew file mode 100644index 00000000000..79b1f2b8bb5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-visited-computed-001.txt@@ -0,0 +1,18 @@+Harness status: OK++Found 12 tests++8 Pass+4 Fail+Pass getComputedStyle() for ::selection at #target1+Pass getComputedStyle() for ::selection at #target2+Fail getComputedStyle() for ::target-text at #target1+Fail getComputedStyle() for ::target-text at #target2+Pass getComputedStyle() for ::search-text at #target1+Pass getComputedStyle() for ::search-text at #target2+Pass getComputedStyle() for ::spelling-error at #target1+Pass getComputedStyle() for ::spelling-error at #target2+Fail getComputedStyle() for ::grammar-error at #target1+Fail getComputedStyle() for ::grammar-error at #target2+Pass getComputedStyle() for ::highlight(foo) at #target1+Pass getComputedStyle() for ::highlight(foo) at #target2\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-shadow/part/pseudo-elements-after-part.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-shadow/part/pseudo-elements-after-part.txtnew file mode 100644index 00000000000..e9f56a4c926--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-shadow/part/pseudo-elements-after-part.txt@@ -0,0 +1,79 @@+Harness status: OK++Found 44 tests++38 Pass+6 Fail+Pass "::part(mypart)::part(anotherpart)" should be an invalid selector+Pass "::part(mypart)::notarealpseudoelement" should be an invalid selector+Pass "::part(mypart)::after" should be a valid selector+Pass "::part(mypart)::backdrop" should be a valid selector+Pass "::part(mypart)::before" should be a valid selector+Fail "::part(mypart)::cue" should be a valid selector+Pass "::part(mypart)::details-content" should be a valid selector+Pass "::part(mypart)::file-selector-button" should be a valid selector+Pass "::part(mypart)::first-letter" should be a valid selector+Pass "::part(mypart)::first-line" should be a valid selector+Fail "::part(mypart)::grammar-error" should be a valid selector+Pass "::part(mypart)::highlight(myhighlight)" should be a valid selector+Pass "::part(mypart)::marker" should be a valid selector+Pass "::part(mypart)::placeholder" should be a valid selector+Pass "::part(mypart)::search-text" should be a valid selector+Pass "::part(mypart)::selection" should be a valid selector+Pass "::part(mypart)::spelling-error" should be a valid selector+Fail "::part(mypart)::target-text" should be a valid selector+Pass "::part(mypart)::view-transition" should be a valid selector+Pass "::part(mypart)::view-transition-group(*)" should be a valid selector+Pass "::part(mypart)::view-transition-image-pair(*)" should be a valid selector+Pass "::part(mypart)::view-transition-new(*)" should be a valid selector+Pass "::part(mypart)::view-transition-old(*)" should be a valid selector+Pass computed style for ::part()::after+Pass computed style for ::part()::backdrop+Pass computed style for ::part()::before+Pass computed style for ::part()::details-content+Pass computed style for ::part()::file-selector-button+Pass computed style for ::part()::first-letter+Pass computed style for ::part()::first-line+Fail computed style for ::part()::grammar-error+Pass computed style for ::part()::highlight(myhighlight)+Pass computed style for ::part()::placeholder+Pass computed style for ::part()::search-text+Pass computed style for ::part()::selection+Pass computed style for ::part()::spelling-error+Fail computed style for ::part()::target-text+Pass ::part styles with ::part(mypart)::after {+ display: block;+ content: "";+ height: 77px;+ } and <div part='mypart'></div>+Pass ::part styles with ::part(mypart)::before {+ display: block;+ content: "";+ height: 46px;+ } and <div part='mypart'></div>+Pass ::part styles with ::part(mypart)::details-content {+ height: 371px;+ } and <details part='mypart'><summary style="height:47px">summary</summary>details</details>+Pass ::part styles with ::part(mypart)::file-selector-button {+ height: 94px;+ padding: 0;+ margin: 0;+ border: none;+ appearance: none;+ } and <input type=file part=mypart>+Pass ::part styles with ::part(mypart) {+ font: 20px/1 Ahem;+ }+ ::part(mypart)::first-letter {+ font-size: 86px;+ } and <div part=mypart>X<br>X</div>+Fail ::part styles with ::part(mypart) {+ font: 20px/1 Ahem;+ }+ ::part(mypart)::first-line {+ font-size: 86px;+ } and <div part=mypart>X<br>X</div>+Pass ::part styles with ::part(mypart)::marker {+ font: 63px/1.0 Ahem;+ content: "X";+ } and <li style="list-style-position: inside" part="mypart"></li>\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo-with-argument.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo-with-argument.txtindex 51c99cd09ad..916ae6785a8 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo-with-argument.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom/getComputedStyle-pseudo-with-argument.txt@@ -2,8 +2,7 @@ Harness status: OKFound 22 tests-17 Pass-5 Fail+22 PassPass This pseudo-element should not parse: ::before(test)Pass This pseudo-element should not parse: ::highlightPass This pseudo-element should not parse: ::highlight(@@ -21,9 +20,9 @@ Pass This pseudo-element should not parse: :view-transition-group(name)Pass This pseudo-element should not parse: :view-transition-image-pair(name)Pass This pseudo-element should not parse: :view-transition-old(name)Pass This pseudo-element should not parse: :view-transition-new(name)-Fail This pseudo-element should parse: ::highlight(name)-Fail This pseudo-element should parse: ::highlight(+Pass This pseudo-element should parse: ::highlight(name)+Pass This pseudo-element should parse: ::highlight(name-Fail This pseudo-element should parse: ::highlight(name-Fail This pseudo-element should parse: ::highlight( name-Fail This pseudo-element should parse: ::highlight( n\61me )\ No newline at end of file+Pass This pseudo-element should parse: ::highlight(name+Pass This pseudo-element should parse: ::highlight( name+Pass This pseudo-element should parse: ::highlight( n\61me )\ No newline at end of filediff --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 f6b8e4ef5d7..07e72360f8a 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,7 @@ Harness status: OKFound 28 tests-26 Pass-1 Fail+27 Pass1 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)@@ -22,7 +21,7 @@ Pass CSSStyleDeclaration is immutablePass Unknown pseudo-element with a known identifier: backdropPass Unknown pseudo-element with a known identifier: file-selector-buttonOptional Feature Unsupported Unknown pseudo-element with a known identifier: grammar-error-Fail Unknown pseudo-element with a known identifier: highlight(name)+Pass 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: placeholderPass Unknown pseudo-element with a known identifier: spelling-errordiff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-inheritance.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-inheritance.htmlnew file mode 100644index 00000000000..55220baf7f4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-inheritance.html@@ -0,0 +1,51 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS Pseudo-Elements Test: highlight selectors inheritance getComputedStyle for currentcolor</title>+<meta name="assert" content="Checks the result of getComputedStyle for each kind of highlight pseudo, when ‘color’ and ‘background-color’ are set to ‘currentColor’ in the parent. The child should inherit both properties as if if they were directly set to ‘currentColor’, due to highlight inheritance and the fact that ‘currentColor’ computes to itself, and the result for both properties should equal the originating element ‘color’.">+<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<style>+ #target {+ background-color: green;+ color: lime;+ }+ #target::selection {+ color: currentcolor;+ background-color: currentcolor;+ }+ #target::target-text {+ color: currentcolor;+ background-color: currentcolor;+ }+ #target::search-text {+ color: currentcolor;+ background-color: currentcolor;+ }+ #target::search-text:current {+ color: red;+ background-color: red;+ }+ #target::spelling-error {+ color: currentcolor;+ background-color: currentcolor;+ }+ #target::grammar-error {+ color: currentcolor;+ background-color: currentcolor;+ }+ #target::highlight(foo) {+ color: currentcolor;+ background-color: currentcolor;+ }+</style>+<div id="target"><span id="child"></span></div>+<script>+ for (const pseudo of ["::selection", "::target-text", "::search-text", "::spelling-error", "::grammar-error", "::highlight(foo)"]) {+ test(() => {+ let style = getComputedStyle(child, pseudo);+ assert_equals(style.backgroundColor, "rgb(0, 255, 0)", "Background color is lime.");+ assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");+ }, `getComputedStyle() for ${pseudo}`);+ }+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-visited.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-visited.htmlnew file mode 100644index 00000000000..62b0e7384c4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed-visited.html@@ -0,0 +1,48 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle for currentcolor on visited</title>+<meta name="assert" content="Checks the result of getComputedStyle for each kind of highlight pseudo, when ‘color’ is set to ‘currentColor’ for visited links (and for unvisited links, via implicit defaulting up to the root). The result for both links should equal the originating element ‘color’ as if the link was unvisited.">+<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<style>+ a {+ color: lime;+ }+ a:visited {+ color: cyan;+ }+ a:visited::selection {+ color: currentcolor;+ }+ a:visited::target-text {+ color: currentcolor;+ }+ a:visited::search-text {+ color: currentcolor;+ }+ a:visited::search-text:current {+ color: red;+ }+ a:visited::spelling-error {+ color: currentcolor;+ }+ a:visited::grammar-error {+ color: currentcolor;+ }+ a:visited::highlight(foo) {+ color: currentcolor;+ }+</style>+<a id="target1" class="target" href=""></a>+<a id="target2" class="target" href="unvisited"></a>+<script>+ for (const pseudo of ["::selection", "::target-text", "::search-text", "::spelling-error", "::grammar-error", "::highlight(foo)"]) {+ for (const target of [target1, target2]) {+ test(() => {+ let style = getComputedStyle(target, pseudo);+ assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");+ }, `getComputedStyle() for ${pseudo} at #${target.id}`);+ }+ }+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed.htmlnew file mode 100644index 00000000000..952b6608579--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-currentcolor-computed.html@@ -0,0 +1,76 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle for currentcolor</title>+<meta name="assert" content="Checks the result of getComputedStyle for each kind of highlight pseudo, when ‘color’ and ‘background-color’ are set to ‘currentColor’. The result for both properties should equal the originating element ‘color’.">+<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<style>+ div {+ background-color: green;+ color: lime;+ }+ .wrapper::selection {+ color: cyan;+ background-color: blue;+ }+ .wrapper::target-text {+ color: cyan;+ background-color: blue;+ }+ .wrapper::spelling-error {+ color: cyan;+ background-color: blue;+ }+ .wrapper::grammar-error {+ color: cyan;+ background-color: blue;+ }+ .wrapper::highlight(foo) {+ color: cyan;+ background-color: blue;+ }+ .target::selection {+ color: currentcolor;+ background-color: currentcolor;+ }+ .target::target-text {+ color: currentcolor;+ background-color: currentcolor;+ }+ .target::search-text {+ color: currentcolor;+ background-color: currentcolor;+ }+ .target::search-text:current {+ color: red;+ background-color: red;+ }+ .target::spelling-error {+ color: currentcolor;+ background-color: currentcolor;+ }+ .target::grammar-error {+ color: currentcolor;+ background-color: currentcolor;+ }+ .target::highlight(foo) {+ color: currentcolor;+ background-color: currentcolor;+ }+</style>+<div id="target1" class="target"></div>+<div class="wrapper">+ <span id="target2" class="target"></span>+</div>+<script>+ for (const pseudo of ["::selection", "::target-text", "::search-text", "::spelling-error", "::grammar-error", "::highlight(foo)"]) {+ for (const target of [target1, target2]) {+ test(() => {+ let style = getComputedStyle(target, pseudo);+ assert_equals(style.backgroundColor, "rgb(0, 255, 0)", "Background color is lime.");+ assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");+ }, `getComputedStyle() for ${pseudo} at #${target.id}`);+ }+ }+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-computed.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-computed.htmlnew file mode 100644index 00000000000..464449d2e89--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-computed.html@@ -0,0 +1,58 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle</title>+<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<style>+ #target::selection {+ background-color: green;+ color: lime;+ }+ #target::target-text {+ background-color: green;+ color: lime;+ }+ #target::spelling-error {+ background-color: green;+ color: lime;+ }+ #target::grammar-error {+ background-color: green;+ color: lime;+ }+ #target::highlight(foo) {+ background-color: green;+ color: lime;+ }+ #target::highlight(bar) {+ background-color: blue;+ color: yellow;+ }+</style>+<div id="target"></div>+<script>+ for (const pseudo of ["::selection", "::target-text", "::spelling-error", "::grammar-error", "::highlight(foo)"]) {+ test(() => {+ let style = getComputedStyle(target, pseudo);+ assert_equals(style.backgroundColor, "rgb(0, 128, 0)", "Background color is green.");+ assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");+ }, `getComputedStyle() for ${pseudo}`);++ for (illFormedPseudo of [`${pseudo}:`, `${pseudo})`, `${pseudo}(`, `${pseudo}(foo)`, `${pseudo}()`, `:${pseudo}`, `${pseudo}.`]) {+ test(() => {+ let style = getComputedStyle(target, illFormedPseudo);+ let defaultStyle = getComputedStyle(target);+ assert_equals(style.backgroundColor, "");+ assert_equals(style.color, "");+ }, `getComputedStyle() for ${illFormedPseudo} should return an empty CSSStyleDeclaration`);+ }+ }++ const pseudo = "::highlight(bar)";+ test(() => {+ let style = getComputedStyle(target, pseudo);+ assert_equals(style.backgroundColor, "rgb(0, 0, 255)", "Background color is blue.");+ assert_equals(style.color, "rgb(255, 255, 0)", "Color is yellow.");+ }, `Different getComputedStyle() for ${pseudo} and same element`);+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-visited-computed-001.html b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-visited-computed-001.htmlnew file mode 100644index 00000000000..973d1effe6f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-pseudo/highlight-cascade/highlight-pseudos-visited-computed-001.html@@ -0,0 +1,62 @@+<!doctype html>+<meta charset="utf-8">+<title>CSS Pseudo-Elements Test: highlight selectors getComputedStyle on visited</title>+<link rel="help" href="https://drafts.csswg.org/css-pseudo/#highlight-selectors">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<style>+ a::selection {+ color: lime;+ }+ a::target-text {+ color: lime;+ }+ a::search-text {+ color: lime;+ }+ a::search-text:current {+ color: red;+ }+ a::spelling-error {+ color: lime;+ }+ a::grammar-error {+ color: lime;+ }+ a::highlight(foo) {+ color: lime;+ }+ a:visited::selection {+ color: yellow;+ }+ a:visited::target-text {+ color: yellow;+ }+ a:visited::search-text {+ color: yellow;+ }+ a:visited::search-text:current {+ color: red;+ }+ a:visited::spelling-error {+ color: yellow;+ }+ a:visited::grammar-error {+ color: yellow;+ }+ a:visited::highlight(foo) {+ color: yellow;+ }+</style>+<a id="target1" class="target" href=""></a>+<a id="target2" class="target" href="unvisited"></a>+<script>+ for (const pseudo of ["::selection", "::target-text", "::search-text", "::spelling-error", "::grammar-error", "::highlight(foo)"]) {+ for (const target of [target1, target2]) {+ test(() => {+ let style = getComputedStyle(target, pseudo);+ assert_equals(style.color, "rgb(0, 255, 0)", "Color is lime.");+ }, `getComputedStyle() for ${pseudo} at #${target.id}`);+ }+ }+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-shadow/part/pseudo-elements-after-part.html b/Tests/LibWeb/Text/input/wpt-import/css/css-shadow/part/pseudo-elements-after-part.htmlnew file mode 100644index 00000000000..014779fe034--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-shadow/part/pseudo-elements-after-part.html@@ -0,0 +1,181 @@+<!DOCTYPE html>+<title>Pseudo-elements allowed after ::part()</title>+<link rel="help" href="https://drafts.csswg.org/css-shadow/#part">+<meta name="flags" content="ahem">+<link rel="stylesheet" href="../../../fonts/ahem.css">+<script src="../../../resources/testharness.js"></script>+<script src="../../../resources/testharnessreport.js"></script>+<script src="../../../css/support/parsing-testcommon.js"></script>++<body>+<span style="font-family: Ahem">X</span>++<script>+"use strict";++test_invalid_selector("::part(mypart)::part(anotherpart)");+test_invalid_selector("::part(mypart)::notarealpseudoelement");++test_valid_selector("::part(mypart)::after");+test_valid_selector("::part(mypart)::backdrop");+test_valid_selector("::part(mypart)::before");+test_valid_selector("::part(mypart)::cue");+test_valid_selector("::part(mypart)::details-content");+test_valid_selector("::part(mypart)::file-selector-button");+test_valid_selector("::part(mypart)::first-letter");+test_valid_selector("::part(mypart)::first-line");+test_valid_selector("::part(mypart)::grammar-error");+test_valid_selector("::part(mypart)::highlight(myhighlight)");+test_valid_selector("::part(mypart)::marker");+test_valid_selector("::part(mypart)::placeholder");+test_valid_selector("::part(mypart)::search-text");+test_valid_selector("::part(mypart)::selection");+test_valid_selector("::part(mypart)::spelling-error");+test_valid_selector("::part(mypart)::target-text");+test_valid_selector("::part(mypart)::view-transition");+test_valid_selector("::part(mypart)::view-transition-group(*)");+test_valid_selector("::part(mypart)::view-transition-image-pair(*)");+test_valid_selector("::part(mypart)::view-transition-new(*)");+test_valid_selector("::part(mypart)::view-transition-old(*)");++// to be used inside of a promise_test() function.+async function run_part_test(t, style_rules, part_html, assertion) {+ let container = document.createElement("div");+ let shadow = container.attachShadow({mode: "open"});+ shadow.innerHTML = `+ ${part_html}+ <slot></slot>+ `;+ document.body.append(container);+ let style = document.createElement("style");+ style.innerText = style_rules;+ document.head.append(style);+ t.add_cleanup(() => {+ container.remove();+ style.remove();+ });+ await assertion(container, shadow.firstElementChild);+}++function test_with_part(style_rules, part_html, assertion) {+ promise_test(async (t) => {+ await run_part_test(t, style_rules, part_html, assertion);+ }, `::part styles with ${style_rules} and ${part_html}`);+}++// Generate a random-looking color using the string input as a "seed"+// (so different tests use different colors).+function generate_color(str) {+ let sum = Array.from(str).reduce((sum, char) => sum + char.charCodeAt(0), 0);+ return `rgb(${sum % 255}, ${(sum * 2 + 17) % 255}, ${(sum * 3 + 139) % 255})`;+}++function test_pseudo_computed_style(pseudo_element, tag, attributes) {+ promise_test(async (t) => {+ let our_color = generate_color(pseudo_element);+ await run_part_test(t,+ `::part(mypart)${pseudo_element} {+ background: ${our_color};+ }`,+ `<${tag} ${attributes} part='mypart'></${tag}>`,+ async (container, part) => {+ assert_equals(getComputedStyle(part, pseudo_element).backgroundColor, our_color);+ });++ }, `computed style for ::part()${pseudo_element}`);+}++test_pseudo_computed_style("::after", "div", "");+test_pseudo_computed_style("::backdrop", "div", "popover='auto'");+test_pseudo_computed_style("::before", "div", "");+// NOTE: not testing :cue at all.+test_pseudo_computed_style("::details-content", "details", "");+test_pseudo_computed_style("::file-selector-button", "input", "type='file'");+test_pseudo_computed_style("::first-letter", "div", "");+test_pseudo_computed_style("::first-line", "div", "");+test_pseudo_computed_style("::grammar-error", "div", "");+test_pseudo_computed_style("::highlight(myhighlight)", "div", "");+test_pseudo_computed_style("::placeholder", "input", "type='text' placeholder='enter text'");+test_pseudo_computed_style("::search-text", "div", "");+test_pseudo_computed_style("::selection", "div", "");+test_pseudo_computed_style("::spelling-error", "div", "");+test_pseudo_computed_style("::target-text", "div", "");+// NOTE: Not yet testing computed style for view transition+// pseudo-elements since they currently only apply to the root element+// (but are intended to apply to others later).++test_with_part(`::part(mypart)::after {+ display: block;+ content: "";+ height: 77px;+ }`,+ `<div part='mypart'></div>`,+ async (container, part) => {+ assert_equals(container.getBoundingClientRect().height, 77);+ });++test_with_part(`::part(mypart)::before {+ display: block;+ content: "";+ height: 46px;+ }`,+ `<div part='mypart'></div>`,+ async (container, part) => {+ assert_equals(container.getBoundingClientRect().height, 46);+ });++test_with_part(`::part(mypart)::details-content {+ height: 371px;+ }`,+ `<details part='mypart'><summary style="height:47px">summary</summary>details</details>`,+ async (container, part) => {+ assert_equals(container.getBoundingClientRect().height, 371 + 47);+ });++test_with_part(`::part(mypart)::file-selector-button {+ height: 94px;+ padding: 0;+ margin: 0;+ border: none;+ appearance: none;+ }`,+ `<input type=file part=mypart>`,+ async (container, part) => {+ assert_equals(container.getBoundingClientRect().height, 94);+ });++test_with_part(`::part(mypart) {+ font: 20px/1 Ahem;+ }+ ::part(mypart)::first-letter {+ font-size: 86px;+ }`,+ `<div part=mypart>X<br>X</div>`,+ async (container, part) => {+ await document.fonts.ready;+ assert_equals(container.getBoundingClientRect().height, 86 + 20);+ });++test_with_part(`::part(mypart) {+ font: 20px/1 Ahem;+ }+ ::part(mypart)::first-line {+ font-size: 86px;+ }`,+ `<div part=mypart>X<br>X</div>`,+ async (container, part) => {+ await document.fonts.ready;+ assert_equals(container.getBoundingClientRect().height, 86 + 20);+ });++test_with_part(`::part(mypart)::marker {+ font: 63px/1.0 Ahem;+ content: "X";+ }`,+ `<li style="list-style-position: inside" part="mypart"></li>`,+ async (container, part) => {+ await document.fonts.ready;+ assert_equals(container.getBoundingClientRect().height, 63);+ });++</script>