2007-06-05 19:41:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=2:tabstop=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/. */
|
2007-06-05 19:41:07 +04:00
|
|
|
|
2013-04-25 07:48:26 +04:00
|
|
|
#ifndef mozilla_a11y_aria_ARIAMap_h_
|
|
|
|
#define mozilla_a11y_aria_ARIAMap_h_
|
2007-06-05 19:41:07 +04:00
|
|
|
|
2012-04-13 18:17:03 +04:00
|
|
|
#include "ARIAStateMap.h"
|
2012-12-21 07:16:44 +04:00
|
|
|
#include "mozilla/a11y/AccTypes.h"
|
2012-01-12 07:07:35 +04:00
|
|
|
#include "mozilla/a11y/Role.h"
|
2007-09-25 05:19:03 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2012-08-11 00:10:18 +04:00
|
|
|
#include "nsIContent.h"
|
2017-12-05 20:05:51 +03:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2012-04-16 13:24:23 +04:00
|
|
|
class nsINode;
|
2009-06-25 06:12:38 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Value constants
|
|
|
|
|
|
|
|
/**
|
2014-10-22 04:49:28 +04:00
|
|
|
* Used to define if role requires to expose Value interface.
|
2009-06-25 06:12:38 +04:00
|
|
|
*/
|
2007-06-05 19:41:07 +04:00
|
|
|
enum EValueRule {
|
2009-06-25 06:12:38 +04:00
|
|
|
/**
|
2014-10-22 04:49:28 +04:00
|
|
|
* Value interface isn't exposed.
|
2009-06-25 06:12:38 +04:00
|
|
|
*/
|
2007-06-05 19:41:07 +04:00
|
|
|
eNoValue,
|
2009-06-25 06:12:38 +04:00
|
|
|
|
|
|
|
/**
|
2014-10-22 04:49:28 +04:00
|
|
|
* Value interface is implemented, supports value, min and max from
|
2009-06-25 06:12:38 +04:00
|
|
|
* aria-valuenow, aria-valuemin and aria-valuemax.
|
|
|
|
*/
|
2017-06-28 14:11:00 +03:00
|
|
|
eHasValueMinMax,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value interface is implemented, but only if the element is focusable.
|
|
|
|
* For instance, in ARIA 1.1 the ability for authors to create adjustable
|
|
|
|
* splitters was provided by supporting the value interface on separators
|
|
|
|
* that are focusable. Non-focusable separators expose no value information.
|
|
|
|
*/
|
|
|
|
eHasValueMinMaxIfFocusable
|
2007-06-05 19:41:07 +04:00
|
|
|
};
|
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Action constants
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to define if the role requires to expose action.
|
|
|
|
*/
|
2008-10-08 16:54:58 +04:00
|
|
|
enum EActionRule {
|
|
|
|
eNoAction,
|
|
|
|
eActivateAction,
|
|
|
|
eClickAction,
|
2012-02-02 05:13:09 +04:00
|
|
|
ePressAction,
|
2008-10-08 16:54:58 +04:00
|
|
|
eCheckUncheckAction,
|
2009-04-20 10:06:19 +04:00
|
|
|
eExpandAction,
|
2008-10-08 16:54:58 +04:00
|
|
|
eJumpAction,
|
|
|
|
eOpenCloseAction,
|
|
|
|
eSelectAction,
|
2009-04-20 10:06:19 +04:00
|
|
|
eSortAction,
|
2008-10-08 16:54:58 +04:00
|
|
|
eSwitchAction
|
|
|
|
};
|
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Live region constants
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to define if role exposes default value of aria-live attribute.
|
|
|
|
*/
|
2009-02-19 09:56:19 +03:00
|
|
|
enum ELiveAttrRule { eNoLiveAttr, eOffLiveAttr, ePoliteLiveAttr };
|
2009-06-25 06:12:38 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Role constants
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ARIA role overrides role from native markup.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool kUseMapRole = true;
|
2009-06-25 06:12:38 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ARIA role doesn't override the role from native markup.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool kUseNativeRole = false;
|
2009-06-11 22:18:24 +04:00
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ARIA attribute characteristic masks
|
2009-02-15 11:15:31 +03:00
|
|
|
|
|
|
|
/**
|
2009-03-10 23:44:43 +03:00
|
|
|
* This mask indicates the attribute should not be exposed as an object
|
2012-10-19 11:15:23 +04:00
|
|
|
* attribute via the catch-all logic in Accessible::Attributes().
|
2009-03-10 23:44:43 +03:00
|
|
|
* This means it either isn't mean't to be exposed as an object attribute, or
|
|
|
|
* that it should, but is already handled in other code.
|
2009-02-15 11:15:31 +03:00
|
|
|
*/
|
2012-11-10 14:26:58 +04:00
|
|
|
const uint8_t ATTR_BYPASSOBJ = 0x1 << 0;
|
2013-02-11 04:54:14 +04:00
|
|
|
const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1;
|
2009-02-15 11:15:31 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This mask indicates the attribute is expected to have an NMTOKEN or bool
|
2012-10-19 11:15:23 +04:00
|
|
|
* value. (See for example usage in Accessible::Attributes())
|
2009-02-15 11:15:31 +03:00
|
|
|
*/
|
2013-02-11 04:54:14 +04:00
|
|
|
const uint8_t ATTR_VALTOKEN = 0x1 << 2;
|
2012-11-10 14:26:58 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicate the attribute is global state or property (refer to
|
|
|
|
* http://www.w3.org/TR/wai-aria/states_and_properties#global_states).
|
|
|
|
*/
|
2013-02-11 04:54:14 +04:00
|
|
|
const uint8_t ATTR_GLOBAL = 0x1 << 3;
|
2009-02-15 11:15:31 +03:00
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// State map entry
|
2007-06-05 19:41:07 +04:00
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
/**
|
|
|
|
* Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for
|
|
|
|
* a given role.
|
|
|
|
*/
|
2007-06-11 13:46:39 +04:00
|
|
|
#define kNoReqStates 0
|
2007-06-05 19:41:07 +04:00
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Role map entry
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For each ARIA role, this maps the nsIAccessible information.
|
|
|
|
*/
|
2007-06-05 19:41:07 +04:00
|
|
|
struct nsRoleMapEntry {
|
2012-06-11 03:44:50 +04:00
|
|
|
/**
|
|
|
|
* Return true if matches to the given ARIA role.
|
|
|
|
*/
|
2018-04-03 03:55:33 +03:00
|
|
|
bool Is(nsAtom* aARIARole) const { return roleAtom == aARIARole; }
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2012-12-21 07:16:44 +04:00
|
|
|
/**
|
|
|
|
* Return true if ARIA role has the given accessible type.
|
|
|
|
*/
|
|
|
|
bool IsOfType(mozilla::a11y::AccGenericType aType) const {
|
|
|
|
return accTypes & aType;
|
|
|
|
}
|
|
|
|
|
2012-06-11 03:44:50 +04:00
|
|
|
/**
|
|
|
|
* Return ARIA role.
|
|
|
|
*/
|
|
|
|
const nsDependentAtomString ARIARoleString() const {
|
2018-04-03 03:55:33 +03:00
|
|
|
return nsDependentAtomString(roleAtom);
|
|
|
|
}
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2007-06-05 19:41:07 +04:00
|
|
|
// ARIA role: string representation such as "button"
|
2018-04-03 03:55:33 +03:00
|
|
|
nsStaticAtom* const roleAtom;
|
2012-06-11 03:44:50 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
// Role mapping rule: maps to enum Role
|
2012-01-12 07:07:35 +04:00
|
|
|
mozilla::a11y::role role;
|
2014-10-22 04:49:28 +04:00
|
|
|
|
2009-06-11 22:18:24 +04:00
|
|
|
// Role rule: whether to use mapped role or native semantics
|
2011-09-29 10:19:26 +04:00
|
|
|
bool roleRule;
|
2014-10-22 04:49:28 +04:00
|
|
|
|
|
|
|
// Value mapping rule: how to compute accessible value
|
2007-06-05 19:41:07 +04:00
|
|
|
EValueRule valueRule;
|
2008-10-08 16:54:58 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
// Action mapping rule, how to expose accessible action
|
2008-10-08 16:54:58 +04:00
|
|
|
EActionRule actionRule;
|
|
|
|
|
2009-02-19 09:56:19 +03:00
|
|
|
// 'live' and 'container-live' object attributes mapping rule: how to expose
|
|
|
|
// these object attributes if ARIA 'live' attribute is missed.
|
|
|
|
ELiveAttrRule liveAttRule;
|
|
|
|
|
2012-11-11 06:16:17 +04:00
|
|
|
// Accessible types this role belongs to.
|
|
|
|
uint32_t accTypes;
|
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
// Automatic state mapping rule: always include in states
|
|
|
|
uint64_t state; // or kNoReqStates if no default state for this role
|
2012-04-05 20:23:30 +04:00
|
|
|
|
2014-10-22 04:49:28 +04:00
|
|
|
// ARIA properties supported for this role (in other words, the aria-foo
|
|
|
|
// attribute to accessible states mapping rules).
|
2007-06-05 19:41:07 +04:00
|
|
|
// Currently you cannot have unlimited mappings, because
|
|
|
|
// a variable sized array would not allow the use of
|
|
|
|
// C++'s struct initialization feature.
|
2012-04-05 20:23:30 +04:00
|
|
|
mozilla::a11y::aria::EStateRule attributeMap1;
|
|
|
|
mozilla::a11y::aria::EStateRule attributeMap2;
|
|
|
|
mozilla::a11y::aria::EStateRule attributeMap3;
|
2014-08-11 16:13:44 +04:00
|
|
|
mozilla::a11y::aria::EStateRule attributeMap4;
|
2007-06-05 19:41:07 +04:00
|
|
|
};
|
|
|
|
|
2009-06-25 06:12:38 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ARIA map
|
|
|
|
|
2007-06-05 19:41:07 +04:00
|
|
|
/**
|
2013-04-25 07:48:26 +04:00
|
|
|
* These provide the mappings for WAI-ARIA roles, states and properties using
|
|
|
|
* the structs defined in this file and ARIAStateMap files.
|
2007-06-05 19:41:07 +04:00
|
|
|
*/
|
2012-04-16 13:24:23 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
namespace aria {
|
|
|
|
|
2013-04-25 07:48:26 +04:00
|
|
|
/**
|
|
|
|
* Empty role map entry. Used by accessibility service to create an accessible
|
|
|
|
* if the accessible can't use role of used accessible class. For example,
|
|
|
|
* it is used for table cells that aren't contained by table.
|
|
|
|
*/
|
|
|
|
extern nsRoleMapEntry gEmptyRoleMap;
|
|
|
|
|
2016-07-18 18:52:44 +03:00
|
|
|
/**
|
|
|
|
* Constants for the role map entry index to indicate that the role map entry
|
|
|
|
* isn't in sWAIRoleMaps, but rather is a special entry: nullptr,
|
|
|
|
* gEmptyRoleMap, and sLandmarkRoleMap
|
|
|
|
*/
|
|
|
|
const uint8_t NO_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 2;
|
|
|
|
const uint8_t EMPTY_ROLE_MAP_ENTRY_INDEX = UINT8_MAX - 1;
|
|
|
|
const uint8_t LANDMARK_ROLE_MAP_ENTRY_INDEX = UINT8_MAX;
|
|
|
|
|
2012-04-16 13:24:23 +04:00
|
|
|
/**
|
|
|
|
* Get the role map entry for a given DOM node. This will use the first
|
|
|
|
* ARIA role if the role attribute provides a space delimited list of roles.
|
|
|
|
*
|
2016-07-18 18:52:44 +03:00
|
|
|
* @param aEl [in] the DOM node to get the role map entry for
|
2012-07-30 18:20:58 +04:00
|
|
|
* @return a pointer to the role map entry for the ARIA role, or nullptr
|
2012-04-16 13:24:23 +04:00
|
|
|
* if none
|
|
|
|
*/
|
2016-03-11 05:13:01 +03:00
|
|
|
const nsRoleMapEntry* GetRoleMap(dom::Element* aEl);
|
2012-04-16 13:24:23 +04:00
|
|
|
|
2016-07-18 18:52:44 +03:00
|
|
|
/**
|
|
|
|
* Get the role map entry pointer's index for a given DOM node. This will use
|
|
|
|
* the first ARIA role if the role attribute provides a space delimited list of
|
|
|
|
* roles.
|
|
|
|
*
|
|
|
|
* @param aEl [in] the DOM node to get the role map entry for
|
|
|
|
* @return the index of the pointer to the role map entry for the ARIA
|
|
|
|
* role, or NO_ROLE_MAP_ENTRY_INDEX if none
|
|
|
|
*/
|
|
|
|
uint8_t GetRoleMapIndex(dom::Element* aEl);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the role map entry pointer for a given role map entry index.
|
|
|
|
*
|
|
|
|
* @param aRoleMapIndex [in] the role map index to get the role map entry
|
|
|
|
* pointer for
|
|
|
|
* @return a pointer to the role map entry for the ARIA role,
|
|
|
|
* or nullptr, if none
|
|
|
|
*/
|
|
|
|
const nsRoleMapEntry* GetRoleMapFromIndex(uint8_t aRoleMapIndex);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the role map entry index for a given role map entry pointer. If the role
|
|
|
|
* map entry is within sWAIRoleMaps, return the index within that array,
|
|
|
|
* otherwise return one of the special index constants listed above.
|
|
|
|
*
|
|
|
|
* @param aRoleMap [in] the role map entry pointer to get the index for
|
|
|
|
* @return the index of the pointer to the role map entry, or
|
|
|
|
* NO_ROLE_MAP_ENTRY_INDEX if none
|
|
|
|
*/
|
|
|
|
uint8_t GetIndexFromRoleMap(const nsRoleMapEntry* aRoleMap);
|
|
|
|
|
2012-07-11 05:00:30 +04:00
|
|
|
/**
|
|
|
|
* Return accessible state from ARIA universal states applied to the given
|
|
|
|
* element.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t UniversalStatesFor(mozilla::dom::Element* aElement);
|
2012-07-11 05:00:30 +04:00
|
|
|
|
2013-04-25 07:48:26 +04:00
|
|
|
/**
|
|
|
|
* Get the ARIA attribute characteristics for a given ARIA attribute.
|
|
|
|
*
|
|
|
|
* @param aAtom ARIA attribute
|
|
|
|
* @return A bitflag representing the attribute characteristics
|
|
|
|
* (see above for possible bit masks, prefixed "ATTR_")
|
|
|
|
*/
|
2017-10-03 01:05:19 +03:00
|
|
|
uint8_t AttrCharacteristicsFor(nsAtom* aAtom);
|
2013-04-25 07:48:26 +04:00
|
|
|
|
2015-02-05 02:33:33 +03:00
|
|
|
/**
|
|
|
|
* Return true if the element has defined aria-hidden.
|
|
|
|
*/
|
|
|
|
bool HasDefinedARIAHidden(nsIContent* aContent);
|
|
|
|
|
2012-08-11 00:10:18 +04:00
|
|
|
/**
|
2014-11-28 18:01:43 +03:00
|
|
|
* Represents a simple enumerator for iterating through ARIA attributes
|
|
|
|
* exposed as object attributes on a given accessible.
|
2012-08-11 00:10:18 +04:00
|
|
|
*/
|
|
|
|
class AttrIterator {
|
|
|
|
public:
|
2017-12-05 20:05:51 +03:00
|
|
|
explicit AttrIterator(nsIContent* aContent)
|
2018-05-30 17:56:24 +03:00
|
|
|
: mElement(Element::FromNode(aContent)), mAttrIdx(0) {
|
2017-12-05 20:05:51 +03:00
|
|
|
mAttrCount = mElement ? mElement->GetAttrCount() : 0;
|
2012-08-11 00:10:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Next(nsAString& aAttrName, nsAString& aAttrValue);
|
|
|
|
|
|
|
|
private:
|
2015-01-07 02:35:02 +03:00
|
|
|
AttrIterator() = delete;
|
|
|
|
AttrIterator(const AttrIterator&) = delete;
|
|
|
|
AttrIterator& operator=(const AttrIterator&) = delete;
|
2012-08-11 00:10:18 +04:00
|
|
|
|
2017-12-05 20:05:51 +03:00
|
|
|
dom::Element* mElement;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mAttrIdx;
|
|
|
|
uint32_t mAttrCount;
|
2012-08-11 00:10:18 +04:00
|
|
|
};
|
|
|
|
|
2012-04-16 13:24:23 +04:00
|
|
|
} // namespace aria
|
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2007-06-05 19:41:07 +04:00
|
|
|
#endif
|