From f2abbd8476b43c61705025e1f20a6bed7c7b2425 Mon Sep 17 00:00:00 2001 From: "danm%netscape.com" Date: Mon, 16 Apr 2001 20:34:33 +0000 Subject: [PATCH] hooking up windowwatcher active window. bug 44809,76011 r=chak,hyatt,saari git-svn-id: svn://10.0.0.236/trunk@92424 18797224-902f-48f8-a5cc-f745e15eee43 --- .../browser/webBrowser/nsWebBrowser.cpp | 42 +++++++++++-------- .../browser/webBrowser/nsWebBrowser.h | 2 + .../embedding/tests/mfcembed/BrowserView.cpp | 1 + 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp index 6fe83914f96..5690ff3adc8 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.cpp @@ -72,6 +72,8 @@ nsWebBrowser::nsWebBrowser() : mDocShellTreeOwner(nsnull), { NS_INIT_REFCNT(); mInitInfo = new nsWebBrowserInitInfo(); + mWWatch = do_GetService("@mozilla.org/embedcomp/window-watcher;1"); + NS_ASSERTION(mWWatch, "failed to get WindowWatcher"); } nsWebBrowser::~nsWebBrowser() @@ -1541,35 +1543,39 @@ NS_IMETHODIMP nsWebBrowser::GetPrimaryContentWindow(nsIDOMWindowInternal **aDOMW /* void activate (); */ NS_IMETHODIMP nsWebBrowser::Activate(void) { - // Make sure we can get the to a valid nsIPresShell - // Without this check we assert when the embeddor calls - // us and the presShell is not yet created - // For ex, under MSFT Windows embeddors can trap - // the WM_ACTIVATE message in response to which - // can call nsIWebBrowser->Activate(). During the initial - // window creation the presShell will not be created when - // the call to the initial Activate() is made + nsCOMPtr domWindow; + GetContentDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { + // tell windowwatcher about the new active window + if (mWWatch) + mWWatch->SetActiveWindow(domWindow); + /* Activate the window itself. Do this only if the PresShell has + been created, since DOMWindow->Activate asserts otherwise. + (This method can be called during window creation before + the PresShell exists. For ex, Windows apps responding to + WM_ACTIVATE). */ NS_ENSURE_STATE(mDocShell); nsCOMPtr presShell; mDocShell->GetPresShell(getter_AddRefs(presShell)); - if(!presShell) - return NS_OK; - - nsCOMPtr domWindow; - GetContentDOMWindow(getter_AddRefs(domWindow)); - if (domWindow) { - nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); - if(privateDOMWindow) - privateDOMWindow->Activate(); + if(presShell) { + nsCOMPtr privateDOMWindow = do_QueryInterface(domWindow); + if(privateDOMWindow) + privateDOMWindow->Activate(); } + } - return NS_OK; + return NS_OK; } /* void deactivate (); */ NS_IMETHODIMP nsWebBrowser::Deactivate(void) { + /* At this time we don't clear mWWatch's ActiveWindow; we just allow + the presumed other newly active window to set it when it comes in. + This seems harmless and maybe safer, but we have no real evidence + either way just yet. */ + NS_ENSURE_STATE(mDocShell); nsCOMPtr presShell; mDocShell->GetPresShell(getter_AddRefs(presShell)); diff --git a/mozilla/embedding/browser/webBrowser/nsWebBrowser.h b/mozilla/embedding/browser/webBrowser/nsWebBrowser.h index a8b50ba4965..908667efe40 100644 --- a/mozilla/embedding/browser/webBrowser/nsWebBrowser.h +++ b/mozilla/embedding/browser/webBrowser/nsWebBrowser.h @@ -48,6 +48,7 @@ #include "nsIWebBrowserFocus.h" #include "nsIWebBrowserFind.h" #include "nsIWebBrowserPrint.h" +#include "nsIWindowWatcher.h" // for painting the background window #include "nsIDeviceContext.h" @@ -140,6 +141,7 @@ protected: nsCOMPtr mDocShellAsScrollable; nsCOMPtr mDocShellAsTextScroll; nsCOMPtr mInternalWidget; + nsCOMPtr mWWatch; nsWebBrowserInitInfo* mInitInfo; PRUint32 mContentType; nativeWindow mParentNativeWindow; diff --git a/mozilla/embedding/tests/mfcembed/BrowserView.cpp b/mozilla/embedding/tests/mfcembed/BrowserView.cpp index b30f997703d..6325bdc38ab 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserView.cpp +++ b/mozilla/embedding/tests/mfcembed/BrowserView.cpp @@ -980,6 +980,7 @@ void CBrowserView::Activate(UINT nState, CWnd* pWndOther, BOOL bMinimized) switch(nState) { case WA_ACTIVE: + case WA_CLICKACTIVE: focus->Activate(); break; case WA_INACTIVE: