pull initial enabled state for menu items from command node, not their own DOM node. fixes keyboard command crashes. b=332949 r=mento sr=pinkerton

This commit is contained in:
joshmoz%gmail.com 2006-06-16 15:05:43 +00:00
parent 426c0e96c5
commit bc82b480b0
4 changed files with 17 additions and 15 deletions

View File

@ -78,9 +78,9 @@ class nsIMenuItem : public nsISupports {
* Creates the MenuItem
*
*/
NS_IMETHOD Create ( nsIMenu* aParent, const nsString & aLabel, PRBool isSeparator,
EMenuItemType aItemType, PRBool aEnabled,
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode ) = 0;
NS_IMETHOD Create(nsIMenu* aParent, const nsString & aLabel, PRBool isSeparator,
EMenuItemType aItemType, nsIChangeManager* aManager,
nsIDocShell* aShell, nsIContent* aNode) = 0;
/**
* Get the MenuItem label

View File

@ -69,8 +69,8 @@ public:
// nsIMenuItem Methods
NS_IMETHOD Create (nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
EMenuItemType aItemType, PRBool aEnabled,
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode);
EMenuItemType aItemType, nsIChangeManager* aManager,
nsIDocShell* aShell, nsIContent* aNode);
NS_IMETHOD GetLabel(nsString &aText);
NS_IMETHOD SetShortcutChar(const nsString &aText);
NS_IMETHOD GetShortcutChar(nsString &aText);

View File

@ -86,14 +86,13 @@ nsMenuItemX::~nsMenuItemX()
NS_METHOD nsMenuItemX::Create(nsIMenu* aParent, const nsString & aLabel, PRBool aIsSeparator,
EMenuItemType aItemType, PRBool aEnabled,
nsIChangeManager* aManager, nsIDocShell* aShell, nsIContent* aNode)
EMenuItemType aItemType, nsIChangeManager* aManager,
nsIDocShell* aShell, nsIContent* aNode)
{
mContent = aNode; // addref
mMenuParent = aParent; // weak
mDocShellWeakRef = do_GetWeakReference(aShell);
mEnabled = aEnabled;
mMenuType = aItemType;
// register for AttributeChanged messages
@ -122,6 +121,13 @@ NS_METHOD nsMenuItemX::Create(nsIMenu* aParent, const nsString & aLabel, PRBool
}
}
// set up mEnabled based on command content if it exists, otherwise do it based
// on our own content
if (mCommandContent)
mEnabled = !mCommandContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters);
else
mEnabled = !mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters);
mIsSeparator = aIsSeparator;
mLabel = aLabel;
@ -134,7 +140,7 @@ NS_METHOD nsMenuItemX::Create(nsIMenu* aParent, const nsString & aLabel, PRBool
mNativeMenuItem = [[NSMenuItem alloc] initWithTitle:newCocoaLabelString action:nil keyEquivalent:@""];
[newCocoaLabelString release];
[mNativeMenuItem setEnabled:(BOOL)aEnabled];
[mNativeMenuItem setEnabled:(BOOL)mEnabled];
}
return NS_OK;

View File

@ -596,10 +596,6 @@ void nsMenuX::LoadMenuItem(nsIMenu* inParentMenu, nsIContent* inMenuItemContent)
inMenuItemContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, menuitemName);
// printf("menuitem %s \n", NS_LossyConvertUTF16toASCII(menuitemName).get());
PRBool enabled =
! (inMenuItemContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
nsWidgetAtoms::_true, eCaseMatters));
static nsIContent::AttrValuesArray strings[] =
{&nsWidgetAtoms::checkbox, &nsWidgetAtoms::radio, nsnull};
@ -615,8 +611,8 @@ void nsMenuX::LoadMenuItem(nsIMenu* inParentMenu, nsIContent* inMenuItemContent)
return;
// Create the item.
pnsMenuItem->Create(inParentMenu, menuitemName, PR_FALSE, itemType,
enabled, mManager, docShell, inMenuItemContent);
pnsMenuItem->Create(inParentMenu, menuitemName, PR_FALSE, itemType, mManager,
docShell, inMenuItemContent);
// Set key shortcut and modifiers