Skip to content

Commit

Permalink
Add an author_style_disabled flag to stylist.update, and associated s…
Browse files Browse the repository at this point in the history
…tructs.

MozReview-Commit-ID: FiXyEN4xVnU
  • Loading branch information
bradwerth committed Apr 14, 2017
1 parent 54e691b commit 91a9fb0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions components/layout_thread/lib.rs
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions components/style/gecko/data.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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())),
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion components/style/gecko_bindings/bindings.rs
Expand Up @@ -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,
Expand Down
19 changes: 18 additions & 1 deletion components/style/stylist.rs
Expand Up @@ -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,

Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion ports/geckolib/glue.rs
Expand Up @@ -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]
Expand Down

0 comments on commit 91a9fb0

Please sign in to comment.