From d72876c01147bd02cfac2e4f13133a246e9bbaf2 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Sat, 1 Apr 2000 22:13:46 +0000 Subject: [PATCH] adding events to constrain z-level git-svn-id: svn://10.0.0.236/trunk@64900 18797224-902f-48f8-a5cc-f745e15eee43 --- .../xpfe/appshell/src/nsWebShellWindow.cpp | 31 +++++-- mozilla/xpfe/appshell/src/nsWebShellWindow.h | 1 + mozilla/xpfe/appshell/src/nsXULWindow.cpp | 88 ++++++++++++++++++- mozilla/xpfe/appshell/src/nsXULWindow.h | 3 + 4 files changed, 113 insertions(+), 10 deletions(-) diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 5866ada4e21..56d5410da63 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -120,9 +120,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #define USE_NATIVE_MENUS #endif - -#include "nsIWindowMediator.h" - #include "nsIPopupSetFrame.h" /* Define Class IDs */ @@ -140,10 +137,6 @@ static NS_DEFINE_CID(kContextMenuCID, NS_CONTEXTMENU_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); - - -static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); - static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID); @@ -244,6 +237,8 @@ nsWebShellWindow::~nsWebShellWindow() NS_RELEASE(mWebShell); } + if (mWindow) + mWindow->SetClientData(0); mWindow = nsnull; // Force release here. PR_Lock(mSPTimerLock); @@ -273,6 +268,7 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, nsIAppShell* aShell, nsIURI* aUrl, PRBool aCreatedVisible, PRBool aLoadDefaultPage, + PRUint32 aZlevel, PRInt32 aInitialWidth, PRInt32 aInitialHeight, nsWidgetInitData& widgetInitData) { @@ -281,6 +277,7 @@ nsresult nsWebShellWindow::Initialize(nsIXULWindow* aParent, mShowAfterLoad = aCreatedVisible; mLoadDefaultPage = aLoadDefaultPage; + mZlevel = aZlevel; // XXX: need to get the default window size from prefs... // Doesn't come from prefs... will come from CSS/XUL/RDF @@ -474,13 +471,29 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) break; } + case NS_SETZLEVEL: { + void *data; + nsZLevelEvent *zEvent = (nsZLevelEvent *) aEvent; + + zEvent->widget->GetClientData(data); + if (data) { + nsWebShellWindow *win; + win = NS_REINTERPRET_CAST(nsWebShellWindow *, data); + zEvent->mAdjusted = win->ConstrainToZLevel(zEvent->mImmediate, + &zEvent->mPlacement, + zEvent->mReqBelow, &zEvent->mActualBelow); + } + break; + } + + case NS_MOUSE_ACTIVATE: case NS_ACTIVATE: { #ifdef DEBUG_saari printf("nsWebShellWindow::NS_ACTIVATE\n"); #endif break; } - + case NS_DEACTIVATE: { #ifdef DEBUG_saari printf("nsWebShellWindow::NS_DEACTIVATE\n"); @@ -562,7 +575,7 @@ nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent) } } - return nsEventStatus_eIgnore; + return result; } diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.h b/mozilla/xpfe/appshell/src/nsWebShellWindow.h index 9414ab0263f..bdc79a0604c 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.h +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.h @@ -111,6 +111,7 @@ public: // nsWebShellWindow methods... nsresult Initialize(nsIXULWindow * aParent, nsIAppShell* aShell, nsIURI* aUrl, PRBool aCreatedVisible, PRBool aLoadDefaultPage, + PRUint32 aZlevel, PRInt32 aInitialWidth, PRInt32 aInitialHeight, nsWidgetInitData& widgetInitData); nsIWidget* GetWidget(void) { return mWindow; } diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.cpp b/mozilla/xpfe/appshell/src/nsXULWindow.cpp index a6be57a8908..012e747ff72 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsXULWindow.cpp @@ -49,6 +49,7 @@ // XXX Get rid of this #pragma message("WARNING: XXX bad include, remove it.") #include "nsIWebShellWindow.h" +#include "nsWebShellWindow.h" // get rid of this one, too... // CIDs static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); @@ -64,7 +65,8 @@ static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); nsXULWindow::nsXULWindow() : mChromeTreeOwner(nsnull), mContentTreeOwner(nsnull), mPrimaryContentTreeOwner(nsnull), mContinueModalLoop(PR_FALSE), mChromeLoaded(PR_FALSE), - mShowAfterLoad(PR_FALSE), mIntrinsicallySized(PR_FALSE) + mShowAfterLoad(PR_FALSE), mIntrinsicallySized(PR_FALSE), + mZlevel(nsIXULWindow::normalZ) { NS_INIT_REFCNT(); @@ -121,6 +123,13 @@ NS_IMETHODIMP nsXULWindow::GetDocShell(nsIDocShell** aDocShell) return NS_OK; } +NS_IMETHODIMP nsXULWindow::GetZlevel(PRUint32 *outLevel) +{ + // report our known zlevel, or be on top if currently modal + *outLevel = mContinueModalLoop ? nsIXULWindow::highestZ : mZlevel; + return NS_OK; +} + NS_IMETHODIMP nsXULWindow::SetIntrinsicallySized(PRBool aIntrinsicallySized) { mIntrinsicallySized = aIntrinsicallySized; @@ -426,6 +435,7 @@ NS_IMETHODIMP nsXULWindow::Destroy() mChromeTreeOwner->XULWindow(nsnull); NS_RELEASE(mChromeTreeOwner); } + mWindow->SetClientData(0); // nsWebShellWindow hackery mWindow = nsnull; return NS_OK; @@ -1161,6 +1171,82 @@ void nsXULWindow::EnableParent(PRBool aEnable) parentWidget->Enable(aEnable); } +// Constrain the window to its proper z-level +PRBool nsXULWindow::ConstrainToZLevel( + PRBool aImmediate, + nsWindowZ *aPlacement, + nsIWidget *aReqBelow, + nsIWidget **aActualBelow) { + +#if 0 + /* Do we have a parent window? This means our z-order is already constrained, + since we're a dependent window. Our window list isn't hierarchical, + so we can't properly calculate placement for such a window. + Should we just abort? */ + nsCOMPtr parentWindow = do_QueryReferent(mParentWindow); + if (parentWindow) + return PR_FALSE; +#endif + + nsCOMPtr mediator(do_GetService(kWindowMediatorCID)); + if(!mediator) + return PR_FALSE; + + PRBool altered; + PRUint32 position, + newPosition; + nsIXULWindow *us = NS_STATIC_CAST(nsIXULWindow *, this); + + altered = PR_FALSE; + + // translate from nsIWindowMediator to nsGUIEvent constants + position = nsIWindowMediator::zLevelTop; + if (*aPlacement == nsWindowZBottom) + position = nsIWindowMediator::zLevelBottom; + else if (*aPlacement == nsWindowZRelative) + position = nsIWindowMediator::zLevelBelow; + + if (NS_SUCCEEDED(mediator->CalculateZPosition(us, position, aReqBelow, + &newPosition, aActualBelow, &altered))) { + if (altered) { + if (newPosition == nsIWindowMediator::zLevelTop) + *aPlacement = nsWindowZTop; + else if (newPosition == nsIWindowMediator::zLevelBottom) + *aPlacement = nsWindowZBottom; + else + *aPlacement = nsWindowZRelative; + + if (aImmediate) { + nsCOMPtr ourBase = do_QueryInterface(NS_STATIC_CAST(nsIXULWindow *,this)); + if (ourBase) { + nsCOMPtr ourWidget; + ourBase->GetMainWidget(getter_AddRefs(ourWidget)); + ourWidget->PlaceBehind(*aActualBelow); + } + } + } + + /* (CalculateZPosition can tell us to be below nothing, because it tries + not to change something it doesn't recognize. A request to verify + being below an unrecognized window, then, is treated as a request + to come to the top (below null) */ + nsCOMPtr windowAbove; + if (newPosition == nsIWindowMediator::zLevelBelow && *aActualBelow) { + void *data; + (*aActualBelow)->GetClientData(data); + if (data) { + nsWebShellWindow *win; + win = NS_REINTERPRET_CAST(nsWebShellWindow *, data); + windowAbove = do_QueryInterface(NS_STATIC_CAST(nsIWebShellWindow *,win)); + } + } + + mediator->SetZPosition(us, newPosition, windowAbove); + } + + return altered; +} + //***************************************************************************** // nsXULWindow: Accessors //***************************************************************************** diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.h b/mozilla/xpfe/appshell/src/nsXULWindow.h index 43e3c27aba2..9baa2747c4c 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.h +++ b/mozilla/xpfe/appshell/src/nsXULWindow.h @@ -90,6 +90,8 @@ protected: protected: void EnableParent(PRBool aEnable); + PRBool ConstrainToZLevel(PRBool aImmediate, nsWindowZ *aPlacement, + nsIWidget *aReqBelow, nsIWidget **aActualBelow); nsChromeTreeOwner* mChromeTreeOwner; nsContentTreeOwner* mContentTreeOwner; @@ -104,6 +106,7 @@ protected: PRBool mChromeLoaded; // True when chrome has loaded PRBool mShowAfterLoad; PRBool mIntrinsicallySized; + unsigned long mZlevel; }; // nsContentShellInfo