Add an author_style_disabled flag to stylist.update, and associated structs.

MozReview-Commit-ID: FiXyEN4xVnU
This commit is contained in:
Brad Werth 2017-04-11 15:48:38 +08:00 committed by Brad Werth
parent 54e691b2aa
commit 91a9fb06c7
5 changed files with 29 additions and 3 deletions

View file

@ -78,6 +78,9 @@ pub struct Stylist {
/// 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,
@ -134,6 +137,10 @@ pub struct ExtraStyleData<'a> {
#[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>,
@ -167,6 +174,7 @@ impl Stylist {
device: Arc::new(device),
is_device_dirty: true,
quirks_mode: false,
author_style_disabled: false,
element_map: PerPseudoElementSelectorMap::new(),
pseudos_map: Default::default(),
@ -274,7 +282,16 @@ impl Stylist {
}
}
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;
let sheets_to_add = doc_stylesheets.iter().filter(
|&s| author_style_enabled || s.origin != Origin::Author);
for ref stylesheet in sheets_to_add {
self.add_stylesheet(stylesheet, guards.author, extra_data);
}