accessible/src/base/nsCoreUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/base/nsCoreUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,317 @@
     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 nsCoreUtils_h_
    1.10 +#define nsCoreUtils_h_
    1.11 +
    1.12 +#include "nsIContent.h"
    1.13 +#include "nsIDocument.h"
    1.14 +#include "nsIPresShell.h"
    1.15 +
    1.16 +#include "nsPoint.h"
    1.17 +#include "nsTArray.h"
    1.18 +
    1.19 +class nsRange;
    1.20 +class nsIBoxObject;
    1.21 +class nsIFrame;
    1.22 +class nsIDocShell;
    1.23 +class nsITreeColumn;
    1.24 +class nsITreeBoxObject;
    1.25 +class nsIWidget;
    1.26 +
    1.27 +/**
    1.28 + * Core utils.
    1.29 + */
    1.30 +class nsCoreUtils
    1.31 +{
    1.32 +public:
    1.33 +  /**
    1.34 +   * Return true if the given node has registered click, mousedown or mouseup
    1.35 +   * event listeners.
    1.36 +   */
    1.37 +  static bool HasClickListener(nsIContent *aContent);
    1.38 +
    1.39 +  /**
    1.40 +   * Dispatch click event to XUL tree cell.
    1.41 +   *
    1.42 +   * @param  aTreeBoxObj  [in] tree box object
    1.43 +   * @param  aRowIndex    [in] row index
    1.44 +   * @param  aColumn      [in] column object
    1.45 +   * @param  aPseudoElm   [in] pseudo elemenet inside the cell, see
    1.46 +   *                       nsITreeBoxObject for available values
    1.47 +   */
    1.48 +  static void DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj,
    1.49 +                                 int32_t aRowIndex, nsITreeColumn *aColumn,
    1.50 +                                 const nsCString& aPseudoElt = EmptyCString());
    1.51 +
    1.52 +  /**
    1.53 +   * Send mouse event to the given element.
    1.54 +   *
    1.55 +   * @param aEventType   [in] an event type (see BasicEvents.h for constants)
    1.56 +   * @param aX           [in] x coordinate in dev pixels
    1.57 +   * @param aY           [in] y coordinate in dev pixels
    1.58 +   * @param aContent     [in] the element
    1.59 +   * @param aFrame       [in] frame of the element
    1.60 +   * @param aPresShell   [in] the presshell for the element
    1.61 +   * @param aRootWidget  [in] the root widget of the element
    1.62 +   */
    1.63 +  static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY,
    1.64 +                                 nsIContent *aContent, nsIFrame *aFrame,
    1.65 +                                 nsIPresShell *aPresShell, nsIWidget *aRootWidget);
    1.66 +
    1.67 +  /**
    1.68 +   * Send a touch event with a single touch point to the given element.
    1.69 +   *
    1.70 +   * @param aEventType   [in] an event type (see BasicEvents.h for constants)
    1.71 +   * @param aX           [in] x coordinate in dev pixels
    1.72 +   * @param aY           [in] y coordinate in dev pixels
    1.73 +   * @param aContent     [in] the element
    1.74 +   * @param aFrame       [in] frame of the element
    1.75 +   * @param aPresShell   [in] the presshell for the element
    1.76 +   * @param aRootWidget  [in] the root widget of the element
    1.77 +   */
    1.78 +  static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY,
    1.79 +                                 nsIContent* aContent, nsIFrame* aFrame,
    1.80 +                                 nsIPresShell* aPresShell, nsIWidget* aRootWidget);
    1.81 +
    1.82 +  /**
    1.83 +   * Return an accesskey registered on the given element by
    1.84 +   * EventStateManager or 0 if there is no registered accesskey.
    1.85 +   *
    1.86 +   * @param aContent - the given element.
    1.87 +   */
    1.88 +  static uint32_t GetAccessKeyFor(nsIContent *aContent);
    1.89 +
    1.90 +  /**
    1.91 +   * Return DOM element related with the given node, i.e.
    1.92 +   * a) itself if it is DOM element
    1.93 +   * b) parent element if it is text node
    1.94 +   * c) otherwise nullptr
    1.95 +   *
    1.96 +   * @param aNode  [in] the given DOM node
    1.97 +   */
    1.98 +  static nsIContent* GetDOMElementFor(nsIContent *aContent);
    1.99 +
   1.100 +  /**
   1.101 +   * Return DOM node for the given DOM point.
   1.102 +   */
   1.103 +  static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset);
   1.104 +
   1.105 +  /**
   1.106 +   * Return the nsIContent* to check for ARIA attributes on -- this may not
   1.107 +   * always be the DOM node for the accessible. Specifically, for doc
   1.108 +   * accessibles, it is not the document node, but either the root element or
   1.109 +   * <body> in HTML.
   1.110 +   *
   1.111 +   * @param aNode  [in] DOM node for the accessible that may be affected by ARIA
   1.112 +   * @return        the nsIContent which may have ARIA markup
   1.113 +   */
   1.114 +  static nsIContent* GetRoleContent(nsINode *aNode);
   1.115 +
   1.116 +  /**
   1.117 +   * Is the first passed in node an ancestor of the second?
   1.118 +   * Note: A node is not considered to be the ancestor of itself.
   1.119 +   *
   1.120 +   * @param  aPossibleAncestorNode   [in] node to test for ancestor-ness of
   1.121 +   *                                   aPossibleDescendantNode
   1.122 +   * @param  aPossibleDescendantNode [in] node to test for descendant-ness of
   1.123 +   *                                   aPossibleAncestorNode
   1.124 +   * @param  aRootNode               [in, optional] the root node that search
   1.125 +   *                                   search should be performed within
   1.126 +   * @return true                     if aPossibleAncestorNode is an ancestor of
   1.127 +   *                                   aPossibleDescendantNode
   1.128 +   */
   1.129 +   static bool IsAncestorOf(nsINode *aPossibleAncestorNode,
   1.130 +                              nsINode *aPossibleDescendantNode,
   1.131 +                              nsINode *aRootNode = nullptr);
   1.132 +
   1.133 +  /**
   1.134 +   * Helper method to scroll range into view, used for implementation of
   1.135 +   * nsIAccessibleText::scrollSubstringTo().
   1.136 +   *
   1.137 +   * @param aFrame        the frame for accessible the range belongs to.
   1.138 +   * @param aRange    the range to scroll to
   1.139 +   * @param aScrollType   the place a range should be scrolled to
   1.140 +   */
   1.141 +  static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
   1.142 +                                    uint32_t aScrollType);
   1.143 +
   1.144 +  /** Helper method to scroll range into view, used for implementation of
   1.145 +   * nsIAccessibleText::scrollSubstringTo[Point]().
   1.146 +   *
   1.147 +   * @param aFrame        the frame for accessible the range belongs to.
   1.148 +   * @param aRange    the range to scroll to
   1.149 +   * @param aVertical     how to align vertically, specified in percents, and when.
   1.150 +   * @param aHorizontal     how to align horizontally, specified in percents, and when.
   1.151 +   */
   1.152 +  static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
   1.153 +                                    nsIPresShell::ScrollAxis aVertical,
   1.154 +                                    nsIPresShell::ScrollAxis aHorizontal);
   1.155 +
   1.156 +  /**
   1.157 +   * Scrolls the given frame to the point, used for implememntation of
   1.158 +   * nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
   1.159 +   *
   1.160 +   * @param aScrollableFrame  the scrollable frame
   1.161 +   * @param aFrame            the frame to scroll
   1.162 +   * @param aPoint            the point scroll to
   1.163 +   */
   1.164 +  static void ScrollFrameToPoint(nsIFrame *aScrollableFrame,
   1.165 +                                 nsIFrame *aFrame, const nsIntPoint& aPoint);
   1.166 +
   1.167 +  /**
   1.168 +   * Converts scroll type constant defined in nsIAccessibleScrollType to
   1.169 +   * vertical and horizontal parameters.
   1.170 +   */
   1.171 +  static void ConvertScrollTypeToPercents(uint32_t aScrollType,
   1.172 +                                          nsIPresShell::ScrollAxis *aVertical,
   1.173 +                                          nsIPresShell::ScrollAxis *aHorizontal);
   1.174 +
   1.175 +  /**
   1.176 +   * Returns coordinates in device pixels relative screen for the top level
   1.177 +   * window.
   1.178 +   *
   1.179 +   * @param aNode  the DOM node hosted in the window.
   1.180 +   */
   1.181 +  static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode);
   1.182 +
   1.183 +  /**
   1.184 +   * Return document shell for the given DOM node.
   1.185 +   */
   1.186 +  static already_AddRefed<nsIDocShell> GetDocShellFor(nsINode *aNode);
   1.187 +
   1.188 +  /**
   1.189 +   * Return true if the given document is root document.
   1.190 +   */
   1.191 +  static bool IsRootDocument(nsIDocument *aDocument);
   1.192 +
   1.193 +  /**
   1.194 +   * Return true if the given document is content document (not chrome).
   1.195 +   */
   1.196 +  static bool IsContentDocument(nsIDocument *aDocument);
   1.197 +
   1.198 +  /**
   1.199 +   * Return true if the given document node is for tab document accessible.
   1.200 +   */
   1.201 +  static bool IsTabDocument(nsIDocument* aDocumentNode);
   1.202 +
   1.203 +  /**
   1.204 +   * Return true if the given document is an error page.
   1.205 +   */
   1.206 +  static bool IsErrorPage(nsIDocument *aDocument);
   1.207 +
   1.208 +  /**
   1.209 +   * Return presShell for the document containing the given DOM node.
   1.210 +   */
   1.211 +  static nsIPresShell *GetPresShellFor(nsINode *aNode)
   1.212 +  {
   1.213 +    return aNode->OwnerDoc()->GetShell();
   1.214 +  }
   1.215 +
   1.216 +  /**
   1.217 +   * Get the ID for an element, in some types of XML this may not be the ID attribute
   1.218 +   * @param aContent  Node to get the ID for
   1.219 +   * @param aID       Where to put ID string
   1.220 +   * @return          true if there is an ID set for this node
   1.221 +   */
   1.222 +  static bool GetID(nsIContent *aContent, nsAString& aID);
   1.223 +
   1.224 +  /**
   1.225 +   * Convert attribute value of the given node to positive integer. If no
   1.226 +   * attribute or wrong value then false is returned.
   1.227 +   */
   1.228 +  static bool GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr,
   1.229 +                            int32_t *aUInt);
   1.230 +
   1.231 +  /**
   1.232 +   * Returns language for the given node.
   1.233 +   *
   1.234 +   * @param aContent     [in] the given node
   1.235 +   * @param aRootContent [in] container of the given node
   1.236 +   * @param aLanguage    [out] language
   1.237 +   */
   1.238 +  static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
   1.239 +                             nsAString& aLanguage);
   1.240 +
   1.241 +  /**
   1.242 +   * Return box object for XUL treechildren element by tree box object.
   1.243 +   */
   1.244 +  static already_AddRefed<nsIBoxObject>
   1.245 +    GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj);
   1.246 +
   1.247 +  /**
   1.248 +   * Return tree box object from any levels DOMNode under the XUL tree.
   1.249 +   */
   1.250 +  static already_AddRefed<nsITreeBoxObject>
   1.251 +    GetTreeBoxObject(nsIContent* aContent);
   1.252 +
   1.253 +  /**
   1.254 +   * Return first sensible column for the given tree box object.
   1.255 +   */
   1.256 +  static already_AddRefed<nsITreeColumn>
   1.257 +    GetFirstSensibleColumn(nsITreeBoxObject *aTree);
   1.258 +
   1.259 +  /**
   1.260 +   * Return sensible columns count for the given tree box object.
   1.261 +   */
   1.262 +  static uint32_t GetSensibleColumnCount(nsITreeBoxObject *aTree);
   1.263 +
   1.264 +  /**
   1.265 +   * Return sensible column at the given index for the given tree box object.
   1.266 +   */
   1.267 +  static already_AddRefed<nsITreeColumn>
   1.268 +    GetSensibleColumnAt(nsITreeBoxObject *aTree, uint32_t aIndex);
   1.269 +
   1.270 +  /**
   1.271 +   * Return next sensible column for the given column.
   1.272 +   */
   1.273 +  static already_AddRefed<nsITreeColumn>
   1.274 +    GetNextSensibleColumn(nsITreeColumn *aColumn);
   1.275 +
   1.276 +  /**
   1.277 +   * Return previous sensible column for the given column.
   1.278 +   */
   1.279 +  static already_AddRefed<nsITreeColumn>
   1.280 +    GetPreviousSensibleColumn(nsITreeColumn *aColumn);
   1.281 +
   1.282 +  /**
   1.283 +   * Return true if the given column is hidden (i.e. not sensible).
   1.284 +   */
   1.285 +  static bool IsColumnHidden(nsITreeColumn *aColumn);
   1.286 +
   1.287 +  /**
   1.288 +   * Scroll content into view.
   1.289 +   */
   1.290 +  static void ScrollTo(nsIPresShell* aPresShell, nsIContent* aContent,
   1.291 +                       uint32_t aScrollType);
   1.292 +
   1.293 +  /**
   1.294 +   * Return true if the given node is table header element.
   1.295 +   */
   1.296 +  static bool IsHTMLTableHeader(nsIContent *aContent)
   1.297 +  {
   1.298 +    return aContent->NodeInfo()->Equals(nsGkAtoms::th) ||
   1.299 +      aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scope);
   1.300 +  }
   1.301 +
   1.302 +  /**
   1.303 +   * Returns true if the given string is empty or contains whitespace symbols
   1.304 +   * only. In contrast to nsWhitespaceTokenizer class it takes into account
   1.305 +   * non-breaking space (0xa0).
   1.306 +   */
   1.307 +  static bool IsWhitespaceString(const nsSubstring& aString);
   1.308 +
   1.309 +  /**
   1.310 +   * Returns true if the given character is whitespace symbol.
   1.311 +   */
   1.312 +  static bool IsWhitespace(char16_t aChar)
   1.313 +  {
   1.314 +    return aChar == ' ' || aChar == '\n' ||
   1.315 +      aChar == '\r' || aChar == '\t' || aChar == 0xa0;
   1.316 +  }
   1.317 +};
   1.318 +
   1.319 +#endif
   1.320 +

mercurial