style: Minor restyle_hints.rs code reorganization. draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 05 Jun 2017 14:19:58 +0800
changeset 588835 9ff7a36d38160b337677f0585b40fc954ed47b39
parent 588834 3b93933b98f7d473f7b3650c28889b8e28b025b2
child 588836 ec76d12c38098157f54feadd65b52fd28c82e0a8
push id62176
push userbmo:cam@mcc.id.au
push dateMon, 05 Jun 2017 07:29:00 +0000
milestone55.0a1
style: Minor restyle_hints.rs code reorganization. MozReview-Commit-ID: 4Rainvu6fQk
servo/components/style/restyle_hints.rs
--- a/servo/components/style/restyle_hints.rs
+++ b/servo/components/style/restyle_hints.rs
@@ -630,61 +630,60 @@ impl<'a, E> Element for ElementWrapper<'
     fn match_non_ts_pseudo_class<F>(&self,
                                     pseudo_class: &NonTSPseudoClass,
                                     context: &mut MatchingContext,
                                     relevant_link: &RelevantLinkStatus,
                                     _setter: &mut F)
                                     -> bool
         where F: FnMut(&Self, ElementSelectorFlags),
     {
-        // :moz-any is quite special, because we need to keep matching as a
-        // snapshot.
-        #[cfg(feature = "gecko")]
-        {
-            use selectors::matching::matches_complex_selector;
-            if let NonTSPseudoClass::MozAny(ref selectors) = *pseudo_class {
+        // Some pseudo-classes need special handling to evaluate them against
+        // the snapshot.
+        match *pseudo_class {
+            #[cfg(feature = "gecko")]
+            NonTSPseudoClass::MozAny(ref selectors) => {
+                use selectors::matching::matches_complex_selector;
                 return selectors.iter().any(|s| {
                     matches_complex_selector(s, self, context, _setter)
-                })
+                });
             }
-        }
 
-        // :dir needs special handling.  It's implemented in terms of state
-        // flags, but which state flag it maps to depends on the argument to
-        // :dir.  That means we can't just add its state flags to the
-        // NonTSPseudoClass, because if we added all of them there, and tested
-        // via intersects() here, we'd get incorrect behavior for :not(:dir())
-        // cases.
-        //
-        // FIXME(bz): How can I set this up so once Servo adds :dir() support we
-        // don't forget to update this code?
-        #[cfg(feature = "gecko")]
-        {
-            if let NonTSPseudoClass::Dir(ref s) = *pseudo_class {
+            // :dir is implemented in terms of state flags, but which state flag
+            // it maps to depends on the argument to :dir.  That means we can't
+            // just add its state flags to the NonTSPseudoClass, because if we
+            // added all of them there, and tested via intersects() here, we'd
+            // get incorrect behavior for :not(:dir()) cases.
+            //
+            // FIXME(bz): How can I set this up so once Servo adds :dir()
+            // support we don't forget to update this code?
+            #[cfg(feature = "gecko")]
+            NonTSPseudoClass::Dir(ref s) => {
                 let selector_flag = dir_selector_to_state(s);
                 if selector_flag.is_empty() {
                     // :dir() with some random argument; does not match.
                     return false;
                 }
                 let state = match self.snapshot().and_then(|s| s.state()) {
                     Some(snapshot_state) => snapshot_state,
                     None => self.element.get_state(),
                 };
                 return state.contains(selector_flag);
             }
-        }
 
-        // For :link and :visited, we don't actually want to test the element
-        // state directly.  Instead, we use the `relevant_link` to determine if
-        // they match.
-        if *pseudo_class == NonTSPseudoClass::Link {
-            return relevant_link.is_unvisited(self, context)
-        }
-        if *pseudo_class == NonTSPseudoClass::Visited {
-            return relevant_link.is_visited(self, context)
+            // For :link and :visited, we don't actually want to test the element
+            // state directly.  Instead, we use the `relevant_link` to determine if
+            // they match.
+            NonTSPseudoClass::Link => {
+                return relevant_link.is_unvisited(self, context);
+            }
+            NonTSPseudoClass::Visited => {
+                return relevant_link.is_visited(self, context);
+            }
+
+            _ => {}
         }
 
         let flag = pseudo_class.state_flag();
         if flag.is_empty() {
             return self.element.match_non_ts_pseudo_class(pseudo_class,
                                                           context,
                                                           relevant_link,
                                                           &mut |_, _| {})
@@ -815,21 +814,21 @@ fn is_attr_selector(sel: &Component<Sele
         Component::AttributeInNoNamespace { .. } |
         Component::AttributeOther(_) => true,
         _ => false,
     }
 }
 
 #[derive(Clone, Debug)]
 #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
-/// The aspects of an selector which are sensitive.
+/// The characteristics that a selector is sensitive to.
 pub struct Sensitivities {
-    /// The states which are sensitive.
+    /// The states which the selector is sensitive to.
     pub states: ElementState,
-    /// Whether attributes are sensitive.
+    /// Whether the selector is sensitive to attributes.
     pub attrs: bool,
 }
 
 impl Sensitivities {
     fn is_empty(&self) -> bool {
         self.states.is_empty() && !self.attrs
     }