Bug 1255645 - Ensure nsXULWindow constrains the window to the bounds of its screen after applying intrinsic sizing (if appropriate), by re-doing positioning after the window has been sized properly. r=emk a=ritu
authorJonathan Kew <jkew@mozilla.com>
Tue, 15 Mar 2016 14:29:44 +0000
changeset 323478 bf6d2a4b10313d8a1c2e8f5fc31beee1fe62c297
parent 323477 306fbf9bdddaf2290c3d51b6e19f5ada994d1863
child 323479 bfc3d42ce860abfbd73c8a33c043e75e4387e54a
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk, ritu
bugs1255645
milestone47.0a2
Bug 1255645 - Ensure nsXULWindow constrains the window to the bounds of its screen after applying intrinsic sizing (if appropriate), by re-doing positioning after the window has been sized properly. r=emk a=ritu
xpfe/appshell/nsXULWindow.cpp
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1050,16 +1050,20 @@ void nsXULWindow::OnChromeLoaded()
 #if defined(XP_UNIX) && !defined(XP_MACOSX)
     // don't override WM placement on unix for independent, top-level windows
     // (however, we think the benefits of intelligent dependent window placement
     // trump that override.)
     if (!parentWindow)
       positionSet = false;
 #endif
     if (positionSet) {
+      // We have to do this before sizing the window, because sizing depends
+      // on the resolution of the screen we're on. But positioning needs to
+      // know the size so that it can constrain to screen bounds.... as an
+      // initial guess here, we'll use the specified size (if any).
       positionSet = LoadPositionFromXUL(specWidth, specHeight);
     }
 
     if (gotSize) {
       SetSpecifiedSize(specWidth, specHeight);
     }
 
     if (mIntrinsicallySized) {
@@ -1071,16 +1075,21 @@ void nsXULWindow::OnChromeLoaded()
         nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
         docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
         if (treeOwner) {
           // GetContentSize can fail, so initialise |width| and |height| to be
           // on the safe side.
           int32_t width = 0, height = 0;
           if (NS_SUCCEEDED(cv->GetContentSize(&width, &height))) {
             treeOwner->SizeShellTo(docShellAsItem, width, height);
+            // Now that we know the window's final size, we can re-do its
+            // positioning so that it is properly constrained to the screen.
+            if (positionSet) {
+              LoadPositionFromXUL(width, height);
+            }
           }
         }
       }
     }
 
     LoadMiscPersistentAttributesFromXUL();
 
     if (mCenterAfterLoad && !positionSet) {