From d1b47d9b276a4eadd26a215d4be63fcc8189de52 Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Tue, 21 Aug 2001 21:18:45 +0000 Subject: [PATCH] Bug 92210 - Window steals focus if you switch to another app during "Transferring data from...". r=saari, sr=hyatt. --- docshell/base/nsDocShell.cpp | 43 +++++++++++++++++++++++++++++++++ docshell/base/nsDocShell.h | 1 + docshell/base/nsIDocShell.idl | 8 +++++- dom/src/base/nsGlobalWindow.cpp | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 3ebdac453897..207674c9d2f2 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -961,6 +961,31 @@ nsresult nsDocShell::FindTarget(const PRUnichar *aWindowTarget, return NS_OK; } +NS_IMETHODIMP +nsDocShell::GetEldestPresContext(nsIPresContext** aPresContext) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(aPresContext); + *aPresContext = nsnull; + + nsCOMPtr viewer = mContentViewer; + while (viewer) { + nsCOMPtr prevViewer; + viewer->GetPreviousViewer(getter_AddRefs(prevViewer)); + if (prevViewer) + viewer = prevViewer; + else { + nsCOMPtr docv(do_QueryInterface(viewer)); + if (docv) + rv = docv->GetPresContext(*aPresContext); + break; + } + } + + return rv; +} + NS_IMETHODIMP nsDocShell::GetPresContext(nsIPresContext ** aPresContext) { @@ -999,6 +1024,24 @@ nsDocShell::GetPresShell(nsIPresShell ** aPresShell) return rv; } +NS_IMETHODIMP +nsDocShell::GetEldestPresShell(nsIPresShell** aPresShell) +{ + nsresult rv = NS_OK; + + NS_ENSURE_ARG_POINTER(aPresShell); + *aPresShell = nsnull; + + nsCOMPtr presContext; + (void) GetEldestPresContext(getter_AddRefs(presContext)); + + if (presContext) { + rv = presContext->GetShell(aPresShell); + } + + return rv; +} + NS_IMETHODIMP nsDocShell::GetContentViewer(nsIContentViewer ** aContentViewer) { diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index dfe8d96809b9..5d641ae7e925 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -210,6 +210,7 @@ protected: nsIStreamListener ** aContentHandler, nsIContentViewer ** aViewer); NS_IMETHOD SetupNewViewer(nsIContentViewer * aNewViewer); + NS_IMETHOD GetEldestPresContext(nsIPresContext** aPresContext); NS_IMETHOD CreateFixupURI(const PRUnichar * aStringURI, nsIURI ** aURI); NS_IMETHOD GetCurrentDocumentOwner(nsISupports ** aOwner); virtual nsresult DoURILoad(nsIURI * aURI, diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index e4c68f8dfa25..b2fb013cd767 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -144,10 +144,16 @@ interface nsIDocShell : nsISupports [noscript] readonly attribute nsIPresContext presContext; /** - * Presentation context for the currently loaded document. This may be null. + * Presentation shell for the currently loaded document. This may be null. */ [noscript] readonly attribute nsIPresShell presShell; + /** + * Presentation shell for the oldest document, if this docshell is + * currently transitioning between documents. + */ + [noscript] readonly attribute nsIPresShell eldestPresShell; + /** * Content Viewer that is currently loaded for this DocShell. This may * change as the underlying content changes. diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index e2514d28c215..fe0cdb3569d4 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -1747,7 +1747,7 @@ NS_IMETHODIMP GlobalWindowImpl::Focus() nsCOMPtr presShell; if (mDocShell) { - mDocShell->GetPresShell(getter_AddRefs(presShell)); + mDocShell->GetEldestPresShell(getter_AddRefs(presShell)); } nsresult result = NS_OK;