diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index edba3c6ad45b..4428c0c47710 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -1085,6 +1085,7 @@ impl LayoutThread { ua_or_user: &ua_or_user_guard, }; let mut extra_data = ExtraStyleData { + author_style_disabled: None, marker: PhantomData, }; let needs_dirtying = Arc::get_mut(&mut rw_data.stylist).unwrap().update( diff --git a/components/style/gecko/data.rs b/components/style/gecko/data.rs index b3b6402f0c99..4ad43d3594af 100644 --- a/components/style/gecko/data.rs +++ b/components/style/gecko/data.rs @@ -32,6 +32,9 @@ pub struct PerDocumentStyleDataImpl { /// Whether the stylesheets list above has changed since the last restyle. pub stylesheets_changed: bool, + /// Has author style been disabled? + pub author_style_disabled: bool, + // FIXME(bholley): Hook these up to something. /// Unused. Will go away when we actually implement transitions and /// animations properly. @@ -65,6 +68,7 @@ impl PerDocumentStyleData { stylist: Arc::new(Stylist::new(device)), stylesheets: vec![], stylesheets_changed: true, + author_style_disabled: false, new_animations_sender: new_anims_sender, new_animations_receiver: new_anims_receiver, running_animations: Arc::new(RwLock::new(HashMap::new())), @@ -103,6 +107,7 @@ impl PerDocumentStyleDataImpl { 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); diff --git a/components/style/gecko_bindings/bindings.rs b/components/style/gecko_bindings/bindings.rs index 87ca62981a42..29f0e5001710 100644 --- a/components/style/gecko_bindings/bindings.rs +++ b/components/style/gecko_bindings/bindings.rs @@ -1525,7 +1525,8 @@ extern "C" { } extern "C" { pub fn Servo_StyleSet_NoteStyleSheetsChanged(set: - RawServoStyleSetBorrowed); + RawServoStyleSetBorrowed, + author_style_disabled: bool); } extern "C" { pub fn Servo_StyleSet_FillKeyframesForName(set: RawServoStyleSetBorrowed, diff --git a/components/style/stylist.rs b/components/style/stylist.rs index 0d43f320d246..5987dd74e447 100644 --- a/components/style/stylist.rs +++ b/components/style/stylist.rs @@ -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>, 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, + #[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); } diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index b321efe467a8..96939ec39943 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -645,9 +645,11 @@ pub extern "C" fn Servo_StyleSet_FlushStyleSheets(raw_data: RawServoStyleSetBorr } #[no_mangle] -pub extern "C" fn Servo_StyleSet_NoteStyleSheetsChanged(raw_data: RawServoStyleSetBorrowed) { +pub extern "C" fn Servo_StyleSet_NoteStyleSheetsChanged(raw_data: RawServoStyleSetBorrowed, + author_style_disabled: bool) { let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut(); data.stylesheets_changed = true; + data.author_style_disabled = author_style_disabled; } #[no_mangle]