diff options
author | Bobby Holley <bobbyholley@gmail.com> | 2016-07-28 17:00:42 -0700 |
---|---|---|
committer | Bobby Holley <bobbyholley@gmail.com> | 2016-07-28 17:19:08 -0700 |
commit | 933cef4adcd96d19429b42c1e5679358febd7012 (patch) | |
tree | baac9f785c6d9e59f93126f1975982c6145bf3d9 | |
parent | d934379f220e72b5771753ab0c5620b47b918e62 (diff) | |
download | servo-933cef4adcd96d19429b42c1e5679358febd7012.tar.gz servo-933cef4adcd96d19429b42c1e5679358febd7012.zip |
Flush stylesheets when doing non-traversal-driven style operations.
Without this, the stylist can be stale when we query it.
-rw-r--r-- | ports/geckolib/data.rs | 11 | ||||
-rw-r--r-- | ports/geckolib/glue.rs | 13 |
2 files changed, 18 insertions, 6 deletions
diff --git a/ports/geckolib/data.rs b/ports/geckolib/data.rs index 8e0b98b4266..be287d66a98 100644 --- a/ports/geckolib/data.rs +++ b/ports/geckolib/data.rs @@ -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 { diff --git a/ports/geckolib/glue.rs b/ports/geckolib/glue.rs index 288e65431e5..7c562099c43 100644 --- a/ports/geckolib/glue.rs +++ b/ports/geckolib/glue.rs @@ -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. // @@ -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()); @@ -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, @@ -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) }; |