Bug 1357461: Ensure the device is up-to-date before evaluating media queries.
Zoom changes can change the meaning of ems, so we can't re-evaluate media
queries with the old values, because otherwise we may miss a restyle.
MozReview-Commit-ID: HQInvR7RPqR
--- a/servo/components/style/gecko/data.rs
+++ b/servo/components/style/gecko/data.rs
@@ -4,17 +4,16 @@
//! Data needed to style a Gecko document.
use Atom;
use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use dom::TElement;
use fnv::FnvHashMap;
use gecko::rules::{CounterStyleRule, FontFaceRule};
-use gecko::wrapper::GeckoElement;
use gecko_bindings::bindings::RawServoStyleSet;
use gecko_bindings::structs::RawGeckoPresContextOwned;
use gecko_bindings::structs::nsIDocument;
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::Device;
use properties::ComputedValues;
use shared_lock::{Locked, StylesheetGuards, SharedRwLockReadGuard};
use stylearc::Arc;
@@ -65,25 +64,16 @@ impl PerDocumentStyleData {
/// Get an mutable reference to this style data.
pub fn borrow_mut(&self) -> AtomicRefMut<PerDocumentStyleDataImpl> {
self.0.borrow_mut()
}
}
impl PerDocumentStyleDataImpl {
- /// Reset the device state because it may have changed.
- ///
- /// Implies also a stylesheet flush.
- pub fn reset_device(&mut self, guard: &SharedRwLockReadGuard) {
- self.stylist.device_mut().reset();
- self.stylesheets.force_dirty();
- self.flush_stylesheets::<GeckoElement>(guard, None);
- }
-
/// Recreate the style data if the stylesheets have changed.
pub fn flush_stylesheets<E>(&mut self,
guard: &SharedRwLockReadGuard,
document_element: Option<E>)
where E: TElement,
{
if !self.stylesheets.has_changed() {
return;
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -753,17 +753,22 @@ pub extern "C" fn Servo_StyleSet_MediumF
) -> bool {
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
// NOTE(emilio): We don't actually need to flush the stylist here and ensure
// it's up to date.
//
// In case it isn't we would trigger a rebuild + restyle as needed too.
- let data = PerDocumentStyleData::from_ffi(raw_data).borrow();
+ //
+ // We need to ensure the default computed values are up to date though,
+ // because those can influence the result of media query evaluation.
+ let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
+ data.stylist.device_mut().reset();
+
data.stylist.media_features_change_changed_style(
data.stylesheets.iter(),
&guard,
)
}
#[no_mangle]
pub extern "C" fn Servo_StyleSet_PrependStyleSheet(raw_data: RawServoStyleSetBorrowed,
@@ -1422,17 +1427,18 @@ pub extern "C" fn Servo_StyleSet_Init(pr
data.into_ffi()
}
#[no_mangle]
pub extern "C" fn Servo_StyleSet_RebuildData(raw_data: RawServoStyleSetBorrowed) {
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
- data.reset_device(&guard);
+ data.stylesheets.force_dirty();
+ data.flush_stylesheets::<GeckoElement>(&guard, None);
}
#[no_mangle]
pub extern "C" fn Servo_StyleSet_Clear(raw_data: RawServoStyleSetBorrowed) {
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();
data.clear_stylist();
}