servo: Merge #18794 - style: use the XBL styleset quirks mode to match XBL rules (from emilio:xbl-quirks-mode); r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 09 Oct 2017 05:04:15 -0500
changeset 427765 ca72a7721ef77a7fb583d4cacc286659a33adb68
parent 427764 ca1126dea7c833ab9b0d26f62d2599e07eb84982
child 427766 5f336a4ae6ce6274feccb2054b1bd6f8dd0fb9ef
push id97
push userfmarier@mozilla.com
push dateSat, 14 Oct 2017 01:12:59 +0000
reviewersheycam
bugs1405543
milestone58.0a1
servo: Merge #18794 - style: use the XBL styleset quirks mode to match XBL rules (from emilio:xbl-quirks-mode); r=heycam This fixes bug 1405543. MozReview-Commit-ID: Dv3mt3Fb8Yp Source-Repo: https://github.com/servo/servo Source-Revision: 604cc4e311f1aec72599d43c5a0138b04c8b780d
servo/components/style/gecko/data.rs
servo/components/style/stylist.rs
--- a/servo/components/style/gecko/data.rs
+++ b/servo/components/style/gecko/data.rs
@@ -118,16 +118,21 @@ pub struct PerDocumentStyleDataImpl {
 /// The data itself is an `AtomicRefCell`, which guarantees the proper semantics
 /// and unexpected races while trying to mutate it.
 pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);
 
 impl PerDocumentStyleData {
     /// Create a dummy `PerDocumentStyleData`.
     pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
         let device = Device::new(pres_context);
+
+        // FIXME(emilio, tlin): How is this supposed to work with XBL? This is
+        // right now not always honored, see bug 1405543...
+        //
+        // Should we just force XBL Stylists to be NoQuirks?
         let quirks_mode = unsafe {
             (*device.pres_context().mDocument.raw::<nsIDocument>()).mCompatMode
         };
 
         PerDocumentStyleData(AtomicRefCell::new(PerDocumentStyleDataImpl {
             stylist: Stylist::new(device, quirks_mode.into()),
         }))
     }
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -1265,22 +1265,31 @@ impl Stylist {
             debug!("skipping user rules");
         }
 
         // Step 3b: XBL rules.
         let cut_off_inheritance = element.each_xbl_stylist(|stylist| {
             // ServoStyleSet::CreateXBLServoStyleSet() loads XBL style sheets
             // under eAuthorSheetFeatures level.
             if let Some(map) = stylist.cascade_data.author.borrow_for_pseudo(pseudo_element) {
+                // NOTE(emilio): This is needed because the XBL stylist may
+                // think it has a different quirks mode than the document.
+                let mut matching_context = MatchingContext::new(
+                    context.matching_mode,
+                    context.bloom_filter,
+                    context.nth_index_cache.as_mut().map(|s| &mut **s),
+                    stylist.quirks_mode,
+                );
+
                 map.get_all_matching_rules(
                     element,
                     &rule_hash_target,
                     applicable_declarations,
-                    context,
-                    self.quirks_mode,
+                    &mut matching_context,
+                    stylist.quirks_mode,
                     flags_setter,
                     CascadeLevel::XBL,
                 );
             }
         });
 
         if rule_hash_target.matches_user_and_author_rules() && !only_default_rules {
             // Gecko skips author normal rules if cutting off inheritance.