Truly independent web browser
LibWeb: Parse the ::highlight() pseudo-element
Andreas Kling94c6cec689b4
diff --git a/Libraries/LibWeb/CSS/PseudoElements.json b/Libraries/LibWeb/CSS/PseudoElements.jsonindex 2c4dccb1483..3bae168d940 100644--- a/Libraries/LibWeb/CSS/PseudoElements.json+++ b/Libraries/LibWeb/CSS/PseudoElements.json@@ -93,6 +93,11 @@],"implementation": "synthetic"},+ "highlight": {+ "spec": "https://drafts.csswg.org/css-pseudo-4/#selectordef-highlight",+ "type": "function",+ "function-syntax": "<highlight-name-selector>"+ },"marker": {"spec": "https://drafts.csswg.org/css-pseudo-4/#selectordef-marker","is-tree-abiding": true,diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cppindex 14d695c4493..afee9a2da3f 100644--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp@@ -201,6 +201,8 @@ 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/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex b27cb5b14ab..79637423c69 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -626,6 +626,7 @@ fn generate_selector_pseudo_types(manifest_dir: &Path, out_dir: &Path) -> Resultlet parameter_type = match function_syntax {None => "None",Some("<compound-selector>") => "CompoundSelector",+ Some("<highlight-name-selector>") => "HighlightNameSelector",Some("<ident>+") => "IdentList",Some("<pt-name-and-class-selector>") => "PTNameAndClassSelector",Some(argument) => return Err(format!("unsupported pseudo-element parameter type {argument}").into()),diff --git a/Libraries/LibWeb/Rust/src/css/selector.rs b/Libraries/LibWeb/Rust/src/css/selector.rsindex f15d5db1223..55f105f0f9d 100644--- a/Libraries/LibWeb/Rust/src/css/selector.rs+++ b/Libraries/LibWeb/Rust/src/css/selector.rs@@ -147,6 +147,7 @@ pub(crate) struct PseudoClassMetadata {pub(crate) enum PseudoElementParameterType {None,CompoundSelector,+ HighlightNameSelector,IdentList,PTNameAndClassSelector,}diff --git a/Libraries/LibWeb/Rust/src/css/selector_parser.rs b/Libraries/LibWeb/Rust/src/css/selector_parser.rsindex 79abd08af0a..3b23fe72e50 100644--- a/Libraries/LibWeb/Rust/src/css/selector_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/selector_parser.rs@@ -478,7 +478,7 @@ impl<'a> SelectorParser<'a> {// ::search-text is checked above, as it allows :current.if matches!(pseudo_element.pseudo_element,- PseudoElementType::Selection | PseudoElementType::SpellingError+ PseudoElementType::Highlight | PseudoElementType::Selection | PseudoElementType::SpellingError) && compound.simple_selectors.len() > 1{return Err(());@@ -1013,6 +1013,20 @@ impl<'a> SelectorParser<'a> {compound,]))))}+ // https://drafts.csswg.org/css-pseudo-4/#typedef-highlight-name-selector+ // <highlight-name-selector> = '*' | <custom-ident>+ // FIXME: Support the '*' argument, which selects every custom highlight.+ PseudoElementParameterType::HighlightNameSelector => {+ let name = stream.next().and_then(ComponentValue::ident).ok_or(())?;+ if is_css_wide_keyword(name) || ascii_eq(name, "default") {+ return Err(());+ }+ stream.discard_whitespace();+ if !stream.is_empty() {+ return Err(());+ }+ Ok(PseudoElementValue::Identifiers(Box::new([name.into()])))+ }PseudoElementParameterType::IdentList => {let mut identifiers = Vec::new();while !stream.is_empty() {diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 9d4531bbded..f83912e3c25 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -2587,10 +2587,10 @@ pub enum FfiDemandedPseudoElement {SliderFill = 14,SliderThumb = 15,SliderTrack = 16,- ViewTransitionGroup = 19,- ViewTransitionImagePair = 20,- ViewTransitionNew = 21,- ViewTransitionOld = 22,+ ViewTransitionGroup = 20,+ ViewTransitionImagePair = 21,+ ViewTransitionNew = 22,+ ViewTransitionOld = 23,}/// The answer to a record demand: the record, or that the pseudo-element read generates no boxdiff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txtindex 4ca2a0dedcd..0ec05a1c3e9 100644--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-highlight-api/highlight-pseudo-parsing.txt@@ -2,17 +2,16 @@ Harness status: OKFound 16 tests-7 Pass-9 Fail-Fail "::highlight(foo)" should be a valid selector-Fail ".a::highlight(foo)" should be a valid selector-Fail "div ::highlight(foo)" should be a valid selector-Fail "::part(my-part)::highlight(foo)" should be a valid selector-Fail "::highlight(multi\\ word)" should be a valid selector-Fail "::highlight(\\31\\32\\33)" should be a valid selector-Fail "::highlight(\\*)" should be a valid selector-Fail "div::highlight(\\*)" should be a valid selector-Fail ":root::highlight(\\*)" should be a valid selector+16 Pass+Pass "::highlight(foo)" should be a valid selector+Pass ".a::highlight(foo)" should be a valid selector+Pass "div ::highlight(foo)" should be a valid selector+Pass "::part(my-part)::highlight(foo)" should be a valid selector+Pass "::highlight(multi\\ word)" should be a valid selector+Pass "::highlight(\\31\\32\\33)" should be a valid selector+Pass "::highlight(\\*)" should be a valid selector+Pass "div::highlight(\\*)" should be a valid selector+Pass ":root::highlight(\\*)" should be a valid selectorPass "::highlight" should be an invalid selectorPass "::before::highlight(foo)" should be an invalid selectorPass "::highlight(foo).a" should be an invalid selectordiff --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 ce31c49e13d..f6b8e4ef5d7 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@@ -3,7 +3,8 @@ Harness status: OKFound 28 tests26 Pass-2 Optional Feature Unsupported+1 Fail+1 Optional Feature UnsupportedPass Resolution of width is correct when pseudo-element argument is ignored (due to no colon)Pass Resolution of width is correct when pseudo-element argument is invalid (due to a trailing token)Pass Resolution of width is correct for ::before and ::after pseudo-elements (single-colon)@@ -21,7 +22,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-Optional Feature Unsupported Unknown pseudo-element with a known identifier: highlight(name)+Fail 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-error