Repository navigation
Closed
Labels
A-content/scriptRelated to the script thread
Description
GetComputedStyle has some manual parsing for pseudo-elements:
servo/components/script/dom/window.rs
Lines 1842 to 1868 in fa86bbe
| // Step 3: If pseudoElt is provided, is not the empty string, and starts with a colon, then: | |
| // Step 3.1: Parse pseudoElt as a <pseudo-element-selector>, and let type be the result. | |
| // TODO(#43095): This is quite hacky and it would be better to have a parsing function that | |
| // is integrated with stylo `PseudoElement` itself. Comparing with stylo, we are now currently | |
| // missing `::backdrop`, `::color-swatch`, and `::details-content`. | |
| let pseudo = pseudo.map(|mut s| { | |
| s.make_ascii_lowercase(); | |
| s | |
| }); | |
| let pseudo = match pseudo { | |
| Some(ref pseudo) if pseudo == ":before" || pseudo == "::before" => { | |
| Some(PseudoElement::Before) | |
| }, | |
| Some(ref pseudo) if pseudo == ":after" || pseudo == "::after" => { | |
| Some(PseudoElement::After) | |
| }, | |
| Some(ref pseudo) if pseudo == "::selection" => Some(PseudoElement::Selection), | |
| Some(ref pseudo) if pseudo == "::marker" => Some(PseudoElement::Marker), | |
| Some(ref pseudo) if pseudo == "::placeholder" => Some(PseudoElement::Placeholder), | |
| Some(ref pseudo) if pseudo.starts_with(':') => { | |
| // Step 3.2: If type is failure, or is a ::slotted() or ::part() | |
| // pseudo-element, let obj be null. | |
| is_null = true; | |
| None | |
| }, | |
| _ => None, | |
| }; |
It would be better to have something like what Gecko does:
pub extern "C" fn Servo_ParsePseudoElement(
data: &nsAString,
ignore_enabled_state: bool,
request: &mut structs::PseudoStyleRequest, /* output */
) -> bool {
let string = data.to_string();
let mut input = ParserInput::new(&string);
let mut parser = Parser::new(&mut input);
// This is unspecced, but we'd like to match other browsers' behavior, so we reject the
// preceding whitespaces and trailing whitespaces.
// FIXME: [Bug 1845712](https://bugzilla.mozilla.org/show_bug.cgi?id=1845712). Figure out if it is necessary to reject preceding and trailing
// whitespaces.
if parser.try_parse(|i| i.expect_whitespace()).is_ok() {
return false;
}
let Ok(pseudo) = PseudoElement::parse_ignore_enabled_state(&mut parser) else {
return false;
};
// The trailing tokens are not allowed, including whitespaces.
if parser.next_including_whitespace().is_ok() {
return false;
}
if !ignore_enabled_state && !pseudo.enabled_in_content() {
return false;
}
let (pseudo_type, name) = pseudo.pseudo_type_and_argument();
let name_ptr = name.map_or(std::ptr::null_mut(), |name| name.as_ptr());
request.mType = pseudo_type;
request.mIdentifier = unsafe { RefPtr::new(name_ptr).forget() };
true
}Metadata
Metadata
Assignees
Labels
A-content/scriptRelated to the script thread
Activity
script: Support all pseudo-elements in `getComputedStyle` (servo#49804)