Skip to content

Commit

Permalink
Auto merge of #17850 - upsuper:bug1382077, r=heycam
Browse files Browse the repository at this point in the history
Record viewport unit usage and generate proper restyle hint

This is the Servo side change of [bug 1382077](https://bugzilla.mozilla.org/show_bug.cgi?id=1382077).
  • Loading branch information
bors-servo committed Jul 25, 2017
2 parents 3eeb0e5 + 388875c commit e825bf1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 3 additions & 2 deletions components/style/gecko/generated/bindings.rs
Expand Up @@ -1921,8 +1921,9 @@ extern "C" {
pub fn Servo_StyleSet_RebuildData(set: RawServoStyleSetBorrowed);
}
extern "C" {
pub fn Servo_StyleSet_MediumFeaturesChanged(set: RawServoStyleSetBorrowed)
-> bool;
pub fn Servo_StyleSet_MediumFeaturesChanged(set: RawServoStyleSetBorrowed,
viewport_changed: bool)
-> nsRestyleHint;
}
extern "C" {
pub fn Servo_StyleSet_CompatModeChanged(raw_data:
Expand Down
11 changes: 11 additions & 0 deletions components/style/gecko/media_queries.rs
Expand Up @@ -54,6 +54,9 @@ pub struct Device {
/// Whether any styles computed in the document relied on the root font-size
/// by using rem units.
used_root_font_size: AtomicBool,
/// Whether any styles computed in the document relied on the viewport size
/// by using vw/vh/vmin/vmax units.
used_viewport_size: AtomicBool,
}

unsafe impl Sync for Device {}
Expand All @@ -69,6 +72,7 @@ impl Device {
viewport_override: None,
root_font_size: AtomicIsize::new(font_size::get_initial_value().0 as isize), // FIXME(bz): Seems dubious?
used_root_font_size: AtomicBool::new(false),
used_viewport_size: AtomicBool::new(false),
}
}

Expand Down Expand Up @@ -112,6 +116,7 @@ impl Device {
self.viewport_override = None;
self.default_values = ComputedValues::default_values(self.pres_context());
self.used_root_font_size.store(false, Ordering::Relaxed);
self.used_viewport_size.store(false, Ordering::Relaxed);
}

/// Returns whether we ever looked up the root font size of the Device.
Expand Down Expand Up @@ -146,6 +151,7 @@ impl Device {

/// Returns the current viewport size in app units.
pub fn au_viewport_size(&self) -> Size2D<Au> {
self.used_viewport_size.store(true, Ordering::Relaxed);
self.viewport_override.as_ref().map(|v| {
Size2D::new(Au::from_f32_px(v.size.width),
Au::from_f32_px(v.size.height))
Expand All @@ -156,6 +162,11 @@ impl Device {
})
}

/// Returns whether we ever looked up the viewport size of the Device.
pub fn used_viewport_size(&self) -> bool {
self.used_viewport_size.load(Ordering::Relaxed)
}

/// Returns the device pixel ratio.
pub fn device_pixel_ratio(&self) -> ScaleFactor<f32, CSSPixel, DevicePixel> {
let override_dppx = self.pres_context().mOverrideDPPX;
Expand Down
4 changes: 4 additions & 0 deletions components/style/stylesheets/viewport_rule.rs
Expand Up @@ -696,6 +696,10 @@ impl MaybeNew for ViewportConstraints {
//
// Note: DEVICE-ADAPT § 5. states that relative length values are
// resolved against initial values
//
// Note, we set used_viewport_size flag for Gecko in au_viewport_size.
// If we ever start supporting ViewportRule in Gecko, we probably want
// to avoid doing so at this place.
let initial_viewport = device.au_viewport_size();

let provider = get_metrics_provider_for_product();
Expand Down
15 changes: 12 additions & 3 deletions ports/geckolib/glue.rs
Expand Up @@ -865,7 +865,8 @@ pub extern "C" fn Servo_StyleSet_AppendStyleSheet(
#[no_mangle]
pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
raw_data: RawServoStyleSetBorrowed,
) -> bool {
viewport_changed: bool,
) -> nsRestyleHint {
let global_style_data = &*GLOBAL_STYLE_DATA;
let guard = global_style_data.shared_lock.read();

Expand All @@ -881,11 +882,19 @@ pub extern "C" fn Servo_StyleSet_MediumFeaturesChanged(
// less often.
let mut data = PerDocumentStyleData::from_ffi(raw_data).borrow_mut();

let viewport_units_used = data.stylist.device().used_viewport_size();
data.stylist.device_mut().reset_computed_values();
data.stylist.media_features_change_changed_style(
let rules_changed = data.stylist.media_features_change_changed_style(
data.stylesheets.iter(),
&guard,
)
);
if rules_changed {
structs::nsRestyleHint_eRestyle_Subtree
} else if viewport_changed && viewport_units_used {
structs::nsRestyleHint_eRestyle_ForceDescendants
} else {
nsRestyleHint(0)
}
}

#[no_mangle]
Expand Down

0 comments on commit e825bf1

Please sign in to comment.