diff --git a/mozilla/widget/public/nsIMenu.h b/mozilla/widget/public/nsIMenu.h index 6ceaa2a25f2..99f9e83b994 100644 --- a/mozilla/widget/public/nsIMenu.h +++ b/mozilla/widget/public/nsIMenu.h @@ -80,6 +80,12 @@ class nsIMenu : public nsISupports { */ NS_IMETHOD SetAccessKey(const nsString &aText) = 0; + /** + * Set the Menu enabled state + * + */ + NS_IMETHOD SetEnabled(PRBool aIsEnabled) = 0; + /** * Adds a Menu Item * diff --git a/mozilla/widget/src/gtk/nsMenu.cpp b/mozilla/widget/src/gtk/nsMenu.cpp index d17c7c12ba4..dd3597ccdc5 100644 --- a/mozilla/widget/src/gtk/nsMenu.cpp +++ b/mozilla/widget/src/gtk/nsMenu.cpp @@ -199,6 +199,16 @@ NS_METHOD nsMenu::SetAccessKey(const nsString &aText) return NS_OK; } +//------------------------------------------------------------------------- +/** +* Set enabled state +* +*/ +NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled) +{ + return NS_OK; +} + //------------------------------------------------------------------------- NS_METHOD nsMenu::AddItem(nsISupports * aItem) { diff --git a/mozilla/widget/src/gtk/nsMenu.h b/mozilla/widget/src/gtk/nsMenu.h index 5d619c1337c..2f8829cb831 100644 --- a/mozilla/widget/src/gtk/nsMenu.h +++ b/mozilla/widget/src/gtk/nsMenu.h @@ -73,6 +73,7 @@ public: NS_IMETHOD SetNativeData(void* aData); NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener); NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener); + NS_IMETHOD SetEnabled(PRBool aIsEnabled); NS_IMETHOD SetDOMNode(nsIDOMNode * aMenuNode); NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement); diff --git a/mozilla/widget/src/mac/nsMenu.cpp b/mozilla/widget/src/mac/nsMenu.cpp index 5346a465f2a..6e020b294af 100644 --- a/mozilla/widget/src/mac/nsMenu.cpp +++ b/mozilla/widget/src/mac/nsMenu.cpp @@ -20,6 +20,8 @@ #include "nsIDocument.h" #include "nsIContent.h" #include "nsIDOMXULDocument.h" +#include "nsIDocumentViewer.h" +#include "nsIDocumentObserver.h" #include "nsIComponentManager.h" #include "nsMenu.h" @@ -62,6 +64,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_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(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID); + // CIDs #include "nsWidgetsCID.h" @@ -92,7 +96,12 @@ nsresult nsMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr) *aInstancePtr = (void*) ((nsIMenuListener*)this); NS_ADDREF_THIS(); return NS_OK; - } + } + if (aIID.Equals(kIDocumentObserverIID)) { + *aInstancePtr = (void*) ((nsIDocumentObserver*)this); + NS_ADDREF_THIS(); + return NS_OK; + } return NS_NOINTERFACE; } @@ -142,6 +151,22 @@ nsMenu::~nsMenu() OSErr err; NS_IF_RELEASE(mListener); + nsCOMPtr cv; + mWebShell->GetContentViewer(getter_AddRefs(cv)); + if (cv) { + + nsCOMPtr docv(do_QueryInterface(cv)); + if (!docv) + return; + + nsCOMPtr doc; + docv->GetDocument(*getter_AddRefs(doc)); + if (!doc) + return; + + doc->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); + } + RemoveAll(); err = ::DisposeUnicodeToTextRunInfo(&mUnicodeTextRunConverter); @@ -837,6 +862,22 @@ nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent) return nsEventStatus_eIgnore; } +//------------------------------------------------------------------------- +/** +* Set enabled state +* +*/ +NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled) +{ + if(aIsEnabled) + ::EnableItem(mMacMenuHandle, 0); + else + ::DisableItem(mMacMenuHandle, 0); + + return NS_OK; +} + + //------------------------------------------------------------------------- /** * Set DOMNode @@ -867,6 +908,29 @@ NS_METHOD nsMenu::SetDOMElement(nsIDOMElement * aMenuElement) NS_METHOD nsMenu::SetWebShell(nsIWebShell * aWebShell) { mWebShell = aWebShell; + + // add ourself as a document observer + + 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; + + nsCOMPtr observer; + QueryInterface(kIDocumentObserverIID, getter_AddRefs(observer)); + if(observer){ + doc->AddObserver(observer); + } + } + return NS_OK; } //------------------------------------------------------------------------- @@ -1202,4 +1266,211 @@ void nsMenu::LoadSubMenu( // We're done with the menu NS_RELEASE(pnsMenu); } +}/////////////////////////////////////////////////////////////// +// nsIDocumentObserver +// this is needed for menubar changes +/////////////////////////////////////////////////////////////// +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::BeginUpdate( + nsIDocument * aDocument) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::EndUpdate( + nsIDocument * aDocument) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::BeginLoad( + nsIDocument * aDocument) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::EndLoad( + nsIDocument * aDocument) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::BeginReflow( + nsIDocument * aDocument, + nsIPresShell * aShell) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::EndReflow( + nsIDocument * aDocument, + nsIPresShell * aShell) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::ContentChanged( + nsIDocument * aDocument, + nsIContent * aContent, + nsISupports * aSubContent) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::ContentStatesChanged( + nsIDocument * aDocument, + nsIContent * aContent1, + nsIContent * aContent2) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::AttributeChanged( + nsIDocument * aDocument, + nsIContent * aContent, + nsIAtom * aAttribute, + PRInt32 aHint) +{ + //printf("AttributeChanged\n"); + + nsCOMPtr openAtom = NS_NewAtom("open"); + if(aAttribute != openAtom) { + + nsCOMPtr element(do_QueryInterface(mDOMNode)); + if(!element) { + NS_ERROR("Unable to QI dom element."); + return NS_OK; + } + + nsCOMPtr contentNode; + contentNode = do_QueryInterface(element); + if (!contentNode) { + NS_ERROR("DOM Node doesn't support the nsIContent interface required to handle DOM events."); + return NS_OK; + } + + if(aContent == contentNode){ + nsCOMPtr disabledAtom = NS_NewAtom("disabled"); + if(aAttribute == disabledAtom) { + nsCOMPtr element(do_QueryInterface(aContent)); + nsString valueString; + element->GetAttribute("disabled", valueString); + if(valueString == "true") + SetEnabled(PR_FALSE); + else + SetEnabled(PR_TRUE); + } + ::DrawMenuBar(); + } + } + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::ContentAppended( + nsIDocument * aDocument, + nsIContent * aContainer, + PRInt32 aNewIndexInContainer) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::ContentInserted( + nsIDocument * aDocument, + nsIContent * aContainer, + nsIContent * aChild, + PRInt32 aIndexInContainer) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::ContentReplaced( + nsIDocument * aDocument, + nsIContent * aContainer, + nsIContent * aOldChild, + nsIContent * aNewChild, + PRInt32 aIndexInContainer) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::ContentRemoved( + nsIDocument * aDocument, + nsIContent * aContainer, + nsIContent * aChild, + PRInt32 aIndexInContainer) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::StyleSheetAdded( + nsIDocument * aDocument, + nsIStyleSheet * aStyleSheet) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::StyleSheetRemoved( + nsIDocument * aDocument, + nsIStyleSheet * aStyleSheet) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::StyleSheetDisabledStateChanged( + nsIDocument * aDocument, + nsIStyleSheet * aStyleSheet, + PRBool aDisabled) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::StyleRuleChanged( + nsIDocument * aDocument, + nsIStyleSheet * aStyleSheet, + nsIStyleRule * aStyleRule, + PRInt32 aHint) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::StyleRuleAdded( + nsIDocument * aDocument, + nsIStyleSheet * aStyleSheet, + nsIStyleRule * aStyleRule) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::StyleRuleRemoved( + nsIDocument * aDocument, + nsIStyleSheet * aStyleSheet, + nsIStyleRule * aStyleRule) +{ + return NS_OK; +} +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsMenu::DocumentWillBeDestroyed( + nsIDocument * aDocument) +{ + return NS_OK; } \ No newline at end of file diff --git a/mozilla/widget/src/mac/nsMenu.h b/mozilla/widget/src/mac/nsMenu.h index 855b4347a93..f1c2b5e3bc9 100644 --- a/mozilla/widget/src/mac/nsMenu.h +++ b/mozilla/widget/src/mac/nsMenu.h @@ -22,6 +22,7 @@ #include "nsIMenu.h" #include "nsVoidArray.h" #include "nsIMenuListener.h" +#include "nsIDocumentObserver.h" #include #include @@ -41,7 +42,7 @@ extern const PRInt16 kAppleMenuID; //static PRInt16 mMacMenuIDCount; // use GetUniqueMenuID() extern PRInt16 mMacMenuIDCount;// = kMacMenuID; -class nsMenu : public nsIMenu, public nsIMenuListener +class nsMenu : public nsIMenu, public nsIMenuListener, public nsIDocumentObserver { public: @@ -82,11 +83,63 @@ public: NS_IMETHOD SetDOMNode(nsIDOMNode * aMenuNode); NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement); NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); + NS_IMETHOD SetEnabled(PRBool aIsEnabled); // NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem); NS_IMETHOD AddMenu(nsIMenu * aMenu); + // 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 ContentStatesChanged(nsIDocument *aDocument, + nsIContent* aContent1, + nsIContent* aContent2); + 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); // MacSpecific static PRInt16 GetUniqueMenuID() { if (mMacMenuIDCount == 32767) diff --git a/mozilla/widget/src/windows/nsMenu.cpp b/mozilla/widget/src/windows/nsMenu.cpp index c8f58f67684..501089ba593 100644 --- a/mozilla/widget/src/windows/nsMenu.cpp +++ b/mozilla/widget/src/windows/nsMenu.cpp @@ -197,6 +197,16 @@ NS_METHOD nsMenu::SetAccessKey(const nsString &aText) return NS_OK; } +//------------------------------------------------------------------------- +/** +* Set enabled state +* +*/ +NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled) +{ + return NS_OK; +} + //------------------------------------------------------------------------- NS_METHOD nsMenu::AddItem(nsISupports * aItem) diff --git a/mozilla/widget/src/windows/nsMenu.h b/mozilla/widget/src/windows/nsMenu.h index 76e2cc2427e..bd0ee2bb572 100644 --- a/mozilla/widget/src/windows/nsMenu.h +++ b/mozilla/widget/src/windows/nsMenu.h @@ -62,6 +62,7 @@ public: NS_IMETHOD SetLabel(const nsString &aText); NS_IMETHOD GetAccessKey(nsString &aText); NS_IMETHOD SetAccessKey(const nsString &aText); + NS_IMETHOD SetEnabled(PRBool aIsEnabled); NS_IMETHOD AddItem(nsISupports * aItem);