diff --git a/ports/geckolib/data.rs b/ports/geckolib/data.rs index 8e0b98b42666..be287d66a98f 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 288e65431e50..7c562099c432 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) };