accessible/src/base/nsAccUtils.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial