From a77ec655c21952b4187f132958d7a8fb2a94b5e0 Mon Sep 17 00:00:00 2001 From: Masatoshi Kimura Date: Tue, 20 May 2014 16:32:17 +0900 Subject: [PATCH] Bug 1005619 - Part 2: Use nsIWidget::GetRestoredBounds from appshell. r=neil --- xpfe/appshell/src/nsXULWindow.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/xpfe/appshell/src/nsXULWindow.cpp b/xpfe/appshell/src/nsXULWindow.cpp index d4d06d8ed22..80987eba455 100644 --- a/xpfe/appshell/src/nsXULWindow.cpp +++ b/xpfe/appshell/src/nsXULWindow.cpp @@ -1449,19 +1449,18 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes() } // get our size, position and mode to persist - int32_t x, y, cx, cy; - NS_ENSURE_SUCCESS(GetPositionAndSize(&x, &y, &cx, &cy), NS_ERROR_FAILURE); + nsIntRect rect; + bool gotRestoredBounds = NS_SUCCEEDED(mWindow->GetRestoredBounds(rect)); - int32_t sizeMode = mWindow->SizeMode(); CSSToLayoutDeviceScale scale = mWindow->GetDefaultScale(); // make our position relative to our parent, if any nsCOMPtr parent(do_QueryReferent(mParentWindow)); - if (parent) { + if (parent && gotRestoredBounds) { int32_t parentX, parentY; if (NS_SUCCEEDED(parent->GetPosition(&parentX, &parentY))) { - x -= parentX; - y -= parentY; + rect.x -= parentX; + rect.y -= parentY; } } @@ -1478,17 +1477,16 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes() ErrorResult rv; // (only for size elements which are persisted) - if ((mPersistentAttributesDirty & PAD_POSITION) && - sizeMode == nsSizeMode_Normal) { + if ((mPersistentAttributesDirty & PAD_POSITION) && gotRestoredBounds) { if (persistString.Find("screenX") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(x / scale.scale)); + PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.x / scale.scale)); sizeString.AssignWithConversion(sizeBuf); docShellElement->SetAttribute(SCREENX_ATTRIBUTE, sizeString, rv); if (ownerXULDoc) // force persistence in case the value didn't change ownerXULDoc->Persist(windowElementId, SCREENX_ATTRIBUTE); } if (persistString.Find("screenY") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(y / scale.scale)); + PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.y / scale.scale)); sizeString.AssignWithConversion(sizeBuf); docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv); if (ownerXULDoc) @@ -1496,17 +1494,16 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes() } } - if ((mPersistentAttributesDirty & PAD_SIZE) && - sizeMode == nsSizeMode_Normal) { + if ((mPersistentAttributesDirty & PAD_SIZE) && gotRestoredBounds) { if (persistString.Find("width") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(cx / scale.scale)); + PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.width / scale.scale)); sizeString.AssignWithConversion(sizeBuf); docShellElement->SetAttribute(WIDTH_ATTRIBUTE, sizeString, rv); if (ownerXULDoc) ownerXULDoc->Persist(windowElementId, WIDTH_ATTRIBUTE); } if (persistString.Find("height") >= 0) { - PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(cy / scale.scale)); + PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.height / scale.scale)); sizeString.AssignWithConversion(sizeBuf); docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv); if (ownerXULDoc) @@ -1515,6 +1512,8 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes() } if (mPersistentAttributesDirty & PAD_MISC) { + int32_t sizeMode = mWindow->SizeMode(); + if (sizeMode != nsSizeMode_Minimized) { if (sizeMode == nsSizeMode_Maximized) sizeString.Assign(SIZEMODE_MAXIMIZED);