style: Make AuthorStylesEnabled an enum.

Chances are we need to pass it around in a bit.

Also invert the boolean because I don't want to reason about double negations,
even if they're simple.

MozReview-Commit-ID: KhX4lDKwDoj
This commit is contained in:
Emilio Cobos Álvarez 2018-02-08 12:40:27 +01:00
parent 4cc5717116
commit 438251cbfc
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 33 additions and 20 deletions

View file

@ -124,6 +124,16 @@ 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. /// A struct to iterate over the different stylesheets to be flushed.
pub struct StylesheetFlusher<'a, S> pub struct StylesheetFlusher<'a, S>
where where
@ -132,7 +142,7 @@ where
origins_dirty: OriginSet, origins_dirty: OriginSet,
collections: &'a mut PerOrigin<SheetCollection<S>>, collections: &'a mut PerOrigin<SheetCollection<S>>,
origin_data_validity: PerOrigin<DataValidity>, origin_data_validity: PerOrigin<DataValidity>,
author_style_disabled: bool, author_styles_enabled: AuthorStylesEnabled,
had_invalidations: bool, had_invalidations: bool,
} }
@ -199,7 +209,9 @@ where
"origin_data_validity should be a subset of origins_dirty!" "origin_data_validity should be a subset of origins_dirty!"
); );
if self.author_style_disabled && origin == Origin::Author { if self.author_styles_enabled == AuthorStylesEnabled::No &&
origin == Origin::Author
{
return PerOriginFlusher { return PerOriginFlusher {
iter: [].iter_mut(), iter: [].iter_mut(),
validity, validity,
@ -400,8 +412,8 @@ where
/// The invalidations for stylesheets added or removed from this document. /// The invalidations for stylesheets added or removed from this document.
invalidations: StylesheetInvalidationSet, invalidations: StylesheetInvalidationSet,
/// Has author style been disabled? /// Whether author styles are enabled.
author_style_disabled: bool, author_styles_enabled: AuthorStylesEnabled,
} }
impl<S> DocumentStylesheetSet<S> impl<S> DocumentStylesheetSet<S>
@ -413,7 +425,7 @@ where
Self { Self {
collections: Default::default(), collections: Default::default(),
invalidations: StylesheetInvalidationSet::new(), invalidations: StylesheetInvalidationSet::new(),
author_style_disabled: false, author_styles_enabled: AuthorStylesEnabled::Yes,
} }
} }
@ -427,12 +439,6 @@ where
self.collections.borrow_for_origin(&origin).get(index) self.collections.borrow_for_origin(&origin).get(index)
} }
/// Returns whether author styles have been disabled for the current
/// stylesheet set.
pub fn author_style_disabled(&self) -> bool {
self.author_style_disabled
}
fn collect_invalidations_for( fn collect_invalidations_for(
&mut self, &mut self,
device: Option<&Device>, device: Option<&Device>,
@ -505,12 +511,12 @@ where
} }
/// Notes that the author style has been disabled for this document. /// Notes that the author style has been disabled for this document.
pub fn set_author_style_disabled(&mut self, disabled: bool) { pub fn set_author_styles_enabled(&mut self, enabled: AuthorStylesEnabled) {
debug!("DocumentStylesheetSet::set_author_style_disabled"); debug!("DocumentStylesheetSet::set_author_styles_enabled");
if self.author_style_disabled == disabled { if self.author_styles_enabled == enabled {
return; return;
} }
self.author_style_disabled = disabled; self.author_styles_enabled = enabled;
self.invalidations.invalidate_fully(); self.invalidations.invalidate_fully();
self.collections.borrow_mut_for_origin(&Origin::Author) self.collections.borrow_mut_for_origin(&Origin::Author)
.set_data_validity_at_least(DataValidity::FullyInvalid) .set_data_validity_at_least(DataValidity::FullyInvalid)
@ -554,7 +560,7 @@ where
StylesheetFlusher { StylesheetFlusher {
collections: &mut self.collections, collections: &mut self.collections,
author_style_disabled: self.author_style_disabled, author_styles_enabled: self.author_styles_enabled,
had_invalidations, had_invalidations,
origins_dirty, origins_dirty,
origin_data_validity, origin_data_validity,

View file

@ -41,7 +41,7 @@ use smallvec::SmallVec;
use std::ops; use std::ops;
use std::sync::Mutex; use std::sync::Mutex;
use style_traits::viewport::ViewportConstraints; use style_traits::viewport::ViewportConstraints;
use stylesheet_set::{DataValidity, SheetRebuildKind, DocumentStylesheetSet, StylesheetFlusher}; use stylesheet_set::{AuthorStylesEnabled, DataValidity, SheetRebuildKind, DocumentStylesheetSet, StylesheetFlusher};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use stylesheets::{CounterStyleRule, FontFaceRule, FontFeatureValuesRule, PageRule}; use stylesheets::{CounterStyleRule, FontFaceRule, FontFeatureValuesRule, PageRule};
use stylesheets::{CssRule, Origin, OriginSet, PerOrigin, PerOriginIter}; use stylesheets::{CssRule, Origin, OriginSet, PerOrigin, PerOriginIter};
@ -592,8 +592,8 @@ impl Stylist {
} }
/// Sets whether author style is enabled or not. /// Sets whether author style is enabled or not.
pub fn set_author_style_disabled(&mut self, disabled: bool) { pub fn set_author_styles_enabled(&mut self, enabled: AuthorStylesEnabled) {
self.stylesheets.set_author_style_disabled(disabled); self.stylesheets.set_author_styles_enabled(enabled);
} }
/// Returns whether we've recorded any stylesheet change so far. /// Returns whether we've recorded any stylesheet change so far.

View file

@ -135,6 +135,7 @@ use style::selector_parser::{PseudoElementCascadeType, SelectorImpl};
use style::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked}; use style::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard, Locked};
use style::string_cache::{Atom, WeakAtom}; use style::string_cache::{Atom, WeakAtom};
use style::style_adjuster::StyleAdjuster; use style::style_adjuster::StyleAdjuster;
use style::stylesheet_set::AuthorStylesEnabled;
use style::stylesheets::{CssRule, CssRules, CssRuleType, CssRulesHelpers, DocumentRule}; use style::stylesheets::{CssRule, CssRules, CssRuleType, CssRulesHelpers, DocumentRule};
use style::stylesheets::{FontFeatureValuesRule, ImportRule, KeyframesRule, MediaRule}; use style::stylesheets::{FontFeatureValuesRule, ImportRule, KeyframesRule, MediaRule};
use style::stylesheets::{NamespaceRule, Origin, OriginSet, PageRule, StyleRule}; use style::stylesheets::{NamespaceRule, Origin, OriginSet, PageRule, StyleRule};
@ -1252,7 +1253,13 @@ pub extern "C" fn Servo_StyleSet_NoteStyleSheetsChanged(
) { ) {
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
data.stylist.force_stylesheet_origins_dirty(OriginSet::from(changed_origins)); data.stylist.force_stylesheet_origins_dirty(OriginSet::from(changed_origins));
data.stylist.set_author_style_disabled(author_style_disabled); let enabled =
if author_style_disabled {
AuthorStylesEnabled::No
} else {
AuthorStylesEnabled::Yes
};
data.stylist.set_author_styles_enabled(enabled);
} }
#[no_mangle] #[no_mangle]