Navigation Menu

Skip to content

Commit

Permalink
Flush stylesheets when doing non-traversal-driven style operations.
Browse files Browse the repository at this point in the history
Without this, the stylist can be stale when we query it.
  • Loading branch information
bholley committed Jul 29, 2016
1 parent d934379 commit 933cef4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 11 additions & 0 deletions ports/geckolib/data.rs
Expand Up @@ -77,6 +77,17 @@ impl PerDocumentStyleData {
pub fn borrow_mut_from_raw<'a>(data: *mut RawServoStyleSet) -> &'a mut Self {
unsafe { &mut *(data as *mut PerDocumentStyleData) }
}

pub fn flush_stylesheets(&mut self) {
// The stylist wants to be flushed if either the stylesheets change or the
// device dimensions change. When we add support for media queries, we'll
// need to detect the latter case and trigger a flush as well.
if self.stylesheets_changed {
let _ = Arc::get_mut(&mut self.stylist).unwrap()
.update(&self.stylesheets, true);
self.stylesheets_changed = false;
}
}
}

impl Drop for PerDocumentStyleData {
Expand Down
13 changes: 7 additions & 6 deletions ports/geckolib/glue.rs
Expand Up @@ -81,8 +81,6 @@ pub extern "C" fn Servo_Initialize() -> () {
fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
debug_assert!(node.is_element() || node.is_text_node());

let per_doc_data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) };

// Force the creation of our lazily-constructed initial computed values on
// the main thread, since it's not safe to call elsewhere.
//
Expand All @@ -92,10 +90,9 @@ fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
// along in startup than the sensible place to call Servo_Initialize.
ComputedValues::initial_values();

let _needs_dirtying = Arc::get_mut(&mut per_doc_data.stylist).unwrap()
.update(&per_doc_data.stylesheets,
per_doc_data.stylesheets_changed);
per_doc_data.stylesheets_changed = false;
// The stylist consumes stylesheets lazily.
let per_doc_data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) };
per_doc_data.flush_stylesheets();

let local_context_data =
LocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone());
Expand Down Expand Up @@ -274,7 +271,9 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *
pseudo_tag: *mut nsIAtom,
raw_data: *mut RawServoStyleSet)
-> *mut ServoComputedValues {
// The stylist consumes stylesheets lazily.
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
data.flush_stylesheets();

let pseudo = match pseudo_element_from_atom(pseudo_tag, /* ua_stylesheet = */ true) {
Ok(pseudo) => pseudo,
Expand Down Expand Up @@ -319,7 +318,9 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
};


// The stylist consumes stylesheets lazily.
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
data.flush_stylesheets();

let element = unsafe { GeckoElement::from_raw(match_element) };

Expand Down

0 comments on commit 933cef4

Please sign in to comment.