style: Make AuthorStylesEnabled an enum.
draft
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
--- a/servo/components/style/stylesheet_set.rs
+++ b/servo/components/style/stylesheet_set.rs
@@ -119,25 +119,35 @@ pub enum DataValidity {
}
impl Default for DataValidity {
fn default() -> Self {
DataValidity::Valid
}
}
+/// 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
S: StylesheetInDocument + PartialEq + 'static,
{
origins_dirty: OriginSet,
collections: &'a mut PerOrigin<SheetCollection<S>>,
origin_data_validity: PerOrigin<DataValidity>,
- author_style_disabled: bool,
+ author_styles_enabled: AuthorStylesEnabled,
had_invalidations: bool,
}
/// The type of rebuild that we need to do for a given stylesheet.
#[derive(Clone, Copy, Debug)]
pub enum SheetRebuildKind {
/// A full rebuild, of both cascade data and invalidation data.
Full,
@@ -194,17 +204,19 @@ where
let validity = self.data_validity(origin);
let origin_dirty = self.origins_dirty.contains(origin.into());
debug_assert!(
origin_dirty || validity == DataValidity::Valid,
"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 {
iter: [].iter_mut(),
validity,
}
}
PerOriginFlusher {
iter: self.collections.borrow_mut_for_origin(&origin).entries.iter_mut(),
validity,
@@ -395,49 +407,43 @@ where
S: StylesheetInDocument + PartialEq + 'static,
{
/// The collections of sheets per each origin.
collections: PerOrigin<SheetCollection<S>>,
/// The invalidations for stylesheets added or removed from this document.
invalidations: StylesheetInvalidationSet,
- /// Has author style been disabled?
- author_style_disabled: bool,
+ /// Whether author styles are enabled.
+ author_styles_enabled: AuthorStylesEnabled,
}
impl<S> DocumentStylesheetSet<S>
where
S: StylesheetInDocument + PartialEq + 'static,
{
/// Create a new empty StylesheetSet.
pub fn new() -> Self {
Self {
collections: Default::default(),
invalidations: StylesheetInvalidationSet::new(),
- author_style_disabled: false,
+ author_styles_enabled: AuthorStylesEnabled::Yes,
}
}
/// Returns the number of stylesheets in the set.
pub fn len(&self) -> usize {
self.collections.iter_origins().fold(0, |s, (item, _)| s + item.len())
}
/// Returns the `index`th stylesheet in the set for the given origin.
pub fn get(&self, origin: Origin, index: usize) -> Option<&S> {
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(
&mut self,
device: Option<&Device>,
sheet: &S,
guard: &SharedRwLockReadGuard,
) {
if let Some(device) = device {
self.invalidations.collect_invalidations_for(device, sheet, guard);
@@ -500,22 +506,22 @@ where
debug!("StylesheetSet::remove_stylesheet");
self.collect_invalidations_for(device, &sheet, guard);
let origin = sheet.contents(guard).origin;
self.collections.borrow_mut_for_origin(&origin).remove(&sheet)
}
/// Notes that the author style has been disabled for this document.
- pub fn set_author_style_disabled(&mut self, disabled: bool) {
- debug!("DocumentStylesheetSet::set_author_style_disabled");
- if self.author_style_disabled == disabled {
+ 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_style_disabled = disabled;
+ 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)
@@ -549,17 +555,17 @@ where
origins_dirty |= origin;
*origin_data_validity.borrow_mut_for_origin(&origin) =
mem::replace(&mut collection.data_validity, DataValidity::Valid);
}
StylesheetFlusher {
collections: &mut self.collections,
- author_style_disabled: self.author_style_disabled,
+ author_styles_enabled: self.author_styles_enabled,
had_invalidations,
origins_dirty,
origin_data_validity,
}
}
/// Flush stylesheets, but without running any of the invalidation passes.
#[cfg(feature = "servo")]
--- a/servo/components/style/stylist.rs
+++ b/servo/components/style/stylist.rs
@@ -36,17 +36,17 @@ use selectors::parser::{SelectorIter, Vi
use selectors::visitor::SelectorVisitor;
use servo_arc::{Arc, ArcBorrow};
use shared_lock::{Locked, SharedRwLockReadGuard, StylesheetGuards};
use smallbitvec::SmallBitVec;
use smallvec::SmallVec;
use std::ops;
use std::sync::Mutex;
use style_traits::viewport::ViewportConstraints;
-use stylesheet_set::{DataValidity, SheetRebuildKind, DocumentStylesheetSet, StylesheetFlusher};
+use stylesheet_set::{AuthorStylesEnabled, DataValidity, SheetRebuildKind, DocumentStylesheetSet, StylesheetFlusher};
#[cfg(feature = "gecko")]
use stylesheets::{CounterStyleRule, FontFaceRule, FontFeatureValuesRule, PageRule};
use stylesheets::{CssRule, Origin, OriginSet, PerOrigin, PerOriginIter};
use stylesheets::StyleRule;
use stylesheets::StylesheetInDocument;
use stylesheets::keyframes_rule::KeyframesAnimation;
use stylesheets::viewport_rule::{self, MaybeNew, ViewportRule};
use thread_state::{self, ThreadState};
@@ -587,18 +587,18 @@ impl Stylist {
///
/// FIXME(emilio): Eventually it'd be nice for this to become more
/// fine-grained.
pub fn force_stylesheet_origins_dirty(&mut self, origins: OriginSet) {
self.stylesheets.force_dirty(origins)
}
/// Sets whether author style is enabled or not.
- pub fn set_author_style_disabled(&mut self, disabled: bool) {
- self.stylesheets.set_author_style_disabled(disabled);
+ pub fn set_author_styles_enabled(&mut self, enabled: AuthorStylesEnabled) {
+ self.stylesheets.set_author_styles_enabled(enabled);
}
/// Returns whether we've recorded any stylesheet change so far.
pub fn stylesheets_have_changed(&self) -> bool {
self.stylesheets.has_changed()
}
/// Appends a new stylesheet to the current set.
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -130,16 +130,17 @@ use style::properties::{parse_one_declar
use style::properties::animated_properties::AnimationValue;
use style::properties::animated_properties::compare_property_priority;
use style::rule_cache::RuleCacheConditions;
use style::rule_tree::{CascadeLevel, StrongRuleNode, StyleSource};
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};
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};
@@ -1247,17 +1248,23 @@ pub unsafe extern "C" fn Servo_StyleSet_
#[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));
- 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]
pub extern "C" fn Servo_StyleSheet_HasRules(
raw_contents: RawServoStyleSheetContentsBorrowed
) -> bool {
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();