Bug 1254019 - Don't attempt to resize a maximized window on DPI change; and when handling a DPI change, constrain the resized window to the screen bounds. r=emk
☠☠ backed out by 375e296794c7 ☠ ☠
authorJonathan Kew <jkew@mozilla.com>
Tue, 15 Mar 2016 19:52:46 +0000
changeset 288924 1c2aac5e9b1cec93623a724b86493093365e5678
parent 288923 6dbf14f1dc41bd5c7e9436a5e89d9f57701884a1
child 288925 21e9dd187ca87f1eec65888aa373559a2c3e9ab1
push id73620
push userjkew@mozilla.com
push dateWed, 16 Mar 2016 08:08:37 +0000
treeherdermozilla-inbound@21e9dd187ca8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersemk
bugs1254019
milestone48.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 1254019 - Don't attempt to resize a maximized window on DPI change; and when handling a DPI change, constrain the resized window to the screen bounds. r=emk
widget/windows/nsWindow.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -6877,33 +6877,49 @@ nsWindow::OnDPIChanged(int32_t x, int32_
   }
   if (DefaultScaleOverride() > 0.0) {
     return;
   }
   double oldScale = mDefaultScale;
   mDefaultScale = -1.0; // force recomputation of scale factor
   double newScale = GetDefaultScaleInternal();
 
-  if (mResizeState != RESIZING) {
+  if (mResizeState != RESIZING && mSizeMode == nsSizeMode_Normal) {
     // We want to try and maintain the size of the client area, rather than
     // the overall size of the window including non-client area, so we prefer
     // to calculate the new size instead of using Windows' suggested values.
     if (oldScale > 0.0) {
       double ratio = newScale / oldScale;
       LayoutDeviceIntRect cr, sr;
       GetClientBounds(cr);
       GetScreenBounds(sr);
       int32_t w = sr.width - cr.width + NSToIntRound(cr.width * ratio);
       int32_t h = sr.height - cr.height + NSToIntRound(cr.height * ratio);
       // Adjust x and y to preserve the center point of the suggested rect.
       x -= (w - width) / 2;
       y -= (h - height) / 2;
       width = w;
       height = h;
     }
+
+    // Limit the position & size, if it would overflow the destination screen
+    nsCOMPtr<nsIScreenManager> sm = do_GetService(sScreenManagerContractID);
+    if (sm) {
+      nsCOMPtr<nsIScreen> screen;
+      sm->ScreenForRect(x, y, width, height, getter_AddRefs(screen));
+      if (screen) {
+        int32_t availLeft, availTop, availWidth, availHeight;
+        screen->GetAvailRect(&availLeft, &availTop, &availWidth, &availHeight);
+        x = std::max(x, availLeft);
+        y = std::max(y, availTop);
+        width = std::min(width, availWidth);
+        height = std::min(height, availHeight);
+      }
+    }
+
     Resize(x, y, width, height, true);
   }
   ChangedDPI();
 }
 
 /**************************************************************
  **************************************************************
  **