Flush stylesheets when doing non-traversal-driven style operations.

Without this, the stylist can be stale when we query it.
This commit is contained in:
Bobby Holley 2016-07-28 17:00:42 -07:00
parent d934379f22
commit 933cef4adc
2 changed files with 18 additions and 6 deletions

View file

@ -77,6 +77,17 @@ impl PerDocumentStyleData {
pub fn borrow_mut_from_raw<'a>(data: *mut RawServoStyleSet) -> &'a mut Self { pub fn borrow_mut_from_raw<'a>(data: *mut RawServoStyleSet) -> &'a mut Self {
unsafe { &mut *(data as *mut PerDocumentStyleData) } 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 { impl Drop for PerDocumentStyleData {

View file

@ -81,8 +81,6 @@ pub extern "C" fn Servo_Initialize() -> () {
fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) { fn restyle_subtree(node: GeckoNode, raw_data: *mut RawServoStyleSet) {
debug_assert!(node.is_element() || node.is_text_node()); 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 // Force the creation of our lazily-constructed initial computed values on
// the main thread, since it's not safe to call elsewhere. // 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. // along in startup than the sensible place to call Servo_Initialize.
ComputedValues::initial_values(); ComputedValues::initial_values();
let _needs_dirtying = Arc::get_mut(&mut per_doc_data.stylist).unwrap() // The stylist consumes stylesheets lazily.
.update(&per_doc_data.stylesheets, let per_doc_data = unsafe { &mut *(raw_data as *mut PerDocumentStyleData) };
per_doc_data.stylesheets_changed); per_doc_data.flush_stylesheets();
per_doc_data.stylesheets_changed = false;
let local_context_data = let local_context_data =
LocalStyleContextCreationInfo::new(per_doc_data.new_animations_sender.clone()); 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, pseudo_tag: *mut nsIAtom,
raw_data: *mut RawServoStyleSet) raw_data: *mut RawServoStyleSet)
-> *mut ServoComputedValues { -> *mut ServoComputedValues {
// The stylist consumes stylesheets lazily.
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data); let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
data.flush_stylesheets();
let pseudo = match pseudo_element_from_atom(pseudo_tag, /* ua_stylesheet = */ true) { let pseudo = match pseudo_element_from_atom(pseudo_tag, /* ua_stylesheet = */ true) {
Ok(pseudo) => pseudo, 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); let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
data.flush_stylesheets();
let element = unsafe { GeckoElement::from_raw(match_element) }; let element = unsafe { GeckoElement::from_raw(match_element) };