From 9e99382cd2965439fa79b6165aec4405d6f30a03 Mon Sep 17 00:00:00 2001 From: "hyatt%netscape.com" Date: Tue, 18 May 1999 08:04:37 +0000 Subject: [PATCH] Taking advantage of Nisheeth and Rick's new method. Thanks guys! --- xpfe/appshell/src/nsWebShellWindow.cpp | 81 ++++++++++++++------------ 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 81b27b07abcd..4160c5ee4a35 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -21,6 +21,7 @@ #include "nsWebShellWindow.h" #include "nsLayoutCID.h" +#include "nsIDocumentLoader.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" @@ -98,6 +99,8 @@ static NS_DEFINE_IID(kContextMenuCID, NS_CONTEXTMENU_CID); static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_IID(kIDocumentLoaderFactoryIID, NS_IDOCUMENTLOADERFACTORY_IID); +static NS_DEFINE_CID(kLayoutDocumentLoaderFactoryCID, NS_LAYOUT_DOCUMENT_LOADER_FACTORY_CID); /* Define Interface IDs */ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -942,32 +945,33 @@ nsWebShellWindow::CreatePopup(nsIDOMElement* aElement, nsIDOMElement* aPopupCont nsresult rv = NS_OK; // Find out if we're a menu. - nsCOMPtr menuNodes; - if (NS_FAILED(rv = aPopupContent->GetElementsByTagName("menu", getter_AddRefs(menuNodes)))) { - NS_ERROR("Error occurred looking for nodes."); - return rv; - } - - // We got something. - PRUint32 length; - menuNodes->GetLength(&length); - if (length > 0) { - nsCOMPtr menuItem; - menuNodes->Item(0, getter_AddRefs(menuItem)); - if (menuItem) { - - // XXX Need to distinguish between popup menus and context menus? - DoContextMenu( - nsnull, - menuItem, - mWindow, - aXPos, - aYPos); - - } + nsCOMPtr popupContent = do_QueryInterface(aPopupContent); + PRInt32 childCount; + popupContent->ChildCount(childCount); + if (childCount == 0) return NS_OK; + + nsCOMPtr rootContent; + if (NS_FAILED(popupContent->ChildAt(0, *getter_AddRefs(rootContent)))) + return NS_OK; // Doesn't matter. Don't report it. + + nsCOMPtr rootElement = do_QueryInterface(rootContent); + + nsString tagName; + if (NS_FAILED(rootElement->GetTagName(tagName))) + return NS_OK; // It's ok. Really. + + if (tagName == "menu") { + + // XXX Need to distinguish between popup menus and context menus? + DoContextMenu(nsnull, rootElement, mWindow, aXPos, aYPos); + + return NS_OK; // Yes yes. It's ok. } + if (tagName != "window") + return NS_OK; // I promise. It really is ok. Stop whining. + // Handle the arbitrary popup XUL case. // (1) Create a top-level chromeless window. The size of the window can be specified @@ -1008,7 +1012,6 @@ nsWebShellWindow::CreatePopup(nsIDOMElement* aElement, nsIDOMElement* aPopupCont if (parentDocument == nsnull) return NS_ERROR_FAILURE; - nsCOMPtr popupContent = do_QueryInterface(aPopupContent); nsCOMPtr popupDocument; if (NS_FAILED(rv = parentDocument->CreatePopupDocument(popupContent, getter_AddRefs(popupDocument)))) { NS_ERROR("Unable to create the child popup document."); @@ -1020,25 +1023,31 @@ nsWebShellWindow::CreatePopup(nsIDOMElement* aElement, nsIDOMElement* aPopupCont // about their documents // (4) Create a document viewer nsCOMPtr documentViewer; - - // (5) Set a UA stylesheet on the doc viewer - - // (6) Bind the document viewer to the new document we made in (3) - - // (7) QI the WebShell from (1) to an nsIContentViewerContainer and feed it to the document - // viewer + nsCOMPtr docFactory; + if (NS_FAILED(rv = nsComponentManager::CreateInstance(kLayoutDocumentLoaderFactoryCID, nsnull, + kIDocumentLoaderFactoryIID, + (void**)getter_AddRefs(docFactory)))) { + NS_ERROR("Unable to instantiate layout's doc loader factory."); + return rv; + } nsCOMPtr cvContainer = do_QueryInterface(newShell); + docFactory->CreateInstanceForDocument(cvContainer, + popupDocument, + "view", + getter_AddRefs(documentViewer)); + + // (5) Feed the webshell to the document viewer - // (8) Tell the content viewer container to embed the content viewer. + // (6) Tell the content viewer container to embed the content viewer. // (This step causes everything to be set up for an initial flow.) - // (9) Hook up a blur handler to the window that will cause it to close. + // (7) Hook up a blur handler to the window that will cause it to close. - // (10) Show the window, and give the window the focus. + // (8) Show the window, and give the window the focus. - // (11) Return the new popup object. + // (9) Return the new popup object. - // (12) Perform cleanup + // (10) Perform cleanup return rv; }