accessible/src/base/ARIAMap.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/base/ARIAMap.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,258 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:expandtab:shiftwidth=2:tabstop=2:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#ifndef mozilla_a11y_aria_ARIAMap_h_
    1.12 +#define mozilla_a11y_aria_ARIAMap_h_
    1.13 +
    1.14 +#include "ARIAStateMap.h"
    1.15 +#include "mozilla/a11y/AccTypes.h"
    1.16 +#include "mozilla/a11y/Role.h"
    1.17 +
    1.18 +#include "nsIAtom.h"
    1.19 +#include "nsIContent.h"
    1.20 +
    1.21 +class nsINode;
    1.22 +
    1.23 +////////////////////////////////////////////////////////////////////////////////
    1.24 +// Value constants
    1.25 +
    1.26 +/**
    1.27 + * Used to define if role requires to expose nsIAccessibleValue.
    1.28 + */
    1.29 +enum EValueRule
    1.30 +{
    1.31 +  /**
    1.32 +   * nsIAccessibleValue isn't exposed.
    1.33 +   */
    1.34 +  eNoValue,
    1.35 +
    1.36 +  /**
    1.37 +   * nsIAccessibleValue is implemented, supports value, min and max from
    1.38 +   * aria-valuenow, aria-valuemin and aria-valuemax.
    1.39 +   */
    1.40 +  eHasValueMinMax
    1.41 +};
    1.42 +
    1.43 +
    1.44 +////////////////////////////////////////////////////////////////////////////////
    1.45 +// Action constants
    1.46 +
    1.47 +/**
    1.48 + * Used to define if the role requires to expose action.
    1.49 + */
    1.50 +enum EActionRule
    1.51 +{
    1.52 +  eNoAction,
    1.53 +  eActivateAction,
    1.54 +  eClickAction,
    1.55 +  ePressAction,
    1.56 +  eCheckUncheckAction,
    1.57 +  eExpandAction,
    1.58 +  eJumpAction,
    1.59 +  eOpenCloseAction,
    1.60 +  eSelectAction,
    1.61 +  eSortAction,
    1.62 +  eSwitchAction
    1.63 +};
    1.64 +
    1.65 +
    1.66 +////////////////////////////////////////////////////////////////////////////////
    1.67 +// Live region constants
    1.68 +
    1.69 +/**
    1.70 + * Used to define if role exposes default value of aria-live attribute.
    1.71 + */
    1.72 +enum ELiveAttrRule
    1.73 +{
    1.74 +  eNoLiveAttr,
    1.75 +  eOffLiveAttr,
    1.76 +  ePoliteLiveAttr
    1.77 +};
    1.78 +
    1.79 +
    1.80 +////////////////////////////////////////////////////////////////////////////////
    1.81 +// Role constants
    1.82 +
    1.83 +/**
    1.84 + * ARIA role overrides role from native markup.
    1.85 + */
    1.86 +const bool kUseMapRole = true;
    1.87 +
    1.88 +/**
    1.89 + * ARIA role doesn't override the role from native markup.
    1.90 + */
    1.91 +const bool kUseNativeRole = false;
    1.92 +
    1.93 +
    1.94 +////////////////////////////////////////////////////////////////////////////////
    1.95 +// ARIA attribute characteristic masks
    1.96 +
    1.97 +/**
    1.98 + * This mask indicates the attribute should not be exposed as an object
    1.99 + * attribute via the catch-all logic in Accessible::Attributes().
   1.100 + * This means it either isn't mean't to be exposed as an object attribute, or
   1.101 + * that it should, but is already handled in other code.
   1.102 + */
   1.103 +const uint8_t ATTR_BYPASSOBJ = 0x1 << 0;
   1.104 +const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1;
   1.105 +
   1.106 +/**
   1.107 + * This mask indicates the attribute is expected to have an NMTOKEN or bool value.
   1.108 + * (See for example usage in Accessible::Attributes())
   1.109 + */
   1.110 +const uint8_t ATTR_VALTOKEN = 0x1 << 2;
   1.111 +
   1.112 +/**
   1.113 + * Indicate the attribute is global state or property (refer to
   1.114 + * http://www.w3.org/TR/wai-aria/states_and_properties#global_states).
   1.115 + */
   1.116 +const uint8_t ATTR_GLOBAL = 0x1 << 3;
   1.117 +
   1.118 +////////////////////////////////////////////////////////////////////////////////
   1.119 +// State map entry
   1.120 +
   1.121 +/**
   1.122 + * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for
   1.123 + * a given role.
   1.124 + */
   1.125 +#define kNoReqStates 0
   1.126 +
   1.127 +////////////////////////////////////////////////////////////////////////////////
   1.128 +// Role map entry
   1.129 +
   1.130 +/**
   1.131 + * For each ARIA role, this maps the nsIAccessible information.
   1.132 + */
   1.133 +struct nsRoleMapEntry
   1.134 +{
   1.135 +  /**
   1.136 +   * Return true if matches to the given ARIA role.
   1.137 +   */
   1.138 +  bool Is(nsIAtom* aARIARole) const
   1.139 +    { return *roleAtom == aARIARole; }
   1.140 +
   1.141 +  /**
   1.142 +   * Return true if ARIA role has the given accessible type.
   1.143 +   */
   1.144 +  bool IsOfType(mozilla::a11y::AccGenericType aType) const
   1.145 +    { return accTypes & aType; }
   1.146 +
   1.147 +  /**
   1.148 +   * Return ARIA role.
   1.149 +   */
   1.150 +  const nsDependentAtomString ARIARoleString() const
   1.151 +    { return nsDependentAtomString(*roleAtom); }
   1.152 +
   1.153 +  // ARIA role: string representation such as "button"
   1.154 +  nsIAtom** roleAtom;
   1.155 +
   1.156 +  // Role mapping rule: maps to this nsIAccessibleRole
   1.157 +  mozilla::a11y::role role;
   1.158 +  
   1.159 +  // Role rule: whether to use mapped role or native semantics
   1.160 +  bool roleRule;
   1.161 +  
   1.162 +  // Value mapping rule: how to compute nsIAccessible value
   1.163 +  EValueRule valueRule;
   1.164 +
   1.165 +  // Action mapping rule, how to expose nsIAccessible action
   1.166 +  EActionRule actionRule;
   1.167 +
   1.168 +  // 'live' and 'container-live' object attributes mapping rule: how to expose
   1.169 +  // these object attributes if ARIA 'live' attribute is missed.
   1.170 +  ELiveAttrRule liveAttRule;
   1.171 +
   1.172 +  // Accessible types this role belongs to.
   1.173 +  uint32_t accTypes;
   1.174 +
   1.175 +  // Automatic state mapping rule: always include in nsIAccessibleStates
   1.176 +  uint64_t state;   // or kNoReqStates if no nsIAccessibleStates are automatic for this role.
   1.177 +
   1.178 +  // ARIA properties supported for this role
   1.179 +  // (in other words, the aria-foo attribute to nsIAccessibleStates mapping rules)
   1.180 +  // Currently you cannot have unlimited mappings, because
   1.181 +  // a variable sized array would not allow the use of
   1.182 +  // C++'s struct initialization feature.
   1.183 +  mozilla::a11y::aria::EStateRule attributeMap1;
   1.184 +  mozilla::a11y::aria::EStateRule attributeMap2;
   1.185 +  mozilla::a11y::aria::EStateRule attributeMap3;
   1.186 +};
   1.187 +
   1.188 +
   1.189 +////////////////////////////////////////////////////////////////////////////////
   1.190 +// ARIA map
   1.191 +
   1.192 +/**
   1.193 + *  These provide the mappings for WAI-ARIA roles, states and properties using
   1.194 + *  the structs defined in this file and ARIAStateMap files.
   1.195 + */
   1.196 +namespace mozilla {
   1.197 +namespace a11y {
   1.198 +namespace aria {
   1.199 +
   1.200 +/**
   1.201 + * Empty role map entry. Used by accessibility service to create an accessible
   1.202 + * if the accessible can't use role of used accessible class. For example,
   1.203 + * it is used for table cells that aren't contained by table.
   1.204 + */
   1.205 +extern nsRoleMapEntry gEmptyRoleMap;
   1.206 +
   1.207 +/**
   1.208 + * Get the role map entry for a given DOM node. This will use the first
   1.209 + * ARIA role if the role attribute provides a space delimited list of roles.
   1.210 + *
   1.211 + * @param aNode  [in] the DOM node to get the role map entry for
   1.212 + * @return        a pointer to the role map entry for the ARIA role, or nullptr
   1.213 + *                if none
   1.214 + */
   1.215 +nsRoleMapEntry* GetRoleMap(nsINode* aNode);
   1.216 +
   1.217 +/**
   1.218 + * Return accessible state from ARIA universal states applied to the given
   1.219 + * element.
   1.220 + */
   1.221 +uint64_t UniversalStatesFor(mozilla::dom::Element* aElement);
   1.222 +
   1.223 +/**
   1.224 + * Get the ARIA attribute characteristics for a given ARIA attribute.
   1.225 + *
   1.226 + * @param aAtom  ARIA attribute
   1.227 + * @return       A bitflag representing the attribute characteristics
   1.228 + *               (see above for possible bit masks, prefixed "ATTR_")
   1.229 + */
   1.230 +uint8_t AttrCharacteristicsFor(nsIAtom* aAtom);
   1.231 +
   1.232 + /**
   1.233 +  * Represents a simple enumerator for iterating through ARIA attributes 
   1.234 +  * exposed as object attributes on a given accessible. 
   1.235 +  */
   1.236 +class AttrIterator
   1.237 +{
   1.238 +public:
   1.239 +  AttrIterator(nsIContent* aContent) : 
   1.240 +    mContent(aContent), mAttrIdx(0) 
   1.241 +  { 
   1.242 +    mAttrCount = mContent->GetAttrCount();
   1.243 +  }
   1.244 +
   1.245 +  bool Next(nsAString& aAttrName, nsAString& aAttrValue);
   1.246 +
   1.247 +private:
   1.248 +  AttrIterator() MOZ_DELETE;
   1.249 +  AttrIterator(const AttrIterator&) MOZ_DELETE;
   1.250 +  AttrIterator& operator= (const AttrIterator&) MOZ_DELETE;
   1.251 +
   1.252 +  nsIContent* mContent;
   1.253 +  uint32_t mAttrIdx;
   1.254 +  uint32_t mAttrCount;
   1.255 +};
   1.256 +
   1.257 +} // namespace aria
   1.258 +} // namespace a11y
   1.259 +} // namespace mozilla
   1.260 +
   1.261 +#endif

mercurial