From 018434f4f06e12937eba7f659bb8ce511db1243b Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Wed, 23 Feb 2000 20:07:31 +0000 Subject: [PATCH] putting size and position persistence on a timer to ease chunky movement. r=scc a=jar --- xpfe/appshell/src/nsWebShellWindow.cpp | 42 ++++++++++++++++++++++++-- xpfe/appshell/src/nsWebShellWindow.h | 6 ++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index aba7b7f77d2..c4ab86d4f99 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -67,6 +67,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsIMenuItem.h" #include "nsIMenuListener.h" #include "nsIContextMenu.h" +#include "nsITimer.h" // For JS Execution #include "nsIScriptGlobalObjectOwner.h" @@ -75,6 +76,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsIEventQueueService.h" #include "plevent.h" #include "prmem.h" +#include "prlock.h" #include "nsIDOMXULDocument.h" #include "nsIDOMXULCommandDispatcher.h" @@ -150,6 +152,8 @@ static NS_DEFINE_CID( kCommonDialogsCID, NS_CommonDialog_CID ); static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID); #include "nsIWebShell.h" +#define SIZE_PERSISTENCE_TIMEOUT 500 // msec + const char * kPrimaryContentTypeValue = "content-primary"; struct ThreadedWindowEvent { @@ -222,6 +226,7 @@ nsWebShellWindow::nsWebShellWindow() : nsXULWindow() mIntrinsicallySized = PR_FALSE; mDebuting = PR_FALSE; mLoadDefaultPage = PR_TRUE; + mSPTimerLock = PR_NewLock(); } @@ -234,6 +239,13 @@ nsWebShellWindow::~nsWebShellWindow() } mWindow = nsnull; // Force release here. + + PR_Lock(mSPTimerLock); + if (mSPTimer) + mSPTimer->Cancel(); + PR_Unlock(mSPTimerLock); + PR_DestroyLock(mSPTimerLock); + NS_IF_RELEASE(mCallbacks); } @@ -427,7 +439,9 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) nsWebShellWindow *win; aEvent->widget->GetClientData(data); win = NS_REINTERPRET_CAST(nsWebShellWindow *, data); - win->StoreBoundsToXUL(PR_TRUE, PR_FALSE); + // persist position, but not immediately, in case this OS is firing + // repeated move events as the user drags the window + win->SetPersistenceTimer(); break; } case NS_SIZE: { @@ -439,7 +453,9 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) sizeEvent->windowSize->height, PR_FALSE); aEvent->widget->GetClientData(data); win = NS_REINTERPRET_CAST(nsWebShellWindow *, data); - win->StoreBoundsToXUL(PR_FALSE, PR_TRUE); + // persist size, but not immediately, in case this OS is firing + // repeated size events as the user drags the sizing handle + win->SetPersistenceTimer(); result = nsEventStatus_eConsumeNoDefault; break; } @@ -1228,6 +1244,28 @@ nsWebShellWindow::DestroyModalDialogEvent(PLEvent *aEvent) PR_Free(aEvent); } +void +nsWebShellWindow::SetPersistenceTimer(void) +{ + PR_Lock(mSPTimerLock); + if (mSPTimer) + mSPTimer->SetDelay(SIZE_PERSISTENCE_TIMEOUT); + else + if (NS_SUCCEEDED(NS_NewTimer(getter_AddRefs(mSPTimer)))) + mSPTimer->Init(FirePersistenceTimer, this, + SIZE_PERSISTENCE_TIMEOUT, NS_TYPE_ONE_SHOT); + PR_Unlock(mSPTimerLock); +} + +void +nsWebShellWindow::FirePersistenceTimer(nsITimer *aTimer, void *aClosure) +{ + nsWebShellWindow *win = NS_STATIC_CAST(nsWebShellWindow *, aClosure); + PR_Lock(win->mSPTimerLock); + win->mSPTimer = nsnull; + PR_Unlock(win->mSPTimerLock); + win->StoreBoundsToXUL(PR_TRUE, PR_TRUE); +} //---------------------------------------- diff --git a/xpfe/appshell/src/nsWebShellWindow.h b/xpfe/appshell/src/nsWebShellWindow.h index 9eafd5100a9..0f40fba0d63 100644 --- a/xpfe/appshell/src/nsWebShellWindow.h +++ b/xpfe/appshell/src/nsWebShellWindow.h @@ -32,6 +32,7 @@ #include "nsIDocumentObserver.h" #include "nsVoidArray.h" #include "nsIMenu.h" +#include "nsITimer.h" #include "nsIPrompt.h" #include "nsINetPrompt.h" @@ -263,6 +264,11 @@ protected: nsString mStatus; nsString mDefaultStatus; + nsCOMPtr mSPTimer; + PRLock * mSPTimerLock; + + void SetPersistenceTimer(void); + static void FirePersistenceTimer(nsITimer *aTimer, void *aClosure); private: