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):
|
|
|
|
* Author: Aaron Leventhal (aaronl@netscape.com)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of 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 ***** */
|
|
|
|
|
|
|
|
#include "nsXULMenuAccessible.h"
|
|
|
|
#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 "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsGUIEvent.h"
|
|
|
|
#include "nsXULFormControlAccessible.h"
|
2008-01-16 22:30:15 -08:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2008-01-16 22:30:15 -08:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/** ------------------------------------------------------ */
|
|
|
|
/** Impl. of nsXULSelectableAccessible */
|
|
|
|
/** ------------------------------------------------------ */
|
|
|
|
|
|
|
|
// Helper methos
|
|
|
|
nsXULSelectableAccessible::nsXULSelectableAccessible(nsIDOMNode* aDOMNode,
|
|
|
|
nsIWeakReference* aShell):
|
|
|
|
nsAccessibleWrap(aDOMNode, aShell)
|
|
|
|
{
|
|
|
|
mSelectControl = do_QueryInterface(aDOMNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsXULSelectableAccessible, nsAccessible, nsIAccessibleSelectable)
|
|
|
|
|
2008-10-31 20:58:07 -07:00
|
|
|
nsresult
|
|
|
|
nsXULSelectableAccessible::Shutdown()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mSelectControl = nsnull;
|
|
|
|
return nsAccessibleWrap::Shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsXULSelectableAccessible::ChangeSelection(PRInt32 aIndex, PRUint8 aMethod, PRBool *aSelState)
|
|
|
|
{
|
|
|
|
*aSelState = PR_FALSE;
|
|
|
|
|
|
|
|
if (!mSelectControl) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIAccessible> childAcc;
|
|
|
|
GetChildAt(aIndex, getter_AddRefs(childAcc));
|
|
|
|
nsCOMPtr<nsIAccessNode> accNode = do_QueryInterface(childAcc);
|
|
|
|
NS_ENSURE_TRUE(accNode, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> childNode;
|
|
|
|
accNode->GetDOMNode(getter_AddRefs(childNode));
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> item(do_QueryInterface(childNode));
|
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
item->GetSelected(aSelState);
|
|
|
|
if (eSelection_GetState == aMethod) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
|
|
|
do_QueryInterface(mSelectControl);
|
|
|
|
|
|
|
|
if (eSelection_Add == aMethod && !(*aSelState)) {
|
|
|
|
return xulMultiSelect ? xulMultiSelect->AddItemToSelection(item) :
|
|
|
|
mSelectControl->SetSelectedItem(item);
|
|
|
|
}
|
|
|
|
if (eSelection_Remove == aMethod && (*aSelState)) {
|
|
|
|
return xulMultiSelect ? xulMultiSelect->RemoveItemFromSelection(item) :
|
|
|
|
mSelectControl->SetSelectedItem(nsnull);
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Interface methods
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::GetSelectedChildren(nsIArray **aChildren)
|
|
|
|
{
|
|
|
|
*aChildren = nsnull;
|
|
|
|
if (!mSelectControl) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
|
|
|
|
NS_ENSURE_TRUE(accService, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> selectedAccessibles =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID);
|
|
|
|
NS_ENSURE_STATE(selectedAccessibles);
|
|
|
|
|
|
|
|
// For XUL multi-select control
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
|
|
|
do_QueryInterface(mSelectControl);
|
|
|
|
nsCOMPtr<nsIAccessible> selectedAccessible;
|
|
|
|
if (xulMultiSelect) {
|
|
|
|
PRInt32 length = 0;
|
|
|
|
xulMultiSelect->GetSelectedCount(&length);
|
|
|
|
for (PRInt32 index = 0; index < length; index++) {
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem;
|
|
|
|
xulMultiSelect->GetSelectedItem(index, getter_AddRefs(selectedItem));
|
|
|
|
nsCOMPtr<nsIDOMNode> selectedNode(do_QueryInterface(selectedItem));
|
|
|
|
accService->GetAccessibleInWeakShell(selectedNode, mWeakShell,
|
|
|
|
getter_AddRefs(selectedAccessible));
|
|
|
|
if (selectedAccessible)
|
|
|
|
selectedAccessibles->AppendElement(selectedAccessible, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // Single select?
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem;
|
|
|
|
mSelectControl->GetSelectedItem(getter_AddRefs(selectedItem));
|
|
|
|
nsCOMPtr<nsIDOMNode> selectedNode(do_QueryInterface(selectedItem));
|
|
|
|
if(selectedNode) {
|
|
|
|
accService->GetAccessibleInWeakShell(selectedNode, mWeakShell,
|
|
|
|
getter_AddRefs(selectedAccessible));
|
|
|
|
if (selectedAccessible)
|
|
|
|
selectedAccessibles->AppendElement(selectedAccessible, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 uLength = 0;
|
|
|
|
selectedAccessibles->GetLength(&uLength);
|
|
|
|
if (uLength != 0) { // length of nsIArray containing selected options
|
|
|
|
NS_ADDREF(*aChildren = selectedAccessibles);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the nth selected child's nsIAccessible object
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::RefSelection(PRInt32 aIndex, nsIAccessible **aAccessible)
|
|
|
|
{
|
|
|
|
*aAccessible = nsnull;
|
|
|
|
if (!mSelectControl) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> selectedItem;
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
|
|
|
do_QueryInterface(mSelectControl);
|
|
|
|
if (xulMultiSelect)
|
|
|
|
xulMultiSelect->GetSelectedItem(aIndex, getter_AddRefs(selectedItem));
|
|
|
|
|
|
|
|
if (aIndex == 0)
|
|
|
|
mSelectControl->GetSelectedItem(getter_AddRefs(selectedItem));
|
|
|
|
|
|
|
|
if (selectedItem) {
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = GetAccService();
|
|
|
|
if (accService) {
|
|
|
|
accService->GetAccessibleInWeakShell(selectedItem, mWeakShell, aAccessible);
|
|
|
|
if (*aAccessible) {
|
|
|
|
NS_ADDREF(*aAccessible);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::GetSelectionCount(PRInt32 *aSelectionCount)
|
|
|
|
{
|
|
|
|
*aSelectionCount = 0;
|
|
|
|
if (!mSelectControl) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For XUL multi-select control
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
|
|
|
do_QueryInterface(mSelectControl);
|
|
|
|
if (xulMultiSelect)
|
|
|
|
return xulMultiSelect->GetSelectedCount(aSelectionCount);
|
|
|
|
|
|
|
|
// For XUL single-select control/menulist
|
|
|
|
PRInt32 index;
|
|
|
|
mSelectControl->GetSelectedIndex(&index);
|
|
|
|
if (index >= 0)
|
|
|
|
*aSelectionCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::AddChildToSelection(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
PRBool isSelected;
|
|
|
|
return ChangeSelection(aIndex, eSelection_Add, &isSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::RemoveChildFromSelection(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
PRBool isSelected;
|
|
|
|
return ChangeSelection(aIndex, eSelection_Remove, &isSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::IsChildSelected(PRInt32 aIndex, PRBool *aIsSelected)
|
|
|
|
{
|
|
|
|
*aIsSelected = PR_FALSE;
|
|
|
|
return ChangeSelection(aIndex, eSelection_GetState, aIsSelected);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::ClearSelection()
|
|
|
|
{
|
|
|
|
if (!mSelectControl) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
|
|
|
do_QueryInterface(mSelectControl);
|
|
|
|
return xulMultiSelect ? xulMultiSelect->ClearSelection() : mSelectControl->SetSelectedIndex(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULSelectableAccessible::SelectAllSelection(PRBool *aSucceeded)
|
|
|
|
{
|
|
|
|
*aSucceeded = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> xulMultiSelect =
|
|
|
|
do_QueryInterface(mSelectControl);
|
|
|
|
if (xulMultiSelect)
|
|
|
|
return xulMultiSelect->SelectAll();
|
|
|
|
|
|
|
|
// otherwise, don't support this method
|
|
|
|
*aSucceeded = PR_FALSE;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------ Menu Item -----------------------------
|
|
|
|
|
|
|
|
nsXULMenuitemAccessible::nsXULMenuitemAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
|
|
|
|
nsAccessibleWrap(aDOMNode, aShell)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-10-31 20:58:07 -07:00
|
|
|
nsresult
|
|
|
|
nsXULMenuitemAccessible::Init()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv = nsAccessibleWrap::Init();
|
|
|
|
nsXULMenupopupAccessible::GenerateMenu(mDOMNode);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenuitemAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-26 20:04:05 -08:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Focused?
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
|
|
|
|
if (!element)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
PRBool isFocused = PR_FALSE;
|
|
|
|
element->HasAttribute(NS_LITERAL_STRING("_moz-menuactive"), &isFocused);
|
|
|
|
if (isFocused)
|
2007-04-02 08:56:24 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_FOCUSED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Has Popup?
|
|
|
|
nsAutoString tagName;
|
|
|
|
element->GetLocalName(tagName);
|
|
|
|
if (tagName.EqualsLiteral("menu")) {
|
2007-04-02 08:56:24 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_HASPOPUP;
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool isOpen;
|
|
|
|
element->HasAttribute(NS_LITERAL_STRING("open"), &isOpen);
|
2007-06-04 01:16:04 -07:00
|
|
|
if (isOpen) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_EXPANDED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_COLLAPSED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString menuItemType;
|
|
|
|
element->GetAttribute(NS_LITERAL_STRING("type"), menuItemType);
|
|
|
|
|
|
|
|
if (!menuItemType.IsEmpty()) {
|
|
|
|
// Checkable?
|
|
|
|
if (menuItemType.EqualsIgnoreCase("radio") ||
|
|
|
|
menuItemType.EqualsIgnoreCase("checkbox"))
|
2007-04-02 08:56:24 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_CHECKABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Checked?
|
|
|
|
nsAutoString checkValue;
|
|
|
|
element->GetAttribute(NS_LITERAL_STRING("checked"), checkValue);
|
|
|
|
if (checkValue.EqualsLiteral("true")) {
|
2007-04-02 08:56:24 -07:00
|
|
|
*aState |= nsIAccessibleStates::STATE_CHECKED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-13 03:54:07 -07:00
|
|
|
// Combo box listitem
|
2008-01-16 22:30:15 -08:00
|
|
|
PRBool isComboboxOption =
|
2008-10-17 03:10:43 -07:00
|
|
|
(nsAccUtils::Role(this) == nsIAccessibleRole::ROLE_COMBOBOX_OPTION);
|
2008-01-16 22:30:15 -08:00
|
|
|
if (isComboboxOption) {
|
2007-06-13 03:54:07 -07:00
|
|
|
// Is selected?
|
|
|
|
PRBool isSelected = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement>
|
|
|
|
item(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);
|
|
|
|
item->GetSelected(&isSelected);
|
|
|
|
|
|
|
|
// Is collapsed?
|
|
|
|
PRBool isCollapsed = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIAccessible> parentAccessible(GetParent());
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::State(parentAccessible) & nsIAccessibleStates::STATE_INVISIBLE)
|
2007-06-13 03:54:07 -07:00
|
|
|
isCollapsed = PR_TRUE;
|
|
|
|
|
|
|
|
if (isSelected) {
|
|
|
|
*aState |= nsIAccessibleStates::STATE_SELECTED;
|
|
|
|
|
|
|
|
// Selected and collapsed?
|
|
|
|
if (isCollapsed) {
|
|
|
|
// Set selected option offscreen/invisible according to combobox state
|
|
|
|
nsCOMPtr<nsIAccessible> grandParentAcc;
|
|
|
|
parentAccessible->GetParent(getter_AddRefs(grandParentAcc));
|
|
|
|
NS_ENSURE_TRUE(grandParentAcc, NS_ERROR_FAILURE);
|
2008-10-17 03:10:43 -07:00
|
|
|
NS_ASSERTION(nsAccUtils::Role(grandParentAcc) == nsIAccessibleRole::ROLE_COMBOBOX,
|
2007-06-13 03:54:07 -07:00
|
|
|
"grandparent of combobox listitem is not combobox");
|
|
|
|
PRUint32 grandParentState, grandParentExtState;
|
2008-11-03 19:37:46 -08:00
|
|
|
grandParentAcc->GetState(&grandParentState, &grandParentExtState);
|
2007-06-13 03:54:07 -07:00
|
|
|
*aState &= ~(nsIAccessibleStates::STATE_OFFSCREEN |
|
|
|
|
nsIAccessibleStates::STATE_INVISIBLE);
|
|
|
|
*aState |= grandParentState & nsIAccessibleStates::STATE_OFFSCREEN |
|
|
|
|
grandParentState & nsIAccessibleStates::STATE_INVISIBLE;
|
|
|
|
if (aExtraState) {
|
|
|
|
*aExtraState |=
|
|
|
|
grandParentExtState & nsIAccessibleStates::EXT_STATE_OPAQUE;
|
|
|
|
}
|
|
|
|
} // isCollapsed
|
|
|
|
} // isSelected
|
2007-11-15 11:46:29 -08:00
|
|
|
} // ROLE_COMBOBOX_OPTION
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-01-16 22:30:15 -08:00
|
|
|
// Set focusable and selectable for items that are available
|
|
|
|
// and whose metric setting does allow disabled items to be focused.
|
|
|
|
if (*aState & nsIAccessibleStates::STATE_UNAVAILABLE) {
|
|
|
|
// Honour the LookAndFeel metric.
|
|
|
|
nsCOMPtr<nsILookAndFeel> lookNFeel(do_GetService(kLookAndFeelCID));
|
|
|
|
PRInt32 skipDisabledMenuItems = 0;
|
|
|
|
lookNFeel->GetMetric(nsILookAndFeel::eMetric_SkipNavigatingDisabledMenuItem,
|
|
|
|
skipDisabledMenuItems);
|
|
|
|
// We don't want the focusable and selectable states for combobox items,
|
|
|
|
// so exclude them here as well.
|
|
|
|
if (skipDisabledMenuItems || isComboboxOption) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*aState|= (nsIAccessibleStates::STATE_FOCUSABLE |
|
|
|
|
nsIAccessibleStates::STATE_SELECTABLE);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
nsresult
|
|
|
|
nsXULMenuitemAccessible::GetNameInternal(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-10-10 05:26:55 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::label, aName);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULMenuitemAccessible::GetDescription(nsAString& aDescription)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
|
|
|
|
if (!element) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
element->GetAttribute(NS_LITERAL_STRING("description"), aDescription);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//return menu accesskey: N or Alt+F
|
2007-08-28 23:52:46 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULMenuitemAccessible::GetKeyboardShortcut(nsAString& aAccessKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-28 23:52:46 -07:00
|
|
|
aAccessKey.Truncate();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRInt32 gMenuAccesskeyModifier = -1; // magic value of -1 indicates unitialized state
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
|
|
|
|
if (elt) {
|
|
|
|
nsAutoString accesskey;
|
2008-10-15 18:52:58 -07:00
|
|
|
// We do not use nsCoreUtils::GetAccesskeyFor() because accesskeys for
|
2007-08-28 23:52:46 -07:00
|
|
|
// menu are't registered by nsIEventStateManager.
|
2007-03-22 10:30:00 -07:00
|
|
|
elt->GetAttribute(NS_LITERAL_STRING("accesskey"), accesskey);
|
|
|
|
if (accesskey.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessible> parentAccessible(GetParent());
|
|
|
|
if (parentAccessible) {
|
2009-03-07 07:38:58 -08:00
|
|
|
if (nsAccUtils::RoleInternal(parentAccessible) ==
|
|
|
|
nsIAccessibleRole::ROLE_MENUBAR) {
|
2007-03-22 10:30:00 -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
|
|
|
|
gMenuAccesskeyModifier = 0;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
|
|
|
if (prefBranch)
|
|
|
|
prefBranch->GetIntPref("ui.key.menuAccessKey", &gMenuAccesskeyModifier);
|
|
|
|
}
|
|
|
|
nsAutoString propertyKey;
|
|
|
|
switch (gMenuAccesskeyModifier) {
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_CONTROL: propertyKey.AssignLiteral("VK_CONTROL"); break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_ALT: propertyKey.AssignLiteral("VK_ALT"); break;
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_META: propertyKey.AssignLiteral("VK_META"); break;
|
|
|
|
}
|
|
|
|
if (!propertyKey.IsEmpty())
|
2007-08-28 23:52:46 -07:00
|
|
|
nsAccessible::GetFullKeyName(propertyKey, accesskey, aAccessKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-08-28 23:52:46 -07:00
|
|
|
if (aAccessKey.IsEmpty())
|
|
|
|
aAccessKey = accesskey;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//return menu shortcut: Ctrl+F or Ctrl+Shift+L
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULMenuitemAccessible::GetDefaultKeyBinding(nsAString& aKeyBinding)
|
|
|
|
{
|
|
|
|
aKeyBinding.Truncate();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
|
|
|
|
NS_ENSURE_TRUE(elt, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsAutoString accelText;
|
|
|
|
elt->GetAttribute(NS_LITERAL_STRING("acceltext"), accelText);
|
|
|
|
if (accelText.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
aKeyBinding = accelText;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenuitemAccessible::GetRoleInternal(PRUint32 *aRole)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-11-21 22:14:39 -08:00
|
|
|
nsCOMPtr<nsIDOMXULContainerElement> xulContainer(do_QueryInterface(mDOMNode));
|
|
|
|
if (xulContainer) {
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_PARENT_MENUITEM;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-23 15:49:10 -08:00
|
|
|
nsCOMPtr<nsIAccessible> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
2008-10-17 03:10:43 -07:00
|
|
|
if (nsAccUtils::Role(parent) == nsIAccessibleRole::ROLE_COMBOBOX_LIST) {
|
2007-11-15 11:46:29 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_OPTION;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-11-21 22:14:39 -08:00
|
|
|
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_MENUITEM;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
|
|
|
|
if (!element)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
nsAutoString menuItemType;
|
|
|
|
element->GetAttribute(NS_LITERAL_STRING("type"), menuItemType);
|
|
|
|
if (menuItemType.EqualsIgnoreCase("radio"))
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_RADIO_MENU_ITEM;
|
|
|
|
else if (menuItemType.EqualsIgnoreCase("checkbox"))
|
|
|
|
*aRole = nsIAccessibleRole::ROLE_CHECK_MENU_ITEM;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
nsresult
|
|
|
|
nsXULMenuitemAccessible::GetAttributesInternal(nsIPersistentProperties *aAttributes)
|
2007-03-27 05:17:11 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAttributes);
|
|
|
|
NS_ENSURE_TRUE(mDOMNode, NS_ERROR_FAILURE);
|
|
|
|
|
2007-04-07 02:07:24 -07:00
|
|
|
nsresult rv = nsAccessible::GetAttributesInternal(aAttributes);
|
2007-03-27 05:17:11 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-10-16 02:12:05 -07:00
|
|
|
nsAccUtils::SetAccAttrsForXULContainerItem(mDOMNode, aAttributes);
|
2007-03-27 05:17:11 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-18 00:37:38 -07:00
|
|
|
PRBool
|
|
|
|
nsXULMenuitemAccessible::GetAllowsAnonChildAccessibles()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// That indicates we don't walk anonymous children for menuitems
|
2009-06-18 00:37:38 -07:00
|
|
|
return PR_FALSE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULMenuitemAccessible::DoAction(PRUint8 index)
|
|
|
|
{
|
|
|
|
if (index == eAction_Click) { // default action
|
|
|
|
DoCommand();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** select us! close combo box if necessary*/
|
|
|
|
NS_IMETHODIMP nsXULMenuitemAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
if (aIndex == eAction_Click) {
|
|
|
|
aName.AssignLiteral("click");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULMenuitemAccessible::GetNumActions(PRUint8 *_retval)
|
|
|
|
{
|
|
|
|
*_retval = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ------------------------ Menu Separator ----------------------------
|
|
|
|
|
|
|
|
nsXULMenuSeparatorAccessible::nsXULMenuSeparatorAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
|
|
|
|
nsXULMenuitemAccessible(aDOMNode, aShell)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenuSeparatorAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
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
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult rv = nsXULMenuitemAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-26 20:04:05 -08:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2007-06-13 03:54:07 -07:00
|
|
|
*aState &= (nsIAccessibleStates::STATE_OFFSCREEN |
|
|
|
|
nsIAccessibleStates::STATE_INVISIBLE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
nsresult
|
|
|
|
nsXULMenuSeparatorAccessible::GetNameInternal(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenuSeparatorAccessible::GetRoleInternal(PRUint32 *aRole)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-03-07 07:38:58 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_SEPARATOR;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULMenuSeparatorAccessible::DoAction(PRUint8 index)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULMenuSeparatorAccessible::GetActionName(PRUint8 aIndex, nsAString& aName)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsXULMenuSeparatorAccessible::GetNumActions(PRUint8 *_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
// ------------------------ Menu Popup -----------------------------
|
|
|
|
|
|
|
|
nsXULMenupopupAccessible::nsXULMenupopupAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
|
|
|
|
nsXULSelectableAccessible(aDOMNode, aShell)
|
|
|
|
{
|
|
|
|
// May be the anonymous <menupopup> inside <menulist> (a combobox)
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode;
|
|
|
|
aDOMNode->GetParentNode(getter_AddRefs(parentNode));
|
|
|
|
mSelectControl = do_QueryInterface(parentNode);
|
|
|
|
}
|
|
|
|
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenupopupAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-26 20:04:05 -08:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-04-02 08:56:24 -07:00
|
|
|
|
2007-09-26 00:46:31 -07:00
|
|
|
#ifdef DEBUG_A11Y
|
2007-06-13 03:54:07 -07:00
|
|
|
// We are onscreen if our parent is active
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool isActive = PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(mDOMNode));
|
|
|
|
element->HasAttribute(NS_LITERAL_STRING("menuactive"), &isActive);
|
|
|
|
if (!isActive) {
|
|
|
|
nsCOMPtr<nsIAccessible> parent(GetParent());
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode;
|
|
|
|
nsCOMPtr<nsIAccessNode> accessNode(do_QueryInterface(parent));
|
|
|
|
if (accessNode)
|
|
|
|
accessNode->GetDOMNode(getter_AddRefs(parentNode));
|
|
|
|
element = do_QueryInterface(parentNode);
|
|
|
|
if (element)
|
|
|
|
element->HasAttribute(NS_LITERAL_STRING("open"), &isActive);
|
|
|
|
}
|
2007-09-26 00:46:31 -07:00
|
|
|
NS_ASSERTION(isActive || *aState & nsIAccessibleStates::STATE_INVISIBLE,
|
|
|
|
"XULMenupopup doesn't have STATE_INVISIBLE when it's inactive");
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-26 00:46:31 -07:00
|
|
|
if (*aState & nsIAccessibleStates::STATE_INVISIBLE)
|
2007-06-13 03:54:07 -07:00
|
|
|
*aState |= (nsIAccessibleStates::STATE_OFFSCREEN |
|
2007-08-29 00:03:02 -07:00
|
|
|
nsIAccessibleStates::STATE_COLLAPSED);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIDOMNode>
|
|
|
|
nsXULMenupopupAccessible::FindInNodeList(nsIDOMNodeList *aNodeList,
|
|
|
|
nsIAtom *aAtom, PRUint32 aNameSpaceID)
|
|
|
|
{
|
|
|
|
PRUint32 numChildren;
|
|
|
|
if (!aNodeList || NS_FAILED(aNodeList->GetLength(&numChildren))) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMNode> childNode;
|
|
|
|
for (PRUint32 childIndex = 0; childIndex < numChildren; childIndex++) {
|
|
|
|
aNodeList->Item(childIndex, getter_AddRefs(childNode));
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(childNode);
|
|
|
|
if (content && content->NodeInfo()->Equals(aAtom, kNameSpaceID_XUL)) {
|
|
|
|
nsIDOMNode *matchNode = childNode;
|
|
|
|
NS_ADDREF(matchNode);
|
|
|
|
return matchNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsXULMenupopupAccessible::GenerateMenu(nsIDOMNode *aNode)
|
|
|
|
{
|
|
|
|
// Set menugenerated="true" on the menupopup node to generate the
|
|
|
|
// sub-menu items if they have not been generated
|
|
|
|
nsCOMPtr<nsIDOMNodeList> nodeList;
|
|
|
|
aNode->GetChildNodes(getter_AddRefs(nodeList));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNode> menuPopup = FindInNodeList(nodeList, nsAccessibilityAtoms::menupopup,
|
|
|
|
kNameSpaceID_XUL);
|
|
|
|
nsCOMPtr<nsIDOMElement> popupElement(do_QueryInterface(menuPopup));
|
|
|
|
if (popupElement) {
|
|
|
|
nsAutoString attr;
|
|
|
|
popupElement->GetAttribute(NS_LITERAL_STRING("menugenerated"), attr);
|
|
|
|
if (!attr.EqualsLiteral("true")) {
|
|
|
|
popupElement->SetAttribute(NS_LITERAL_STRING("menugenerated"), NS_LITERAL_STRING("true"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
nsresult
|
|
|
|
nsXULMenupopupAccessible::GetNameInternal(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-08-22 01:05:33 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
while (content && aName.IsEmpty()) {
|
|
|
|
content->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::label, aName);
|
|
|
|
content = content->GetParent();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-08-22 01:05:33 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenupopupAccessible::GetRoleInternal(PRUint32 *aRole)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-21 06:53:57 -07:00
|
|
|
nsCOMPtr<nsIContent> content(do_QueryInterface(mDOMNode));
|
|
|
|
if (!content) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-01-23 15:49:10 -08:00
|
|
|
nsCOMPtr<nsIAccessible> parent;
|
|
|
|
GetParent(getter_AddRefs(parent));
|
|
|
|
if (parent) {
|
|
|
|
// Some widgets like the search bar have several popups, owned by buttons
|
2008-10-17 03:10:43 -07:00
|
|
|
PRUint32 role = nsAccUtils::Role(parent);
|
2008-01-23 15:49:10 -08:00
|
|
|
if (role == nsIAccessibleRole::ROLE_COMBOBOX ||
|
2008-04-14 23:09:42 -07:00
|
|
|
role == nsIAccessibleRole::ROLE_PUSHBUTTON ||
|
|
|
|
role == nsIAccessibleRole::ROLE_AUTOCOMPLETE) {
|
2008-01-23 15:49:10 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_COMBOBOX_LIST;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-01-23 15:49:10 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_MENUPOPUP;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------ Menu Bar -----------------------------
|
|
|
|
|
|
|
|
nsXULMenubarAccessible::nsXULMenubarAccessible(nsIDOMNode* aDOMNode, nsIWeakReference* aShell):
|
|
|
|
nsAccessibleWrap(aDOMNode, aShell)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenubarAccessible::GetStateInternal(PRUint32 *aState,
|
|
|
|
PRUint32 *aExtraState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-11-03 19:37:46 -08:00
|
|
|
nsresult rv = nsAccessible::GetStateInternal(aState, aExtraState);
|
2008-11-26 20:04:05 -08:00
|
|
|
NS_ENSURE_A11Y_SUCCESS(rv, rv);
|
2007-04-02 08:56:24 -07:00
|
|
|
|
|
|
|
// Menu bar iteself is not actually focusable
|
|
|
|
*aState &= ~nsIAccessibleStates::STATE_FOCUSABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-10 05:26:55 -07:00
|
|
|
nsresult
|
|
|
|
nsXULMenubarAccessible::GetNameInternal(nsAString& aName)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-08-24 09:45:56 -07:00
|
|
|
aName.AssignLiteral("Application");
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-07 07:38:58 -08:00
|
|
|
nsresult
|
|
|
|
nsXULMenubarAccessible::GetRoleInternal(PRUint32 *aRole)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-03-07 07:38:58 -08:00
|
|
|
*aRole = nsIAccessibleRole::ROLE_MENUBAR;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|