michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:expandtab:shiftwidth=2:tabstop=2: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_a11y_aria_ARIAMap_h_ michael@0: #define mozilla_a11y_aria_ARIAMap_h_ michael@0: michael@0: #include "ARIAStateMap.h" michael@0: #include "mozilla/a11y/AccTypes.h" michael@0: #include "mozilla/a11y/Role.h" michael@0: michael@0: #include "nsIAtom.h" michael@0: #include "nsIContent.h" michael@0: michael@0: class nsINode; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Value constants michael@0: michael@0: /** michael@0: * Used to define if role requires to expose nsIAccessibleValue. michael@0: */ michael@0: enum EValueRule michael@0: { michael@0: /** michael@0: * nsIAccessibleValue isn't exposed. michael@0: */ michael@0: eNoValue, michael@0: michael@0: /** michael@0: * nsIAccessibleValue is implemented, supports value, min and max from michael@0: * aria-valuenow, aria-valuemin and aria-valuemax. michael@0: */ michael@0: eHasValueMinMax michael@0: }; michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Action constants michael@0: michael@0: /** michael@0: * Used to define if the role requires to expose action. michael@0: */ michael@0: enum EActionRule michael@0: { michael@0: eNoAction, michael@0: eActivateAction, michael@0: eClickAction, michael@0: ePressAction, michael@0: eCheckUncheckAction, michael@0: eExpandAction, michael@0: eJumpAction, michael@0: eOpenCloseAction, michael@0: eSelectAction, michael@0: eSortAction, michael@0: eSwitchAction michael@0: }; michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Live region constants michael@0: michael@0: /** michael@0: * Used to define if role exposes default value of aria-live attribute. michael@0: */ michael@0: enum ELiveAttrRule michael@0: { michael@0: eNoLiveAttr, michael@0: eOffLiveAttr, michael@0: ePoliteLiveAttr michael@0: }; michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Role constants michael@0: michael@0: /** michael@0: * ARIA role overrides role from native markup. michael@0: */ michael@0: const bool kUseMapRole = true; michael@0: michael@0: /** michael@0: * ARIA role doesn't override the role from native markup. michael@0: */ michael@0: const bool kUseNativeRole = false; michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // ARIA attribute characteristic masks michael@0: michael@0: /** michael@0: * This mask indicates the attribute should not be exposed as an object michael@0: * attribute via the catch-all logic in Accessible::Attributes(). michael@0: * This means it either isn't mean't to be exposed as an object attribute, or michael@0: * that it should, but is already handled in other code. michael@0: */ michael@0: const uint8_t ATTR_BYPASSOBJ = 0x1 << 0; michael@0: const uint8_t ATTR_BYPASSOBJ_IF_FALSE = 0x1 << 1; michael@0: michael@0: /** michael@0: * This mask indicates the attribute is expected to have an NMTOKEN or bool value. michael@0: * (See for example usage in Accessible::Attributes()) michael@0: */ michael@0: const uint8_t ATTR_VALTOKEN = 0x1 << 2; michael@0: michael@0: /** michael@0: * Indicate the attribute is global state or property (refer to michael@0: * http://www.w3.org/TR/wai-aria/states_and_properties#global_states). michael@0: */ michael@0: const uint8_t ATTR_GLOBAL = 0x1 << 3; michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // State map entry michael@0: michael@0: /** michael@0: * Used in nsRoleMapEntry.state if no nsIAccessibleStates are automatic for michael@0: * a given role. michael@0: */ michael@0: #define kNoReqStates 0 michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Role map entry michael@0: michael@0: /** michael@0: * For each ARIA role, this maps the nsIAccessible information. michael@0: */ michael@0: struct nsRoleMapEntry michael@0: { michael@0: /** michael@0: * Return true if matches to the given ARIA role. michael@0: */ michael@0: bool Is(nsIAtom* aARIARole) const michael@0: { return *roleAtom == aARIARole; } michael@0: michael@0: /** michael@0: * Return true if ARIA role has the given accessible type. michael@0: */ michael@0: bool IsOfType(mozilla::a11y::AccGenericType aType) const michael@0: { return accTypes & aType; } michael@0: michael@0: /** michael@0: * Return ARIA role. michael@0: */ michael@0: const nsDependentAtomString ARIARoleString() const michael@0: { return nsDependentAtomString(*roleAtom); } michael@0: michael@0: // ARIA role: string representation such as "button" michael@0: nsIAtom** roleAtom; michael@0: michael@0: // Role mapping rule: maps to this nsIAccessibleRole michael@0: mozilla::a11y::role role; michael@0: michael@0: // Role rule: whether to use mapped role or native semantics michael@0: bool roleRule; michael@0: michael@0: // Value mapping rule: how to compute nsIAccessible value michael@0: EValueRule valueRule; michael@0: michael@0: // Action mapping rule, how to expose nsIAccessible action michael@0: EActionRule actionRule; michael@0: michael@0: // 'live' and 'container-live' object attributes mapping rule: how to expose michael@0: // these object attributes if ARIA 'live' attribute is missed. michael@0: ELiveAttrRule liveAttRule; michael@0: michael@0: // Accessible types this role belongs to. michael@0: uint32_t accTypes; michael@0: michael@0: // Automatic state mapping rule: always include in nsIAccessibleStates michael@0: uint64_t state; // or kNoReqStates if no nsIAccessibleStates are automatic for this role. michael@0: michael@0: // ARIA properties supported for this role michael@0: // (in other words, the aria-foo attribute to nsIAccessibleStates mapping rules) michael@0: // Currently you cannot have unlimited mappings, because michael@0: // a variable sized array would not allow the use of michael@0: // C++'s struct initialization feature. michael@0: mozilla::a11y::aria::EStateRule attributeMap1; michael@0: mozilla::a11y::aria::EStateRule attributeMap2; michael@0: mozilla::a11y::aria::EStateRule attributeMap3; michael@0: }; michael@0: michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // ARIA map michael@0: michael@0: /** michael@0: * These provide the mappings for WAI-ARIA roles, states and properties using michael@0: * the structs defined in this file and ARIAStateMap files. michael@0: */ michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: namespace aria { michael@0: michael@0: /** michael@0: * Empty role map entry. Used by accessibility service to create an accessible michael@0: * if the accessible can't use role of used accessible class. For example, michael@0: * it is used for table cells that aren't contained by table. michael@0: */ michael@0: extern nsRoleMapEntry gEmptyRoleMap; michael@0: michael@0: /** michael@0: * Get the role map entry for a given DOM node. This will use the first michael@0: * ARIA role if the role attribute provides a space delimited list of roles. michael@0: * michael@0: * @param aNode [in] the DOM node to get the role map entry for michael@0: * @return a pointer to the role map entry for the ARIA role, or nullptr michael@0: * if none michael@0: */ michael@0: nsRoleMapEntry* GetRoleMap(nsINode* aNode); michael@0: michael@0: /** michael@0: * Return accessible state from ARIA universal states applied to the given michael@0: * element. michael@0: */ michael@0: uint64_t UniversalStatesFor(mozilla::dom::Element* aElement); michael@0: michael@0: /** michael@0: * Get the ARIA attribute characteristics for a given ARIA attribute. michael@0: * michael@0: * @param aAtom ARIA attribute michael@0: * @return A bitflag representing the attribute characteristics michael@0: * (see above for possible bit masks, prefixed "ATTR_") michael@0: */ michael@0: uint8_t AttrCharacteristicsFor(nsIAtom* aAtom); michael@0: michael@0: /** michael@0: * Represents a simple enumerator for iterating through ARIA attributes michael@0: * exposed as object attributes on a given accessible. michael@0: */ michael@0: class AttrIterator michael@0: { michael@0: public: michael@0: AttrIterator(nsIContent* aContent) : michael@0: mContent(aContent), mAttrIdx(0) michael@0: { michael@0: mAttrCount = mContent->GetAttrCount(); michael@0: } michael@0: michael@0: bool Next(nsAString& aAttrName, nsAString& aAttrValue); michael@0: michael@0: private: michael@0: AttrIterator() MOZ_DELETE; michael@0: AttrIterator(const AttrIterator&) MOZ_DELETE; michael@0: AttrIterator& operator= (const AttrIterator&) MOZ_DELETE; michael@0: michael@0: nsIContent* mContent; michael@0: uint32_t mAttrIdx; michael@0: uint32_t mAttrCount; michael@0: }; michael@0: michael@0: } // namespace aria michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif