Bug 1137009 - Do not persist xul window attributes when in fullscreen. r=enndeakin

--HG--
extra : rebase_source : 38400b63c4f9d6be3f2ff9ba963546f72f77a65f
extra : source : 78f7f5498016232d889579add8f9ec7d0f4a86e6
This commit is contained in:
Xidorn Quan 2015-10-22 11:08:35 +11:00
parent 8375973fa2
commit 19f7f9e9e4
2 changed files with 43 additions and 13 deletions

View File

@ -916,6 +916,23 @@ XULDocument::AttributeWillChange(nsIDocument* aDocument,
}
}
static bool
ShouldPersistAttribute(Element* aElement, nsIAtom* aAttribute)
{
if (aElement->IsXULElement(nsGkAtoms::window)) {
// The following attributes of xul:window should be handled in
// nsXULWindow::SavePersistentAttributes instead of here.
if (aAttribute == nsGkAtoms::screenX ||
aAttribute == nsGkAtoms::screenY ||
aAttribute == nsGkAtoms::width ||
aAttribute == nsGkAtoms::height ||
aAttribute == nsGkAtoms::sizemode) {
return false;
}
}
return true;
}
void
XULDocument::AttributeChanged(nsIDocument* aDocument,
Element* aElement, int32_t aNameSpaceID,
@ -995,14 +1012,14 @@ XULDocument::AttributeChanged(nsIDocument* aDocument,
// XXX Namespace handling broken :-(
nsAutoString persist;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist);
if (!persist.IsEmpty()) {
// Persistence of attributes of xul:window is handled in nsXULWindow.
if (ShouldPersistAttribute(aElement, aAttribute) && !persist.IsEmpty() &&
// XXXldb This should check that it's a token, not just a substring.
if (persist.Find(nsDependentAtomString(aAttribute)) >= 0) {
nsContentUtils::AddScriptRunner(NS_NewRunnableMethodWithArgs
<nsIContent*, int32_t, nsIAtom*>
(this, &XULDocument::DoPersist, aElement, kNameSpaceID_None,
aAttribute));
}
persist.Find(nsDependentAtomString(aAttribute)) >= 0) {
nsContentUtils::AddScriptRunner(NS_NewRunnableMethodWithArgs
<nsIContent*, int32_t, nsIAtom*>
(this, &XULDocument::DoPersist, aElement, kNameSpaceID_None,
aAttribute));
}
}

View File

@ -1478,6 +1478,11 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
return NS_OK;
}
bool isFullscreen = false;
if (nsPIDOMWindow* domWindow = mDocShell->GetWindow()) {
domWindow->GetFullScreen(&isFullscreen);
}
// get our size, position and mode to persist
nsIntRect rect;
bool gotRestoredBounds = NS_SUCCEEDED(mWindow->GetRestoredBounds(rect));
@ -1505,6 +1510,7 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
docShellElement->GetId(windowElementId);
}
bool shouldPersist = !isFullscreen && ownerXULDoc;
ErrorResult rv;
// (only for size elements which are persisted)
if ((mPersistentAttributesDirty & PAD_POSITION) && gotRestoredBounds) {
@ -1512,15 +1518,17 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
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
if (shouldPersist) {
ownerXULDoc->Persist(windowElementId, SCREENX_ATTRIBUTE);
}
}
if (persistString.Find("screenY") >= 0) {
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.y / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc)
if (shouldPersist) {
ownerXULDoc->Persist(windowElementId, SCREENY_ATTRIBUTE);
}
}
}
@ -1529,15 +1537,17 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.width / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(WIDTH_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc)
if (shouldPersist) {
ownerXULDoc->Persist(windowElementId, WIDTH_ATTRIBUTE);
}
}
if (persistString.Find("height") >= 0) {
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.height / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc)
if (shouldPersist) {
ownerXULDoc->Persist(windowElementId, HEIGHT_ATTRIBUTE);
}
}
}
@ -1552,8 +1562,9 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
else
sizeString.Assign(SIZEMODE_NORMAL);
docShellElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc && persistString.Find("sizemode") >= 0)
if (shouldPersist && persistString.Find("sizemode") >= 0) {
ownerXULDoc->Persist(windowElementId, MODE_ATTRIBUTE);
}
}
if (persistString.Find("zlevel") >= 0) {
uint32_t zLevel;
@ -1563,7 +1574,9 @@ NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%lu", (unsigned long)zLevel);
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(ZLEVEL_ATTRIBUTE, sizeString, rv);
ownerXULDoc->Persist(windowElementId, ZLEVEL_ATTRIBUTE);
if (shouldPersist) {
ownerXULDoc->Persist(windowElementId, ZLEVEL_ATTRIBUTE);
}
}
}
}