Align eRestyle_Subtree value with RESTYLE_DESCENDANTS. r?bholley draft
authorCameron McCormack <cam@mcc.id.au>
Fri, 10 Mar 2017 17:55:36 +0800
changeset 496709 70f96100a292aa731c0bfd6f399a3688eb154ddf
parent 496708 4c539a88fe566efadeac9ef6220d45adf2b69270
child 548675 42d71a302c03b2293cedc2a913677fc9ef10ae04
push id48664
push userbmo:cam@mcc.id.au
push dateFri, 10 Mar 2017 14:07:02 +0000
reviewersbholley
milestone55.0a1
Align eRestyle_Subtree value with RESTYLE_DESCENDANTS. r?bholley Handle the translation of eRestyle_Subtree into (RESTYLE_SELF | RESTYLE_DESCENDANTS) in the From impl, too. MozReview-Commit-ID: DXrr0CwQpjM
servo/components/style/restyle_hints.rs
--- a/servo/components/style/restyle_hints.rs
+++ b/servo/components/style/restyle_hints.rs
@@ -36,17 +36,17 @@ bitflags! {
     pub flags RestyleHint: u32 {
         /// Rerun selector matching on the element.
         const RESTYLE_SELF = 0x01,
 
         /// Rerun selector matching on all of the element's descendants.
         ///
         /// NB: In Gecko, we have RESTYLE_SUBTREE which is inclusive of self,
         /// but heycam isn't aware of a good reason for that.
-        const RESTYLE_DESCENDANTS = 0x02,
+        const RESTYLE_DESCENDANTS = 0x04,
 
         /// Rerun selector matching on all later siblings of the element and all
         /// of their descendants.
         const RESTYLE_LATER_SIBLINGS = 0x08,
 
         /// Don't re-run selector-matching on the element, only the style
         /// attribute has changed, and this change didn't have any other
         /// dependencies.
@@ -70,23 +70,21 @@ pub fn assert_restyle_hints_match() {
                 )*
                 assert_eq!(hints, RestyleHint::empty(), "all RestyleHint bits should have an assertion");
             }
         }
     }
 
     check_restyle_hints! {
         nsRestyleHint_eRestyle_Self => RESTYLE_SELF,
-        // XXX This for Servo actually means something like an hypothetical
-        // Restyle_AllDescendants (but without running selector matching on the
-        // element). ServoRestyleManager interprets it like that, but in practice we
-        // should align the behavior with Gecko adding a new restyle hint, maybe?
-        //
-        // See https://bugzilla.mozilla.org/show_bug.cgi?id=1291786
-        nsRestyleHint_eRestyle_SomeDescendants => RESTYLE_DESCENDANTS,
+        // Note that eRestyle_Subtree means "self and descendants", while
+        // RESTYLE_DESCENDANTS means descendants only.  The From impl
+        // below handles converting eRestyle_Subtree into
+        // (RESTYLE_SELF | RESTYLE_DESCENDANTS).
+        nsRestyleHint_eRestyle_Subtree => RESTYLE_DESCENDANTS,
         nsRestyleHint_eRestyle_LaterSiblings => RESTYLE_LATER_SIBLINGS,
         nsRestyleHint_eRestyle_StyleAttribute => RESTYLE_STYLE_ATTRIBUTE,
     }
 }
 
 impl RestyleHint {
     /// The subset hints that affect the styling of a single element during the
     /// traversal.
@@ -101,17 +99,24 @@ impl From<nsRestyleHint> for RestyleHint
         use std::mem;
         let raw_bits: u32 = unsafe { mem::transmute(raw) };
         // FIXME(bholley): Finish aligning the binary representations here and
         // then .expect() the result of the checked version.
         if Self::from_bits(raw_bits).is_none() {
             warn!("stylo: dropping unsupported restyle hint bits");
         }
 
-        Self::from_bits_truncate(raw_bits)
+        let mut bits = Self::from_bits_truncate(raw_bits);
+
+        // eRestyle_Subtree converts to (RESTYLE_SELF | RESTYLE_DESCENDANTS).
+        if bits.contains(RESTYLE_DESCENDANTS) {
+            bits |= RESTYLE_SELF;
+        }
+
+        bits
     }
 }
 
 #[cfg(feature = "servo")]
 impl HeapSizeOf for RestyleHint {
     fn heap_size_of_children(&self) -> usize { 0 }
 }