Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsAccUtils_h_ |
michael@0 | 7 | #define nsAccUtils_h_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/a11y/Accessible.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsAccessibilityService.h" |
michael@0 | 12 | #include "nsCoreUtils.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "nsIDocShell.h" |
michael@0 | 15 | #include "nsPoint.h" |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | |
michael@0 | 19 | namespace dom { |
michael@0 | 20 | class Element; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | namespace a11y { |
michael@0 | 24 | |
michael@0 | 25 | class HyperTextAccessible; |
michael@0 | 26 | class DocAccessible; |
michael@0 | 27 | |
michael@0 | 28 | class nsAccUtils |
michael@0 | 29 | { |
michael@0 | 30 | public: |
michael@0 | 31 | /** |
michael@0 | 32 | * Returns value of attribute from the given attributes container. |
michael@0 | 33 | * |
michael@0 | 34 | * @param aAttributes - attributes container |
michael@0 | 35 | * @param aAttrName - the name of requested attribute |
michael@0 | 36 | * @param aAttrValue - value of attribute |
michael@0 | 37 | */ |
michael@0 | 38 | static void GetAccAttr(nsIPersistentProperties *aAttributes, |
michael@0 | 39 | nsIAtom *aAttrName, |
michael@0 | 40 | nsAString& aAttrValue); |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Set value of attribute for the given attributes container. |
michael@0 | 44 | * |
michael@0 | 45 | * @param aAttributes - attributes container |
michael@0 | 46 | * @param aAttrName - the name of requested attribute |
michael@0 | 47 | * @param aAttrValue - new value of attribute |
michael@0 | 48 | */ |
michael@0 | 49 | static void SetAccAttr(nsIPersistentProperties *aAttributes, |
michael@0 | 50 | nsIAtom *aAttrName, |
michael@0 | 51 | const nsAString& aAttrValue); |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * Set group attributes ('level', 'setsize', 'posinset'). |
michael@0 | 55 | */ |
michael@0 | 56 | static void SetAccGroupAttrs(nsIPersistentProperties *aAttributes, |
michael@0 | 57 | int32_t aLevel, int32_t aSetSize, |
michael@0 | 58 | int32_t aPosInSet); |
michael@0 | 59 | |
michael@0 | 60 | /** |
michael@0 | 61 | * Get default value of the level for the given accessible. |
michael@0 | 62 | */ |
michael@0 | 63 | static int32_t GetDefaultLevel(Accessible* aAcc); |
michael@0 | 64 | |
michael@0 | 65 | /** |
michael@0 | 66 | * Return ARIA level value or the default one if ARIA is missed for the |
michael@0 | 67 | * given accessible. |
michael@0 | 68 | */ |
michael@0 | 69 | static int32_t GetARIAOrDefaultLevel(Accessible* aAccessible); |
michael@0 | 70 | |
michael@0 | 71 | /** |
michael@0 | 72 | * Compute group level for nsIDOMXULContainerItemElement node. |
michael@0 | 73 | */ |
michael@0 | 74 | static int32_t GetLevelForXULContainerItem(nsIContent *aContent); |
michael@0 | 75 | |
michael@0 | 76 | /** |
michael@0 | 77 | * Set container-foo live region attributes for the given node. |
michael@0 | 78 | * |
michael@0 | 79 | * @param aAttributes where to store the attributes |
michael@0 | 80 | * @param aStartContent node to start from |
michael@0 | 81 | * @param aTopContent node to end at |
michael@0 | 82 | */ |
michael@0 | 83 | static void SetLiveContainerAttributes(nsIPersistentProperties *aAttributes, |
michael@0 | 84 | nsIContent *aStartContent, |
michael@0 | 85 | nsIContent *aTopContent); |
michael@0 | 86 | |
michael@0 | 87 | /** |
michael@0 | 88 | * Any ARIA property of type boolean or NMTOKEN is undefined if the ARIA |
michael@0 | 89 | * property is not present, or is "" or "undefined". Do not call |
michael@0 | 90 | * this method for properties of type string, decimal, IDREF or IDREFS. |
michael@0 | 91 | * |
michael@0 | 92 | * Return true if the ARIA property is defined, otherwise false |
michael@0 | 93 | */ |
michael@0 | 94 | static bool HasDefinedARIAToken(nsIContent *aContent, nsIAtom *aAtom); |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * Return atomic value of ARIA attribute of boolean or NMTOKEN type. |
michael@0 | 98 | */ |
michael@0 | 99 | static nsIAtom* GetARIAToken(mozilla::dom::Element* aElement, nsIAtom* aAttr); |
michael@0 | 100 | |
michael@0 | 101 | /** |
michael@0 | 102 | * Return document accessible for the given DOM node. |
michael@0 | 103 | */ |
michael@0 | 104 | static DocAccessible* GetDocAccessibleFor(nsINode* aNode) |
michael@0 | 105 | { |
michael@0 | 106 | nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode); |
michael@0 | 107 | return GetAccService()->GetDocAccessible(presShell); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * Return document accessible for the given docshell. |
michael@0 | 112 | */ |
michael@0 | 113 | static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer) |
michael@0 | 114 | { |
michael@0 | 115 | nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer)); |
michael@0 | 116 | return GetAccService()->GetDocAccessible(docShell->GetPresShell()); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Return single or multi selectable container for the given item. |
michael@0 | 121 | * |
michael@0 | 122 | * @param aAccessible [in] the item accessible |
michael@0 | 123 | * @param aState [in] the state of the item accessible |
michael@0 | 124 | */ |
michael@0 | 125 | static Accessible* GetSelectableContainer(Accessible* aAccessible, |
michael@0 | 126 | uint64_t aState); |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * Return a text container accessible for the given node. |
michael@0 | 130 | */ |
michael@0 | 131 | static HyperTextAccessible* GetTextContainer(nsINode* aNode); |
michael@0 | 132 | |
michael@0 | 133 | /** |
michael@0 | 134 | * Return true if the DOM node of given accessible has aria-selected="true" |
michael@0 | 135 | * attribute. |
michael@0 | 136 | */ |
michael@0 | 137 | static bool IsARIASelected(Accessible* aAccessible); |
michael@0 | 138 | |
michael@0 | 139 | /** |
michael@0 | 140 | * Converts the given coordinates to coordinates relative screen. |
michael@0 | 141 | * |
michael@0 | 142 | * @param aX [in] the given x coord |
michael@0 | 143 | * @param aY [in] the given y coord |
michael@0 | 144 | * @param aCoordinateType [in] specifies coordinates origin (refer to |
michael@0 | 145 | * nsIAccessibleCoordinateType) |
michael@0 | 146 | * @param aAccessible [in] the accessible if coordinates are given |
michael@0 | 147 | * relative it. |
michael@0 | 148 | * @return converted coordinates |
michael@0 | 149 | */ |
michael@0 | 150 | static nsIntPoint ConvertToScreenCoords(int32_t aX, int32_t aY, |
michael@0 | 151 | uint32_t aCoordinateType, |
michael@0 | 152 | Accessible* aAccessible); |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * Converts the given coordinates relative screen to another coordinate |
michael@0 | 156 | * system. |
michael@0 | 157 | * |
michael@0 | 158 | * @param aX [in, out] the given x coord |
michael@0 | 159 | * @param aY [in, out] the given y coord |
michael@0 | 160 | * @param aCoordinateType [in] specifies coordinates origin (refer to |
michael@0 | 161 | * nsIAccessibleCoordinateType) |
michael@0 | 162 | * @param aAccessible [in] the accessible if coordinates are given |
michael@0 | 163 | * relative it |
michael@0 | 164 | */ |
michael@0 | 165 | static void ConvertScreenCoordsTo(int32_t* aX, int32_t* aY, |
michael@0 | 166 | uint32_t aCoordinateType, |
michael@0 | 167 | Accessible* aAccessible); |
michael@0 | 168 | |
michael@0 | 169 | /** |
michael@0 | 170 | * Returns coordinates relative screen for the parent of the given accessible. |
michael@0 | 171 | * |
michael@0 | 172 | * @param [in] aAccessible the accessible |
michael@0 | 173 | */ |
michael@0 | 174 | static nsIntPoint GetScreenCoordsForParent(Accessible* aAccessible); |
michael@0 | 175 | |
michael@0 | 176 | /** |
michael@0 | 177 | * Get the 'live' or 'container-live' object attribute value from the given |
michael@0 | 178 | * ELiveAttrRule constant. |
michael@0 | 179 | * |
michael@0 | 180 | * @param aRule [in] rule constant (see ELiveAttrRule in nsAccMap.h) |
michael@0 | 181 | * @param aValue [out] object attribute value |
michael@0 | 182 | * |
michael@0 | 183 | * @return true if object attribute should be exposed |
michael@0 | 184 | */ |
michael@0 | 185 | static bool GetLiveAttrValue(uint32_t aRule, nsAString& aValue); |
michael@0 | 186 | |
michael@0 | 187 | #ifdef DEBUG |
michael@0 | 188 | /** |
michael@0 | 189 | * Detect whether the given accessible object implements nsIAccessibleText, |
michael@0 | 190 | * when it is text or has text child node. |
michael@0 | 191 | */ |
michael@0 | 192 | static bool IsTextInterfaceSupportCorrect(Accessible* aAccessible); |
michael@0 | 193 | #endif |
michael@0 | 194 | |
michael@0 | 195 | /** |
michael@0 | 196 | * Return text length of the given accessible, return 0 on failure. |
michael@0 | 197 | */ |
michael@0 | 198 | static uint32_t TextLength(Accessible* aAccessible); |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * Return true if the given accessible is embedded object. |
michael@0 | 202 | */ |
michael@0 | 203 | static bool IsEmbeddedObject(Accessible* aAcc) |
michael@0 | 204 | { |
michael@0 | 205 | uint32_t role = aAcc->Role(); |
michael@0 | 206 | return role != roles::TEXT_LEAF && |
michael@0 | 207 | role != roles::WHITESPACE && |
michael@0 | 208 | role != roles::STATICTEXT; |
michael@0 | 209 | } |
michael@0 | 210 | |
michael@0 | 211 | /** |
michael@0 | 212 | * Transform nsIAccessibleStates constants to internal state constant. |
michael@0 | 213 | */ |
michael@0 | 214 | static inline uint64_t To64State(uint32_t aState1, uint32_t aState2) |
michael@0 | 215 | { |
michael@0 | 216 | return static_cast<uint64_t>(aState1) + |
michael@0 | 217 | (static_cast<uint64_t>(aState2) << 31); |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | /** |
michael@0 | 221 | * Transform internal state constant to nsIAccessibleStates constants. |
michael@0 | 222 | */ |
michael@0 | 223 | static inline void To32States(uint64_t aState64, |
michael@0 | 224 | uint32_t* aState1, uint32_t* aState2) |
michael@0 | 225 | { |
michael@0 | 226 | *aState1 = aState64 & 0x7fffffff; |
michael@0 | 227 | if (aState2) |
michael@0 | 228 | *aState2 = static_cast<uint32_t>(aState64 >> 31); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | static uint32_t To32States(uint64_t aState, bool* aIsExtra) |
michael@0 | 232 | { |
michael@0 | 233 | uint32_t extraState = aState >> 31; |
michael@0 | 234 | *aIsExtra = !!extraState; |
michael@0 | 235 | return aState | extraState; |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | /** |
michael@0 | 239 | * Return true if the given accessible can't have children. Used when exposing |
michael@0 | 240 | * to platform accessibility APIs, should the children be pruned off? |
michael@0 | 241 | */ |
michael@0 | 242 | static bool MustPrune(Accessible* aAccessible); |
michael@0 | 243 | }; |
michael@0 | 244 | |
michael@0 | 245 | } // namespace a11y |
michael@0 | 246 | } // namespace mozilla |
michael@0 | 247 | |
michael@0 | 248 | #endif |