Bug 1575097 Part 2: Make nsScreen::GetRDMScreenSize accept a CSSIntSize instead of an nsRect. r=Ehsan
authorBrad Werth <bwerth@mozilla.com>
Sun, 25 Aug 2019 23:53:31 +0000
changeset 489815 6125b2b41908aa287480369c36572e2bc706244b
parent 489814 7e2f3bd041dea95343062a87bdef6b4babf8700e
child 489816 651580f22a7c17e0718326bcee79b4cc5b49ee0b
push id36489
push userdluca@mozilla.com
push dateMon, 26 Aug 2019 09:42:55 +0000
treeherdermozilla-central@c75d6a0539eb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1575097
milestone70.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 1575097 Part 2: Make nsScreen::GetRDMScreenSize accept a CSSIntSize instead of an nsRect. r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D42743
dom/base/nsScreen.cpp
dom/base/nsScreen.h
--- a/dom/base/nsScreen.cpp
+++ b/dom/base/nsScreen.cpp
@@ -111,17 +111,22 @@ nsresult nsScreen::GetAvailRect(nsRect& 
   // Return window inner rect to prevent fingerprinting.
   if (ShouldResistFingerprinting()) {
     return GetWindowInnerRect(aRect);
   }
 
   // Here we manipulate the value of aRect to represent the screen avail size,
   // if in RDM.
   if (IsInRDMPane()) {
-    return GetRDMScreenSize(aRect);
+    mozilla::CSSIntSize size;
+    if (NS_SUCCEEDED(GetRDMScreenSize(size))) {
+      aRect.SetRect(0, 0, size.width, size.height);
+      return NS_OK;
+    }
+    return NS_ERROR_FAILURE;
   }
 
   nsDeviceContext* context = GetDeviceContext();
 
   if (!context) {
     return NS_ERROR_FAILURE;
   }
 
@@ -140,32 +145,30 @@ nsresult nsScreen::GetAvailRect(nsRect& 
             nsPresContext::AppUnitsToIntCSSPixels(aRect.y - r.y);
 
   aRect.SetHeight(nsPresContext::AppUnitsToIntCSSPixels(aRect.Height()));
   aRect.SetWidth(nsPresContext::AppUnitsToIntCSSPixels(aRect.Width()));
 
   return NS_OK;
 }
 
-nsresult nsScreen::GetRDMScreenSize(nsRect& aRect) {
-  GetWindowInnerRect(aRect);
-
+nsresult nsScreen::GetRDMScreenSize(mozilla::CSSIntSize& aSize) {
   // GetOwner(), GetDocShell(), and GetPresContext() can potentially return
   // nullptr, so to be safe let's make sure we check these before proceeding.
   nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner();
   if (owner) {
     nsIDocShell* docShell = owner->GetDocShell();
     if (docShell) {
       RefPtr<nsPresContext> presContext = docShell->GetPresContext();
       if (presContext) {
+        nsRect rect;
+        GetWindowInnerRect(rect);
         float zoom = presContext->GetDeviceFullZoom();
-        int32_t width = std::round(aRect.Width() * zoom);
-        int32_t height = std::round(aRect.Height() * zoom);
-        aRect.SetHeight(height);
-        aRect.SetWidth(width);
+        aSize.width = std::round(rect.Width() * zoom);
+        aSize.height = std::round(rect.Height() * zoom);
         return NS_OK;
       }
     }
   }
   return NS_ERROR_FAILURE;
 }
 
 mozilla::dom::ScreenOrientation* nsScreen::Orientation() const {
--- a/dom/base/nsScreen.h
+++ b/dom/base/nsScreen.h
@@ -41,49 +41,51 @@ class nsScreen : public mozilla::DOMEven
 
   int32_t GetLeft(ErrorResult& aRv) {
     nsRect rect;
     aRv = GetRect(rect);
     return rect.x;
   }
 
   int32_t GetWidth(ErrorResult& aRv) {
-    nsRect rect;
     if (IsDeviceSizePageSize()) {
       if (IsInRDMPane()) {
-        GetRDMScreenSize(rect);
-        return rect.Width();
+        mozilla::CSSIntSize size;
+        GetRDMScreenSize(size);
+        return size.width;
       }
 
       if (nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner()) {
         int32_t innerWidth = 0;
         aRv = owner->GetInnerWidth(&innerWidth);
         return innerWidth;
       }
     }
 
+    nsRect rect;
     aRv = GetRect(rect);
     return rect.Width();
   }
 
   int32_t GetHeight(ErrorResult& aRv) {
-    nsRect rect;
     if (IsDeviceSizePageSize()) {
       if (IsInRDMPane()) {
-        GetRDMScreenSize(rect);
-        return rect.Height();
+        mozilla::CSSIntSize size;
+        GetRDMScreenSize(size);
+        return size.height;
       }
 
       if (nsCOMPtr<nsPIDOMWindowInner> owner = GetOwner()) {
         int32_t innerHeight = 0;
         aRv = owner->GetInnerHeight(&innerHeight);
         return innerHeight;
       }
     }
 
+    nsRect rect;
     aRv = GetRect(rect);
     return rect.Height();
   }
 
   int32_t GetPixelDepth(ErrorResult& aRv);
   int32_t GetColorDepth(ErrorResult& aRv) { return GetPixelDepth(aRv); }
 
   int32_t GetAvailTop(ErrorResult& aRv) {
@@ -141,17 +143,17 @@ class nsScreen : public mozilla::DOMEven
 
   mozilla::dom::ScreenOrientation* Orientation() const;
 
  protected:
   nsDeviceContext* GetDeviceContext();
   nsresult GetRect(nsRect& aRect);
   nsresult GetAvailRect(nsRect& aRect);
   nsresult GetWindowInnerRect(nsRect& aRect);
-  nsresult GetRDMScreenSize(nsRect& aRect);
+  nsresult GetRDMScreenSize(mozilla::CSSIntSize& aSize);
 
  private:
   explicit nsScreen(nsPIDOMWindowInner* aWindow);
   virtual ~nsScreen();
 
   bool IsDeviceSizePageSize();
 
   bool ShouldResistFingerprinting() const;