mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Add a way to match a single compound selector.
Also improve the ergonomics of matches_complex_selector. Bug: 1368240 MozReview-Commit-ID: 9DWDvyZmetM
This commit is contained in:
parent
262f6adc30
commit
151b636562
3 changed files with 91 additions and 17 deletions
|
@ -449,18 +449,36 @@ impl<Impl: SelectorImpl> Selector<Impl> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over the entire sequence of simple selectors and combinators,
|
||||
/// from right to left.
|
||||
/// Returns the combinator at index `index`, or panics if the component is
|
||||
/// not a combinator.
|
||||
pub fn combinator_at(&self, index: usize) -> Combinator {
|
||||
match self.0.slice[self.0.slice.len() - index] {
|
||||
Component::Combinator(c) => c,
|
||||
ref other => {
|
||||
panic!("Not a combinator: {:?}, {:?}, index: {}",
|
||||
other, self, index)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns an iterator over the entire sequence of simple selectors and
|
||||
/// combinators, from right to left.
|
||||
pub fn iter_raw(&self) -> Rev<slice::Iter<Component<Impl>>> {
|
||||
self.iter_raw_rev().rev()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the entire sequence of simple selectors and combinators,
|
||||
/// from left to right.
|
||||
/// Returns an iterator over the entire sequence of simple selectors and
|
||||
/// combinators, from left to right.
|
||||
pub fn iter_raw_rev(&self) -> slice::Iter<Component<Impl>> {
|
||||
self.0.slice.iter()
|
||||
}
|
||||
|
||||
/// Returns an iterator over the sequence of simple selectors and
|
||||
/// combinators after `offset`, from left to right.
|
||||
pub fn iter_raw_rev_from(&self, offset: usize) -> slice::Iter<Component<Impl>> {
|
||||
self.0.slice[(self.0.slice.len() - offset)..].iter()
|
||||
}
|
||||
|
||||
/// Creates a Selector from a vec of Components. Used in tests.
|
||||
pub fn from_vec(vec: Vec<Component<Impl>>, specificity_and_flags: u32) -> Self {
|
||||
let header = HeaderWithLength::new(SpecificityAndFlags(specificity_and_flags), vec.len());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue