Bug 1443864: Apply size constraints on nsXULWindow too. r?xidorn
MozReview-Commit-ID: BwL4sEDlVKl
--- 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)