style: Implement selector-matching for ::part().

Also fairly straight-forward. This may get more complicated when we do part
forwarding, if any.

I've opened https://github.com/w3c/csswg-drafts/issues/3841 in what I think
would be a cleaner model for forwarding.

Differential Revision: https://phabricator.services.mozilla.com/D28063
This commit is contained in:
Emilio Cobos Álvarez 2019-05-01 17:28:23 +00:00
parent a23ad3be50
commit 627514b737
4 changed files with 40 additions and 12 deletions

View file

@ -58,6 +58,10 @@ pub trait ElementSnapshot: Sized {
/// if `has_attrs()` returns true.
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
/// Whether this snapshot represents the part named `name`. Should only be
/// called if `has_attrs()` returns true.
fn is_part(&self, name: &Atom) -> bool;
/// A callback that should be called for each class of the snapshot. Should
/// only be called if `has_attrs()` returns true.
fn each_class<F>(&self, _: F)
@ -340,8 +344,11 @@ where
}
}
fn is_part(&self, _name: &Atom) -> bool {
unimplemented!();
fn is_part(&self, name: &Atom) -> bool {
match self.snapshot() {
Some(snapshot) if snapshot.has_attrs() => snapshot.is_part(name),
_ => self.element.is_part(name),
}
}
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {