diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-01-19 12:40:17 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-01-19 12:40:17 +0100 |
commit | e4f08ee2bb5da5d8fc41bbe43af091b480aa265b (patch) | |
tree | 28ea0206044027446f867545ef54660adeb4f9a7 /components/selectors/context.rs | |
parent | 88d2982e23eeb7d395a575d1d0ed470c597382c5 (diff) | |
download | servo-e4f08ee2bb5da5d8fc41bbe43af091b480aa265b.tar.gz servo-e4f08ee2bb5da5d8fc41bbe43af091b480aa265b.zip |
selectors: Add a MatchingContext::nest function, make nesting_level private.
Diffstat (limited to 'components/selectors/context.rs')
-rw-r--r-- | components/selectors/context.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/components/selectors/context.rs b/components/selectors/context.rs index 856e18497d9..be18c29e1f9 100644 --- a/components/selectors/context.rs +++ b/components/selectors/context.rs @@ -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 + } } |