From be513f584e1fbf651d5475245b2b740438671b59 Mon Sep 17 00:00:00 2001 From: "aaronl%netscape.com" Date: Thu, 15 Aug 2002 05:36:54 +0000 Subject: [PATCH] Not part of build. Bug 30088 - type ahead find. Simplify code to go from docshell -> dom window using nsIInterfaceRequestor git-svn-id: svn://10.0.0.236/trunk@127349 18797224-902f-48f8-a5cc-f745e15eee43 --- .../typeaheadfind/nsTypeAheadFind.cpp | 74 +++++++------------ 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp b/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp index 47a4b832b6b..7c72a7cb26a 100644 --- a/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp +++ b/mozilla/extensions/typeaheadfind/nsTypeAheadFind.cpp @@ -83,6 +83,7 @@ #include "nsPIDOMWindow.h" #include "nsIDOMKeyEvent.h" #include "nsIDocShellTreeItem.h" +#include "nsIWebNavigation.h" #include "nsIInterfaceRequestor.h" #include "nsIInterfaceRequestorUtils.h" #include "nsISound.h" @@ -372,30 +373,13 @@ NS_IMETHODIMP nsTypeAheadFind::Observe(nsISupports *aSubject, const char *aTopic // When a window closes, we have to remove it and all of it's subwindows // from mManualFindWindows so that we don't leak. // Eek, lots of work for such a simple thing. - nsCOMPtr domWin(do_QueryInterface(aSubject)); - if (!domWin) - return NS_OK; + nsCOMPtr ifreq(do_QueryInterface(aSubject)); + NS_ENSURE_TRUE(ifreq, NS_OK); - nsCOMPtr domDoc; - domWin->GetDocument(getter_AddRefs(domDoc)); - nsCOMPtr doc(do_QueryInterface(domDoc)); - if (!doc) - return NS_OK; - - nsCOMPtr presShell; - doc->GetShellAt(0, getter_AddRefs(presShell)); - if (!presShell) - return NS_OK; - - nsCOMPtr presContext; - presShell->GetPresContext(getter_AddRefs(presContext)); - if (!presContext) - return NS_OK; - - // Don't listen for events on chrome windows - nsCOMPtr pcContainer; - presContext->GetContainer(getter_AddRefs(pcContainer)); - nsCOMPtr docShell(do_QueryInterface(pcContainer)); + nsCOMPtr webNav; + ifreq->GetInterface(NS_GET_IID(nsIWebNavigation), getter_AddRefs(webNav)); + nsCOMPtr docShell(do_QueryInterface(webNav)); + NS_ENSURE_TRUE(docShell, NS_OK); nsCOMPtr docShellEnumerator; docShell->GetDocShellEnumerator(nsIDocShellTreeItem::typeAll, @@ -407,12 +391,14 @@ NS_IMETHODIMP nsTypeAheadFind::Observe(nsISupports *aSubject, const char *aTopic PRBool hasMoreDocShells; while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMoreDocShells)) && hasMoreDocShells) { - docShellEnumerator->GetNext(getter_AddRefs(pcContainer)); - nsCOMPtr ifreq(do_QueryInterface(pcContainer)); + nsCOMPtr container; + docShellEnumerator->GetNext(getter_AddRefs(container)); + nsCOMPtr ifreq(do_QueryInterface(container)); if (ifreq) { + nsCOMPtr domWin; ifreq->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWin)); - if (domWin) { - nsCOMPtr windowSupports(do_QueryInterface(domWin)); + nsCOMPtr windowSupports(do_QueryInterface(domWin)); + if (windowSupports) { PRInt32 index = mManualFindWindows->IndexOf(windowSupports); if (index >= 0) mManualFindWindows->RemoveElementAt(index); @@ -1218,29 +1204,15 @@ NS_IMETHODIMP nsTypeAheadFind::GetAutoStart(nsIDOMWindow *aDOMWin, { *aIsAutoStartOn = PR_FALSE; - if (!aDOMWin) - return NS_OK; - - nsCOMPtr domDoc; - aDOMWin->GetDocument(getter_AddRefs(domDoc)); - nsCOMPtr doc(do_QueryInterface(domDoc)); - if (!doc) - return NS_OK; - - nsCOMPtr presShell; - doc->GetShellAt(0, getter_AddRefs(presShell)); - if (!presShell) - return NS_OK; - - nsCOMPtr presContext; - presShell->GetPresContext(getter_AddRefs(presContext)); - if (!presContext) - return NS_OK; + nsCOMPtr ifreq(do_QueryInterface(aDOMWin)); + NS_ENSURE_TRUE(ifreq, NS_OK); + nsCOMPtr webNav; + ifreq->GetInterface(NS_GET_IID(nsIWebNavigation), getter_AddRefs(webNav)); + nsCOMPtr treeItem(do_QueryInterface(webNav)); + NS_ENSURE_TRUE(treeItem, NS_OK); + // Don't listen for events on chrome windows - nsCOMPtr pcContainer; - presContext->GetContainer(getter_AddRefs(pcContainer)); - nsCOMPtr treeItem(do_QueryInterface(pcContainer)); PRInt32 itemType = nsIDocShellTreeItem::typeChrome; if (treeItem) treeItem->GetItemType(&itemType); @@ -1263,6 +1235,12 @@ NS_IMETHODIMP nsTypeAheadFind::GetAutoStart(nsIDOMWindow *aDOMWin, // do our check from here rather than create a new interface or attribute on // the browser element. // XXX We'll use autotypeaheadfind="false" in future trunk builds + + nsCOMPtr domDoc; + aDOMWin->GetDocument(getter_AddRefs(domDoc)); + nsCOMPtr doc(do_QueryInterface(domDoc)); + NS_ENSURE_TRUE(doc, NS_OK); + nsCOMPtr parentDoc; doc->GetParentDocument(getter_AddRefs(parentDoc)); if (parentDoc) {