Bug 1341721 Part 3: Update Stylist to maintain a state of whether author styles are disabled, and ExtraData parameters to modify that setting. draft
authorBrad Werth <bwerth@mozilla.com>
Thu, 13 Apr 2017 12:55:45 +0800
changeset 561915 0855445eb10397daf9549e316390a40119999f45
parent 561914 26dfbab75e6ab1172325893b69f499b82a6eb6da
child 561916 8467161550fed231928378f5722c518cda245319
push id53894
push userbwerth@mozilla.com
push dateThu, 13 Apr 2017 08:30:03 +0000
bugs1341721
milestone55.0a1
Bug 1341721 Part 3: Update Stylist to maintain a state of whether author styles are disabled, and ExtraData parameters to modify that setting. MozReview-Commit-ID: A5WCJwEBOp9
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
@@ -102,16 +102,17 @@ impl PerDocumentStyleDataImpl {
     }
 
     /// Recreate the style data if the stylesheets have changed.
     pub fn flush_stylesheets(&mut self, guard: &SharedRwLockReadGuard) {
         if self.stylesheets_changed {
             let mut stylist = Arc::get_mut(&mut self.stylist).unwrap();
             let mut extra_data = ExtraStyleData {
                 font_faces: &mut self.font_faces,
+                author_style_disabled: Some(self.author_style_disabled),
             };
             stylist.update(&self.stylesheets, &StylesheetGuards::same(guard),
                            None, true, &mut extra_data);
             self.stylesheets_changed = false;
         }
     }
 
     /// Get the default computed values for this document.
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -74,16 +74,19 @@ pub struct Stylist {
     pub device: Arc<Device>,
 
     /// Viewport constraints based on the current device.
     viewport_constraints: Option<ViewportConstraints>,
 
     /// If true, the quirks-mode stylesheet is applied.
     quirks_mode: bool,
 
+    /// If true, authored styles are ignored.
+    author_style_disabled: bool,
+
     /// If true, the device has changed, and the stylist needs to be updated.
     is_device_dirty: bool,
 
     /// The current selector maps, after evaluating media
     /// rules against the current device.
     element_map: PerPseudoElementSelectorMap,
 
     /// The rule tree, that stores the results of selector matching.
@@ -121,16 +124,20 @@ pub struct Stylist {
 
 /// This struct holds data which user of Stylist may want to extract
 /// from stylesheets which can be done at the same time as updating.
 pub struct ExtraStyleData<'a> {
     /// A list of effective font-face rules and their origin.
     #[cfg(feature = "gecko")]
     pub font_faces: &'a mut Vec<(Arc<Locked<FontFaceRule>>, Origin)>,
 
+    /// A parameter to change a setting to ignore author styles during update.
+    /// A None value indicates that update should use existing settings.
+    pub author_style_disabled: Option<bool>,
+
     #[allow(missing_docs)]
     #[cfg(feature = "servo")]
     pub marker: PhantomData<&'a usize>,
 }
 
 #[cfg(feature = "gecko")]
 impl<'a> ExtraStyleData<'a> {
     /// Clear the internal @font-face rule list.
@@ -154,16 +161,17 @@ impl Stylist {
     /// Construct a new `Stylist`, using a given `Device`.
     #[inline]
     pub fn new(device: Device) -> Self {
         let mut stylist = Stylist {
             viewport_constraints: None,
             device: Arc::new(device),
             is_device_dirty: true,
             quirks_mode: false,
+            author_style_disabled: false,
 
             element_map: PerPseudoElementSelectorMap::new(),
             pseudos_map: Default::default(),
             animations: Default::default(),
             precomputed_pseudo_element_decls: Default::default(),
             rules_source_order: 0,
             rule_tree: RuleTree::new(),
             state_deps: DependencySet::new(),
@@ -232,17 +240,25 @@ impl Stylist {
             }
 
             if self.quirks_mode {
                 self.add_stylesheet(&ua_stylesheets.quirks_mode_stylesheet,
                                     guards.ua_or_user, extra_data);
             }
         }
 
-        for ref stylesheet in doc_stylesheets.iter() {
+        // Absorb changes to author_style_disabled, if supplied.
+        if let Some(author_style_disabled) = extra_data.author_style_disabled {
+          self.author_style_disabled = author_style_disabled;
+        }
+
+        // Only use author stylesheets if author styles are enabled.
+        let author_style_enabled = !self.author_style_disabled;
+        for ref stylesheet in doc_stylesheets.iter()
+          .filter(|&s| author_style_enabled || s.origin != Origin::Author) {
             self.add_stylesheet(stylesheet, guards.author, extra_data);
         }
 
         debug!("Stylist stats:");
         debug!(" - Got {} selectors for cache revalidation",
                self.selectors_for_cache_revalidation.len());
         debug!(" - Got {} deps for style-hint calculation",
                self.state_deps.len());