accessible/src/base/nsAccUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/base/nsAccUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,248 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef nsAccUtils_h_
    1.10 +#define nsAccUtils_h_
    1.11 +
    1.12 +#include "mozilla/a11y/Accessible.h"
    1.13 +
    1.14 +#include "nsAccessibilityService.h"
    1.15 +#include "nsCoreUtils.h"
    1.16 +
    1.17 +#include "nsIDocShell.h"
    1.18 +#include "nsPoint.h"
    1.19 +
    1.20 +namespace mozilla {
    1.21 +
    1.22 +namespace dom {
    1.23 +class Element;
    1.24 +}
    1.25 +
    1.26 +namespace a11y {
    1.27 +
    1.28 +class HyperTextAccessible;
    1.29 +class DocAccessible;
    1.30 +
    1.31 +class nsAccUtils
    1.32 +{
    1.33 +public:
    1.34 +  /**
    1.35 +   * Returns value of attribute from the given attributes container.
    1.36 +   *
    1.37 +   * @param aAttributes - attributes container
    1.38 +   * @param aAttrName - the name of requested attribute
    1.39 +   * @param aAttrValue - value of attribute
    1.40 +   */
    1.41 +  static void GetAccAttr(nsIPersistentProperties *aAttributes,
    1.42 +                         nsIAtom *aAttrName,
    1.43 +                         nsAString& aAttrValue);
    1.44 +
    1.45 +  /**
    1.46 +   * Set value of attribute for the given attributes container.
    1.47 +   *
    1.48 +   * @param aAttributes - attributes container
    1.49 +   * @param aAttrName - the name of requested attribute
    1.50 +   * @param aAttrValue - new value of attribute
    1.51 +   */
    1.52 +  static void SetAccAttr(nsIPersistentProperties *aAttributes,
    1.53 +                         nsIAtom *aAttrName,
    1.54 +                         const nsAString& aAttrValue);
    1.55 +
    1.56 +  /**
    1.57 +   * Set group attributes ('level', 'setsize', 'posinset').
    1.58 +   */
    1.59 +  static void SetAccGroupAttrs(nsIPersistentProperties *aAttributes,
    1.60 +                               int32_t aLevel, int32_t aSetSize,
    1.61 +                               int32_t aPosInSet);
    1.62 +
    1.63 +  /**
    1.64 +   * Get default value of the level for the given accessible.
    1.65 +   */
    1.66 +  static int32_t GetDefaultLevel(Accessible* aAcc);
    1.67 +
    1.68 +  /**
    1.69 +   * Return ARIA level value or the default one if ARIA is missed for the
    1.70 +   * given accessible.
    1.71 +   */
    1.72 +  static int32_t GetARIAOrDefaultLevel(Accessible* aAccessible);
    1.73 +
    1.74 +  /**
    1.75 +   * Compute group level for nsIDOMXULContainerItemElement node.
    1.76 +   */
    1.77 +  static int32_t GetLevelForXULContainerItem(nsIContent *aContent);
    1.78 +
    1.79 +  /**
    1.80 +   * Set container-foo live region attributes for the given node.
    1.81 +   *
    1.82 +   * @param aAttributes    where to store the attributes
    1.83 +   * @param aStartContent  node to start from
    1.84 +   * @param aTopContent    node to end at
    1.85 +   */
    1.86 +  static void SetLiveContainerAttributes(nsIPersistentProperties *aAttributes,
    1.87 +                                         nsIContent *aStartContent,
    1.88 +                                         nsIContent *aTopContent);
    1.89 +
    1.90 +  /**
    1.91 +   * Any ARIA property of type boolean or NMTOKEN is undefined if the ARIA
    1.92 +   * property is not present, or is "" or "undefined". Do not call 
    1.93 +   * this method for properties of type string, decimal, IDREF or IDREFS.
    1.94 +   * 
    1.95 +   * Return true if the ARIA property is defined, otherwise false
    1.96 +   */
    1.97 +  static bool HasDefinedARIAToken(nsIContent *aContent, nsIAtom *aAtom);
    1.98 +
    1.99 +  /**
   1.100 +   * Return atomic value of ARIA attribute of boolean or NMTOKEN type.
   1.101 +   */
   1.102 +  static nsIAtom* GetARIAToken(mozilla::dom::Element* aElement, nsIAtom* aAttr);
   1.103 +
   1.104 +  /**
   1.105 +   * Return document accessible for the given DOM node.
   1.106 +   */
   1.107 +  static DocAccessible* GetDocAccessibleFor(nsINode* aNode)
   1.108 +  {
   1.109 +    nsIPresShell *presShell = nsCoreUtils::GetPresShellFor(aNode);
   1.110 +    return GetAccService()->GetDocAccessible(presShell);
   1.111 +  }
   1.112 +
   1.113 +  /**
   1.114 +   * Return document accessible for the given docshell.
   1.115 +   */
   1.116 +  static DocAccessible* GetDocAccessibleFor(nsIDocShellTreeItem* aContainer)
   1.117 +  {
   1.118 +    nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
   1.119 +    return GetAccService()->GetDocAccessible(docShell->GetPresShell());
   1.120 +  }
   1.121 +
   1.122 +  /**
   1.123 +   * Return single or multi selectable container for the given item.
   1.124 +   *
   1.125 +   * @param  aAccessible  [in] the item accessible
   1.126 +   * @param  aState       [in] the state of the item accessible
   1.127 +   */
   1.128 +  static Accessible* GetSelectableContainer(Accessible* aAccessible,
   1.129 +                                            uint64_t aState);
   1.130 +
   1.131 +  /**
   1.132 +   * Return a text container accessible for the given node.
   1.133 +   */
   1.134 +  static HyperTextAccessible* GetTextContainer(nsINode* aNode);
   1.135 +
   1.136 +  /**
   1.137 +   * Return true if the DOM node of given accessible has aria-selected="true"
   1.138 +   * attribute.
   1.139 +   */
   1.140 +  static bool IsARIASelected(Accessible* aAccessible);
   1.141 +
   1.142 +  /**
   1.143 +   * Converts the given coordinates to coordinates relative screen.
   1.144 +   *
   1.145 +   * @param aX               [in] the given x coord
   1.146 +   * @param aY               [in] the given y coord
   1.147 +   * @param aCoordinateType  [in] specifies coordinates origin (refer to
   1.148 +   *                         nsIAccessibleCoordinateType)
   1.149 +   * @param aAccessible      [in] the accessible if coordinates are given
   1.150 +   *                         relative it.
   1.151 +   * @return converted coordinates
   1.152 +   */
   1.153 +  static nsIntPoint ConvertToScreenCoords(int32_t aX, int32_t aY,
   1.154 +                                          uint32_t aCoordinateType,
   1.155 +                                          Accessible* aAccessible);
   1.156 +
   1.157 +  /**
   1.158 +   * Converts the given coordinates relative screen to another coordinate
   1.159 +   * system.
   1.160 +   *
   1.161 +   * @param aX               [in, out] the given x coord
   1.162 +   * @param aY               [in, out] the given y coord
   1.163 +   * @param aCoordinateType  [in] specifies coordinates origin (refer to
   1.164 +   *                         nsIAccessibleCoordinateType)
   1.165 +   * @param aAccessible      [in] the accessible if coordinates are given
   1.166 +   *                         relative it
   1.167 +   */
   1.168 +  static void ConvertScreenCoordsTo(int32_t* aX, int32_t* aY,
   1.169 +                                    uint32_t aCoordinateType,
   1.170 +                                    Accessible* aAccessible);
   1.171 +
   1.172 +  /**
   1.173 +   * Returns coordinates relative screen for the parent of the given accessible.
   1.174 +   *
   1.175 +   * @param [in] aAccessible  the accessible
   1.176 +   */
   1.177 +  static nsIntPoint GetScreenCoordsForParent(Accessible* aAccessible);
   1.178 +
   1.179 +  /**
   1.180 +   * Get the 'live' or 'container-live' object attribute value from the given
   1.181 +   * ELiveAttrRule constant.
   1.182 +   *
   1.183 +   * @param  aRule   [in] rule constant (see ELiveAttrRule in nsAccMap.h)
   1.184 +   * @param  aValue  [out] object attribute value
   1.185 +   *
   1.186 +   * @return         true if object attribute should be exposed
   1.187 +   */
   1.188 +  static bool GetLiveAttrValue(uint32_t aRule, nsAString& aValue);
   1.189 +
   1.190 +#ifdef DEBUG
   1.191 +  /**
   1.192 +   * Detect whether the given accessible object implements nsIAccessibleText,
   1.193 +   * when it is text or has text child node.
   1.194 +   */
   1.195 +  static bool IsTextInterfaceSupportCorrect(Accessible* aAccessible);
   1.196 +#endif
   1.197 +
   1.198 +  /**
   1.199 +   * Return text length of the given accessible, return 0 on failure.
   1.200 +   */
   1.201 +  static uint32_t TextLength(Accessible* aAccessible);
   1.202 +
   1.203 +  /**
   1.204 +   * Return true if the given accessible is embedded object.
   1.205 +   */
   1.206 +  static bool IsEmbeddedObject(Accessible* aAcc)
   1.207 +  {
   1.208 +    uint32_t role = aAcc->Role();
   1.209 +    return role != roles::TEXT_LEAF &&
   1.210 +           role != roles::WHITESPACE &&
   1.211 +           role != roles::STATICTEXT;
   1.212 +  }
   1.213 +
   1.214 +  /**
   1.215 +   * Transform nsIAccessibleStates constants to internal state constant.
   1.216 +   */
   1.217 +  static inline uint64_t To64State(uint32_t aState1, uint32_t aState2)
   1.218 +  {
   1.219 +    return static_cast<uint64_t>(aState1) +
   1.220 +        (static_cast<uint64_t>(aState2) << 31);
   1.221 +  }
   1.222 +
   1.223 +  /**
   1.224 +   * Transform internal state constant to nsIAccessibleStates constants.
   1.225 +   */
   1.226 +  static inline void To32States(uint64_t aState64,
   1.227 +                                uint32_t* aState1, uint32_t* aState2)
   1.228 +  {
   1.229 +    *aState1 = aState64 & 0x7fffffff;
   1.230 +    if (aState2)
   1.231 +      *aState2 = static_cast<uint32_t>(aState64 >> 31);
   1.232 +  }
   1.233 +
   1.234 +  static uint32_t To32States(uint64_t aState, bool* aIsExtra)
   1.235 +  {
   1.236 +    uint32_t extraState = aState >> 31;
   1.237 +    *aIsExtra = !!extraState;
   1.238 +    return aState | extraState;
   1.239 +  }
   1.240 +
   1.241 +  /**
   1.242 +   * Return true if the given accessible can't have children. Used when exposing
   1.243 +   * to platform accessibility APIs, should the children be pruned off?
   1.244 +   */
   1.245 +  static bool MustPrune(Accessible* aAccessible);
   1.246 +};
   1.247 +
   1.248 +} // namespace a11y
   1.249 +} // namespace mozilla
   1.250 +
   1.251 +#endif

mercurial