aboutsummaryrefslogtreecommitdiffstats
path: root/components/selectors/context.rs
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2018-01-19 13:19:16 +0100
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-01-19 13:22:37 +0100
commit8e25c9e6747941afcff30ba227cddcbb4261d10a (patch)
treed57db8f6a3570f086bd6521fb6efa7030224fcb1 /components/selectors/context.rs
parente4f08ee2bb5da5d8fc41bbe43af091b480aa265b (diff)
downloadservo-8e25c9e6747941afcff30ba227cddcbb4261d10a.tar.gz
servo-8e25c9e6747941afcff30ba227cddcbb4261d10a.zip
style: Track the visited-handling-mode on the MatchingContext.
Instead of on the stack. This fixes bugs where we're not passing the value around correctly, like from ::-moz-any. This is a fix for https://bugzilla.mozilla.org/show_bug.cgi?id=1431539.
Diffstat (limited to 'components/selectors/context.rs')
-rw-r--r--components/selectors/context.rs31
1 files changed, 27 insertions, 4 deletions
diff --git a/components/selectors/context.rs b/components/selectors/context.rs
index be18c29e1f9..4df494eca98 100644
--- a/components/selectors/context.rs
+++ b/components/selectors/context.rs
@@ -105,8 +105,6 @@ where
pub bloom_filter: Option<&'a BloomFilter>,
/// An optional cache to speed up nth-index-like selectors.
pub nth_index_cache: Option<&'a mut NthIndexCache>,
- /// Input that controls how matching for links is handled.
- pub visited_handling: VisitedHandlingMode,
/// The element which is going to match :scope pseudo-class. It can be
/// either one :scope element, or the scoping element.
///
@@ -120,10 +118,13 @@ where
/// See https://drafts.csswg.org/selectors-4/#scope-pseudo
pub scope_element: Option<OpaqueElement>,
+ /// Controls how matching for links is handled.
+ visited_handling: VisitedHandlingMode,
+
/// The current nesting level of selectors that we're matching.
///
- /// FIXME(emilio): Consider putting the mutable stuff in a Cell.
- /// immutable again.
+ /// FIXME(emilio): Consider putting the mutable stuff in a Cell, then make
+ /// MatchingContext immutable again.
nesting_level: usize,
/// An optional hook function for checking whether a pseudo-element
@@ -210,4 +211,26 @@ where
self.nesting_level -= 1;
result
}
+
+ #[inline]
+ pub fn visited_handling(&self) -> VisitedHandlingMode {
+ self.visited_handling
+ }
+
+ /// Runs F with a different VisitedHandlingMode.
+ #[inline]
+ pub fn with_visited_handling_mode<F, R>(
+ &mut self,
+ handling_mode: VisitedHandlingMode,
+ f: F,
+ ) -> R
+ where
+ F: FnOnce(&mut Self) -> R,
+ {
+ let original_handling_mode = self.visited_handling;
+ self.visited_handling = handling_mode;
+ let result = f(self);
+ self.visited_handling = original_handling_mode;
+ result
+ }
}