diff --git a/mozilla/xpfe/appshell/public/nsIXULWindow.idl b/mozilla/xpfe/appshell/public/nsIXULWindow.idl index c7049094293..07e14a125a2 100644 --- a/mozilla/xpfe/appshell/public/nsIXULWindow.idl +++ b/mozilla/xpfe/appshell/public/nsIXULWindow.idl @@ -63,16 +63,18 @@ interface nsIXULWindow : nsISupports nsIDocShellTreeItem getContentShellById(in wstring ID); /* - Sets the persistence of different dimentions of the window. + Sets the persistence of different dimensions of the window. */ void setPersistence(in boolean persistX, in boolean persistY, - in boolean persistCX, in boolean persistCY); + in boolean persistCX, in boolean persistCY, + in boolean persistSizeMode); /* Gets the current persistence states of the window. */ void getPersistence(out boolean persistX, out boolean persistY, - out boolean persistCX, out boolean persistCY); + out boolean persistCX, out boolean persistCY, + out boolean persistSizeMode); /* Shows the window as a modal window diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 855a6426da4..364901066f6 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -432,6 +432,22 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) result = nsEventStatus_eConsumeNoDefault; break; } + case NS_SIZEMODE: { + void* data; + nsWebShellWindow *win; + nsSizeModeEvent* modeEvent = (nsSizeModeEvent*)aEvent; + aEvent->widget->SetSizeMode(modeEvent->mSizeMode); + aEvent->widget->GetClientData(data); + win = NS_REINTERPRET_CAST(nsWebShellWindow *, data); + win->StoreBoundsToXUL(PR_FALSE, PR_FALSE, PR_TRUE); + result = nsEventStatus_eConsumeDoDefault; + // Note the current implementation of SetSizeMode just stores + // the new state; it doesn't actually resize. So here we store + // the state and pass the event on to the OS. The day is coming + // when we'll handle the event here, and the return result will + // then need to be different. + break; + } case NS_XUL_CLOSE: { void* data; nsWebShellWindow *win; @@ -1209,7 +1225,7 @@ nsWebShellWindow::FirePersistenceTimer(nsITimer *aTimer, void *aClosure) PR_Lock(win->mSPTimerLock); win->mSPTimer = nsnull; PR_Unlock(win->mSPTimerLock); - win->StoreBoundsToXUL(win->mSPTimerPosition, win->mSPTimerSize); + win->StoreBoundsToXUL(win->mSPTimerPosition, win->mSPTimerSize, PR_FALSE); } @@ -1434,9 +1450,9 @@ void nsWebShellWindow::ExecuteStartupCode() } /* copy the window's size and position to the window tag */ -void nsWebShellWindow::StoreBoundsToXUL(PRBool aPosition, PRBool aSize) +void nsWebShellWindow::StoreBoundsToXUL(PRBool aPosition, PRBool aSize, PRBool aSizeMode) { - PersistPositionAndSize(aPosition, aSize); + PersistPositionAndSize(aPosition, aSize, aSizeMode); } // StoreBoundsToXUL @@ -1444,8 +1460,8 @@ void nsWebShellWindow::KillPersistentSize() { PRBool persistX, persistY; - GetPersistence(&persistX, &persistY, nsnull, nsnull); - SetPersistence(persistX, persistY, PR_FALSE, PR_FALSE); + GetPersistence(&persistX, &persistY, nsnull, nsnull, nsnull); + SetPersistence(persistX, persistY, PR_FALSE, PR_FALSE, PR_FALSE); } @@ -1774,7 +1790,7 @@ NS_IMETHODIMP nsWebShellWindow::Init(nsIAppShell* aAppShell, NS_IMETHODIMP nsWebShellWindow::MoveTo(PRInt32 aX, PRInt32 aY) { mWindow->Move(aX, aY); - StoreBoundsToXUL(PR_TRUE, PR_FALSE); + StoreBoundsToXUL(PR_TRUE, PR_FALSE, PR_FALSE); return NS_OK; } @@ -1785,7 +1801,7 @@ NS_IMETHODIMP nsWebShellWindow::SizeWindowTo(PRInt32 aWidth, PRInt32 aHeight, if (aWidthTransient || aHeightTransient) KillPersistentSize(); mWindow->Resize(aWidth, aHeight, PR_TRUE); - StoreBoundsToXUL(PR_FALSE, PR_TRUE); + StoreBoundsToXUL(PR_FALSE, PR_TRUE, PR_FALSE); return NS_OK; } @@ -1810,7 +1826,7 @@ NS_IMETHODIMP nsWebShellWindow::SizeContentTo(PRInt32 aWidth, PRInt32 aHeight) mWindow->Resize(windowBounds.width + widthDelta, windowBounds.height + heightDelta, PR_TRUE); - StoreBoundsToXUL(PR_FALSE, PR_TRUE); + StoreBoundsToXUL(PR_FALSE, PR_TRUE, PR_FALSE); } } return NS_OK; diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.h b/mozilla/xpfe/appshell/src/nsWebShellWindow.h index 42a8e68f689..da9d38fcc51 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.h +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.h @@ -233,7 +233,7 @@ protected: nsCOMPtr GetDOMNodeFromWebShell(nsIWebShell *aShell); void ExecuteStartupCode(); - void StoreBoundsToXUL(PRBool aPosition, PRBool aSize); + void StoreBoundsToXUL(PRBool aPosition, PRBool aSize, PRBool aSizeMode); void KillPersistentSize(); void LoadContentAreas(); PRBool ExecuteCloseHandler(); diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.cpp b/mozilla/xpfe/appshell/src/nsXULWindow.cpp index 9a49d8eac30..53156be224a 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsXULWindow.cpp @@ -177,7 +177,8 @@ NS_IMETHODIMP nsXULWindow::GetContentShellById(const PRUnichar* aID, } NS_IMETHODIMP nsXULWindow::SetPersistence(PRBool aPersistX, PRBool aPersistY, - PRBool aPersistCX, PRBool aPersistCY) + PRBool aPersistCX, PRBool aPersistCY, + PRBool aPersistSizeMode) { nsCOMPtr docShellElement; @@ -240,6 +241,15 @@ NS_IMETHODIMP nsXULWindow::SetPersistence(PRBool aPersistX, PRBool aPersistY, saveString = PR_TRUE; } + index = persistString.Find("sizemode"); + if (!aPersistSizeMode && index >= 0) { + persistString.Append(" sizemode"); + saveString = PR_TRUE; + } else if (aPersistSizeMode && index < 0) { + persistString.Cut(index, 8); + saveString = PR_TRUE; + } + if(saveString) docShellElement->SetAttribute("persist", persistString); @@ -247,7 +257,8 @@ NS_IMETHODIMP nsXULWindow::SetPersistence(PRBool aPersistX, PRBool aPersistY, } NS_IMETHODIMP nsXULWindow::GetPersistence(PRBool* aPersistX, PRBool* aPersistY, - PRBool* aPersistCX, PRBool* aPersistCY) + PRBool* aPersistCX, PRBool* aPersistCY, + PRBool* aPersistSizeMode) { nsCOMPtr docShellElement; GetDOMElementFromDocShell(mDocShell, getter_AddRefs(docShellElement)); @@ -265,6 +276,8 @@ NS_IMETHODIMP nsXULWindow::GetPersistence(PRBool* aPersistX, PRBool* aPersistY, *aPersistCX = persistString.Find("width") >= 0 ? PR_TRUE : PR_FALSE; if(aPersistCY) *aPersistCY = persistString.Find("height") >= 0 ? PR_TRUE : PR_FALSE; + if(aPersistSizeMode) + *aPersistSizeMode = persistString.Find("sizemode") >= 0 ? PR_TRUE : PR_FALSE; return NS_OK; } @@ -418,7 +431,7 @@ NS_IMETHODIMP nsXULWindow::Destroy() NS_IMETHODIMP nsXULWindow::SetPosition(PRInt32 aX, PRInt32 aY) { NS_ENSURE_SUCCESS(mWindow->Move(aX, aY), NS_ERROR_FAILURE); - PersistPositionAndSize(PR_TRUE, PR_FALSE); + PersistPositionAndSize(PR_TRUE, PR_FALSE, PR_FALSE); return NS_OK; } @@ -431,7 +444,7 @@ NS_IMETHODIMP nsXULWindow::SetSize(PRInt32 aCX, PRInt32 aCY, PRBool aRepaint) { mIntrinsicallySized = PR_FALSE; NS_ENSURE_SUCCESS(mWindow->Resize(aCX, aCY, aRepaint), NS_ERROR_FAILURE); - PersistPositionAndSize(PR_FALSE, PR_TRUE); + PersistPositionAndSize(PR_FALSE, PR_TRUE, PR_FALSE); return NS_OK; } @@ -445,7 +458,7 @@ NS_IMETHODIMP nsXULWindow::SetPositionAndSize(PRInt32 aX, PRInt32 aY, { mIntrinsicallySized = PR_FALSE; NS_ENSURE_SUCCESS(mWindow->Resize(aX, aY, aCX, aCY, aRepaint), NS_ERROR_FAILURE); - PersistPositionAndSize(PR_TRUE, PR_TRUE); + PersistPositionAndSize(PR_TRUE, PR_TRUE, PR_FALSE); return NS_OK; } @@ -677,6 +690,10 @@ void nsXULWindow::OnChromeLoaded() NS_IMETHODIMP nsXULWindow::LoadPositionAndSizeFromXUL(PRBool aPosition, PRBool aSize) { +/* NB: we'll want to pay attention to the "sizemode" attribute (maximizing + the window if it asks) someday after the widget implementations know how + to do that. +*/ nsCOMPtr docShellElement; GetDOMElementFromDocShell(mDocShell, getter_AddRefs(docShellElement)); NS_ENSURE_TRUE(docShellElement, NS_ERROR_FAILURE); @@ -763,7 +780,7 @@ NS_IMETHODIMP nsXULWindow::LoadTitleFromXUL() return NS_OK; } -NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize) +NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize, PRBool aSizeMode) { // can happen when the persistence timer fires at an inopportune time // during window shutdown @@ -776,7 +793,10 @@ NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize return NS_ERROR_FAILURE; PRInt32 x, y, cx, cy; + PRInt32 sizeMode; + NS_ENSURE_SUCCESS(GetPositionAndSize(&x, &y, &cx, &cy), NS_ERROR_FAILURE); + mWindow->GetSizeMode(&sizeMode); // (But only for size elements which are persisted.) /* Note we use the same cheesy way to determine that as in @@ -790,7 +810,7 @@ NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize char sizeBuf[10]; nsAutoString sizeString; - if(aPosition) + if(aPosition && sizeMode == nsSizeMode_Normal) { if(persistString.Find("screenX") >= 0) { @@ -806,7 +826,7 @@ NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize } } - if(aSize) + if(aSize && sizeMode == nsSizeMode_Normal) { if(persistString.Find("width") >= 0) { @@ -822,6 +842,18 @@ NS_IMETHODIMP nsXULWindow::PersistPositionAndSize(PRBool aPosition, PRBool aSize } } + if (aSizeMode && persistString.Find("sizemode") >= 0) { + PRInt32 sizemode; + if (NS_FAILED(mWindow->GetSizeMode(&sizemode))) + sizemode = nsSizeMode_Normal; + sizeString = "n"; + if (sizemode == nsSizeMode_Minimized) + sizeString = "m"; + else if (sizemode == nsSizeMode_Maximized) + sizeString = "M"; + docShellElement->SetAttribute("sizemode", sizeString); + } + return NS_OK; } @@ -910,7 +942,7 @@ NS_IMETHODIMP nsXULWindow::SizeShellTo(nsIDocShellTreeItem* aShellItem, GetSize(&winCX, &winCY); SetSize(winCX + widthDelta, winCY + heightDelta, PR_TRUE); - PersistPositionAndSize(PR_FALSE, PR_TRUE); + PersistPositionAndSize(PR_FALSE, PR_TRUE, PR_FALSE); } return NS_OK; diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.h b/mozilla/xpfe/appshell/src/nsXULWindow.h index df346bfc783..d91d864c16f 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.h +++ b/mozilla/xpfe/appshell/src/nsXULWindow.h @@ -69,7 +69,7 @@ protected: void OnChromeLoaded(); NS_IMETHOD LoadPositionAndSizeFromXUL(PRBool aPosition, PRBool aSize); NS_IMETHOD LoadTitleFromXUL(); - NS_IMETHOD PersistPositionAndSize(PRBool aPosition, PRBool aSize); + NS_IMETHOD PersistPositionAndSize(PRBool aPosition, PRBool aSize, PRBool aSizeMode); NS_IMETHOD GetDOMElementFromDocShell(nsIDocShell* aDocShell, nsIDOMElement** aDOMElement);