Bug 1443864: Apply size constraints on nsXULWindow too. r?xidorn draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Thu, 01 Mar 2018 17:40:23 +0100
changeset 764325 45e5823f359ba0694cf109323c0e9e93f10664ea
parent 764293 98fe392d2d0d350abc730c301e8702341d508e93
child 764334 eee7aaf2fb42ffcbc96f53514b87ced21f024307
push id101740
push userbmo:emilio@crisal.io
push dateWed, 07 Mar 2018 17:47:14 +0000
reviewersxidorn
bugs1443864
milestone60.0a1
Bug 1443864: Apply size constraints on nsXULWindow too. r?xidorn MozReview-Commit-ID: BwL4sEDlVKl
xpfe/appshell/nsXULWindow.cpp
--- a/xpfe/appshell/nsXULWindow.cpp
+++ b/xpfe/appshell/nsXULWindow.cpp
@@ -1246,48 +1246,68 @@ bool nsXULWindow::LoadPositionFromXUL(in
   mWindow->ConstrainPosition(false, &specX, &specY);
   if (specX != currX || specY != currY) {
     SetPositionDesktopPix(specX, specY);
   }
 
   return gotPosition;
 }
 
+static Maybe<int32_t>
+ReadIntAttribute(const Element& aElement, nsAtom* aAtom)
+{
+  nsAutoString attrString;
+  if (!aElement.GetAttr(kNameSpaceID_None, aAtom, attrString)) {
+    return Nothing();
+  }
+
+  nsresult res = NS_OK;
+  int32_t ret = attrString.ToInteger(&res);
+  return NS_SUCCEEDED(res) ? Some(ret) : Nothing();
+}
+
 bool
 nsXULWindow::LoadSizeFromXUL(int32_t& aSpecWidth, int32_t& aSpecHeight)
 {
   bool     gotSize = false;
 
   // if we're the hidden window, don't try to validate our size/position. We're
   // special.
   if (mIsHiddenWindow) {
     return false;
   }
 
   nsCOMPtr<dom::Element> windowElement = GetWindowDOMElement();
   NS_ENSURE_TRUE(windowElement, false);
 
-  nsresult errorCode;
-  int32_t temp;
-
   // Obtain the sizing information from the <xul:window> element.
   aSpecWidth = 100;
   aSpecHeight = 100;
-  nsAutoString sizeString;
 
-  windowElement->GetAttribute(WIDTH_ATTRIBUTE, sizeString);
-  temp = sizeString.ToInteger(&errorCode);
-  if (NS_SUCCEEDED(errorCode) && temp > 0) {
-    aSpecWidth = std::max(temp, 100);
+  if (auto width = ReadIntAttribute(*windowElement, nsGkAtoms::width)) {
+    int32_t min =
+      ReadIntAttribute(*windowElement, nsGkAtoms::minwidth)
+        .valueOr(100);
+    int32_t max =
+      ReadIntAttribute(*windowElement, nsGkAtoms::maxwidth)
+        .valueOr(std::numeric_limits<int32_t>::max());
+
+    aSpecWidth = std::min(max, std::max(*width, min));
     gotSize = true;
   }
-  windowElement->GetAttribute(HEIGHT_ATTRIBUTE, sizeString);
-  temp = sizeString.ToInteger(&errorCode);
-  if (NS_SUCCEEDED(errorCode) && temp > 0) {
-    aSpecHeight = std::max(temp, 100);
+
+  if (auto height = ReadIntAttribute(*windowElement, nsGkAtoms::height)) {
+    int32_t min =
+      ReadIntAttribute(*windowElement, nsGkAtoms::minheight)
+        .valueOr(100);
+    int32_t max =
+      ReadIntAttribute(*windowElement, nsGkAtoms::maxheight)
+        .valueOr(std::numeric_limits<int32_t>::max());
+
+    aSpecHeight = std::min(max, std::max(*height, min));
     gotSize = true;
   }
 
   return gotSize;
 }
 
 void
 nsXULWindow::SetSpecifiedSize(int32_t aSpecWidth, int32_t aSpecHeight)