Bug 1247335 - patch 1 - Provide a desktop-pixel variant of SetPosition on nsIBaseWindow and its implementations. r=emk
authorJonathan Kew <jkew@mozilla.com>
Thu, 18 Feb 2016 10:46:16 +0000
changeset 331888 291cf27e6e55e20279fdb53219038b171abc945a
parent 331887 09b52ee5396030d49e946114c2cb7507645b8c96
child 331889 134d63b3e942785c325d7c1a35d9c46c9775a072
push id11113
push userrjesup@wgate.com
push dateThu, 18 Feb 2016 19:00:12 +0000
reviewersemk
bugs1247335
milestone47.0a1
Bug 1247335 - patch 1 - Provide a desktop-pixel variant of SetPosition on nsIBaseWindow and its implementations. r=emk
docshell/base/nsDocShell.cpp
dom/base/nsGlobalWindow.cpp
embedding/browser/nsDocShellTreeOwner.cpp
embedding/browser/nsWebBrowser.cpp
widget/nsIBaseWindow.idl
xpfe/appshell/nsChromeTreeOwner.cpp
xpfe/appshell/nsContentTreeOwner.cpp
xpfe/appshell/nsXULWindow.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -5810,16 +5810,25 @@ nsDocShell::SetPosition(int32_t aX, int3
   if (mContentViewer) {
     NS_ENSURE_SUCCESS(mContentViewer->Move(aX, aY), NS_ERROR_FAILURE);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShell::SetPositionDesktopPix(int32_t aX, int32_t aY)
+{
+  // Added to nsIBaseWindow in bug 1247335;
+  // implement if a use-case is found.
+  NS_ASSERTION(false, "implement me!");
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 nsDocShell::GetPosition(int32_t* aX, int32_t* aY)
 {
   return GetPositionAndSize(aX, aY, nullptr, nullptr);
 }
 
 NS_IMETHODIMP
 nsDocShell::SetSize(int32_t aWidth, int32_t aHeight, bool aRepaint)
 {
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -7058,39 +7058,37 @@ nsGlobalWindow::MoveToOuter(int32_t aXPo
   nsCOMPtr<nsIScreen> screen;
   if (screenMgr) {
     CSSIntSize size;
     GetInnerSize(size);
     screenMgr->ScreenForRect(aXPos, aYPos, size.width, size.height,
                              getter_AddRefs(screen));
   }
 
-  LayoutDevicePoint devPos;
   if (screen) {
     int32_t screenLeftDeskPx, screenTopDeskPx, w, h;
     screen->GetRectDisplayPix(&screenLeftDeskPx, &screenTopDeskPx, &w, &h);
     CSSIntPoint cssPos(aXPos - screenLeftDeskPx, aYPos - screenTopDeskPx);
     CheckSecurityLeftAndTop(&cssPos.x, &cssPos.y, aCallerIsChrome);
 
     double scale;
     screen->GetDefaultCSSScaleFactor(&scale);
-    devPos = cssPos * CSSToLayoutDeviceScale(scale);
-
-    int32_t screenLeftDevPx, screenTopDevPx;
-    screen->GetRect(&screenLeftDevPx, &screenTopDevPx, &w, &h);
-    devPos.x += screenLeftDevPx;
-    devPos.y += screenTopDevPx;
+    LayoutDevicePoint devPos = cssPos * CSSToLayoutDeviceScale(scale);
+
+    screen->GetContentsScaleFactor(&scale);
+    DesktopPoint deskPos = devPos / DesktopToLayoutDeviceScale(scale);
+    aError = treeOwnerAsWin->SetPositionDesktopPix(screenLeftDeskPx + deskPos.x,
+                                                   screenTopDeskPx + deskPos.y);
   } else {
     // We couldn't find a screen? Just assume a 1:1 mapping.
     CSSIntPoint cssPos(aXPos, aXPos);
     CheckSecurityLeftAndTop(&cssPos.x, &cssPos.y, aCallerIsChrome);
-    devPos = cssPos * CSSToLayoutDeviceScale(1.0);
-  }
-
-  aError = treeOwnerAsWin->SetPosition(devPos.x, devPos.y);
+    LayoutDevicePoint devPos = cssPos * CSSToLayoutDeviceScale(1.0);
+    aError = treeOwnerAsWin->SetPosition(devPos.x, devPos.y);
+  }
 }
 
 void
 nsGlobalWindow::MoveTo(int32_t aXPos, int32_t aYPos, ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(MoveToOuter, (aXPos, aYPos, aError, nsContentUtils::IsCallerChrome()), aError, );
 }
 
--- a/embedding/browser/nsDocShellTreeOwner.cpp
+++ b/embedding/browser/nsDocShellTreeOwner.cpp
@@ -566,16 +566,25 @@ nsDocShellTreeOwner::GetDevicePixelsPerD
     return mWebBrowser->GetDevicePixelsPerDesktopPixel(aScale);
   }
 
   *aScale = 1.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDocShellTreeOwner::SetPositionDesktopPix(int32_t aX, int32_t aY)
+{
+  // Added to nsIBaseWindow in bug 1247335;
+  // implement if a use-case is found.
+  NS_ASSERTION(false, "implement me!");
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 nsDocShellTreeOwner::SetPosition(int32_t aX, int32_t aY)
 {
   nsCOMPtr<nsIEmbeddingSiteWindow> ownerWin = GetOwnerWin();
   if (ownerWin) {
     return ownerWin->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION,
                                    aX, aY, 0, 0);
   }
   return NS_ERROR_NULL_POINTER;
--- a/embedding/browser/nsWebBrowser.cpp
+++ b/embedding/browser/nsWebBrowser.cpp
@@ -1298,16 +1298,25 @@ NS_IMETHODIMP
 nsWebBrowser::GetDevicePixelsPerDesktopPixel(double* aScale)
 {
   *aScale = mParentWidget ? mParentWidget->GetDesktopToDeviceScale().scale
                           : 1.0;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsWebBrowser::SetPositionDesktopPix(int32_t aX, int32_t aY)
+{
+  // Added to nsIBaseWindow in bug 1247335;
+  // implement if a use-case is found.
+  NS_ASSERTION(false, "implement me!");
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
 nsWebBrowser::SetPosition(int32_t aX, int32_t aY)
 {
   int32_t cx = 0;
   int32_t cy = 0;
 
   GetSize(&cx, &cy);
 
   return SetPositionAndSize(aX, aY, cx, cy, false);
--- a/widget/nsIBaseWindow.idl
+++ b/widget/nsIBaseWindow.idl
@@ -86,16 +86,22 @@ interface nsIBaseWindow : nsISupports
 	void destroy();
 
 	/*
 	Sets the current x and y coordinates of the control.  This is relative to
 	the parent window.
 	*/
 	void setPosition(in long x, in long y);
 
+  /*
+  Ditto, with arguments in global desktop pixels rather than (potentially
+  ambiguous) device pixels
+  */
+	void setPositionDesktopPix(in long x, in long y);
+
 	/*
 	Gets the current x and y coordinates of the control.  This is relatie to the
 	parent window.
 	*/
 	void getPosition(out long x, out long y);
 
 	/*
 	Sets the width and height of the control.
--- a/xpfe/appshell/nsChromeTreeOwner.cpp
+++ b/xpfe/appshell/nsChromeTreeOwner.cpp
@@ -383,16 +383,22 @@ NS_IMETHODIMP nsChromeTreeOwner::GetUnsc
 }
 
 NS_IMETHODIMP nsChromeTreeOwner::GetDevicePixelsPerDesktopPixel(double *aScale)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->GetDevicePixelsPerDesktopPixel(aScale);
 }
 
+NS_IMETHODIMP nsChromeTreeOwner::SetPositionDesktopPix(int32_t x, int32_t y)
+{
+   NS_ENSURE_STATE(mXULWindow);
+   return mXULWindow->SetPositionDesktopPix(x, y);
+}
+
 NS_IMETHODIMP nsChromeTreeOwner::SetPosition(int32_t x, int32_t y)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->SetPosition(x, y);
 }
 
 NS_IMETHODIMP nsChromeTreeOwner::GetPosition(int32_t* x, int32_t* y)
 {
--- a/xpfe/appshell/nsContentTreeOwner.cpp
+++ b/xpfe/appshell/nsContentTreeOwner.cpp
@@ -623,16 +623,22 @@ NS_IMETHODIMP nsContentTreeOwner::GetUns
 }
 
 NS_IMETHODIMP nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(double* aScale)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->GetDevicePixelsPerDesktopPixel(aScale);
 }
 
+NS_IMETHODIMP nsContentTreeOwner::SetPositionDesktopPix(int32_t aX, int32_t aY)
+{
+   NS_ENSURE_STATE(mXULWindow);
+   return mXULWindow->SetPositionDesktopPix(aX, aY);
+}
+
 NS_IMETHODIMP nsContentTreeOwner::SetPosition(int32_t aX, int32_t aY)
 {
    NS_ENSURE_STATE(mXULWindow);
    return mXULWindow->SetPosition(aX, aY);
 }
 
 NS_IMETHODIMP nsContentTreeOwner::GetPosition(int32_t* aX, int32_t* aY)
 {
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -610,16 +610,31 @@ nsXULWindow::GetScaleForDestinationPosit
     } else {
       // this fallback should never actually be needed
       scale = mWindow->GetDesktopToDeviceScale();
     }
   }
   return scale;
 }
 
+NS_IMETHODIMP nsXULWindow::SetPositionDesktopPix(int32_t aX, int32_t aY)
+{
+  nsresult rv = mWindow->Move(aX, aY);
+  NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+  if (!mChromeLoaded) {
+    // If we're called before the chrome is loaded someone obviously wants this
+    // window at this position. We don't persist this one-time position.
+    mIgnoreXULPosition = true;
+    return NS_OK;
+  }
+  PersistentAttributesDirty(PAD_POSITION);
+  SavePersistentAttributes();
+  return NS_OK;
+}
+
 NS_IMETHODIMP nsXULWindow::SetPosition(int32_t aX, int32_t aY)
 {
   // Don't reset the window's size mode here - platforms that don't want to move
   // maximized windows should reset it in their respective Move implementation.
   DesktopToLayoutDeviceScale scale = GetScaleForDestinationPosition(aX, aY);
   DesktopPoint pos = LayoutDeviceIntPoint(aX, aY) / scale;
   nsresult rv = mWindow->Move(pos.x, pos.y);
   NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);