Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=2:tabstop=2: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef mozilla_a11y_aria_ARIAMap_h_ |
michael@0 | 9 | #define mozilla_a11y_aria_ARIAMap_h_ |
michael@0 | 10 | |
michael@0 | 11 | #include "ARIAStateMap.h" |
michael@0 | 12 | #include "mozilla/a11y/AccTypes.h" |
michael@0 | 13 | #include "mozilla/a11y/Role.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "nsIAtom.h" |
michael@0 | 16 | #include "nsIContent.h" |
michael@0 | 17 | |
michael@0 | 18 | class nsINode; |
michael@0 | 19 | |
michael@0 | 20 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 21 | // Value constants |
michael@0 | 22 | |
michael@0 | 23 | /** |
michael@0 | 24 | * Used to define if role requires to expose nsIAccessibleValue. |
michael@0 | 25 | */ |
michael@0 | 26 | enum EValueRule |
michael@0 | 27 | { |
michael@0 | 28 | /** |
michael@0 | 29 | * nsIAccessibleValue isn't exposed. |
michael@0 | 30 | */ |
michael@0 | 31 | eNoValue, |
michael@0 | 32 | |
michael@0 | 33 | /** |
michael@0 | 34 | * nsIAccessibleValue is implemented, supports value, min and max from |
michael@0 | 35 | * aria-valuenow, aria-valuemin and aria-valuemax. |
michael@0 | 36 | */ |
michael@0 | 37 | eHasValueMinMax |
michael@0 | 38 | }; |
michael@0 | 39 | |
michael@0 | 40 | |
michael@0 | 41 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 42 | // Action constants |
michael@0 | 43 | |
michael@0 | 44 | /** |
michael@0 | 45 | * Used to define if the role requires to expose action. |
michael@0 | 46 | */ |
michael@0 | 47 | enum EActionRule |
michael@0 | 48 | { |
michael@0 | 49 | eNoAction, |
michael@0 | 50 | eActivateAction, |
michael@0 | 51 | eClickAction, |
michael@0 | 52 | ePressAction, |
michael@0 | 53 | eCheckUncheckAction, |
michael@0 | 54 | eExpandAction, |
michael@0 | 55 | eJumpAction, |
michael@0 | 56 | eOpenCloseAction, |
michael@0 | 57 | eSelectAction, |
michael@0 | 58 | eSortAction, |
michael@0 | 59 | eSwitchAction |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 64 | // Live region constants |
michael@0 | 65 | |
michael@0 | 66 | /** |
michael@0 | 67 | * Used to define if role exposes default value of aria-live attribute. |
michael@0 | 68 | */ |
michael@0 | 69 | enum ELiveAttrRule |
michael@0 | 70 | { |
michael@0 | 71 | eNoLiveAttr, |
michael@0 | 72 | eOffLiveAttr, |
michael@0 | 73 | ePoliteLiveAttr |
michael@0 | 74 | }; |
michael@0 | 75 | |
michael@0 | 76 | |
michael@0 | 77 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 78 | // Role constants |
michael@0 | 79 | |
michael@0 | 80 | /** |
michael@0 | 81 | * ARIA role overrides role from native markup. |
michael@0 | 82 | */ |
michael@0 | 83 | const bool kUseMapRole = true; |
michael@0 | 84 | |
michael@0 | 85 | /** |
michael@0 | 86 | * ARIA role doesn't override the role from native markup. |
michael@0 | 87 | */ |
michael@0 | 88 | const bool kUseNativeRole = false; |
michael@0 | 89 | |
michael@0 | 90 | |
michael@0 | 91 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 92 | // ARIA attribute characteristic masks |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * This mask indicates the attribute should not be exposed as an object |
michael@0 | 96 | * attribute via the catch-all logic in Accessible::Attributes(). |
michael@0 | 97 | * This means it either isn't mean't to be exposed as an object attribute, or |
michael@0 | 98 | * that it should, but is already handled in other code. |
michael@0 | 99 | */ |
michael@0 | 100 | const uint8_t ATTR_BYPASSOBJ = 0x1 << 0; |
michael@0 | 101 | const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1; |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * This mask indicates the attribute is expected to have an NMTOKEN or bool value. |
michael@0 | 105 | * (See for example usage in Accessible::Attributes()) |
michael@0 | 106 | */ |
michael@0 | 107 | const uint8_t ATTR_VALTOKEN = 0x1 << 2; |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Indicate the attribute is global state or property (refer to |
michael@0 | 111 | * http://www.w3.org/TR/wai-aria/states_and_properties#global_states). |
michael@0 | 112 | */ |
michael@0 | 113 | const uint8_t ATTR_GLOBAL = 0x1 << 3; |
michael@0 | 114 | |
michael@0 | 115 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 116 | // State map entry |
michael@0 | 117 | |
michael@0 | 118 | /** |
michael@0 | 119 | * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for |
michael@0 | 120 | * a given role. |
michael@0 | 121 | */ |
michael@0 | 122 | #define kNoReqStates 0 |
michael@0 | 123 | |
michael@0 | 124 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 125 | // Role map entry |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * For each ARIA role, this maps the nsIAccessible information. |
michael@0 | 129 | */ |
michael@0 | 130 | struct nsRoleMapEntry |
michael@0 | 131 | { |
michael@0 | 132 | /** |
michael@0 | 133 | * Return true if matches to the given ARIA role. |
michael@0 | 134 | */ |
michael@0 | 135 | bool Is(nsIAtom* aARIARole) const |
michael@0 | 136 | { return *roleAtom == aARIARole; } |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Return true if ARIA role has the given accessible type. |
michael@0 | 140 | */ |
michael@0 | 141 | bool IsOfType(mozilla::a11y::AccGenericType aType) const |
michael@0 | 142 | { return accTypes & aType; } |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * Return ARIA role. |
michael@0 | 146 | */ |
michael@0 | 147 | const nsDependentAtomString ARIARoleString() const |
michael@0 | 148 | { return nsDependentAtomString(*roleAtom); } |
michael@0 | 149 | |
michael@0 | 150 | // ARIA role: string representation such as "button" |
michael@0 | 151 | nsIAtom** roleAtom; |
michael@0 | 152 | |
michael@0 | 153 | // Role mapping rule: maps to this nsIAccessibleRole |
michael@0 | 154 | mozilla::a11y::role role; |
michael@0 | 155 | |
michael@0 | 156 | // Role rule: whether to use mapped role or native semantics |
michael@0 | 157 | bool roleRule; |
michael@0 | 158 | |
michael@0 | 159 | // Value mapping rule: how to compute nsIAccessible value |
michael@0 | 160 | EValueRule valueRule; |
michael@0 | 161 | |
michael@0 | 162 | // Action mapping rule, how to expose nsIAccessible action |
michael@0 | 163 | EActionRule actionRule; |
michael@0 | 164 | |
michael@0 | 165 | // 'live' and 'container-live' object attributes mapping rule: how to expose |
michael@0 | 166 | // these object attributes if ARIA 'live' attribute is missed. |
michael@0 | 167 | ELiveAttrRule liveAttRule; |
michael@0 | 168 | |
michael@0 | 169 | // Accessible types this role belongs to. |
michael@0 | 170 | uint32_t accTypes; |
michael@0 | 171 | |
michael@0 | 172 | // Automatic state mapping rule: always include in nsIAccessibleStates |
michael@0 | 173 | uint64_t state; // or kNoReqStates if no nsIAccessibleStates are automatic for this role. |
michael@0 | 174 | |
michael@0 | 175 | // ARIA properties supported for this role |
michael@0 | 176 | // (in other words, the aria-foo attribute to nsIAccessibleStates mapping rules) |
michael@0 | 177 | // Currently you cannot have unlimited mappings, because |
michael@0 | 178 | // a variable sized array would not allow the use of |
michael@0 | 179 | // C++'s struct initialization feature. |
michael@0 | 180 | mozilla::a11y::aria::EStateRule attributeMap1; |
michael@0 | 181 | mozilla::a11y::aria::EStateRule attributeMap2; |
michael@0 | 182 | mozilla::a11y::aria::EStateRule attributeMap3; |
michael@0 | 183 | }; |
michael@0 | 184 | |
michael@0 | 185 | |
michael@0 | 186 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 187 | // ARIA map |
michael@0 | 188 | |
michael@0 | 189 | /** |
michael@0 | 190 | * These provide the mappings for WAI-ARIA roles, states and properties using |
michael@0 | 191 | * the structs defined in this file and ARIAStateMap files. |
michael@0 | 192 | */ |
michael@0 | 193 | namespace mozilla { |
michael@0 | 194 | namespace a11y { |
michael@0 | 195 | namespace aria { |
michael@0 | 196 | |
michael@0 | 197 | /** |
michael@0 | 198 | * Empty role map entry. Used by accessibility service to create an accessible |
michael@0 | 199 | * if the accessible can't use role of used accessible class. For example, |
michael@0 | 200 | * it is used for table cells that aren't contained by table. |
michael@0 | 201 | */ |
michael@0 | 202 | extern nsRoleMapEntry gEmptyRoleMap; |
michael@0 | 203 | |
michael@0 | 204 | /** |
michael@0 | 205 | * Get the role map entry for a given DOM node. This will use the first |
michael@0 | 206 | * ARIA role if the role attribute provides a space delimited list of roles. |
michael@0 | 207 | * |
michael@0 | 208 | * @param aNode [in] the DOM node to get the role map entry for |
michael@0 | 209 | * @return a pointer to the role map entry for the ARIA role, or nullptr |
michael@0 | 210 | * if none |
michael@0 | 211 | */ |
michael@0 | 212 | nsRoleMapEntry* GetRoleMap(nsINode* aNode); |
michael@0 | 213 | |
michael@0 | 214 | /** |
michael@0 | 215 | * Return accessible state from ARIA universal states applied to the given |
michael@0 | 216 | * element. |
michael@0 | 217 | */ |
michael@0 | 218 | uint64_t UniversalStatesFor(mozilla::dom::Element* aElement); |
michael@0 | 219 | |
michael@0 | 220 | /** |
michael@0 | 221 | * Get the ARIA attribute characteristics for a given ARIA attribute. |
michael@0 | 222 | * |
michael@0 | 223 | * @param aAtom ARIA attribute |
michael@0 | 224 | * @return A bitflag representing the attribute characteristics |
michael@0 | 225 | * (see above for possible bit masks, prefixed "ATTR_") |
michael@0 | 226 | */ |
michael@0 | 227 | uint8_t AttrCharacteristicsFor(nsIAtom* aAtom); |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Represents a simple enumerator for iterating through ARIA attributes |
michael@0 | 231 | * exposed as object attributes on a given accessible. |
michael@0 | 232 | */ |
michael@0 | 233 | class AttrIterator |
michael@0 | 234 | { |
michael@0 | 235 | public: |
michael@0 | 236 | AttrIterator(nsIContent* aContent) : |
michael@0 | 237 | mContent(aContent), mAttrIdx(0) |
michael@0 | 238 | { |
michael@0 | 239 | mAttrCount = mContent->GetAttrCount(); |
michael@0 | 240 | } |
michael@0 | 241 | |
michael@0 | 242 | bool Next(nsAString& aAttrName, nsAString& aAttrValue); |
michael@0 | 243 | |
michael@0 | 244 | private: |
michael@0 | 245 | AttrIterator() MOZ_DELETE; |
michael@0 | 246 | AttrIterator(const AttrIterator&) MOZ_DELETE; |
michael@0 | 247 | AttrIterator& operator= (const AttrIterator&) MOZ_DELETE; |
michael@0 | 248 | |
michael@0 | 249 | nsIContent* mContent; |
michael@0 | 250 | uint32_t mAttrIdx; |
michael@0 | 251 | uint32_t mAttrCount; |
michael@0 | 252 | }; |
michael@0 | 253 | |
michael@0 | 254 | } // namespace aria |
michael@0 | 255 | } // namespace a11y |
michael@0 | 256 | } // namespace mozilla |
michael@0 | 257 | |
michael@0 | 258 | #endif |