Adding support for disabled items to XP menus.

git-svn-id: svn://10.0.0.236/trunk@41091 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
hyatt%netscape.com 1999-07-26 01:35:39 +00:00
parent 17997964ba
commit 5aa6e55336
6 changed files with 82 additions and 41 deletions

View File

@ -29,6 +29,7 @@
#include "nsIDocument.h"
#include "nsIDOMEventReceiver.h"
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsMenuFrame.h"
#include "nsIView.h"
#include "nsIViewManager.h"
@ -165,10 +166,7 @@ nsMenuBarFrame::FindMenuWithShortcut(PRUint32 aLetter)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
// Get the shortcut attribute.
nsString shortcutKey = "";
current->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey, shortcutKey);
@ -269,10 +267,7 @@ nsMenuBarFrame::GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -287,10 +282,7 @@ nsMenuBarFrame::GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -319,10 +311,7 @@ nsMenuBarFrame::GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -337,10 +326,7 @@ nsMenuBarFrame::GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -434,4 +420,28 @@ nsMenuBarFrame::DismissChain()
SetCurrentMenuItem(nsnull);
SetActive(PR_FALSE);
return NS_OK;
}
}
PRBool
nsMenuBarFrame::IsValidItem(nsIContent* aContent)
{
nsCOMPtr<nsIAtom> tag;
aContent->GetTag(*getter_AddRefs(tag));
if (tag && (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) &&
!IsDisabled(aContent))
return PR_TRUE;
return PR_FALSE;
}
PRBool
nsMenuBarFrame::IsDisabled(nsIContent* aContent)
{
nsString disabled = "";
aContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
if (disabled == "true")
return PR_TRUE;
return PR_FALSE;
}

View File

@ -77,6 +77,9 @@ public:
// Called to execute a menu item.
void Enter();
PRBool IsValidItem(nsIContent* aContent);
PRBool IsDisabled(nsIContent* aContent);
protected:
nsMenuBarListener* mMenuBarListener; // The listener that tells us about key and mouse events.
PRBool mIsActive; // Whether or not the menu bar is active (a menu item is highlighted or shown).

View File

@ -17,6 +17,7 @@
*/
#include "nsXULAtoms.h"
#include "nsHTMLAtoms.h"
#include "nsMenuFrame.h"
#include "nsBoxFrame.h"
#include "nsIContent.h"
@ -193,6 +194,10 @@ nsMenuFrame::HandleEvent(nsIPresContext& aPresContext,
nsEventStatus& aEventStatus)
{
aEventStatus = nsEventStatus_eConsumeDoDefault;
if (IsDisabled()) // Disabled menus process no events.
return NS_OK;
if (aEvent->message == NS_MOUSE_LEFT_BUTTON_DOWN) {
PRBool isMenuBar = PR_TRUE;
if (mMenuParent)
@ -469,3 +474,13 @@ nsMenuFrame::Notify(nsITimer* aTimer)
}
mOpenTimer = nsnull;
}
PRBool
nsMenuFrame::IsDisabled()
{
nsString disabled = "";
mContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
if (disabled == "true")
return PR_TRUE;
return PR_FALSE;
}

View File

@ -100,6 +100,8 @@ public:
void GetMenuParent(nsIMenuParent** aResult) { NS_IF_ADDREF(mMenuParent); *aResult = mMenuParent; };
PRBool IsDisabled();
protected:
void GetMenuChildrenElement(nsIContent** aResult);

View File

@ -233,10 +233,7 @@ nsMenuPopupFrame::GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -251,10 +248,7 @@ nsMenuPopupFrame::GetNextMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -283,10 +277,7 @@ nsMenuPopupFrame::GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -301,10 +292,7 @@ nsMenuPopupFrame::GetPreviousMenuItem(nsIFrame* aStart, nsIFrame** aResult)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
*aResult = currFrame;
return NS_OK;
}
@ -411,10 +399,7 @@ nsMenuPopupFrame::FindMenuWithShortcut(PRUint32 aLetter)
currFrame->GetContent(getter_AddRefs(current));
// See if it's a menu item.
nsCOMPtr<nsIAtom> tag;
current->GetTag(*getter_AddRefs(tag));
if (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) {
if (IsValidItem(current)) {
// Get the shortcut attribute.
nsString shortcutKey = "";
current->GetAttribute(kNameSpaceID_None, nsXULAtoms::accesskey, shortcutKey);
@ -528,3 +513,26 @@ nsMenuPopupFrame::DismissChain()
return NS_OK;
}
PRBool
nsMenuPopupFrame::IsValidItem(nsIContent* aContent)
{
nsCOMPtr<nsIAtom> tag;
aContent->GetTag(*getter_AddRefs(tag));
if (tag && (tag.get() == nsXULAtoms::xpmenu ||
tag.get() == nsXULAtoms::xpmenuitem) &&
!IsDisabled(aContent))
return PR_TRUE;
return PR_FALSE;
}
PRBool
nsMenuPopupFrame::IsDisabled(nsIContent* aContent)
{
nsString disabled = "";
aContent->GetAttribute(kNameSpaceID_None, nsHTMLAtoms::disabled, disabled);
if (disabled == "true")
return PR_TRUE;
return PR_FALSE;
}

View File

@ -74,6 +74,9 @@ public:
void Escape(PRBool& aHandledFlag);
void Enter();
PRBool IsValidItem(nsIContent* aContent);
PRBool IsDisabled(nsIContent* aContent);
protected:
nsIFrame* mCurrentMenu; // The current menu that is active.
PRBool mIsCapturingMouseEvents; // Whether or not we're grabbing the mouse events.