Backed out 2 changesets (bug 1137009)

Backed out changeset 2c77e4edc2a5 (bug 1137009)
Backed out changeset 7a5322e5fa07 (bug 1137009)
This commit is contained in:
Wes Kocher 2015-10-13 18:33:51 -07:00
parent c335f06a80
commit a195766b70
4 changed files with 87 additions and 73 deletions

View File

@ -916,23 +916,6 @@ XULDocument::AttributeWillChange(nsIDocument* aDocument,
}
}
static bool
ShouldPersistAttribute(nsIDocument* aDocument, Element* aElement)
{
if (aElement->IsXULElement(nsGkAtoms::window)) {
if (nsCOMPtr<nsPIDOMWindow> window = aDocument->GetWindow()) {
bool isFullscreen;
window->GetFullScreen(&isFullscreen);
if (isFullscreen) {
// Don't persist attributes if it is window element and
// we are in fullscreen state.
return false;
}
}
}
return true;
}
void
XULDocument::AttributeChanged(nsIDocument* aDocument,
Element* aElement, int32_t aNameSpaceID,
@ -1007,19 +990,18 @@ XULDocument::AttributeChanged(nsIDocument* aDocument,
bool listener, resolved;
CheckBroadcasterHookup(aElement, &listener, &resolved);
if (ShouldPersistAttribute(aDocument, aElement)) {
// See if there is anything we need to persist in the localstore.
//
// XXX Namespace handling broken :-(
nsString persist;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist);
if (!persist.IsEmpty() &&
// XXXldb This should check that it's a token, not just a substring.
persist.Find(nsDependentAtomString(aAttribute)) >= 0) {
// See if there is anything we need to persist in the localstore.
//
// XXX Namespace handling broken :-(
nsAutoString persist;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::persist, persist);
if (!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));
<nsIContent*, int32_t, nsIAtom*>
(this, &XULDocument::DoPersist, aElement, kNameSpaceID_None,
aAttribute));
}
}
}

View File

@ -419,8 +419,8 @@ nsWebShellWindow::WindowActivated()
fm->WindowRaised(window);
if (mChromeLoaded) {
SetAttributesDirty(PAD_POSITION | PAD_SIZE | PAD_MISC);
SaveAttributes();
PersistentAttributesDirty(PAD_POSITION | PAD_SIZE | PAD_MISC);
SavePersistentAttributes();
}
}
@ -512,14 +512,14 @@ nsWebShellWindow::SetPersistenceTimer(uint32_t aDirtyFlags)
mSPTimer->InitWithCallback(callback, SIZE_PERSISTENCE_TIMEOUT,
nsITimer::TYPE_ONE_SHOT);
SetAttributesDirty(aDirtyFlags);
PersistentAttributesDirty(aDirtyFlags);
}
void
nsWebShellWindow::FirePersistenceTimer()
{
MutexAutoLock lock(mSPTimerLock);
SaveAttributes();
SavePersistentAttributes();
}
@ -772,7 +772,7 @@ NS_IMETHODIMP nsWebShellWindow::Destroy()
MutexAutoLock lock(mSPTimerLock);
if (mSPTimer) {
mSPTimer->Cancel();
SaveAttributes();
SavePersistentAttributes();
mSPTimer = nullptr;
}
}

View File

@ -222,8 +222,8 @@ NS_IMETHODIMP nsXULWindow::SetZLevel(uint32_t aLevel)
// do it
mediator->SetZLevel(this, aLevel);
SetAttributesDirty(PAD_MISC);
SaveAttributes();
PersistentAttributesDirty(PAD_MISC);
SavePersistentAttributes();
nsCOMPtr<nsIContentViewer> cv;
mDocShell->GetContentViewer(getter_AddRefs(cv));
@ -577,8 +577,8 @@ NS_IMETHODIMP nsXULWindow::SetPosition(int32_t aX, int32_t aY)
mIgnoreXULPosition = true;
return NS_OK;
}
SetAttributesDirty(PAD_POSITION);
SaveAttributes();
PersistentAttributesDirty(PAD_POSITION);
SavePersistentAttributes();
return NS_OK;
}
@ -609,8 +609,8 @@ NS_IMETHODIMP nsXULWindow::SetSize(int32_t aCX, int32_t aCY, bool aRepaint)
mIgnoreXULSizeMode = true;
return NS_OK;
}
SetAttributesDirty(PAD_SIZE);
SaveAttributes();
PersistentAttributesDirty(PAD_SIZE);
SavePersistentAttributes();
return NS_OK;
}
@ -643,8 +643,8 @@ NS_IMETHODIMP nsXULWindow::SetPositionAndSize(int32_t aX, int32_t aY,
mIgnoreXULSizeMode = true;
return NS_OK;
}
SetAttributesDirty(PAD_POSITION | PAD_SIZE);
SaveAttributes();
PersistentAttributesDirty(PAD_POSITION | PAD_SIZE);
SavePersistentAttributes();
return NS_OK;
}
@ -1460,17 +1460,22 @@ void nsXULWindow::SyncAttributesToWidget()
}
}
void nsXULWindow::SaveAttributes()
NS_IMETHODIMP nsXULWindow::SavePersistentAttributes()
{
// can happen when the persistence timer fires at an inopportune time
// during window shutdown
if (!mDocShell) {
return;
}
if (!mDocShell)
return NS_ERROR_FAILURE;
nsCOMPtr<dom::Element> docShellElement = GetWindowDOMElement();
if (!docShellElement) {
return;
if (!docShellElement)
return NS_ERROR_FAILURE;
nsAutoString persistString;
docShellElement->GetAttribute(PERSIST_ATTRIBUTE, persistString);
if (persistString.IsEmpty()) { // quick check which sometimes helps
mPersistentAttributesDirty = 0;
return NS_OK;
}
// get our size, position and mode to persist
@ -1491,27 +1496,49 @@ void nsXULWindow::SaveAttributes()
char sizeBuf[10];
nsAutoString sizeString;
nsAutoString windowElementId;
nsCOMPtr<nsIDOMXULDocument> ownerXULDoc;
// fetch docShellElement's ID and XUL owner document
ownerXULDoc = do_QueryInterface(docShellElement->OwnerDoc());
if (docShellElement->IsXULElement()) {
docShellElement->GetId(windowElementId);
}
ErrorResult rv;
// (only for size elements which are persisted)
if ((mPersistentAttributesDirty & PAD_POSITION) && gotRestoredBounds) {
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.x / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(SCREENX_ATTRIBUTE, sizeString, rv);
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.y / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv);
if (persistString.Find("screenX") >= 0) {
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(rect.y / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(SCREENY_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc)
ownerXULDoc->Persist(windowElementId, SCREENY_ATTRIBUTE);
}
}
if ((mPersistentAttributesDirty & PAD_SIZE) && gotRestoredBounds) {
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.width / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(WIDTH_ATTRIBUTE, sizeString, rv);
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%d", NSToIntRound(rect.height / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv);
if (persistString.Find("width") >= 0) {
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(rect.height / scale.scale));
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(HEIGHT_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc)
ownerXULDoc->Persist(windowElementId, HEIGHT_ATTRIBUTE);
}
}
if (mPersistentAttributesDirty & PAD_MISC) {
@ -1525,19 +1552,24 @@ void nsXULWindow::SaveAttributes()
else
sizeString.Assign(SIZEMODE_NORMAL);
docShellElement->SetAttribute(MODE_ATTRIBUTE, sizeString, rv);
if (ownerXULDoc && persistString.Find("sizemode") >= 0)
ownerXULDoc->Persist(windowElementId, MODE_ATTRIBUTE);
}
uint32_t zLevel;
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
if (mediator) {
mediator->GetZLevel(this, &zLevel);
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%lu", (unsigned long)zLevel);
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(ZLEVEL_ATTRIBUTE, sizeString, rv);
if (persistString.Find("zlevel") >= 0) {
uint32_t zLevel;
nsCOMPtr<nsIWindowMediator> mediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
if (mediator) {
mediator->GetZLevel(this, &zLevel);
PR_snprintf(sizeBuf, sizeof(sizeBuf), "%lu", (unsigned long)zLevel);
sizeString.AssignWithConversion(sizeBuf);
docShellElement->SetAttribute(ZLEVEL_ATTRIBUTE, sizeString, rv);
ownerXULDoc->Persist(windowElementId, ZLEVEL_ATTRIBUTE);
}
}
}
mPersistentAttributesDirty = 0;
return NS_OK;
}
NS_IMETHODIMP nsXULWindow::GetWindowDOMWindow(nsIDOMWindow** aDOMWindow)
@ -2008,7 +2040,7 @@ bool nsXULWindow::GetContentScrollbarVisibility()
}
// during spinup, attributes that haven't been loaded yet can't be dirty
void nsXULWindow::SetAttributesDirty(uint32_t aDirtyFlags)
void nsXULWindow::PersistentAttributesDirty(uint32_t aDirtyFlags)
{
mPersistentAttributesDirty |= aDirtyFlags & mPersistentAttributesMask;
}

View File

@ -96,7 +96,7 @@ protected:
bool LoadSizeFromXUL();
bool LoadMiscPersistentAttributesFromXUL();
void SyncAttributesToWidget();
void SaveAttributes();
NS_IMETHOD SavePersistentAttributes();
NS_IMETHOD GetWindowDOMWindow(nsIDOMWindow** aDOMWindow);
mozilla::dom::Element* GetWindowDOMElement() const;
@ -119,7 +119,7 @@ protected:
nsIXULWindow *aBehind);
void SetContentScrollbarVisibility(bool aVisible);
bool GetContentScrollbarVisibility();
void SetAttributesDirty(uint32_t aDirtyFlags);
void PersistentAttributesDirty(uint32_t aDirtyFlags);
nsChromeTreeOwner* mChromeTreeOwner;
nsContentTreeOwner* mContentTreeOwner;