selectors: Add a MatchingContext::nest function, make nesting_level private.

This commit is contained in:
Emilio Cobos Álvarez 2018-01-19 12:40:17 +01:00
parent 88d2982e23
commit e4f08ee2bb
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
4 changed files with 52 additions and 33 deletions

View file

@ -122,9 +122,9 @@ where
/// The current nesting level of selectors that we're matching.
///
/// FIXME(emilio): Move this somewhere else and make MatchingContext
/// FIXME(emilio): Consider putting the mutable stuff in a Cell.
/// immutable again.
pub nesting_level: usize,
nesting_level: usize,
/// An optional hook function for checking whether a pseudo-element
/// should match when matching_mode is ForStatelessPseudoElement.
@ -181,6 +181,12 @@ where
}
}
/// How many times deep are we in a selector.
#[inline]
pub fn nesting_level(&self) -> usize {
self.nesting_level
}
/// The quirks mode of the document.
#[inline]
pub fn quirks_mode(&self) -> QuirksMode {
@ -192,4 +198,16 @@ where
pub fn classes_and_ids_case_sensitivity(&self) -> CaseSensitivity {
self.classes_and_ids_case_sensitivity
}
/// Runs F with a deeper nesting level.
#[inline]
pub fn nest<F, R>(&mut self, f: F) -> R
where
F: FnOnce(&mut Self) -> R,
{
self.nesting_level += 1;
let result = f(self);
self.nesting_level -= 1;
result
}
}