Bug 1005619 - Part 2: Use nsIWidget::GetRestoredBounds from appshell. r=neil

This commit is contained in:
Masatoshi Kimura 2014-05-20 16:32:17 +09:00
parent 2c87e8ea8f
commit a77ec655c2

View File

@ -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<nsIBaseWindow> 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);