Bug 1442521 - Treat args of nsXULWindow::SetSpecifiedSize as client area size and convert them to outer window size for SetSize. r?smaug draft
authorXidorn Quan <me@upsuper.org>
Fri, 02 Mar 2018 16:13:46 +1100
changeset 762343 ed19df9a7e2f0ac06f5fa379d872bab2abb0849b
parent 762341 f47fd84c487cbde6443c462168f7b80d9dc15064
push id101147
push userxquan@mozilla.com
push dateFri, 02 Mar 2018 05:19:54 +0000
reviewerssmaug
bugs1442521
milestone60.0a1
Bug 1442521 - Treat args of nsXULWindow::SetSpecifiedSize as client area size and convert them to outer window size for SetSize. r?smaug MozReview-Commit-ID: 7aRoxyu9LGy
xpfe/appshell/nsXULWindow.cpp
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1222,42 +1222,49 @@ nsXULWindow::LoadSizeFromXUL(int32_t& aS
   }
 
   return gotSize;
 }
 
 void
 nsXULWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight)
 {
+  // we cannot resize anything if there's no window
+  if (mWindow) {
+    return;
+  }
+
+  // convert specified values to outer window size with device pixels
+  double cssToDevPx = mWindow->GetDefaultScale().scale;
+  LayoutDeviceIntSize specSize = mWindow->ClientToWindowSize(
+    LayoutDeviceIntSize(NSToIntRound(aSpecWidth * cssToDevPx),
+                        NSToIntRound(aSpecHeight * cssToDevPx)));
+
   // constrain to screen size
   int32_t screenWidth;
   int32_t screenHeight;
-
   if (NS_SUCCEEDED(GetAvailScreenSize(&screenWidth, &screenHeight))) {
-    if (aSpecWidth > screenWidth) {
-      aSpecWidth = screenWidth;
+    screenWidth = NSToIntRound(screenWidth * cssToDevPx);
+    screenHeight = NSToIntRound(screenHeight * cssToDevPx);
+    if (specSize.width > screenWidth) {
+      specSize.width = screenWidth;
     }
-    if (aSpecHeight > screenHeight) {
-      aSpecHeight = screenHeight;
+    if (specSize.height > screenHeight) {
+      specSize.height = screenHeight;
     }
   }
 
-  NS_ASSERTION(mWindow, "we expected to have a window already");
-
   int32_t currWidth = 0;
   int32_t currHeight = 0;
   GetSize(&currWidth, &currHeight); // returns device pixels
 
-  // convert specified values to device pixels, and resize if needed
-  double cssToDevPx = mWindow ? mWindow->GetDefaultScale().scale : 1.0;
-  aSpecWidth = NSToIntRound(aSpecWidth * cssToDevPx);
-  aSpecHeight = NSToIntRound(aSpecHeight * cssToDevPx);
+  // resize if needed
   mIntrinsicallySized = false;
-  if (aSpecWidth != currWidth || aSpecHeight != currHeight) {
-    SetSize(aSpecWidth, aSpecHeight, false);
+  if (specSize.width != currWidth || specSize.height != currHeight) {
+    SetSize(specSize.width, specSize.height, false);
   }
 }
 
 /* Miscellaneous persistent attributes are attributes named in the
    |persist| attribute, other than size and position. Those are special
    because it's important to load those before one of the misc
    attributes (sizemode) and they require extra processing. */
 bool nsXULWindow::LoadMiscPersistentAttributesFromXUL()