2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Josh Aas <josh@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
#include "nsMenuItemX.h"
|
|
|
|
#include "nsMenuBarX.h"
|
|
|
|
#include "nsMenuX.h"
|
|
|
|
#include "nsMenuItemIconX.h"
|
|
|
|
#include "nsMenuUtilsX.h"
|
|
|
|
|
|
|
|
#include "nsObjCExceptions.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2008-06-28 00:55:30 -07:00
|
|
|
#include "nsWidgetAtoms.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
|
2010-06-21 22:39:53 -07:00
|
|
|
#include "nsIContent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
2007-05-14 02:11:38 -07:00
|
|
|
#include "nsIDOMEventTarget.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMDocumentEvent.h"
|
2008-06-28 00:55:30 -07:00
|
|
|
#include "nsIDOMElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsMenuItemX::nsMenuItemX()
|
|
|
|
{
|
2008-06-28 00:55:30 -07:00
|
|
|
mType = eRegularMenuItemType;
|
|
|
|
mNativeMenuItem = nil;
|
|
|
|
mMenuParent = nsnull;
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner = nsnull;
|
2008-06-28 00:55:30 -07:00
|
|
|
mIsChecked = PR_FALSE;
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(nsMenuItemX);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuItemX::~nsMenuItemX()
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2009-07-06 13:59:46 -07:00
|
|
|
// Prevent the icon object from outliving us.
|
|
|
|
if (mIcon)
|
|
|
|
mIcon->Destroy();
|
|
|
|
|
2009-02-20 13:55:25 -08:00
|
|
|
// autorelease the native menu item so that anything else happening to this
|
|
|
|
// object happens before the native menu item actually dies
|
2007-03-22 10:30:00 -07:00
|
|
|
[mNativeMenuItem autorelease];
|
2009-02-20 13:55:25 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mContent)
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner->UnregisterForContentChanges(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCommandContent)
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner->UnregisterForContentChanges(mCommandContent);
|
2008-02-20 15:47:05 -08:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
MOZ_COUNT_DTOR(nsMenuItemX);
|
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
nsresult nsMenuItemX::Create(nsMenuX* aParent, const nsString& aLabel, EMenuItemType aItemType,
|
2010-01-26 22:14:40 -08:00
|
|
|
nsMenuGroupOwnerX* aMenuGroupOwner, nsIContent* aNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-09-14 15:04:59 -07:00
|
|
|
mType = aItemType;
|
2008-06-28 00:55:30 -07:00
|
|
|
mMenuParent = aParent;
|
|
|
|
mContent = aNode;
|
2007-09-14 15:04:59 -07:00
|
|
|
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner = aMenuGroupOwner;
|
|
|
|
NS_ASSERTION(mMenuGroupOwner, "No menu owner given, must have one!");
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner->RegisterForContentChanges(mContent, this);
|
2008-01-22 20:04:15 -08:00
|
|
|
|
2010-06-21 22:39:53 -07:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(mContent->GetCurrentDoc()));
|
2007-08-16 13:26:04 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// if we have a command associated with this menu item, register for changes
|
|
|
|
// to the command DOM node
|
2010-06-21 22:39:53 -07:00
|
|
|
if (domDoc) {
|
2007-08-16 13:26:04 -07:00
|
|
|
nsAutoString ourCommand;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::command, ourCommand);
|
|
|
|
|
|
|
|
if (!ourCommand.IsEmpty()) {
|
2010-06-21 22:39:53 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> commandElement;
|
|
|
|
domDoc->GetElementById(ourCommand, getter_AddRefs(commandElement));
|
2007-08-16 13:26:04 -07:00
|
|
|
|
|
|
|
if (commandElement) {
|
2010-06-21 22:39:53 -07:00
|
|
|
mCommandContent = do_QueryInterface(commandElement);
|
2007-08-16 13:26:04 -07:00
|
|
|
// register to observe the command DOM element
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner->RegisterForContentChanges(mCommandContent, this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-28 00:55:30 -07:00
|
|
|
|
|
|
|
// decide enabled state based on command content if it exists, otherwise do it based
|
2007-03-22 10:30:00 -07:00
|
|
|
// on our own content
|
2008-06-28 00:55:30 -07:00
|
|
|
PRBool isEnabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCommandContent)
|
2008-06-28 00:55:30 -07:00
|
|
|
isEnabled = !mCommandContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters);
|
2007-03-22 10:30:00 -07:00
|
|
|
else
|
2008-06-28 00:55:30 -07:00
|
|
|
isEnabled = !mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// set up the native menu item
|
2008-06-28 00:55:30 -07:00
|
|
|
if (mType == eSeparatorMenuItemType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mNativeMenuItem = [[NSMenuItem separatorItem] retain];
|
|
|
|
}
|
|
|
|
else {
|
2009-04-29 23:48:14 -07:00
|
|
|
NSString *newCocoaLabelString = nsMenuUtilsX::GetTruncatedCocoaLabel(aLabel);
|
2007-03-22 10:30:00 -07:00
|
|
|
mNativeMenuItem = [[NSMenuItem alloc] initWithTitle:newCocoaLabelString action:nil keyEquivalent:@""];
|
2008-06-28 00:55:30 -07:00
|
|
|
|
|
|
|
[mNativeMenuItem setEnabled:(BOOL)isEnabled];
|
2007-08-16 13:26:04 -07:00
|
|
|
|
|
|
|
SetChecked(mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
|
|
|
|
nsWidgetAtoms::_true, eCaseMatters));
|
|
|
|
|
|
|
|
// Set key shortcut and modifiers
|
2010-06-21 22:39:53 -07:00
|
|
|
if (domDoc) {
|
2007-08-16 13:26:04 -07:00
|
|
|
nsAutoString keyValue;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::key, keyValue);
|
|
|
|
if (!keyValue.IsEmpty()) {
|
2010-06-21 22:39:53 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> keyElement;
|
|
|
|
domDoc->GetElementById(keyValue, getter_AddRefs(keyElement));
|
|
|
|
if (keyElement) {
|
|
|
|
nsCOMPtr<nsIContent> keyContent(do_QueryInterface(keyElement));
|
2007-08-16 13:26:04 -07:00
|
|
|
nsAutoString keyChar(NS_LITERAL_STRING(" "));
|
|
|
|
keyContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::key, keyChar);
|
2008-01-28 22:11:06 -08:00
|
|
|
|
2007-08-16 13:26:04 -07:00
|
|
|
nsAutoString modifiersStr;
|
|
|
|
keyContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::modifiers, modifiersStr);
|
2008-06-28 00:55:30 -07:00
|
|
|
PRUint8 modifiers = nsMenuUtilsX::GeckoModifiersForNodeAttribute(modifiersStr);
|
2008-01-28 22:11:06 -08:00
|
|
|
|
|
|
|
SetKeyEquiv(modifiers, keyChar);
|
2007-08-16 13:26:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-21 18:42:17 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
mIcon = new nsMenuItemIconX(this, mContent, mNativeMenuItem);
|
|
|
|
if (!mIcon)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-26 23:52:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2008-06-26 23:52:18 -07:00
|
|
|
}
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
nsresult nsMenuItemX::SetChecked(PRBool aIsChecked)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mIsChecked = aIsChecked;
|
|
|
|
|
|
|
|
// update the content model. This will also handle unchecking our siblings
|
|
|
|
// if we are a radiomenu
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked,
|
|
|
|
mIsChecked ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"), PR_TRUE);
|
|
|
|
|
|
|
|
// update native menu item
|
|
|
|
if (mIsChecked)
|
|
|
|
[mNativeMenuItem setState:NSOnState];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setState:NSOffState];
|
|
|
|
|
|
|
|
return NS_OK;
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
EMenuItemType nsMenuItemX::GetMenuItemType()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-06-28 00:55:30 -07:00
|
|
|
return mType;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-31 01:08:03 -07:00
|
|
|
// Executes the "cached" javaScript command.
|
|
|
|
// Returns NS_OK if the command was executed properly, otherwise an error code.
|
2008-06-28 00:55:30 -07:00
|
|
|
void nsMenuItemX::DoCommand()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// flip "checked" state if we're a checkbox menu, or an un-checked radio menu
|
2008-06-28 00:55:30 -07:00
|
|
|
if (mType == eCheckboxMenuItemType ||
|
|
|
|
(mType == eRadioMenuItemType && !mIsChecked)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::autocheck,
|
|
|
|
nsWidgetAtoms::_false, eCaseMatters))
|
|
|
|
SetChecked(!mIsChecked);
|
|
|
|
/* the AttributeChanged code will update all the internal state */
|
|
|
|
}
|
|
|
|
|
2009-06-30 00:56:40 -07:00
|
|
|
nsMenuUtilsX::DispatchCommandTo(mContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
nsresult nsMenuItemX::DispatchDOMEvent(const nsString &eventName, PRBool *preventDefaultCalled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// get owner document for content
|
|
|
|
nsCOMPtr<nsIDocument> parentDoc = mContent->GetOwnerDoc();
|
|
|
|
if (!parentDoc) {
|
|
|
|
NS_WARNING("Failed to get owner nsIDocument for menu item content");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// get interface for creating DOM events from content owner document
|
|
|
|
nsCOMPtr<nsIDOMDocumentEvent> DOMEventFactory = do_QueryInterface(parentDoc);
|
|
|
|
if (!DOMEventFactory) {
|
|
|
|
NS_WARNING("Failed to QI parent nsIDocument to nsIDOMDocumentEvent");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// create DOM event
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
nsresult rv = DOMEventFactory->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to create nsIDOMEvent");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
event->InitEvent(eventName, PR_TRUE, PR_TRUE);
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// mark DOM event as trusted
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event));
|
|
|
|
privateEvent->SetTrusted(PR_TRUE);
|
2008-06-28 00:55:30 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// send DOM event
|
|
|
|
nsCOMPtr<nsIDOMEventTarget> eventTarget = do_QueryInterface(mContent);
|
|
|
|
rv = eventTarget->DispatchEvent(event, preventDefaultCalled);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to send DOM event via nsIDOMEventTarget");
|
|
|
|
return rv;
|
|
|
|
}
|
2007-08-31 01:08:03 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
return NS_OK;
|
2008-06-26 23:52:18 -07:00
|
|
|
}
|
|
|
|
|
2007-08-31 01:08:03 -07:00
|
|
|
// Walk the sibling list looking for nodes with the same name and
|
2007-03-22 10:30:00 -07:00
|
|
|
// uncheck them all.
|
2008-06-28 00:55:30 -07:00
|
|
|
void nsMenuItemX::UncheckRadioSiblings(nsIContent* inCheckedContent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAutoString myGroupName;
|
|
|
|
inCheckedContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::name, myGroupName);
|
|
|
|
if (!myGroupName.Length()) // no groupname, nothing to do
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> parent = inCheckedContent->GetParent();
|
|
|
|
if (!parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// loop over siblings
|
|
|
|
PRUint32 count = parent->GetChildCount();
|
|
|
|
for (PRUint32 i = 0; i < count; i++) {
|
|
|
|
nsIContent *sibling = parent->GetChildAt(i);
|
|
|
|
if (sibling) {
|
|
|
|
if (sibling != inCheckedContent) { // skip this node
|
|
|
|
// if the current sibling is in the same group, clear it
|
|
|
|
if (sibling->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::name,
|
|
|
|
myGroupName, eCaseMatters))
|
|
|
|
sibling->SetAttr(kNameSpaceID_None, nsWidgetAtoms::checked, NS_LITERAL_STRING("false"), PR_TRUE);
|
|
|
|
}
|
|
|
|
}
|
2007-08-31 01:08:03 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-28 22:11:06 -08:00
|
|
|
void nsMenuItemX::SetKeyEquiv(PRUint8 aModifiers, const nsString &aText)
|
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
unsigned int macModifiers = nsMenuUtilsX::MacModifiersForGeckoModifiers(aModifiers);
|
2008-01-28 22:11:06 -08:00
|
|
|
[mNativeMenuItem setKeyEquivalentModifierMask:macModifiers];
|
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
NSString *keyEquivalent = [[NSString stringWithCharacters:(unichar*)aText.get()
|
|
|
|
length:aText.Length()] lowercaseString];
|
2008-01-28 22:11:06 -08:00
|
|
|
if ([keyEquivalent isEqualToString:@" "])
|
|
|
|
[mNativeMenuItem setKeyEquivalent:@""];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setKeyEquivalent:keyEquivalent];
|
|
|
|
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2008-01-28 22:11:06 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2008-01-22 20:04:15 -08:00
|
|
|
// nsChangeObserver
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
|
2008-01-22 20:04:15 -08:00
|
|
|
void
|
|
|
|
nsMenuItemX::ObserveAttributeChanged(nsIDocument *aDocument, nsIContent *aContent, nsIAtom *aAttribute)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-20 15:47:05 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aContent)
|
2008-01-22 20:04:15 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (aContent == mContent) { // our own content node changed
|
|
|
|
if (aAttribute == nsWidgetAtoms::checked) {
|
|
|
|
// 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 00:55:30 -07:00
|
|
|
if (mType == eRadioMenuItemType) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
|
|
|
|
nsWidgetAtoms::_true, eCaseMatters))
|
|
|
|
UncheckRadioSiblings(mContent);
|
|
|
|
}
|
2007-11-09 09:38:33 -08:00
|
|
|
mMenuParent->SetRebuild(PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else if (aAttribute == nsWidgetAtoms::hidden ||
|
|
|
|
aAttribute == nsWidgetAtoms::collapsed ||
|
|
|
|
aAttribute == nsWidgetAtoms::label) {
|
2007-11-09 09:38:33 -08:00
|
|
|
mMenuParent->SetRebuild(PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-04-21 18:42:17 -07:00
|
|
|
else if (aAttribute == nsWidgetAtoms::image) {
|
|
|
|
SetupIcon();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (aAttribute == nsWidgetAtoms::disabled) {
|
|
|
|
if (aContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters))
|
|
|
|
[mNativeMenuItem setEnabled:NO];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setEnabled:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
if (aAttribute == nsWidgetAtoms::disabled) {
|
|
|
|
// first we sync our menu item DOM node with the command DOM node
|
|
|
|
nsAutoString commandDisabled;
|
|
|
|
nsAutoString menuDisabled;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled);
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, menuDisabled);
|
|
|
|
if (!commandDisabled.Equals(menuDisabled)) {
|
|
|
|
// The menu's disabled state needs to be updated to match the command.
|
|
|
|
if (commandDisabled.IsEmpty())
|
|
|
|
mContent->UnsetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, PR_TRUE);
|
|
|
|
else
|
|
|
|
mContent->SetAttr(kNameSpaceID_None, nsWidgetAtoms::disabled, commandDisabled, PR_TRUE);
|
|
|
|
}
|
|
|
|
// now we sync our native menu item with the command DOM node
|
|
|
|
if (aContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters))
|
|
|
|
[mNativeMenuItem setEnabled:NO];
|
|
|
|
else
|
|
|
|
[mNativeMenuItem setEnabled:YES];
|
|
|
|
}
|
|
|
|
}
|
2008-02-20 15:47:05 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-08-31 01:08:03 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
void nsMenuItemX::ObserveContentRemoved(nsIDocument *aDocument, nsIContent *aChild, PRInt32 aIndexInContainer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aChild == mCommandContent) {
|
2010-01-26 22:14:40 -08:00
|
|
|
mMenuGroupOwner->UnregisterForContentChanges(mCommandContent);
|
2007-03-22 10:30:00 -07:00
|
|
|
mCommandContent = nsnull;
|
|
|
|
}
|
2007-11-09 09:38:33 -08:00
|
|
|
|
|
|
|
mMenuParent->SetRebuild(PR_TRUE);
|
2007-08-31 01:08:03 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
void nsMenuItemX::ObserveContentInserted(nsIDocument *aDocument, nsIContent *aChild, PRInt32 aIndexInContainer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-11-09 09:38:33 -08:00
|
|
|
mMenuParent->SetRebuild(PR_TRUE);
|
2007-08-31 01:08:03 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-06-28 00:55:30 -07:00
|
|
|
void nsMenuItemX::SetupIcon()
|
2008-06-26 23:52:18 -07:00
|
|
|
{
|
2008-06-28 00:55:30 -07:00
|
|
|
if (mIcon)
|
|
|
|
mIcon->SetupIcon();
|
2007-03-22 17:57:45 -07:00
|
|
|
}
|