Bug 1402942 Part 1: Use double precision match in computation of Window.devicePixelRatio. draft
authorBrad Werth <bwerth@mozilla.com>
Mon, 25 Sep 2017 11:53:09 -0700
changeset 670160 061591e350ae6178abea5860e953d7c561971478
parent 669742 5f3f19824efa14cc6db546baf59c54a0fc15ddc9
child 733153 53b8a5e42044b58396e41240cbfdbc1b7deb0abb
push id81538
push userbwerth@mozilla.com
push dateMon, 25 Sep 2017 23:49:59 +0000
bugs1402942
milestone58.0a1
Bug 1402942 Part 1: Use double precision match in computation of Window.devicePixelRatio. MozReview-Commit-ID: 9OCtSgE6jYj
dom/base/nsGlobalWindow.cpp
dom/base/nsGlobalWindow.h
dom/webidl/Window.webidl
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -6269,17 +6269,17 @@ nsGlobalWindow::GetMozInnerScreenYOuter(
 }
 
 float
 nsGlobalWindow::GetMozInnerScreenY(CallerType aCallerType, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetMozInnerScreenYOuter, (aCallerType), aError, 0);
 }
 
-float
+double
 nsGlobalWindow::GetDevicePixelRatioOuter(CallerType aCallerType)
 {
   MOZ_RELEASE_ASSERT(IsOuterWindow());
 
   if (!mDocShell) {
     return 1.0;
   }
 
@@ -6291,24 +6291,24 @@ nsGlobalWindow::GetDevicePixelRatioOuter
 
   if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return 1.0;
   }
 
   float overrideDPPX = presContext->GetOverrideDPPX();
 
   if (overrideDPPX > 0) {
-    return overrideDPPX;
-  }
-
-  return float(nsPresContext::AppUnitsPerCSSPixel())/
-      presContext->AppUnitsPerDevPixel();
-}
-
-float
+    return (double)overrideDPPX;
+  }
+
+  return double(nsPresContext::AppUnitsPerCSSPixel()) /
+         double(presContext->AppUnitsPerDevPixel());
+}
+
+double
 nsGlobalWindow::GetDevicePixelRatio(CallerType aCallerType, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetDevicePixelRatioOuter, (aCallerType), aError, 0.0);
 }
 
 float
 nsPIDOMWindowOuter::GetDevicePixelRatio(CallerType aCallerType)
 {
--- a/dom/base/nsGlobalWindow.h
+++ b/dom/base/nsGlobalWindow.h
@@ -1157,19 +1157,19 @@ public:
   mozilla::dom::Element* GetRealFrameElementOuter();
   mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError);
   float GetMozInnerScreenXOuter(mozilla::dom::CallerType aCallerType);
   float GetMozInnerScreenX(mozilla::dom::CallerType aCallerType,
                            mozilla::ErrorResult& aError);
   float GetMozInnerScreenYOuter(mozilla::dom::CallerType aCallerType);
   float GetMozInnerScreenY(mozilla::dom::CallerType aCallerType,
                            mozilla::ErrorResult& aError);
-  float GetDevicePixelRatioOuter(mozilla::dom::CallerType aCallerType);
-  float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType,
-                            mozilla::ErrorResult& aError);
+  double GetDevicePixelRatioOuter(mozilla::dom::CallerType aCallerType);
+  double GetDevicePixelRatio(mozilla::dom::CallerType aCallerType,
+                             mozilla::ErrorResult& aError);
   int32_t GetScrollMinX(mozilla::ErrorResult& aError);
   int32_t GetScrollMinY(mozilla::ErrorResult& aError);
   int32_t GetScrollMaxX(mozilla::ErrorResult& aError);
   int32_t GetScrollMaxY(mozilla::ErrorResult& aError);
   bool GetFullScreenOuter();
   bool GetFullScreen(mozilla::ErrorResult& aError);
   bool GetFullScreen() override;
   void SetFullScreenOuter(bool aFullScreen, mozilla::ErrorResult& aError);
--- a/dom/webidl/Window.webidl
+++ b/dom/webidl/Window.webidl
@@ -254,17 +254,17 @@ partial interface Window {
 
   [ChromeOnly, Throws] readonly attribute Element? realFrameElement;
 
   [Throws, NeedsCallerType]
   readonly attribute float mozInnerScreenX;
   [Throws, NeedsCallerType]
   readonly attribute float mozInnerScreenY;
   [Replaceable, Throws, NeedsCallerType]
-  readonly attribute float devicePixelRatio;
+  readonly attribute double devicePixelRatio;
 
   /* The maximum offset that the window can be scrolled to
      (i.e., the document width/height minus the scrollport width/height) */
   [ChromeOnly, Throws]  readonly attribute long   scrollMinX;
   [ChromeOnly, Throws]  readonly attribute long   scrollMinY;
   [Replaceable, Throws] readonly attribute long   scrollMaxX;
   [Replaceable, Throws] readonly attribute long   scrollMaxY;