Bug 1483808 - Make webkit device-pixel-ratio media queries a proper alias to resolution. r=dholbert
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 17 Aug 2018 21:25:37 +0000
changeset 487291 b107fee86cbae4bc30815c89a2590bb052dd57c8
parent 487290 92102de55ba4ae9cb130c1cfa89c006895572c49
child 487292 cd628c962e757d258c5fca92e9586e88851caf7c
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1483808
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1483808 - Make webkit device-pixel-ratio media queries a proper alias to resolution. r=dholbert According to the spec: https://compat.spec.whatwg.org/#css-media-queries-webkit-device-pixel-ratio And to the Chromium implementation: https://cs.chromium.org/chromium/src/third_party/blink/renderer/core/css/media_query_evaluator.cc?l=366&rcl=1d7328865bcf06a687aafc18ff95d55317030672 They're no different than resolution. In our implementation `resolution` does slightly different stuff. Given we still haven't shipped -webkit-device-pixel-ratio, making this match resolution looks better than the opposite. Differential Revision: https://phabricator.services.mozilla.com/D3588
layout/style/nsMediaFeatures.cpp
servo/components/style/gecko/media_features.rs
servo/components/style/values/computed/resolution.rs
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -211,36 +211,16 @@ Gecko_MediaFeatures_GetDisplayMode(nsIDo
   uint32_t displayMode = nsIDocShell::DISPLAY_MODE_BROWSER;
   if (nsIDocShell* docShell = rootDocument->GetDocShell()) {
     docShell->GetDisplayMode(&displayMode);
   }
 
   return static_cast<StyleDisplayMode>(displayMode);
 }
 
-float
-Gecko_MediaFeatures_GetDevicePixelRatio(nsIDocument* aDocument)
-{
-  if (nsContentUtils::ShouldResistFingerprinting(aDocument)) {
-    return 1.0;
-  }
-
-  nsIPresShell* presShell = aDocument->GetShell();
-  if (!presShell) {
-    return 1.0;
-  }
-
-  nsPresContext* pc = presShell->GetPresContext();
-  if (!pc) {
-    return 1.0;
-  }
-
-  return pc->CSSPixelsToDevPixels(1.0f);
-}
-
 bool
 Gecko_MediaFeatures_HasSystemMetric(nsIDocument* aDocument,
                                     nsAtom* aMetric,
                                     bool aIsAccessibleFromContent)
 {
   if (aIsAccessibleFromContent &&
       nsContentUtils::ShouldResistFingerprinting(aDocument)) {
     return false;
--- a/servo/components/style/gecko/media_features.rs
+++ b/servo/components/style/gecko/media_features.rs
@@ -145,24 +145,20 @@ fn eval_device_aspect_ratio(
 /// FIXME(emilio): This should be an alias of `resolution`, according to the
 /// spec, and also according to the code in Chromium. Unify with
 /// `eval_resolution`.
 fn eval_device_pixel_ratio(
     device: &Device,
     query_value: Option<f32>,
     range_or_operator: Option<RangeOrOperator>,
 ) -> bool {
-    let ratio = unsafe {
-        bindings::Gecko_MediaFeatures_GetDevicePixelRatio(device.document())
-    };
-
-    RangeOrOperator::evaluate(
+    eval_resolution(
+        device,
+        query_value.map(Resolution::from_dppx),
         range_or_operator,
-        query_value,
-        ratio,
     )
 }
 
 #[derive(Debug, Copy, Clone, FromPrimitive, ToCss, Parse)]
 #[repr(u8)]
 enum Orientation {
     Landscape,
     Portrait,
--- a/servo/components/style/values/computed/resolution.rs
+++ b/servo/components/style/values/computed/resolution.rs
@@ -16,16 +16,22 @@ use values::specified;
 pub struct Resolution(CSSFloat);
 
 impl Resolution {
     /// Returns this resolution value as dppx.
     #[inline]
     pub fn dppx(&self) -> CSSFloat {
         self.0
     }
+
+    /// Return a computed `resolution` value from a dppx float value.
+    #[inline]
+    pub fn from_dppx(dppx: CSSFloat) -> Self {
+        Resolution(dppx)
+    }
 }
 
 impl ToComputedValue for specified::Resolution {
     type ComputedValue = Resolution;
 
     #[inline]
     fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
         Resolution(self.to_dppx())