diff --git a/components/style/stylesheet_set.rs b/components/style/stylesheet_set.rs index 0277842262e..eeb75e738e6 100644 --- a/components/style/stylesheet_set.rs +++ b/components/style/stylesheet_set.rs @@ -124,16 +124,6 @@ impl Default for DataValidity { } } -/// Whether author styles are enabled. -/// -/// This is used to support Gecko. -#[allow(missing_docs)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum AuthorStylesEnabled { - Yes, - No, -} - /// A struct to iterate over the different stylesheets to be flushed. pub struct StylesheetFlusher<'a, S> where @@ -142,7 +132,6 @@ where origins_dirty: OriginSet, collections: &'a mut PerOrigin>, origin_data_validity: PerOrigin, - author_styles_enabled: AuthorStylesEnabled, had_invalidations: bool, } @@ -209,14 +198,6 @@ where "origin_data_validity should be a subset of origins_dirty!" ); - if self.author_styles_enabled == AuthorStylesEnabled::No && - origin == Origin::Author - { - return PerOriginFlusher { - iter: [].iter_mut(), - validity, - } - } PerOriginFlusher { iter: self.collections.borrow_mut_for_origin(&origin).entries.iter_mut(), validity, @@ -411,9 +392,6 @@ where /// The invalidations for stylesheets added or removed from this document. invalidations: StylesheetInvalidationSet, - - /// Whether author styles are enabled. - author_styles_enabled: AuthorStylesEnabled, } impl DocumentStylesheetSet @@ -425,7 +403,6 @@ where Self { collections: Default::default(), invalidations: StylesheetInvalidationSet::new(), - author_styles_enabled: AuthorStylesEnabled::Yes, } } @@ -510,18 +487,6 @@ where self.collections.borrow_mut_for_origin(&origin).remove(&sheet) } - /// Notes that the author style has been disabled for this document. - pub fn set_author_styles_enabled(&mut self, enabled: AuthorStylesEnabled) { - debug!("DocumentStylesheetSet::set_author_styles_enabled"); - if self.author_styles_enabled == enabled { - return; - } - self.author_styles_enabled = enabled; - self.invalidations.invalidate_fully(); - self.collections.borrow_mut_for_origin(&Origin::Author) - .set_data_validity_at_least(DataValidity::FullyInvalid) - } - /// Returns whether the given set has changed from the last flush. pub fn has_changed(&self) -> bool { self.collections.iter_origins().any(|(collection, _)| collection.dirty) @@ -560,7 +525,6 @@ where StylesheetFlusher { collections: &mut self.collections, - author_styles_enabled: self.author_styles_enabled, had_invalidations, origins_dirty, origin_data_validity, diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 160c70df673..f656f77476b 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -41,7 +41,7 @@ use smallvec::SmallVec; use std::ops; use std::sync::Mutex; use style_traits::viewport::ViewportConstraints; -use stylesheet_set::{AuthorStylesEnabled, DataValidity, SheetRebuildKind, DocumentStylesheetSet, StylesheetFlusher}; +use stylesheet_set::{DataValidity, SheetRebuildKind, DocumentStylesheetSet, StylesheetFlusher}; #[cfg(feature = "gecko")] use stylesheets::{CounterStyleRule, FontFaceRule, FontFeatureValuesRule, PageRule}; use stylesheets::{CssRule, Origin, OriginSet, PerOrigin, PerOriginIter}; @@ -332,6 +332,16 @@ impl DocumentCascadeData { } } +/// Whether author styles are enabled. +/// +/// This is used to support Gecko. +#[allow(missing_docs)] +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq)] +pub enum AuthorStylesEnabled { + Yes, + No, +} + /// A wrapper over a DocumentStylesheetSet that can be `Sync`, since it's only /// used and exposed via mutable methods in the `Stylist`. #[cfg_attr(feature = "servo", derive(MallocSizeOf))] @@ -397,6 +407,9 @@ pub struct Stylist { /// cascade level. cascade_data: DocumentCascadeData, + /// Whether author styles are enabled. + author_styles_enabled: AuthorStylesEnabled, + /// The rule tree, that stores the results of selector matching. rule_tree: RuleTree, @@ -437,6 +450,7 @@ impl Stylist { quirks_mode, stylesheets: StylistStylesheetSet::new(), cascade_data: Default::default(), + author_styles_enabled: AuthorStylesEnabled::Yes, rule_tree: RuleTree::new(), num_rebuilds: 0, } @@ -593,7 +607,7 @@ impl Stylist { /// Sets whether author style is enabled or not. pub fn set_author_styles_enabled(&mut self, enabled: AuthorStylesEnabled) { - self.stylesheets.set_author_styles_enabled(enabled); + self.author_styles_enabled = enabled; } /// Returns whether we've recorded any stylesheet change so far. @@ -1221,8 +1235,11 @@ impl Stylist { let only_default_rules = rule_inclusion == RuleInclusion::DefaultOnly; - let matches_user_and_author_rules = + let matches_user_rules = rule_hash_target.matches_user_and_author_rules(); + let matches_author_rules = + matches_user_rules && + self.author_styles_enabled == AuthorStylesEnabled::Yes; // Step 1: Normal user-agent rules. if let Some(map) = self.cascade_data.user_agent.cascade_data.normal_rules(pseudo_element) { @@ -1260,7 +1277,7 @@ impl Stylist { // rule_hash_target.matches_user_and_author_rules()) // // Which may be more what you would probably expect. - if matches_user_and_author_rules { + if matches_user_rules { // Step 3a: User normal rules. if let Some(map) = self.cascade_data.user.normal_rules(pseudo_element) { map.get_all_matching_rules( @@ -1280,7 +1297,7 @@ impl Stylist { // particular, normally document rules override ::slotted() rules, but // for !important it should be the other way around. So probably we need // to add some sort of AuthorScoped cascade level or something. - if !only_default_rules { + if matches_author_rules && !only_default_rules { // Match slotted rules in reverse order, so that the outer slotted // rules come before the inner rules (and thus have less priority). let mut slots = SmallVec::<[_; 3]>::new(); @@ -1308,9 +1325,9 @@ impl Stylist { // FIXME(emilio): It looks very wrong to match XBL / Shadow DOM rules // even for getDefaultComputedStyle! + // + // Also, this doesn't account for the author_styles_enabled stuff. 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.normal_rules(pseudo_element) { // NOTE(emilio): This is needed because the XBL stylist may // think it has a different quirks mode than the document. @@ -1337,9 +1354,7 @@ impl Stylist { } }); - if matches_user_and_author_rules && !only_default_rules && - !cut_off_inheritance - { + if matches_author_rules && !only_default_rules && !cut_off_inheritance { // Step 3c: Author normal rules. if let Some(map) = self.cascade_data.author.normal_rules(pseudo_element) { map.get_all_matching_rules( diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 94a46e3395f..fe46a215188 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -135,7 +135,6 @@ use style::selector_parser::{PseudoElementCascadeType, SelectorImpl}; use style::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked}; use style::string_cache::{Atom, WeakAtom}; use style::style_adjuster::StyleAdjuster; -use style::stylesheet_set::AuthorStylesEnabled; use style::stylesheets::{CssRule, CssRules, CssRuleType, CssRulesHelpers, DocumentRule}; use style::stylesheets::{FontFeatureValuesRule, ImportRule, KeyframesRule, MediaRule}; use style::stylesheets::{NamespaceRule, Origin, OriginSet, PageRule, StyleRule}; @@ -143,7 +142,7 @@ use style::stylesheets::{StylesheetContents, SupportsRule}; use style::stylesheets::StylesheetLoader as StyleStylesheetLoader; use style::stylesheets::keyframes_rule::{Keyframe, KeyframeSelector, KeyframesStepValue}; use style::stylesheets::supports_rule::parse_condition_or_declaration; -use style::stylist::{add_size_of_ua_cache, RuleInclusion, Stylist}; +use style::stylist::{add_size_of_ua_cache, AuthorStylesEnabled, RuleInclusion, Stylist}; use style::thread_state; use style::timer::Timer; use style::traversal::DomTraversal; @@ -1248,11 +1247,18 @@ pub unsafe extern "C" fn Servo_StyleSet_FlushStyleSheets( #[no_mangle] pub extern "C" fn Servo_StyleSet_NoteStyleSheetsChanged( raw_data: RawServoStyleSetBorrowed, - author_style_disabled: bool, changed_origins: OriginFlags, ) { let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); data.stylist.force_stylesheet_origins_dirty(OriginSet::from(changed_origins)); +} + +#[no_mangle] +pub extern "C" fn Servo_StyleSet_SetAuthorStyleDisabled( + raw_data: RawServoStyleSetBorrowed, + author_style_disabled: bool, +) { + let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); let enabled = if author_style_disabled { AuthorStylesEnabled::No