From 7d83f1db2c86cad577029266ad58d7ca45d9035b Mon Sep 17 00:00:00 2001 From: "tbogard%aol.net" Date: Wed, 15 Mar 2000 04:32:16 +0000 Subject: [PATCH] Implemented FindItemWithName and ContentShellAdded. Changed FindNamedBrowserChrome to deal with nsIWebBrowser instead of nsIWebBrowserChrome and changed the name to FindNamedBrowser. Changed FindNamedBrowser and GetNamedBrowser to return the type instead of having it as an out parameter. This is cleaner for JS. --- .../webBrowser/nsDocShellTreeOwner.cpp | 85 ++++++++----------- .../webBrowser/nsIWebBrowserChrome.idl | 4 +- 2 files changed, 38 insertions(+), 51 deletions(-) diff --git a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp index 80b62618045..3c7493428c9 100644 --- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp +++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp @@ -30,6 +30,8 @@ #include "nsHTMLReflowState.h" // Interfaces needed to be included +#include "nsIDOMDocument.h" +#include "nsIDOMElement.h" #include "nsIPresShell.h" // CIDs @@ -88,69 +90,42 @@ NS_IMETHODIMP nsDocShellTreeOwner::FindItemWithName(const PRUnichar* aName, nsIDocShellTreeItem* aRequestor, nsIDocShellTreeItem** aFoundItem) { NS_ENSURE_ARG_POINTER(aFoundItem); + *aFoundItem = nsnull; - return NS_ERROR_FAILURE; + nsAutoString name(aName); -//XXXTAB -/* *aFoundItem = nsnull; - - nsAutoString name(aName); - - PRBool fIs_Content = PR_FALSE; - - /* Special Cases */ /* + /* Special Cases */ if(name.Length() == 0) return NS_OK; if(name.EqualsIgnoreCase("_blank")) return NS_OK; if(name.EqualsIgnoreCase("_content")) { - fIs_Content = PR_TRUE; - mXULWindow->GetPrimaryContentShell(aFoundItem); - if(*aFoundItem) - return NS_OK; + *aFoundItem = mWebBrowser->mDocShellAsItem; + NS_IF_ADDREF(*aFoundItem); + return NS_OK; } - nsCOMPtr windowMediator(do_GetService(kWindowMediatorCID)); - NS_ENSURE_TRUE(windowMediator, NS_ERROR_FAILURE); + if(mTreeOwner) + return mTreeOwner->FindItemWithName(aName, aRequestor, aFoundItem); - nsCOMPtr windowEnumerator; - NS_ENSURE_SUCCESS(windowMediator->GetXULWindowEnumerator(nsnull, - getter_AddRefs(windowEnumerator)), NS_ERROR_FAILURE); - - PRBool more; - - windowEnumerator->HasMoreElements(&more); - while(more) - { - nsCOMPtr nextWindow = nsnull; - windowEnumerator->GetNext(getter_AddRefs(nextWindow)); - nsCOMPtr xulWindow(do_QueryInterface(nextWindow)); - NS_ENSURE_TRUE(xulWindow, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mWebBrowserChrome, NS_ERROR_FAILURE); - nsCOMPtr shellAsTreeItem; - xulWindow->GetPrimaryContentShell(getter_AddRefs(shellAsTreeItem)); + nsCOMPtr foundWebBrowser; + NS_ENSURE_SUCCESS(mWebBrowserChrome->FindNamedBrowser(aName, + getter_AddRefs(foundWebBrowser)), NS_ERROR_FAILURE); - if(shellAsTreeItem) - { - if(fIs_Content) - *aFoundItem = shellAsTreeItem; - else if(aRequestor != shellAsTreeItem.get()) - { - // Do this so we can pass in the tree owner as the requestor so the child knows not - // to call back up. - nsCOMPtr shellOwner; - shellAsTreeItem->GetTreeOwner(getter_AddRefs(shellOwner)); - nsCOMPtr shellOwnerSupports(do_QueryInterface(shellOwner)); + if(!foundWebBrowser) + return NS_OK; - shellAsTreeItem->FindItemWithName(aName, shellOwnerSupports, aFoundItem); - } - if(*aFoundItem) - return NS_OK; - } - windowEnumerator->HasMoreElements(&more); - } - return NS_OK;*/ + nsCOMPtr foundDocShell; + foundWebBrowser->GetDocShell(getter_AddRefs(foundDocShell)); + + nsCOMPtr foundDocShellAsItem; + *aFoundItem = foundDocShellAsItem; + NS_IF_ADDREF(*aFoundItem); + + return NS_OK; } NS_IMETHODIMP nsDocShellTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell, @@ -183,6 +158,18 @@ NS_IMETHODIMP nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, if(aShellItem == mWebBrowser->mDocShellAsItem.get()) return mWebBrowserChrome->SizeBrowserTo(aCX, aCY); + nsCOMPtr webNav(do_QueryInterface(aShellItem)); + NS_ENSURE_TRUE(webNav, NS_ERROR_FAILURE); + + nsCOMPtr domDocument; + webNav->GetDocument(getter_AddRefs(domDocument)); + NS_ENSURE_TRUE(domDocument, NS_ERROR_FAILURE); + + nsCOMPtr domElement; + domDocument->GetDocumentElement(getter_AddRefs(domElement)); + NS_ENSURE_TRUE(domElement, NS_ERROR_FAILURE); + + // Set the preferred Size //XXX NS_ERROR("Implement this"); /* diff --git a/embedding/browser/webBrowser/nsIWebBrowserChrome.idl b/embedding/browser/webBrowser/nsIWebBrowserChrome.idl index a98b51e23e2..218108c9c70 100644 --- a/embedding/browser/webBrowser/nsIWebBrowserChrome.idl +++ b/embedding/browser/webBrowser/nsIWebBrowserChrome.idl @@ -95,9 +95,9 @@ interface nsIWebBrowserChrome : nsISupports setWebBrowser will be called with the new widget to instantiate in this new window. */ - void getNewBrowser(in unsigned long chromeMask, out nsIWebBrowser webBrowser); + nsIWebBrowser getNewBrowser(in unsigned long chromeMask); - void findNamedBrowserChrome(in wstring aName, out nsIWebBrowserChrome webBrowserChrome); + nsIWebBrowser findNamedBrowser(in wstring aName); /* Tells the chrome to size itself such that the browser will be the