2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
#include "XULMenuAccessible.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-05-27 02:01:40 -07:00
|
|
|
#include "DocAccessible.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2011-04-09 16:38:06 -07:00
|
|
|
#include "States.h"
|
2012-04-12 04:11:40 -07:00
|
|
|
#include "XULFormControlAccessible.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIMutableArray.h"
|
2007-11-21 22:14:39 -08:00
|
|
|
#include "nsIDOMXULContainerElement.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
|
|
|
#include "nsIDOMXULMultSelectCntrlEl.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIContent.h"
|
2011-09-27 18:46:11 -07:00
|
|
|
#include "nsMenuBarFrame.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-01 18:05:12 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-09-08 19:27:12 -07:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2011-06-01 18:05:12 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenuitemAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::
|
|
|
|
XULMenuitemAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t state = Accessible::NativeState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Has Popup?
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->NodeInfo()->Equals(nsGkAtoms::menu, kNameSpaceID_XUL)) {
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::HASPOPUP;
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::open))
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::EXPANDED;
|
2010-06-11 01:23:18 -07:00
|
|
|
else
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::COLLAPSED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
// Checkable/checked?
|
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 07:20:58 -07:00
|
|
|
{ &nsGkAtoms::radio, &nsGkAtoms::checkbox, nullptr };
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type, strings,
|
|
|
|
eCaseMatters) >= 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Checkable?
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::CHECKABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Checked?
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::checked,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::CHECKED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-06-13 03:54:07 -07:00
|
|
|
// Combo box listitem
|
2012-01-11 19:07:35 -08:00
|
|
|
bool isComboboxOption = (Role() == roles::COMBOBOX_OPTION);
|
2008-01-16 22:30:15 -08:00
|
|
|
if (isComboboxOption) {
|
2007-06-13 03:54:07 -07:00
|
|
|
// Is selected?
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isSelected = false;
|
2007-06-13 03:54:07 -07:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement>
|
2010-06-11 01:23:18 -07:00
|
|
|
item(do_QueryInterface(mContent));
|
2011-04-09 16:38:06 -07:00
|
|
|
NS_ENSURE_TRUE(item, state);
|
2007-06-13 03:54:07 -07:00
|
|
|
item->GetSelected(&isSelected);
|
|
|
|
|
|
|
|
// Is collapsed?
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCollapsed = false;
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = Parent();
|
2011-07-23 01:38:33 -07:00
|
|
|
if (parent && parent->State() & states::INVISIBLE)
|
2011-10-17 07:59:28 -07:00
|
|
|
isCollapsed = true;
|
2010-01-11 06:14:06 -08:00
|
|
|
|
2007-06-13 03:54:07 -07:00
|
|
|
if (isSelected) {
|
2011-04-09 16:38:06 -07:00
|
|
|
state |= states::SELECTED;
|
2010-01-11 06:14:06 -08:00
|
|
|
|
2007-06-13 03:54:07 -07:00
|
|
|
// Selected and collapsed?
|
|
|
|
if (isCollapsed) {
|
|
|
|
// Set selected option offscreen/invisible according to combobox state
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* grandParent = parent->Parent();
|
2011-07-23 01:38:33 -07:00
|
|
|
if (!grandParent)
|
|
|
|
return state;
|
2012-01-11 19:07:35 -08:00
|
|
|
NS_ASSERTION(grandParent->Role() == roles::COMBOBOX,
|
2007-06-13 03:54:07 -07:00
|
|
|
"grandparent of combobox listitem is not combobox");
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t grandParentState = grandParent->State();
|
2011-04-09 16:38:06 -07:00
|
|
|
state &= ~(states::OFFSCREEN | states::INVISIBLE);
|
|
|
|
state |= (grandParentState & states::OFFSCREEN) |
|
|
|
|
(grandParentState & states::INVISIBLE) |
|
|
|
|
(grandParentState & states::OPAQUE1);
|
2007-06-13 03:54:07 -07:00
|
|
|
} // isCollapsed
|
|
|
|
} // isSelected
|
2007-11-15 11:46:29 -08:00
|
|
|
} // ROLE_COMBOBOX_OPTION
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::NativeInteractiveState() const
|
2012-06-03 22:41:06 -07:00
|
|
|
{
|
|
|
|
if (NativelyUnavailable()) {
|
|
|
|
// Note: keep in sinc with nsXULPopupManager::IsValidMenuItem() logic.
|
|
|
|
bool skipNavigatingDisabledMenuItem = true;
|
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(GetFrame());
|
2012-06-10 16:44:50 -07:00
|
|
|
if (!menuFrame || !menuFrame->IsOnMenuBar()) {
|
2012-06-03 22:41:06 -07:00
|
|
|
skipNavigatingDisabledMenuItem = LookAndFeel::
|
|
|
|
GetInt(LookAndFeel::eIntID_SkipNavigatingDisabledMenuItem, 0) != 0;
|
2008-01-16 22:30:15 -08:00
|
|
|
}
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
if (skipNavigatingDisabledMenuItem)
|
|
|
|
return states::UNAVAILABLE;
|
2008-01-16 22:30:15 -08:00
|
|
|
|
2012-06-03 22:41:06 -07:00
|
|
|
return states::UNAVAILABLE | states::FOCUSABLE | states::SELECTABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return states::FOCUSABLE | states::SELECTABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
XULMenuitemAccessible::NativeName(nsString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-23 06:14:05 -07:00
|
|
|
void
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::Description(nsString& aDescription)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::description,
|
2010-06-11 01:23:18 -07:00
|
|
|
aDescription);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
KeyBinding
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::AccessKey() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-07-19 01:30:24 -07:00
|
|
|
// Return menu accesskey: N or Alt+F.
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t gMenuAccesskeyModifier = -1; // magic value of -1 indicates unitialized state
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
// We do not use nsCoreUtils::GetAccesskeyFor() because accesskeys for
|
2014-03-31 21:09:23 -07:00
|
|
|
// menu are't registered by EventStateManager.
|
2010-06-11 01:23:18 -07:00
|
|
|
nsAutoString accesskey;
|
2011-06-03 14:35:17 -07:00
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey,
|
2010-06-11 01:23:18 -07:00
|
|
|
accesskey);
|
|
|
|
if (accesskey.IsEmpty())
|
2011-07-19 01:30:24 -07:00
|
|
|
return KeyBinding();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t modifierKey = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parentAcc = Parent();
|
2010-06-11 01:23:18 -07:00
|
|
|
if (parentAcc) {
|
2012-01-11 19:07:35 -08:00
|
|
|
if (parentAcc->NativeRole() == roles::MENUBAR) {
|
2010-06-11 01:23:18 -07:00
|
|
|
// If top level menu item, add Alt+ or whatever modifier text to string
|
|
|
|
// No need to cache pref service, this happens rarely
|
|
|
|
if (gMenuAccesskeyModifier == -1) {
|
|
|
|
// Need to initialize cached global accesskey pref
|
2011-06-01 18:05:12 -07:00
|
|
|
gMenuAccesskeyModifier = Preferences::GetInt("ui.key.menuAccessKey", 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
|
|
|
|
switch (gMenuAccesskeyModifier) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
2011-07-19 01:30:24 -07:00
|
|
|
modifierKey = KeyBinding::kControl;
|
2010-06-11 01:23:18 -07:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT:
|
2011-07-19 01:30:24 -07:00
|
|
|
modifierKey = KeyBinding::kAlt;
|
2010-06-11 01:23:18 -07:00
|
|
|
break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META:
|
2011-07-19 01:30:24 -07:00
|
|
|
modifierKey = KeyBinding::kMeta;
|
2010-06-11 01:23:18 -07:00
|
|
|
break;
|
2012-07-18 18:28:16 -07:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_WIN:
|
|
|
|
modifierKey = KeyBinding::kOS;
|
|
|
|
break;
|
2010-06-11 01:23:18 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
return KeyBinding(accesskey[0], modifierKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
KeyBinding
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::KeyboardShortcut() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-07-19 01:30:24 -07:00
|
|
|
nsAutoString keyElmId;
|
|
|
|
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyElmId);
|
|
|
|
if (keyElmId.IsEmpty())
|
|
|
|
return KeyBinding();
|
|
|
|
|
2011-10-18 04:19:44 -07:00
|
|
|
nsIContent* keyElm = mContent->OwnerDoc()->GetElementById(keyElmId);
|
2011-07-19 01:30:24 -07:00
|
|
|
if (!keyElm)
|
|
|
|
return KeyBinding();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t key = 0;
|
2011-07-19 01:30:24 -07:00
|
|
|
|
|
|
|
nsAutoString keyStr;
|
|
|
|
keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::key, keyStr);
|
|
|
|
if (keyStr.IsEmpty()) {
|
|
|
|
nsAutoString keyCodeStr;
|
|
|
|
keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::keycode, keyCodeStr);
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult errorCode;
|
2011-07-19 01:30:24 -07:00
|
|
|
key = keyStr.ToInteger(&errorCode, kAutoDetect);
|
|
|
|
} else {
|
|
|
|
key = keyStr[0];
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
nsAutoString modifiersStr;
|
|
|
|
keyElm->GetAttr(kNameSpaceID_None, nsGkAtoms::modifiers, modifiersStr);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t modifierMask = 0;
|
2011-07-19 01:30:24 -07:00
|
|
|
if (modifiersStr.Find("shift") != -1)
|
2011-07-21 17:49:40 -07:00
|
|
|
modifierMask |= KeyBinding::kShift;
|
2011-07-19 01:30:24 -07:00
|
|
|
if (modifiersStr.Find("alt") != -1)
|
|
|
|
modifierMask |= KeyBinding::kAlt;
|
|
|
|
if (modifiersStr.Find("meta") != -1)
|
|
|
|
modifierMask |= KeyBinding::kMeta;
|
2012-07-18 18:28:16 -07:00
|
|
|
if (modifiersStr.Find("os") != -1)
|
|
|
|
modifierMask |= KeyBinding::kOS;
|
2011-07-19 01:30:24 -07:00
|
|
|
if (modifiersStr.Find("control") != -1)
|
|
|
|
modifierMask |= KeyBinding::kControl;
|
|
|
|
if (modifiersStr.Find("accel") != -1) {
|
2014-05-21 21:06:05 -07:00
|
|
|
modifierMask |= KeyBinding::AccelModifier();
|
2011-07-19 01:30:24 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-07-19 01:30:24 -07:00
|
|
|
return KeyBinding(key, modifierMask);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> xulContainer(do_QueryInterface(mContent));
|
2010-09-04 19:14:01 -07:00
|
|
|
if (xulContainer)
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::PARENT_MENUITEM;
|
2007-11-21 22:14:39 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (mParent && mParent->Role() == roles::COMBOBOX_LIST)
|
|
|
|
return roles::COMBOBOX_OPTION;
|
2007-11-21 22:14:39 -08:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
2012-01-11 19:07:35 -08:00
|
|
|
nsGkAtoms::radio, eCaseMatters))
|
|
|
|
return roles::RADIO_MENU_ITEM;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-06-03 14:35:17 -07:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
|
|
|
|
nsGkAtoms::checkbox,
|
2012-01-11 19:07:35 -08:00
|
|
|
eCaseMatters))
|
|
|
|
return roles::CHECK_MENU_ITEM;
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::MENUITEM;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::GetLevelInternal()
|
2007-03-27 05:17:11 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
return nsAccUtils::GetLevelForXULContainerItem(mContent);
|
2010-01-06 02:36:50 -08:00
|
|
|
}
|
2007-03-27 05:17:11 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::CanHaveAnonChildren()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// That indicates we don't walk anonymous children for menuitems
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
XULMenuitemAccessible::DoAction(uint8_t index)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (index == eAction_Click) { // default action
|
|
|
|
DoCommand();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** select us! close combo box if necessary*/
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
XULMenuitemAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aIndex == eAction_Click) {
|
|
|
|
aName.AssignLiteral("click");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::ActionCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
return 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenuitemAccessible: Widgets
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::IsActiveWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
// Parent menu item is a widget, it's active when its popup is open.
|
|
|
|
nsIContent* menuPopupContent = mContent->GetFirstChild();
|
|
|
|
if (menuPopupContent) {
|
|
|
|
nsMenuPopupFrame* menuPopupFrame =
|
|
|
|
do_QueryFrame(menuPopupContent->GetPrimaryFrame());
|
|
|
|
return menuPopupFrame && menuPopupFrame->IsOpen();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::AreItemsOperable() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
// Parent menu item is a widget, its items are operable when its popup is open.
|
|
|
|
nsIContent* menuPopupContent = mContent->GetFirstChild();
|
|
|
|
if (menuPopupContent) {
|
|
|
|
nsMenuPopupFrame* menuPopupFrame =
|
|
|
|
do_QueryFrame(menuPopupContent->GetPrimaryFrame());
|
|
|
|
return menuPopupFrame && menuPopupFrame->IsOpen();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuitemAccessible::ContainerWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(GetFrame());
|
|
|
|
if (menuFrame) {
|
|
|
|
nsMenuParent* menuParent = menuFrame->GetMenuParent();
|
|
|
|
if (menuParent) {
|
|
|
|
if (menuParent->IsMenuBar()) // menubar menu
|
|
|
|
return mParent;
|
|
|
|
|
|
|
|
// a menupoup or parent menu item
|
|
|
|
if (menuParent->IsMenu())
|
|
|
|
return mParent;
|
|
|
|
|
|
|
|
// otherwise it's different kind of popups (like panel or tooltip), it
|
|
|
|
// shouldn't be a real case.
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenuSeparatorAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuSeparatorAccessible::
|
|
|
|
XULMenuSeparatorAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
|
|
|
XULMenuitemAccessible(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuSeparatorAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-06-13 03:54:07 -07:00
|
|
|
// Isn't focusable, but can be offscreen/invisible -- only copy those states
|
2012-06-10 16:44:50 -07:00
|
|
|
return XULMenuitemAccessible::NativeState() &
|
2011-04-09 16:38:06 -07:00
|
|
|
(states::OFFSCREEN | states::INVISIBLE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
XULMenuSeparatorAccessible::NativeName(nsString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuSeparatorAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::SEPARATOR;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
XULMenuSeparatorAccessible::DoAction(uint8_t index)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
XULMenuSeparatorAccessible::GetActionName(uint8_t aIndex, nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenuSeparatorAccessible::ActionCount()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-06-05 12:35:43 -07:00
|
|
|
return 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenupopupAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::
|
|
|
|
XULMenupopupAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-02-07 14:38:54 -08:00
|
|
|
XULSelectControlAccessible(aContent, aDoc)
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetFrame());
|
|
|
|
if (menuPopupFrame && menuPopupFrame->IsMenu())
|
2012-12-17 21:22:26 -08:00
|
|
|
mType = eMenuPopupType;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// May be the anonymous <menupopup> inside <menulist> (a combobox)
|
2013-05-01 15:50:08 -07:00
|
|
|
mSelectControl = do_QueryInterface(mContent->GetFlattenedTreeParent());
|
2012-11-10 18:16:17 -08:00
|
|
|
if (!mSelectControl)
|
2012-12-17 21:22:26 -08:00
|
|
|
mGenericTypes &= ~eSelect;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::NativeState()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t state = Accessible::NativeState();
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2012-05-07 16:49:41 -07:00
|
|
|
#ifdef DEBUG
|
2007-06-13 03:54:07 -07:00
|
|
|
// We are onscreen if our parent is active
|
2012-05-07 16:49:41 -07:00
|
|
|
bool isActive = mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::menuactive);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!isActive) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* parent = Parent();
|
2012-05-07 16:49:41 -07:00
|
|
|
if (parent) {
|
|
|
|
nsIContent* parentContent = parent->GetContent();
|
|
|
|
if (parentContent)
|
|
|
|
isActive = parentContent->HasAttr(kNameSpaceID_None, nsGkAtoms::open);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 01:23:18 -07:00
|
|
|
|
2012-05-07 16:49:41 -07:00
|
|
|
NS_ASSERTION(isActive || (state & states::INVISIBLE),
|
2011-04-09 16:38:06 -07:00
|
|
|
"XULMenupopup doesn't have INVISIBLE when it's inactive");
|
2007-09-26 00:46:31 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
if (state & states::INVISIBLE)
|
|
|
|
state |= states::OFFSCREEN | states::COLLAPSED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
return state;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
XULMenupopupAccessible::NativeName(nsString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-13 21:18:39 -07:00
|
|
|
nsIContent* content = mContent;
|
2007-08-22 01:05:33 -07:00
|
|
|
while (content && aName.IsEmpty()) {
|
2011-06-03 14:35:17 -07:00
|
|
|
content->GetAttr(kNameSpaceID_None, nsGkAtoms::label, aName);
|
2013-05-01 15:50:08 -07:00
|
|
|
content = content->GetFlattenedTreeParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-09-03 17:32:13 -07:00
|
|
|
// If accessible is not bound to the tree (this happens while children are
|
|
|
|
// cached) return general role.
|
|
|
|
if (mParent) {
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = mParent->Role();
|
|
|
|
if (role == roles::COMBOBOX || role == roles::AUTOCOMPLETE)
|
|
|
|
return roles::COMBOBOX_LIST;
|
2009-11-09 21:58:52 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (role == roles::PUSHBUTTON) {
|
2009-11-09 21:58:52 -08:00
|
|
|
// Some widgets like the search bar have several popups, owned by buttons.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* grandParent = mParent->Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (grandParent && grandParent->Role() == roles::AUTOCOMPLETE)
|
|
|
|
return roles::COMBOBOX_LIST;
|
2008-01-23 15:49:10 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-11-09 21:58:52 -08:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::MENUPOPUP;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenupopupAccessible: Widgets
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::IsWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::IsActiveWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
// If menupopup is a widget (the case of context menus) then active when open.
|
|
|
|
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetFrame());
|
|
|
|
return menuPopupFrame && menuPopupFrame->IsOpen();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::AreItemsOperable() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetFrame());
|
|
|
|
return menuPopupFrame && menuPopupFrame->IsOpen();
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenupopupAccessible::ContainerWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* document = Document();
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
nsMenuPopupFrame* menuPopupFrame = do_QueryFrame(GetFrame());
|
|
|
|
while (menuPopupFrame) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* menuPopup =
|
2011-09-27 18:46:11 -07:00
|
|
|
document->GetAccessible(menuPopupFrame->GetContent());
|
|
|
|
if (!menuPopup) // shouldn't be a real case
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
2012-07-30 17:43:28 -07:00
|
|
|
nsMenuFrame* menuFrame = do_QueryFrame(menuPopupFrame->GetParent());
|
2011-09-27 18:46:11 -07:00
|
|
|
if (!menuFrame) // context menu or popups
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
nsMenuParent* menuParent = menuFrame->GetMenuParent();
|
|
|
|
if (!menuParent) // menulist or menubutton
|
|
|
|
return menuPopup->Parent();
|
|
|
|
|
|
|
|
if (menuParent->IsMenuBar()) { // menubar menu
|
|
|
|
nsMenuBarFrame* menuBarFrame = static_cast<nsMenuBarFrame*>(menuParent);
|
|
|
|
return document->GetAccessible(menuBarFrame->GetContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
// different kind of popups like panel or tooltip
|
|
|
|
if (!menuParent->IsMenu())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
menuPopupFrame = static_cast<nsMenuPopupFrame*>(menuParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("Shouldn't be a real case.");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenubarAccessible
|
2010-06-11 01:23:18 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenubarAccessible::
|
|
|
|
XULMenubarAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc)
|
2010-06-11 01:23:18 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-13 21:18:39 -07:00
|
|
|
ENameValueFlag
|
|
|
|
XULMenubarAccessible::NativeName(nsString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-08-24 09:45:56 -07:00
|
|
|
aName.AssignLiteral("Application");
|
2012-10-13 21:18:39 -07:00
|
|
|
return eNameOK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
role
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenubarAccessible::NativeRole()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-01-11 19:07:35 -08:00
|
|
|
return roles::MENUBAR;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-27 18:46:11 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-06-10 16:44:50 -07:00
|
|
|
// XULMenubarAccessible: Widgets
|
2011-09-27 18:46:11 -07:00
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenubarAccessible::IsActiveWidget() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
nsMenuBarFrame* menuBarFrame = do_QueryFrame(GetFrame());
|
|
|
|
return menuBarFrame && menuBarFrame->IsActive();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenubarAccessible::AreItemsOperable() const
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenubarAccessible::CurrentItem()
|
2011-09-27 18:46:11 -07:00
|
|
|
{
|
|
|
|
nsMenuBarFrame* menuBarFrame = do_QueryFrame(GetFrame());
|
|
|
|
if (menuBarFrame) {
|
|
|
|
nsMenuFrame* menuFrame = menuBarFrame->GetCurrentMenuItem();
|
|
|
|
if (menuFrame) {
|
|
|
|
nsIContent* menuItemNode = menuFrame->GetContent();
|
2012-02-15 11:22:17 -08:00
|
|
|
return mDoc->GetAccessible(menuItemNode);
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-09-27 18:46:11 -07:00
|
|
|
}
|
2011-12-08 04:20:15 -08:00
|
|
|
|
|
|
|
void
|
2012-06-10 16:44:50 -07:00
|
|
|
XULMenubarAccessible::SetCurrentItem(Accessible* aItem)
|
2011-12-08 04:20:15 -08:00
|
|
|
{
|
2012-06-10 16:44:50 -07:00
|
|
|
NS_ERROR("XULMenubarAccessible::SetCurrentItem not implemented");
|
2011-12-08 04:20:15 -08:00
|
|
|
}
|