diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index d9741ac60c5..f4712e92c24 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -33,7 +33,6 @@ #include "nsIWidgetController.h" #include "nsAppShellCIDs.h" -#include "nsIXULCommand.h" #include "nsXULCommand.h" #include "nsIDOMCharacterData.h" #include "nsIDOMNodeList.h" @@ -53,8 +52,10 @@ #include "nsIDOMNode.h" #include "nsIDOMElement.h" #include "nsIDocumentLoader.h" -#include "nsIDOMHTMLInputElement.h" -#include "nsIDOMHTMLImageElement.h" +//#include "nsIDOMHTMLInputElement.h" +//#include "nsIDOMHTMLImageElement.h" + +#include "nsIContent.h" // for menus // For calculating size #include "nsIFrame.h" @@ -70,7 +71,6 @@ static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_IID(kMenuBarCID, NS_MENUBAR_CID); static NS_DEFINE_IID(kMenuCID, NS_MENU_CID); static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID); -static NS_DEFINE_IID(kXULCommandCID, NS_XULCOMMAND_CID); /* Define Interface IDs */ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -85,16 +85,17 @@ static NS_DEFINE_IID(kIDocumentViewerIID, NS_IDOCUMENT_VIEWER_IID); static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID); static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID); -static NS_DEFINE_IID(kIXULCommandIID, NS_IXULCOMMAND_IID); static NS_DEFINE_IID(kIDOMCharacterDataIID, NS_IDOMCHARACTERDATA_IID); -static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); -static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID); +//static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); +//static NS_DEFINE_IID(kIDOMHTMLImageElementIID, NS_IDOMHTMLIMAGEELEMENT_IID); -static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); -static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID); -static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +static NS_DEFINE_IID(kIXULCommandIID, NS_IXULCOMMAND_IID); +static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); -#define DEBUGCMDS 0 +#define DEBUG_MENUSDEL 1 #include "nsIWebShell.h" @@ -108,9 +109,6 @@ nsWebShellWindow::nsWebShellWindow() mWebShell = nsnull; mWindow = nsnull; mController = nsnull; - mStatusText = nsnull; - mURLBarText = nsnull; - mThrobber = nsnull; } @@ -123,9 +121,6 @@ nsWebShellWindow::~nsWebShellWindow() NS_IF_RELEASE(mWindow); NS_IF_RELEASE(mController); - NS_IF_RELEASE(mStatusText); - NS_IF_RELEASE(mURLBarText); - NS_IF_RELEASE(mThrobber); } @@ -204,7 +199,7 @@ nsresult nsWebShellWindow::Initialize(nsIWidget* aParent, rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID, (void**)&mWindow); if (NS_OK != rv) { - goto done; + return rv; } initData.mBorderStyle = eBorderStyle_dialog; @@ -225,7 +220,7 @@ nsresult nsWebShellWindow::Initialize(nsIWidget* aParent, kIWebShellIID, (void**)&mWebShell); if (NS_OK != rv) { - goto done; + return rv; } r.x = r.y = 0; @@ -256,7 +251,6 @@ nsresult nsWebShellWindow::Initialize(nsIWidget* aParent, //rv = nsRepository::CreateInstance(iid, nsnull, // kIWidgetControllerIID, // (void**)&mController); -done: return rv; } @@ -322,25 +316,6 @@ NS_IMETHODIMP nsWebShellWindow::WillLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, nsLoadType aReason) { - if (nsnull != mThrobber) { - mThrobber->SetSrc(kThrobberOnStr); - } - - nsAutoString url(aURL); - nsAutoString gecko("Gecko - "); - gecko.Append(url); - - mWindow->SetTitle(gecko); - - if (nsnull != mURLBarText) { - mURLBarText->SetValue(url); - } - - if (nsnull != mStatusText) { - nsAutoString msg(aURL); - msg.Append(" :Start"); - mStatusText->SetData(msg); - } return NS_OK; } @@ -354,17 +329,6 @@ NS_IMETHODIMP nsWebShellWindow::ProgressLoadURL(nsIWebShell* aShell, const PRUnichar* aURL, PRInt32 aProgress, PRInt32 aProgressMax) { - if (nsnull != mStatusText) { - nsAutoString url(aURL); - url.Append(": progress "); - url.Append(aProgress, 10); - if (0 != aProgressMax) { - url.Append(" (out of "); - url.Append(aProgressMax, 10); - url.Append(")"); - } - mStatusText->SetData(url); - } return NS_OK; } @@ -372,16 +336,6 @@ NS_IMETHODIMP nsWebShellWindow::EndLoadURL(nsIWebShell* aWebShell, const PRUnichar* aURL, PRInt32 aStatus) { - if (nsnull != mThrobber) { - mThrobber->SetSrc(kThrobberOffStr); - } - - if (nsnull != mStatusText) { - nsAutoString msg(aURL); - msg.Append(" :Stop"); - mStatusText->SetData(msg); - } - return NS_OK; } @@ -412,14 +366,100 @@ nsCOMPtr nsWebShellWindow::FindNamedParentFromDoc(nsIDOMDocument * a return node; } + +//---------------------------------------- +NS_IMETHODIMP nsWebShellWindow::CreateMenu(nsIMenuBar * aMenuBar, + nsIDOMNode * aMenuNode, + nsString & aMenuName) +{ + // Create nsMenu + nsIMenu * pnsMenu = nsnull; + nsresult rv = nsRepository::CreateInstance(kMenuCID, nsnull, kIMenuIID, (void**)&pnsMenu); + if (NS_OK == rv) { + // Call Create + pnsMenu->Create(aMenuBar, aMenuName); + + // Set nsMenu Name + pnsMenu->SetLabel(aMenuName); + // Make nsMenu a child of nsMenuBar + aMenuBar->AddMenu(pnsMenu); // XXX adds an additional menu + + // Begin menuitem inner loop + nsCOMPtr menuitemNode; + aMenuNode->GetFirstChild(getter_AddRefs(menuitemNode)); + while (menuitemNode) { + nsCOMPtr menuitemElement(do_QueryInterface(menuitemNode)); + if (menuitemElement) { + nsString menuitemNodeType; + nsString menuitemName; + nsString menuitemCmd; + menuitemElement->GetNodeName(menuitemNodeType); + if (menuitemNodeType.Equals("menuitem")) { + menuitemElement->GetAttribute(nsAutoString("name"), menuitemName); + menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd); + //printf("Creating MenuItem [%s]\n", menuitemName.ToNewCString()); // this leaks + // Create nsMenuItem + nsIMenuItem * pnsMenuItem = nsnull; + rv = nsRepository::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem); + if (NS_OK == rv) { + pnsMenuItem->Create(pnsMenu, menuitemName, 0); + // Set nsMenuItem Name + pnsMenuItem->SetLabel(menuitemName); + // Make nsMenuItem a child of nsMenu + pnsMenu->AddMenuItem(pnsMenuItem); // XXX adds an additional item + + // Create MenuDelegate - this is the intermediator inbetween + // the DOM node and the nsIMenuItem + // The nsWebShellWindow wacthes for Document changes and then notifies the + // the appropriate nsMenuDelegate object + nsCOMPtr domElement(do_QueryInterface(menuitemNode)); + if (!domElement) { + return NS_ERROR_FAILURE; + } + + nsAutoString cmdAtom("onClick"); + nsString cmdName; + + domElement->GetAttribute(cmdAtom, cmdName); + + nsXULCommand * menuDelegate = new nsXULCommand(); + menuDelegate->SetCommand(cmdName); + menuDelegate->SetWebShell(mWebShell); + menuDelegate->SetDOMElement(domElement); + menuDelegate->SetMenuItem(pnsMenuItem); + nsIXULCommand * icmd; + if (NS_OK == menuDelegate->QueryInterface(kIXULCommandIID, (void**) &icmd)) { + mMenuDelegates.AppendElement(icmd); + nsCOMPtr listener(do_QueryInterface(menuDelegate)); + if (listener) { + pnsMenuItem->AddMenuListener(listener); + if (DEBUG_MENUSDEL) printf("Adding menu listener to [%s]\n", menuitemName.ToNewCString()); + } else { + if (DEBUG_MENUSDEL) printf("*** NOT Adding menu listener to [%s]\n", menuitemName.ToNewCString()); + } + } + } + } else if (menuitemNodeType.Equals("separator")) { + pnsMenu->AddSeparator(); + } + } + nsCOMPtr oldmenuitemNode(menuitemNode); + oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); + } // end menu item innner loop + } + + return NS_OK; +} + //---------------------------------------- void nsWebShellWindow::LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWindow) { // locate the window element which holds toolbars and menus and commands nsCOMPtr element; aDOMDoc->GetDocumentElement(getter_AddRefs(element)); - if (!element) + if (!element) { return; + } nsCOMPtr window(do_QueryInterface(element)); nsresult rv; @@ -428,120 +468,42 @@ void nsWebShellWindow::LoadMenus(nsIDOMDocument * aDOMDoc, nsIWidget * aParentWi if (menubarNode) { nsIMenuBar * pnsMenuBar = nsnull; rv = nsRepository::CreateInstance(kMenuBarCID, nsnull, kIMenuBarIID, (void**)&pnsMenuBar); - if (NS_OK != rv) { - // Error - } - if (nsnull != pnsMenuBar) { - pnsMenuBar->Create(aParentWindow); + if (NS_OK == rv) { + if (nsnull != pnsMenuBar) { + pnsMenuBar->Create(aParentWindow); - // set pnsMenuBar as a nsMenuListener on aParentWindow - nsCOMPtr menuListener; - pnsMenuBar->QueryInterface(kIMenuListenerIID, getter_AddRefs(menuListener)); - mWindow->AddMenuListener(menuListener); + // set pnsMenuBar as a nsMenuListener on aParentWindow + nsCOMPtr menuListener; + pnsMenuBar->QueryInterface(kIMenuListenerIID, getter_AddRefs(menuListener)); + mWindow->AddMenuListener(menuListener); - nsCOMPtr menuNode; - menubarNode->GetFirstChild(getter_AddRefs(menuNode)); - while (menuNode) { - nsCOMPtr menuElement(do_QueryInterface(menuNode)); - if (menuElement) { - nsString menuNodeType; - nsString menuName; - menuElement->GetNodeName(menuNodeType); - if (menuNodeType.Equals("menu")) { - menuElement->GetAttribute(nsAutoString("name"), menuName); - printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks - - // Create nsMenu - nsIMenu * pnsMenu = nsnull; - rv = nsRepository::CreateInstance(kMenuCID, nsnull, kIMenuIID, (void**)&pnsMenu); - if (NS_OK == rv) { - // Call Create - pnsMenu->Create(pnsMenuBar, menuName); - - // Set nsMenu Name - pnsMenu->SetLabel(menuName); - // Make nsMenu a child of nsMenuBar - pnsMenuBar->AddMenu(pnsMenu); // XXX adds an additional menu + nsCOMPtr menuNode; + menubarNode->GetFirstChild(getter_AddRefs(menuNode)); + while (menuNode) { + nsCOMPtr menuElement(do_QueryInterface(menuNode)); + if (menuElement) { + nsString menuNodeType; + nsString menuName; + menuElement->GetNodeName(menuNodeType); + if (menuNodeType.Equals("menu")) { + menuElement->GetAttribute(nsAutoString("name"), menuName); + printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks + CreateMenu(pnsMenuBar, menuNode, menuName); + } - // Begin menuitem inner loop - nsCOMPtr menuitemNode; - menuNode->GetFirstChild(getter_AddRefs(menuitemNode)); - while (menuitemNode) { - nsCOMPtr - menuitemElement(do_QueryInterface(menuitemNode)); - if (menuitemElement) { - nsString menuitemNodeType; - nsString menuitemName; - nsString menuitemCmd; - menuitemElement->GetNodeName(menuitemNodeType); - printf("Type [%s] %d\n", menuitemNodeType.ToNewCString(), menuitemNodeType.Equals("separator")); - if (menuitemNodeType.Equals("menuitem")) { - menuitemElement->GetAttribute(nsAutoString("name"), menuitemName); - menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd); - //printf("Creating MenuItem [%s]\n", menuitemName.ToNewCString()); // this leaks - // Create nsMenuItem - nsIMenuItem * pnsMenuItem = nsnull; - rv = nsRepository::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem); - if (NS_OK == rv) { - pnsMenuItem->Create(pnsMenu, menuitemName, 0); - // Set nsMenuItem Name - pnsMenuItem->SetLabel(menuitemName); - // Make nsMenuItem a child of nsMenu - pnsMenu->AddMenuItem(pnsMenuItem); // XXX adds an additional item - - //ConnectCommandToOneGUINode(menuitemNode); -#if 1 - //----------------------------------------------------------- - // This block contains temporary menu hookup code. - //----------------------------------------------------------- - { - nsCOMPtr domElement(do_QueryInterface(menuitemNode)); - if (!domElement) - return; - - nsAutoString cmdAtom("onClick"); - nsString cmdName; - - domElement->GetAttribute(cmdAtom, cmdName); - - nsXULCommand * xulCmd = new nsXULCommand(); - xulCmd->SetName(cmdName); - xulCmd->SetCommand(cmdName); - xulCmd->SetWebShell(mWebShell); - xulCmd->SetDOMElement(domElement); - nsIXULCommand * icmd; - if (NS_OK == xulCmd->QueryInterface(kIXULCommandIID, (void**) &icmd)) { - mMenuDelegates.AppendElement(icmd); - } - nsCOMPtr listener(do_QueryInterface(icmd)); - pnsMenuItem->AddMenuListener(listener); - - } - //----------------------------------------------------------- -#endif - } - } else if (menuitemNodeType.Equals("separator")) { - pnsMenu->AddSeparator(); - } - } - nsCOMPtr oldmenuitemNode(menuitemNode); - oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); - } // end menu item innner loop - } - } - - } - nsCOMPtr oldmenuNode(menuNode); - oldmenuNode->GetNextSibling(getter_AddRefs(menuNode)); - } // end while (nsnull != menuNode) + } + nsCOMPtr oldmenuNode(menuNode); + oldmenuNode->GetNextSibling(getter_AddRefs(menuNode)); + } // end while (nsnull != menuNode) - // Give the aParentWindow this nsMenuBar to hold onto. - mWindow->SetMenuBar(pnsMenuBar); + // Give the aParentWindow this nsMenuBar to hold onto. + mWindow->SetMenuBar(pnsMenuBar); - // HACK: force a paint for now - pnsMenuBar->Paint(); + // HACK: force a paint for now + pnsMenuBar->Paint(); } // end if ( nsnull != pnsMenuBar ) - } // end if (nsnull != node) + } + } // end if (menuBar) } // nsWebShellWindow::LoadMenus @@ -715,7 +677,25 @@ PRInt32 nsWebShellWindow::GetDocHeight(nsIDocument * aDoc) //---------------------------------------- NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete() { - if (DEBUGCMDS) printf("OnConnectionsComplete\n"); + if (DEBUG_MENUSDEL) printf("OnConnectionsComplete\n"); + + // register as document listener + // this is needed for menus + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + + nsCOMPtr docv(do_QueryInterface(cv)); + if (!docv) + return NS_OK; + + nsCOMPtr doc; + docv->GetDocument(*getter_AddRefs(doc)); + if (!doc) + return NS_OK; + + doc->AddObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); + } ExecuteStartupCode(); @@ -726,25 +706,6 @@ NS_IMETHODIMP nsWebShellWindow::OnConnectionsComplete() if (menubarDOMDoc) LoadMenus(menubarDOMDoc, mWindow); - /////////////////////////////// - // Find the Status Text DOM Node. EVIL ASSUMPTION THAT ALL SUCH WINDOWS HAVE ONE. - /////////////////////////////// - nsCOMPtr statusDOMDoc(GetNamedDOMDoc(nsAutoString("status"))); - if (!statusDOMDoc) - return NS_ERROR_FAILURE; - nsCOMPtr parent(GetParentNodeFromDOMDoc(statusDOMDoc)); - if (!parent) - return NS_ERROR_FAILURE; - PRInt32 count = 0; - nsCOMPtr statusNode(FindNamedDOMNode(nsAutoString("#text"), parent, count, 7)); - if (!statusNode) - return NS_ERROR_FAILURE; - nsCOMPtr charData(do_QueryInterface(statusNode)); - if (!charData) - return NS_ERROR_FAILURE; - mStatusText = charData; - mStatusText->SetData(nsAutoString("Ready.....")); // <<====== EVIL HARD-CODED STRING. - // Calculate size of windows #if 0 @@ -839,7 +800,7 @@ void nsWebShellWindow::ExecuteJavaScriptString(nsString& aJavaScript) PRBool isUndefined = PR_FALSE; nsString rVal("xxx"); scriptContext->EvaluateString(aJavaScript, url, 0, rVal, &isUndefined); - if (DEBUGCMDS) printf("EvaluateString - %d [%s]\n", isUndefined, rVal.ToNewCString()); + if (DEBUG_MENUSDEL) printf("EvaluateString - %d [%s]\n", isUndefined, rVal.ToNewCString()); } } @@ -866,3 +827,173 @@ void nsWebShellWindow::ExecuteStartupCode() if (NS_SUCCEEDED(webshellElement->GetAttribute("onConstruction", startupCode))) ExecuteJavaScriptString(startupCode); } + + + +//---------------------------------------------------------------- +//-- nsIDocumentObserver +//---------------------------------------------------------------- +NS_IMETHODIMP +nsWebShellWindow::BeginUpdate(nsIDocument *aDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::EndUpdate(nsIDocument *aDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::BeginLoad(nsIDocument *aDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::EndLoad(nsIDocument *aDocument) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::EndReflow(nsIDocument *aDocument, nsIPresShell* aShell) +{ + return NS_OK; +} + +/////////////////////////////////////////////////////////////// +// nsIDocumentObserver +// this is needed for menu changes +/////////////////////////////////////////////////////////////// +NS_IMETHODIMP +nsWebShellWindow::ContentChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsISupports* aSubContent) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::AttributeChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsIAtom* aAttribute, + PRInt32 aHint) +{ + //printf("AttributeChanged\n"); + PRInt32 i; + for (i=0;iGetDOMElement(&node); + //nsCOMPtr content(do_QueryInterface(node)); + // Doing this for the must speed + nsIContent * content; + if (NS_OK == node->QueryInterface(kIContentIID, (void**) &content)) { + if (content == aContent) { + nsAutoString attr; + aAttribute->ToString(attr); + cmd->AttributeHasBeenSet(attr); + } + NS_RELEASE(content); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::ContentAppended(nsIDocument *aDocument, + nsIContent* aContainer, + PRInt32 aNewIndexInContainer) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::ContentInserted(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::ContentReplaced(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aOldChild, + nsIContent* aNewChild, + PRInt32 aIndexInContainer) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::ContentRemoved(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::StyleSheetAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::StyleSheetRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::StyleSheetDisabledStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aDisabled) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::StyleRuleChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule, + PRInt32 aHint) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::StyleRuleAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::StyleRuleRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsWebShellWindow::DocumentWillBeDestroyed(nsIDocument *aDocument) +{ + return NS_OK; +} diff --git a/xpfe/appshell/src/nsWebShellWindow.h b/xpfe/appshell/src/nsWebShellWindow.h index 54b67792338..1af5abe15f3 100644 --- a/xpfe/appshell/src/nsWebShellWindow.h +++ b/xpfe/appshell/src/nsWebShellWindow.h @@ -25,12 +25,12 @@ #include "nsGUIEvent.h" #include "nsIWebShell.h" #include "nsIDocumentLoaderObserver.h" +#include "nsIDocumentObserver.h" #include "nsVoidArray.h" // can't use forward class decl's because of template bugs on Solaris #include "nsIDOMDocument.h" #include "nsIDOMNode.h" -#include "nsIXULCommand.h" #include "nsCOMPtr.h" @@ -46,9 +46,12 @@ class nsIDOMElement; class nsIStreamObserver; class nsIDocument; +class nsIContent; + class nsWebShellWindow : public nsIWebShellWindow, public nsIWebShellContainer, - public nsIDocumentLoaderObserver + public nsIDocumentLoaderObserver, + public nsIDocumentObserver { public: nsWebShellWindow(); @@ -99,6 +102,55 @@ public: NS_IMETHOD OnStartURLLoad(nsIURL* aURL, const char* aContentType, nsIContentViewer* aViewer); NS_IMETHOD OnConnectionsComplete(); + // nsIDocumentObserver + NS_IMETHOD BeginUpdate(nsIDocument *aDocument); + NS_IMETHOD EndUpdate(nsIDocument *aDocument); + NS_IMETHOD BeginLoad(nsIDocument *aDocument); + NS_IMETHOD EndLoad(nsIDocument *aDocument); + NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell); + NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell); + NS_IMETHOD ContentChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsISupports* aSubContent); + NS_IMETHOD AttributeChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsIAtom* aAttribute, + PRInt32 aHint); + NS_IMETHOD ContentAppended(nsIDocument *aDocument, + nsIContent* aContainer, + PRInt32 aNewIndexInContainer); + NS_IMETHOD ContentInserted(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer); + NS_IMETHOD ContentReplaced(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aOldChild, + nsIContent* aNewChild, + PRInt32 aIndexInContainer); + NS_IMETHOD ContentRemoved(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer); + NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet); + NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet); + NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aDisabled); + NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule, + PRInt32 aHint); + NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule); + NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule); + NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); + protected: void ExecuteJavaScriptString(nsString& aJavaScript); @@ -109,6 +161,7 @@ protected: nsCOMPtr FindNamedDOMNode(const nsString &aName, nsIDOMNode * aParent, PRInt32 & aCount, PRInt32 aEndCount); nsCOMPtr GetNamedDOMDoc(const nsString & aWebShellName); nsCOMPtr GetParentNodeFromDOMDoc(nsIDOMDocument * aDOMDoc); + NS_IMETHOD CreateMenu(nsIMenuBar * aMenuBar, nsIDOMNode * aMenuNode, nsString & aMenuName); nsCOMPtr GetDOMNodeFromWebShell(nsIWebShell *aShell); void ExecuteStartupCode(); @@ -121,9 +174,6 @@ protected: nsIWidget* mWindow; nsIWebShell* mWebShell; nsIWidgetController* mController; - nsIDOMCharacterData* mStatusText; - nsIDOMHTMLInputElement* mURLBarText; - nsIDOMHTMLImageElement* mThrobber; nsVoidArray mMenuDelegates; }; diff --git a/xpfe/appshell/src/nsXULCommand.cpp b/xpfe/appshell/src/nsXULCommand.cpp index 5c61d510ab6..87774e4256d 100644 --- a/xpfe/appshell/src/nsXULCommand.cpp +++ b/xpfe/appshell/src/nsXULCommand.cpp @@ -17,10 +17,7 @@ * Netscape Communications Corporation. All Rights Reserved. */ #include "nsIDOMNode.h" -#include "nsIDOMEvent.h" -#include "nsIDOMEventReceiver.h" -#include "nsIDOMHTMLInputElement.h" -#include "nsIDOMHTMLButtonElement.h" +#include "nsIMenuItem.h" // FOr JS Execution #include "nsIScriptContextOwner.h" @@ -29,39 +26,30 @@ #include "nsXULCommand.h" -#define DEBUGCMDS 0 +#define DEBUG_MENUSDEL 1 //---------------------------------------------------------------------- // Class IID's -static NS_DEFINE_IID(kXULCommandCID, NS_XULCOMMAND_CID); // IID's -static NS_DEFINE_IID(kIXULCommandIID, NS_IXULCOMMAND_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIDOMMouseListenerIID, NS_IDOMMOUSELISTENER_IID); -static NS_DEFINE_IID(kIDOMKeyListenerIID, NS_IDOMKEYLISTENER_IID); -static NS_DEFINE_IID(kIDOMEventReceiverIID, NS_IDOMEVENTRECEIVER_IID); -static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); -static NS_DEFINE_IID(kIDOMHTMLButtonElement, NS_IDOMHTMLBUTTONELEMENT_IID); static NS_DEFINE_IID(kIScriptContextOwnerIID, NS_ISCRIPTCONTEXTOWNER_IID); +static NS_DEFINE_IID(kIXULCommandIID, NS_IXULCOMMAND_IID); //---------------------------------------------------------------------- nsXULCommand::nsXULCommand() { NS_INIT_REFCNT(); - mIsEnabled = PR_FALSE; + mMenuItem = nsnull; + } //---------------------------------------------------------------------- nsXULCommand::~nsXULCommand() { - while (mSrcWidgets.Count() > 0) { - nsCOMPtr node = dont_AddRef(NS_STATIC_CAST(nsIDOMNode*,mSrcWidgets.ElementAt(0))); - mSrcWidgets.RemoveElementAt(0); - } + NS_IF_RELEASE(mMenuItem); } @@ -77,100 +65,33 @@ nsXULCommand::QueryInterface(REFNSIID aIID, void** aInstancePtr) if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } + + if (aIID.Equals(kIMenuListenerIID)) { + *aInstancePtr = (void*)(nsIMenuListener*)this; + NS_ADDREF_THIS(); + return NS_OK; + } if (aIID.Equals(kIXULCommandIID)) { *aInstancePtr = (void*)(nsIXULCommand*)this; NS_ADDREF_THIS(); return NS_OK; } - if (aIID.Equals(kIDOMMouseListenerIID)) { - NS_ADDREF_THIS(); // Increase reference count for caller - *aInstancePtr = (void *)((nsIDOMMouseListener*)this); - return NS_OK; - } - if (aIID.Equals(kIDOMKeyListenerIID)) { - NS_ADDREF_THIS(); // Increase reference count for caller - *aInstancePtr = (void *)((nsIDOMKeyListener*)this); - return NS_OK; - } if (aIID.Equals(kISupportsIID)) { - *aInstancePtr = (void*)(nsISupports*)(nsIXULCommand*)this; + *aInstancePtr = (void*)(nsISupports*)this; NS_ADDREF_THIS(); return NS_OK; } - return rv; + return NS_ERROR_NO_INTERFACE; } -// XUL UI Objects //---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::SetName(const nsString &aName) +NS_IMETHODIMP nsXULCommand::GetDOMElement(nsIDOMElement ** aDOMElement) { - mName = aName; + *aDOMElement = mDOMElement; return NS_OK; -} -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::GetName(nsString &aName) const -{ - aName = mName; - return NS_OK; -} - -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::AddUINode(nsIDOMNode * aNode) -{ - NS_PRECONDITION(nsnull != aNode, "adding event listener to null node"); - - nsCOMPtr receiver ( aNode ); - if ( receiver ) { - receiver->AddEventListener((nsIDOMMouseListener*)this, kIDOMMouseListenerIID); - receiver->AddEventListener((nsIDOMKeyListener*)this, kIDOMKeyListenerIID); - mSrcWidgets.AppendElement(aNode); - NS_ADDREF(aNode); - return NS_OK; - } - return NS_ERROR_FAILURE; -} - -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::RemoveUINode(nsIDOMNode * aCmd) -{ - PRInt32 index = mSrcWidgets.IndexOf(aCmd); - if (index > 0) { - mSrcWidgets.RemoveElementAt(index); - } - return NS_OK; -} - -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::SetEnabled(PRBool aIsEnabled) -{ - mIsEnabled = aIsEnabled; - PRInt32 i, n = mSrcWidgets.Count(); - for (i = 0; i < n; i++) { - nsCOMPtr node = dont_AddRef(NS_STATIC_CAST(nsIDOMNode*,mSrcWidgets.ElementAt(i))); - nsCOMPtr input ( do_QueryInterface(node) ); - //*** rewrite this part to set an attribute on a nsIDOMElement - if ( input ) { - input->SetDisabled(aIsEnabled); - } else { - nsCOMPtr btn ( do_QueryInterface(node) ); - if ( btn ) - btn->SetDisabled(!aIsEnabled); - } - //*** - } - - return NS_OK; -} - -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::GetEnabled(PRBool & aIsEnabled) -{ - //*** rewrite this part to get an attribute on a nsIDOMElement - aIsEnabled = mIsEnabled; - return NS_OK; } //---------------------------------------------------------------------- @@ -180,6 +101,27 @@ NS_IMETHODIMP nsXULCommand::SetCommand(const nsString & aStrCmd) return NS_OK; } + +//---------------------------------------------------------------------- +NS_IMETHODIMP nsXULCommand::SetMenuItem(nsIMenuItem * aMenuItem) +{ + mMenuItem = aMenuItem; + NS_ADDREF(mMenuItem); + return NS_OK; +} + +//---------------------------------------------------------------------- +NS_IMETHODIMP nsXULCommand::AttributeHasBeenSet(const nsString & aAttr) +{ + nsAutoString value; + mDOMElement->GetAttribute(aAttr, value); + if (DEBUG_MENUSDEL) printf("New value is [%s]=[%s]\n", aAttr.ToNewCString(), value.ToNewCString()); + if (aAttr.Equals("disabled")) { + mMenuItem->SetEnabled((PRBool)(!value.Equals("true"))); + } + return NS_OK; +} + //---------------------------------------------------------------------- NS_IMETHODIMP nsXULCommand::DoCommand() { @@ -187,7 +129,7 @@ NS_IMETHODIMP nsXULCommand::DoCommand() mWebShell->GetName( &name); nsAutoString str(name); - if (DEBUGCMDS) printf("DoCommand - mWebShell is [%s] 0x%x\n", str.ToNewCString(), mWebShell); + if (DEBUG_MENUSDEL) printf("DoCommand - mWebShell is [%s] 0x%x\n", str.ToNewCString(), mWebShell); return ExecuteJavaScriptString(mWebShell, mCommandStr); } @@ -227,125 +169,16 @@ NS_IMETHODIMP nsXULCommand::ExecuteJavaScriptString(nsIWebShell* aWebShell, nsSt PRBool isUndefined = PR_FALSE; nsString rVal("xxx"); scriptContext->EvaluateString(aJavaScript, url, 0, rVal, &isUndefined); - if (DEBUGCMDS) printf("EvaluateString - %d [%s]\n", isUndefined, rVal.ToNewCString()); + if (DEBUG_MENUSDEL) printf("EvaluateString - %d [%s]\n", isUndefined, rVal.ToNewCString()); } } return status; } -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::SetTooltip(const nsString &aTip) -{ - mTooltip = aTip; - return NS_OK; -} - -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::GetTooltip(nsString &aTip) const -{ - aTip = mTooltip; - return NS_OK; -} -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::SetDescription(const nsString &aDescription) -{ - mDescription = aDescription; - return NS_OK; -} - -//---------------------------------------------------------------------- -NS_IMETHODIMP nsXULCommand::GetDescription(nsString &aDescription) const -{ - aDescription = mDescription; - return NS_OK; -} - -//----------------------------------------------------------------- -//-- nsIDOMMouseListener -//----------------------------------------------------------------- - -//----------------------------------------------------------------- -nsresult nsXULCommand::ProcessEvent(nsIDOMEvent* aEvent) -{ - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::MouseUp(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::MouseDown(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::MouseClick(nsIDOMEvent* aMouseEvent) -{ - if (DEBUGCMDS) printf("Executing [%s]\n", mCommandStr.ToNewCString()); - if (mIsEnabled) { - DoCommand(); - } - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::MouseDblClick(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::MouseOver(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::MouseOut(nsIDOMEvent* aMouseEvent) -{ - return NS_OK; -} - -//----------------------------------------------------------------- -//----------------------------------------------------------------- -// nsIDOMKeyListener -//----------------------------------------------------------------- -nsresult nsXULCommand::KeyDown(nsIDOMEvent* aKeyEvent) -{ - PRUint32 type; - aKeyEvent->GetKeyCode(&type); - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::KeyUp(nsIDOMEvent* aKeyEvent) -{ - PRUint32 type; - aKeyEvent->GetKeyCode(&type); - if (nsIDOMEvent::VK_RETURN != type) { - return NS_OK; - } - nsCOMPtr input ( do_QueryInterface(mDOMElement) ); - if ( input ) { - nsAutoString value; - input->GetValue(value); - //printf("Value [%s]\n", value.ToNewCString()); - mWebShell->LoadURL(value); - } - return NS_OK; -} - -//----------------------------------------------------------------- -nsresult nsXULCommand::KeyPress(nsIDOMEvent* aKeyEvent) -{ - return NS_OK; -} - +///////////////////////////////////////////////////////////////////////// +// nsIMenuListener Method(s) +///////////////////////////////////////////////////////////////////////// nsEventStatus nsXULCommand::MenuSelected(const nsMenuEvent & aMenuEvent) { @@ -353,135 +186,3 @@ nsEventStatus nsXULCommand::MenuSelected(const nsMenuEvent & aMenuEvent) return nsEventStatus_eConsumeNoDefault; } -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -//---------------------------------------------------------------------- -// Factory code for creating nsXULCommand's - -class nsXULCommandFactory : public nsIFactory -{ -public: - nsXULCommandFactory(); - virtual ~nsXULCommandFactory(); - - // nsISupports methods - NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult); - NS_IMETHOD_(nsrefcnt) AddRef(void); - NS_IMETHOD_(nsrefcnt) Release(void); - - // nsIFactory methods - NS_IMETHOD CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult); - - NS_IMETHOD LockFactory(PRBool aLock); - -private: - nsrefcnt mRefCnt; -}; - - -nsXULCommandFactory::nsXULCommandFactory() -{ - mRefCnt = 0; -} - -nsXULCommandFactory::~nsXULCommandFactory() -{ - NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); -} - -nsresult -nsXULCommandFactory::QueryInterface(const nsIID &aIID, void **aResult) -{ - if (aResult == NULL) { - return NS_ERROR_NULL_POINTER; - } - - // Always NULL result, in case of failure - *aResult = NULL; - - if (aIID.Equals(kISupportsIID)) { - *aResult = (void *)(nsISupports*)this; - } else if (aIID.Equals(kIFactoryIID)) { - *aResult = (void *)(nsIFactory*)this; - } - - if (*aResult == NULL) { - return NS_NOINTERFACE; - } - - NS_ADDREF_THIS(); // Increase reference count for caller - return NS_OK; -} - -nsrefcnt -nsXULCommandFactory::AddRef() -{ - return ++mRefCnt; -} - -nsrefcnt -nsXULCommandFactory::Release() -{ - if (--mRefCnt == 0) { - delete this; - return 0; // Don't access mRefCnt after deleting! - } - return mRefCnt; -} - -nsresult -nsXULCommandFactory::CreateInstance(nsISupports *aOuter, - const nsIID &aIID, - void **aResult) -{ - nsresult rv; - nsXULCommand *inst; - - if (aResult == NULL) { - return NS_ERROR_NULL_POINTER; - } - *aResult = NULL; - if (nsnull != aOuter) { - rv = NS_ERROR_NO_AGGREGATION; - goto done; - } - - NS_NEWXPCOM(inst, nsXULCommand); - if (inst == NULL) { - rv = NS_ERROR_OUT_OF_MEMORY; - goto done; - } - - NS_ADDREF(inst); - rv = inst->QueryInterface(aIID, aResult); - NS_RELEASE(inst); - -done: - return rv; -} - -nsresult -nsXULCommandFactory::LockFactory(PRBool aLock) -{ - // Not implemented in simplest case. - return NS_OK; -} - -extern "C" nsresult -NS_NewXULCommandFactory(nsIFactory** aFactory) -{ - nsresult rv = NS_OK; - nsIFactory* inst = new nsXULCommandFactory(); - if (nsnull == inst) { - rv = NS_ERROR_OUT_OF_MEMORY; - } - else { - NS_ADDREF(inst); - } - *aFactory = inst; - return rv; -} diff --git a/xpfe/appshell/src/nsXULCommand.h b/xpfe/appshell/src/nsXULCommand.h index 333028c5a2a..ea621a746a2 100644 --- a/xpfe/appshell/src/nsXULCommand.h +++ b/xpfe/appshell/src/nsXULCommand.h @@ -20,10 +20,8 @@ #ifndef nsXULCommand_h__ #define nsXULCommand_h__ +//#include "nsIMenuListener.h" #include "nsIXULCommand.h" -#include "nsIDOMMouseListener.h" -#include "nsIDOMKeyListener.h" -#include "nsVoidArray.h" #include "nsString.h" #include "nsCRT.h" #include "nsIDOMElement.h" // for some older c++ compilers. @@ -37,9 +35,7 @@ class nsIDOMEvent; //---------------------------------------------------------------------- -class nsXULCommand : public nsIXULCommand, - public nsIDOMMouseListener, - public nsIDOMKeyListener +class nsXULCommand : public nsIXULCommand //public nsIMenuListener { public: @@ -49,44 +45,16 @@ public: // nsISupports NS_DECL_ISUPPORTS - // XUL UI Objects - NS_IMETHOD SetName(const nsString &aName); - NS_IMETHOD GetName(nsString &aName) const; - NS_IMETHOD AddUINode(nsIDOMNode * aNode); - NS_IMETHOD RemoveUINode(nsIDOMNode * aCmd); - - NS_IMETHOD SetEnabled(PRBool aIsEnabled); - NS_IMETHOD GetEnabled(PRBool & aIsEnabled); - - NS_IMETHOD SetTooltip(const nsString &aTip); - NS_IMETHOD GetTooltip(nsString &aTip) const; - NS_IMETHOD SetDescription(const nsString &aDescription); - NS_IMETHOD GetDescription(nsString &aDescription) const; + NS_IMETHOD SetMenuItem(nsIMenuItem * aMenuItem); + NS_IMETHOD AttributeHasBeenSet(const nsString & aAttr); + NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMElement); + NS_IMETHOD GetDOMElement(nsIDOMElement ** aDOMElement); + NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); + NS_IMETHOD SetCommand(const nsString & aStrCmd); NS_IMETHOD DoCommand(); - // Non-Interface Methods - NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMNode); - NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); - NS_IMETHOD SetCommand(const nsString & aStrCmd); - - - // nsIDOMEventListener - virtual nsresult ProcessEvent(nsIDOMEvent* aEvent); - - // nsIDOMMouseListener (is derived from nsIDOMEventListener) - virtual nsresult MouseDown(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseUp(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseDblClick(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOver(nsIDOMEvent* aMouseEvent); - virtual nsresult MouseOut(nsIDOMEvent* aMouseEvent); - - // nsIDOMKeyListener - virtual nsresult KeyDown(nsIDOMEvent* aKeyEvent); - virtual nsresult KeyUp(nsIDOMEvent* aKeyEvent); - virtual nsresult KeyPress(nsIDOMEvent* aKeyEvent); // nsIMenuListener virtual nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); @@ -94,17 +62,12 @@ public: protected: NS_IMETHOD ExecuteJavaScriptString(nsIWebShell* aWebShell, nsString& aJavaScript); - nsString mName; - nsString mCommandStr; - nsString mTooltip; - nsString mDescription; - PRBool mIsEnabled; - - nsVoidArray mSrcWidgets; - + nsString mCommandStr; nsCOMPtr mWebShell; nsCOMPtr mDOMElement; + nsIMenuItem * mMenuItem; + };