2001-11-06 18:35:24 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
#include "nsMenuItemX.h"
|
|
|
|
#include "nsMenuBarX.h"
|
|
|
|
#include "nsMenuX.h"
|
|
|
|
#include "nsMenuItemIconX.h"
|
|
|
|
#include "nsMenuUtilsX.h"
|
2013-07-10 18:11:07 +04:00
|
|
|
#include "nsCocoaUtils.h"
|
2008-06-28 11:55:30 +04:00
|
|
|
|
|
|
|
#include "nsObjCExceptions.h"
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2011-10-14 22:11:22 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2010-06-24 01:35:57 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2001-11-06 18:35:24 +03:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2008-06-28 11:55:30 +04:00
|
|
|
#include "nsIDOMElement.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "nsIDOMEvent.h"
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
nsMenuItemX::nsMenuItemX()
|
|
|
|
{
|
2008-06-28 11:55:30 +04:00
|
|
|
mType = eRegularMenuItemType;
|
|
|
|
mNativeMenuItem = nil;
|
2012-07-30 18:20:58 +04:00
|
|
|
mMenuParent = nullptr;
|
|
|
|
mMenuGroupOwner = nullptr;
|
2011-10-01 04:20:33 +04:00
|
|
|
mIsChecked = false;
|
2008-06-28 11:55:30 +04:00
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(nsMenuItemX);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuItemX::~nsMenuItemX()
|
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-07-07 00:59:46 +04:00
|
|
|
// Prevent the icon object from outliving us.
|
|
|
|
if (mIcon)
|
|
|
|
mIcon->Destroy();
|
|
|
|
|
2009-02-21 00:55:25 +03:00
|
|
|
// autorelease the native menu item so that anything else happening to this
|
|
|
|
// object happens before the native menu item actually dies
|
2006-04-06 11:41:34 +04:00
|
|
|
[mNativeMenuItem autorelease];
|
2009-02-21 00:55:25 +03:00
|
|
|
|
2006-06-15 19:54:58 +04:00
|
|
|
if (mContent)
|
2010-01-27 09:14:40 +03:00
|
|
|
mMenuGroupOwner->UnregisterForContentChanges(mContent);
|
2006-06-15 19:54:58 +04:00
|
|
|
if (mCommandContent)
|
2010-01-27 09:14:40 +03:00
|
|
|
mMenuGroupOwner->UnregisterForContentChanges(mCommandContent);
|
2008-02-21 02:47:05 +03:00
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
MOZ_COUNT_DTOR(nsMenuItemX);
|
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
nsresult nsMenuItemX::Create(nsMenuX* aParent, const nsString& aLabel, EMenuItemType aItemType,
|
2010-01-27 09:14:40 +03:00
|
|
|
nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-09-15 02:04:59 +04:00
|
|
|
mType = aItemType;
|
2008-06-28 11:55:30 +04:00
|
|
|
mMenuParent = aParent;
|
|
|
|
mContent = aNode;
|
2007-09-15 02:04:59 +04:00
|
|
|
|
2010-01-27 09:14:40 +03:00
|
|
|
mMenuGroupOwner = aMenuGroupOwner;
|
|
|
|
NS_ASSERTION(mMenuGroupOwner, "No menu owner given, must have one!");
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2010-01-27 09:14:40 +03:00
|
|
|
mMenuGroupOwner->RegisterForContentChanges(mContent, this);
|
2008-01-23 07:04:15 +03:00
|
|
|
|
2010-06-24 01:35:57 +04:00
|
|
|
nsIDocument *doc = mContent->GetCurrentDoc();
|
2007-08-17 00:26:04 +04:00
|
|
|
|
2006-06-15 19:54:58 +04:00
|
|
|
// if we have a command associated with this menu item, register for changes
|
|
|
|
// to the command DOM node
|
2010-06-24 01:35:57 +04:00
|
|
|
if (doc) {
|
2007-08-17 00:26:04 +04:00
|
|
|
nsAutoString ourCommand;
|
2011-10-14 22:11:22 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::command, ourCommand);
|
2007-08-17 00:26:04 +04:00
|
|
|
|
|
|
|
if (!ourCommand.IsEmpty()) {
|
2010-06-24 01:35:57 +04:00
|
|
|
nsIContent *commandElement = doc->GetElementById(ourCommand);
|
2007-08-17 00:26:04 +04:00
|
|
|
|
|
|
|
if (commandElement) {
|
2010-06-24 01:35:57 +04:00
|
|
|
mCommandContent = commandElement;
|
2007-08-17 00:26:04 +04:00
|
|
|
// register to observe the command DOM element
|
2010-01-27 09:14:40 +03:00
|
|
|
mMenuGroupOwner->RegisterForContentChanges(mCommandContent, this);
|
2006-06-15 19:54:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-28 11:55:30 +04:00
|
|
|
|
|
|
|
// decide enabled state based on command content if it exists, otherwise do it based
|
2006-06-16 19:05:43 +04:00
|
|
|
// on our own content
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEnabled;
|
2006-06-16 19:05:43 +04:00
|
|
|
if (mCommandContent)
|
2011-10-14 22:11:22 +04:00
|
|
|
isEnabled = !mCommandContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled, nsGkAtoms::_true, eCaseMatters);
|
2006-06-16 19:05:43 +04:00
|
|
|
else
|
2011-10-14 22:11:22 +04:00
|
|
|
isEnabled = !mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled, nsGkAtoms::_true, eCaseMatters);
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2005-12-03 00:39:26 +03:00
|
|
|
// set up the native menu item
|
2008-06-28 11:55:30 +04:00
|
|
|
if (mType == eSeparatorMenuItemType) {
|
2005-12-03 00:39:26 +03:00
|
|
|
mNativeMenuItem = [[NSMenuItem separatorItem] retain];
|
|
|
|
}
|
|
|
|
else {
|
2009-04-30 10:48:14 +04:00
|
|
|
NSString *newCocoaLabelString = nsMenuUtilsX::GetTruncatedCocoaLabel(aLabel);
|
2005-12-03 00:39:26 +03:00
|
|
|
mNativeMenuItem = [[NSMenuItem alloc] initWithTitle:newCocoaLabelString action:nil keyEquivalent:@""];
|
2008-06-28 11:55:30 +04:00
|
|
|
|
|
|
|
[mNativeMenuItem setEnabled:(BOOL)isEnabled];
|
2007-08-17 00:26:04 +04:00
|
|
|
|
2011-10-14 22:11:22 +04:00
|
|
|
SetChecked(mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::checked,
|
|
|
|
nsGkAtoms::_true, eCaseMatters));
|
2011-02-13 15:28:00 +03:00
|
|
|
SetKeyEquiv();
|
2005-12-03 00:39:26 +03:00
|
|
|
}
|
2007-04-22 05:42:17 +04:00
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
mIcon = new nsMenuItemIconX(this, mContent, mNativeMenuItem);
|
|
|
|
if (!mIcon)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2008-06-27 10:52:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2008-06-27 10:52:18 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsMenuItemX::SetChecked(bool aIsChecked)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2005-12-03 00:39:26 +03:00
|
|
|
mIsChecked = aIsChecked;
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
// update the content model. This will also handle unchecking our siblings
|
|
|
|
// if we are a radiomenu
|
2011-10-14 22:11:22 +04:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::checked,
|
2011-10-01 04:20:33 +04:00
|
|
|
mIsChecked ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"), true);
|
2005-12-03 00:39:26 +03:00
|
|
|
|
|
|
|
// update native menu item
|
|
|
|
if (mIsChecked)
|
|
|
|
[mNativeMenuItem setState:NSOnState];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setState:NSOffState];
|
2001-11-06 18:35:24 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
EMenuItemType nsMenuItemX::GetMenuItemType()
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-06-28 11:55:30 +04:00
|
|
|
return mType;
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
|
2007-08-31 12:08:03 +04:00
|
|
|
// Executes the "cached" javaScript command.
|
|
|
|
// Returns NS_OK if the command was executed properly, otherwise an error code.
|
2008-06-28 11:55:30 +04:00
|
|
|
void nsMenuItemX::DoCommand()
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2006-12-18 23:14:47 +03:00
|
|
|
// flip "checked" state if we're a checkbox menu, or an un-checked radio menu
|
2008-06-28 11:55:30 +04:00
|
|
|
if (mType == eCheckboxMenuItemType ||
|
|
|
|
(mType == eRadioMenuItemType && !mIsChecked)) {
|
2011-10-14 22:11:22 +04:00
|
|
|
if (!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::autocheck,
|
|
|
|
nsGkAtoms::_false, eCaseMatters))
|
2006-12-18 23:14:47 +03:00
|
|
|
SetChecked(!mIsChecked);
|
|
|
|
/* the AttributeChanged code will update all the internal state */
|
|
|
|
}
|
|
|
|
|
2009-06-30 11:56:40 +04:00
|
|
|
nsMenuUtilsX::DispatchCommandTo(mContent);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
2006-03-15 02:58:57 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult nsMenuItemX::DispatchDOMEvent(const nsString &eventName, bool *preventDefaultCalled)
|
2006-03-15 02:58:57 +03:00
|
|
|
{
|
2006-03-15 08:22:53 +03:00
|
|
|
if (!mContent)
|
2006-03-15 03:23:31 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2006-03-15 03:23:31 +03:00
|
|
|
// get owner document for content
|
2011-10-18 14:53:36 +04:00
|
|
|
nsCOMPtr<nsIDocument> parentDoc = mContent->OwnerDoc();
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2006-03-15 03:23:31 +03:00
|
|
|
// get interface for creating DOM events from content owner document
|
2011-05-23 20:46:36 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(parentDoc);
|
|
|
|
if (!domDoc) {
|
|
|
|
NS_WARNING("Failed to QI parent nsIDocument to nsIDOMDocument");
|
2006-03-15 03:23:31 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2006-03-15 03:23:31 +03:00
|
|
|
// create DOM event
|
2006-03-15 19:52:31 +03:00
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
2011-05-23 20:46:36 +04:00
|
|
|
nsresult rv = domDoc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
2006-03-15 19:52:31 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to create nsIDOMEvent");
|
|
|
|
return rv;
|
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
event->InitEvent(eventName, true, true);
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2006-03-15 03:23:31 +03:00
|
|
|
// mark DOM event as trusted
|
2012-06-11 03:44:50 +04:00
|
|
|
event->SetTrusted(true);
|
2008-06-28 11:55:30 +04:00
|
|
|
|
2006-03-15 03:23:31 +03:00
|
|
|
// send DOM event
|
2013-04-20 02:18:32 +04:00
|
|
|
rv = mContent->DispatchEvent(event, preventDefaultCalled);
|
2006-03-15 03:23:31 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2013-04-22 05:25:28 +04:00
|
|
|
NS_WARNING("Failed to send DOM event via EventTarget");
|
2006-03-15 19:52:31 +03:00
|
|
|
return rv;
|
2006-03-15 03:23:31 +03:00
|
|
|
}
|
2007-08-31 12:08:03 +04:00
|
|
|
|
2013-04-20 02:18:32 +04:00
|
|
|
return NS_OK;
|
2008-06-27 10:52:18 +04:00
|
|
|
}
|
|
|
|
|
2007-08-31 12:08:03 +04:00
|
|
|
// Walk the sibling list looking for nodes with the same name and
|
2001-11-06 18:35:24 +03:00
|
|
|
// uncheck them all.
|
2008-06-28 11:55:30 +04:00
|
|
|
void nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
|
|
|
nsAutoString myGroupName;
|
2011-10-14 22:11:22 +04:00
|
|
|
inCheckedContent->GetAttr(kNameSpaceID_None, nsGkAtoms::name, myGroupName);
|
2005-12-03 00:39:26 +03:00
|
|
|
if (!myGroupName.Length()) // no groupname, nothing to do
|
2001-11-06 18:35:24 +03:00
|
|
|
return;
|
2013-04-20 02:18:32 +04:00
|
|
|
|
2003-07-29 01:35:53 +04:00
|
|
|
nsCOMPtr<nsIContent> parent = inCheckedContent->GetParent();
|
2005-12-03 00:39:26 +03:00
|
|
|
if (!parent)
|
2001-11-06 18:35:24 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
// loop over siblings
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = parent->GetChildCount();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2003-10-01 01:04:27 +04:00
|
|
|
nsIContent *sibling = parent->GetChildAt(i);
|
2005-12-03 00:39:26 +03:00
|
|
|
if (sibling) {
|
|
|
|
if (sibling != inCheckedContent) { // skip this node
|
2001-11-06 18:35:24 +03:00
|
|
|
// if the current sibling is in the same group, clear it
|
2011-10-14 22:11:22 +04:00
|
|
|
if (sibling->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
2006-06-09 10:02:30 +04:00
|
|
|
myGroupName, eCaseMatters))
|
2011-10-14 22:11:22 +04:00
|
|
|
sibling->SetAttr(kNameSpaceID_None, nsGkAtoms::checked, NS_LITERAL_STRING("false"), true);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
|
|
|
}
|
2007-08-31 12:08:03 +04:00
|
|
|
}
|
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2011-02-13 15:28:00 +03:00
|
|
|
void nsMenuItemX::SetKeyEquiv()
|
2008-01-29 09:11:06 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2011-02-13 15:28:00 +03:00
|
|
|
// Set key shortcut and modifiers
|
|
|
|
nsAutoString keyValue;
|
2011-10-14 22:11:22 +04:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyValue);
|
2011-02-13 15:28:00 +03:00
|
|
|
if (!keyValue.IsEmpty() && mContent->GetCurrentDoc()) {
|
|
|
|
nsIContent *keyContent = mContent->GetCurrentDoc()->GetElementById(keyValue);
|
|
|
|
if (keyContent) {
|
2010-01-22 22:24:00 +03:00
|
|
|
nsAutoString keyChar;
|
|
|
|
bool hasKey = keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyChar);
|
|
|
|
|
|
|
|
if (!hasKey || keyChar.IsEmpty()) {
|
|
|
|
nsAutoString keyCodeName;
|
|
|
|
keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::keycode, keyCodeName);
|
2013-07-10 18:11:07 +04:00
|
|
|
uint32_t charCode =
|
|
|
|
nsCocoaUtils::ConvertGeckoNameToMacCharCode(keyCodeName);
|
|
|
|
if (charCode) {
|
|
|
|
keyChar.Assign(charCode);
|
2010-01-22 22:24:00 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
keyChar.Assign(NS_LITERAL_STRING(" "));
|
|
|
|
}
|
|
|
|
}
|
2011-02-13 15:28:00 +03:00
|
|
|
|
|
|
|
nsAutoString modifiersStr;
|
2011-10-14 22:11:22 +04:00
|
|
|
keyContent->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiersStr);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t modifiers = nsMenuUtilsX::GeckoModifiersForNodeAttribute(modifiersStr);
|
2011-02-13 15:28:00 +03:00
|
|
|
|
|
|
|
unsigned int macModifiers = nsMenuUtilsX::MacModifiersForGeckoModifiers(modifiers);
|
|
|
|
[mNativeMenuItem setKeyEquivalentModifierMask:macModifiers];
|
|
|
|
|
|
|
|
NSString *keyEquivalent = [[NSString stringWithCharacters:(unichar*)keyChar.get()
|
|
|
|
length:keyChar.Length()] lowercaseString];
|
|
|
|
if ([keyEquivalent isEqualToString:@" "])
|
|
|
|
[mNativeMenuItem setKeyEquivalent:@""];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setKeyEquivalent:keyEquivalent];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2008-01-29 09:11:06 +03:00
|
|
|
|
2011-02-13 15:28:00 +03:00
|
|
|
// if the key was removed, clear the key
|
|
|
|
[mNativeMenuItem setKeyEquivalent:@""];
|
2008-01-29 09:11:06 +03:00
|
|
|
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2008-01-29 09:11:06 +03:00
|
|
|
}
|
|
|
|
|
2001-11-06 18:35:24 +03:00
|
|
|
//
|
2008-01-23 07:04:15 +03:00
|
|
|
// nsChangeObserver
|
2001-11-06 18:35:24 +03:00
|
|
|
//
|
|
|
|
|
2008-01-23 07:04:15 +03:00
|
|
|
void
|
|
|
|
nsMenuItemX::ObserveAttributeChanged(nsIDocument *aDocument, nsIContent *aContent, nsIAtom *aAttribute)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2008-02-21 02:47:05 +03:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2006-06-15 19:54:58 +04:00
|
|
|
if (!aContent)
|
2008-01-23 07:04:15 +03:00
|
|
|
return;
|
2006-06-15 19:54:58 +04:00
|
|
|
|
|
|
|
if (aContent == mContent) { // our own content node changed
|
2011-10-14 22:11:22 +04:00
|
|
|
if (aAttribute == nsGkAtoms::checked) {
|
2006-06-15 19:54:58 +04:00
|
|
|
// if we're a radio menu, uncheck our sibling radio items. No need to
|
|
|
|
// do any of this if we're just a normal check menu.
|
2008-06-28 11:55:30 +04:00
|
|
|
if (mType == eRadioMenuItemType) {
|
2011-10-14 22:11:22 +04:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::checked,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
2006-06-15 19:54:58 +04:00
|
|
|
UncheckRadioSiblings(mContent);
|
|
|
|
}
|
2011-10-01 04:20:33 +04:00
|
|
|
mMenuParent->SetRebuild(true);
|
2006-06-15 19:54:58 +04:00
|
|
|
}
|
2011-10-14 22:11:22 +04:00
|
|
|
else if (aAttribute == nsGkAtoms::hidden ||
|
|
|
|
aAttribute == nsGkAtoms::collapsed ||
|
|
|
|
aAttribute == nsGkAtoms::label) {
|
2011-10-01 04:20:33 +04:00
|
|
|
mMenuParent->SetRebuild(true);
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
2011-10-14 22:11:22 +04:00
|
|
|
else if (aAttribute == nsGkAtoms::key) {
|
2011-02-13 15:28:00 +03:00
|
|
|
SetKeyEquiv();
|
|
|
|
}
|
2011-10-14 22:11:22 +04:00
|
|
|
else if (aAttribute == nsGkAtoms::image) {
|
2007-04-22 05:42:17 +04:00
|
|
|
SetupIcon();
|
|
|
|
}
|
2011-10-14 22:11:22 +04:00
|
|
|
else if (aAttribute == nsGkAtoms::disabled) {
|
|
|
|
if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled, nsGkAtoms::_true, eCaseMatters))
|
2006-10-11 19:53:24 +04:00
|
|
|
[mNativeMenuItem setEnabled:NO];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setEnabled:YES];
|
|
|
|
}
|
2005-12-03 00:39:26 +03:00
|
|
|
}
|
2006-06-15 19:54:58 +04:00
|
|
|
else if (aContent == mCommandContent) {
|
|
|
|
// the only thing that really matters when the menu isn't showing is the
|
|
|
|
// enabled state since it enables/disables keyboard commands
|
2011-10-14 22:11:22 +04:00
|
|
|
if (aAttribute == nsGkAtoms::disabled) {
|
2006-06-15 19:54:58 +04:00
|
|
|
// first we sync our menu item DOM node with the command DOM node
|
|
|
|
nsAutoString commandDisabled;
|
|
|
|
nsAutoString menuDisabled;
|
2011-10-14 22:11:22 +04:00
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandDisabled);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::disabled, menuDisabled);
|
2006-06-15 19:54:58 +04:00
|
|
|
if (!commandDisabled.Equals(menuDisabled)) {
|
|
|
|
// The menu's disabled state needs to be updated to match the command.
|
|
|
|
if (commandDisabled.IsEmpty())
|
2011-10-14 22:11:22 +04:00
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsGkAtoms::disabled, true);
|
2006-06-15 19:54:58 +04:00
|
|
|
else
|
2011-10-14 22:11:22 +04:00
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::disabled, commandDisabled, true);
|
2006-06-15 19:54:58 +04:00
|
|
|
}
|
|
|
|
// now we sync our native menu item with the command DOM node
|
2011-10-14 22:11:22 +04:00
|
|
|
if (aContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled, nsGkAtoms::_true, eCaseMatters))
|
2006-06-15 19:54:58 +04:00
|
|
|
[mNativeMenuItem setEnabled:NO];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setEnabled:YES];
|
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
}
|
2008-02-21 02:47:05 +03:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-08-31 12:08:03 +04:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void nsMenuItemX::ObserveContentRemoved(nsIDocument *aDocument, nsIContent *aChild, int32_t aIndexInContainer)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2006-06-15 19:54:58 +04:00
|
|
|
if (aChild == mCommandContent) {
|
2010-01-27 09:14:40 +03:00
|
|
|
mMenuGroupOwner->UnregisterForContentChanges(mCommandContent);
|
2012-07-30 18:20:58 +04:00
|
|
|
mCommandContent = nullptr;
|
2006-06-15 19:54:58 +04:00
|
|
|
}
|
2007-11-09 20:38:33 +03:00
|
|
|
|
2011-10-01 04:20:33 +04:00
|
|
|
mMenuParent->SetRebuild(true);
|
2007-08-31 12:08:03 +04:00
|
|
|
}
|
2001-11-06 18:35:24 +03:00
|
|
|
|
2011-06-03 02:37:18 +04:00
|
|
|
void nsMenuItemX::ObserveContentInserted(nsIDocument *aDocument, nsIContent* aContainer,
|
|
|
|
nsIContent *aChild)
|
2001-11-06 18:35:24 +03:00
|
|
|
{
|
2011-10-01 04:20:33 +04:00
|
|
|
mMenuParent->SetRebuild(true);
|
2007-08-31 12:08:03 +04:00
|
|
|
}
|
2006-08-01 05:25:43 +04:00
|
|
|
|
2008-06-28 11:55:30 +04:00
|
|
|
void nsMenuItemX::SetupIcon()
|
2008-06-27 10:52:18 +04:00
|
|
|
{
|
2008-06-28 11:55:30 +04:00
|
|
|
if (mIcon)
|
|
|
|
mIcon->SetupIcon();
|
2007-03-23 03:57:45 +03:00
|
|
|
}
|