accessible/src/base/nsCoreUtils.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 nsCoreUtils_h_
     7 #define nsCoreUtils_h_
     9 #include "nsIContent.h"
    10 #include "nsIDocument.h"
    11 #include "nsIPresShell.h"
    13 #include "nsPoint.h"
    14 #include "nsTArray.h"
    16 class nsRange;
    17 class nsIBoxObject;
    18 class nsIFrame;
    19 class nsIDocShell;
    20 class nsITreeColumn;
    21 class nsITreeBoxObject;
    22 class nsIWidget;
    24 /**
    25  * Core utils.
    26  */
    27 class nsCoreUtils
    28 {
    29 public:
    30   /**
    31    * Return true if the given node has registered click, mousedown or mouseup
    32    * event listeners.
    33    */
    34   static bool HasClickListener(nsIContent *aContent);
    36   /**
    37    * Dispatch click event to XUL tree cell.
    38    *
    39    * @param  aTreeBoxObj  [in] tree box object
    40    * @param  aRowIndex    [in] row index
    41    * @param  aColumn      [in] column object
    42    * @param  aPseudoElm   [in] pseudo elemenet inside the cell, see
    43    *                       nsITreeBoxObject for available values
    44    */
    45   static void DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj,
    46                                  int32_t aRowIndex, nsITreeColumn *aColumn,
    47                                  const nsCString& aPseudoElt = EmptyCString());
    49   /**
    50    * Send mouse event to the given element.
    51    *
    52    * @param aEventType   [in] an event type (see BasicEvents.h for constants)
    53    * @param aX           [in] x coordinate in dev pixels
    54    * @param aY           [in] y coordinate in dev pixels
    55    * @param aContent     [in] the element
    56    * @param aFrame       [in] frame of the element
    57    * @param aPresShell   [in] the presshell for the element
    58    * @param aRootWidget  [in] the root widget of the element
    59    */
    60   static void DispatchMouseEvent(uint32_t aEventType, int32_t aX, int32_t aY,
    61                                  nsIContent *aContent, nsIFrame *aFrame,
    62                                  nsIPresShell *aPresShell, nsIWidget *aRootWidget);
    64   /**
    65    * Send a touch event with a single touch point to the given element.
    66    *
    67    * @param aEventType   [in] an event type (see BasicEvents.h for constants)
    68    * @param aX           [in] x coordinate in dev pixels
    69    * @param aY           [in] y coordinate in dev pixels
    70    * @param aContent     [in] the element
    71    * @param aFrame       [in] frame of the element
    72    * @param aPresShell   [in] the presshell for the element
    73    * @param aRootWidget  [in] the root widget of the element
    74    */
    75   static void DispatchTouchEvent(uint32_t aEventType, int32_t aX, int32_t aY,
    76                                  nsIContent* aContent, nsIFrame* aFrame,
    77                                  nsIPresShell* aPresShell, nsIWidget* aRootWidget);
    79   /**
    80    * Return an accesskey registered on the given element by
    81    * EventStateManager or 0 if there is no registered accesskey.
    82    *
    83    * @param aContent - the given element.
    84    */
    85   static uint32_t GetAccessKeyFor(nsIContent *aContent);
    87   /**
    88    * Return DOM element related with the given node, i.e.
    89    * a) itself if it is DOM element
    90    * b) parent element if it is text node
    91    * c) otherwise nullptr
    92    *
    93    * @param aNode  [in] the given DOM node
    94    */
    95   static nsIContent* GetDOMElementFor(nsIContent *aContent);
    97   /**
    98    * Return DOM node for the given DOM point.
    99    */
   100   static nsINode *GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset);
   102   /**
   103    * Return the nsIContent* to check for ARIA attributes on -- this may not
   104    * always be the DOM node for the accessible. Specifically, for doc
   105    * accessibles, it is not the document node, but either the root element or
   106    * <body> in HTML.
   107    *
   108    * @param aNode  [in] DOM node for the accessible that may be affected by ARIA
   109    * @return        the nsIContent which may have ARIA markup
   110    */
   111   static nsIContent* GetRoleContent(nsINode *aNode);
   113   /**
   114    * Is the first passed in node an ancestor of the second?
   115    * Note: A node is not considered to be the ancestor of itself.
   116    *
   117    * @param  aPossibleAncestorNode   [in] node to test for ancestor-ness of
   118    *                                   aPossibleDescendantNode
   119    * @param  aPossibleDescendantNode [in] node to test for descendant-ness of
   120    *                                   aPossibleAncestorNode
   121    * @param  aRootNode               [in, optional] the root node that search
   122    *                                   search should be performed within
   123    * @return true                     if aPossibleAncestorNode is an ancestor of
   124    *                                   aPossibleDescendantNode
   125    */
   126    static bool IsAncestorOf(nsINode *aPossibleAncestorNode,
   127                               nsINode *aPossibleDescendantNode,
   128                               nsINode *aRootNode = nullptr);
   130   /**
   131    * Helper method to scroll range into view, used for implementation of
   132    * nsIAccessibleText::scrollSubstringTo().
   133    *
   134    * @param aFrame        the frame for accessible the range belongs to.
   135    * @param aRange    the range to scroll to
   136    * @param aScrollType   the place a range should be scrolled to
   137    */
   138   static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
   139                                     uint32_t aScrollType);
   141   /** Helper method to scroll range into view, used for implementation of
   142    * nsIAccessibleText::scrollSubstringTo[Point]().
   143    *
   144    * @param aFrame        the frame for accessible the range belongs to.
   145    * @param aRange    the range to scroll to
   146    * @param aVertical     how to align vertically, specified in percents, and when.
   147    * @param aHorizontal     how to align horizontally, specified in percents, and when.
   148    */
   149   static nsresult ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
   150                                     nsIPresShell::ScrollAxis aVertical,
   151                                     nsIPresShell::ScrollAxis aHorizontal);
   153   /**
   154    * Scrolls the given frame to the point, used for implememntation of
   155    * nsIAccessible::scrollToPoint and nsIAccessibleText::scrollSubstringToPoint.
   156    *
   157    * @param aScrollableFrame  the scrollable frame
   158    * @param aFrame            the frame to scroll
   159    * @param aPoint            the point scroll to
   160    */
   161   static void ScrollFrameToPoint(nsIFrame *aScrollableFrame,
   162                                  nsIFrame *aFrame, const nsIntPoint& aPoint);
   164   /**
   165    * Converts scroll type constant defined in nsIAccessibleScrollType to
   166    * vertical and horizontal parameters.
   167    */
   168   static void ConvertScrollTypeToPercents(uint32_t aScrollType,
   169                                           nsIPresShell::ScrollAxis *aVertical,
   170                                           nsIPresShell::ScrollAxis *aHorizontal);
   172   /**
   173    * Returns coordinates in device pixels relative screen for the top level
   174    * window.
   175    *
   176    * @param aNode  the DOM node hosted in the window.
   177    */
   178   static nsIntPoint GetScreenCoordsForWindow(nsINode *aNode);
   180   /**
   181    * Return document shell for the given DOM node.
   182    */
   183   static already_AddRefed<nsIDocShell> GetDocShellFor(nsINode *aNode);
   185   /**
   186    * Return true if the given document is root document.
   187    */
   188   static bool IsRootDocument(nsIDocument *aDocument);
   190   /**
   191    * Return true if the given document is content document (not chrome).
   192    */
   193   static bool IsContentDocument(nsIDocument *aDocument);
   195   /**
   196    * Return true if the given document node is for tab document accessible.
   197    */
   198   static bool IsTabDocument(nsIDocument* aDocumentNode);
   200   /**
   201    * Return true if the given document is an error page.
   202    */
   203   static bool IsErrorPage(nsIDocument *aDocument);
   205   /**
   206    * Return presShell for the document containing the given DOM node.
   207    */
   208   static nsIPresShell *GetPresShellFor(nsINode *aNode)
   209   {
   210     return aNode->OwnerDoc()->GetShell();
   211   }
   213   /**
   214    * Get the ID for an element, in some types of XML this may not be the ID attribute
   215    * @param aContent  Node to get the ID for
   216    * @param aID       Where to put ID string
   217    * @return          true if there is an ID set for this node
   218    */
   219   static bool GetID(nsIContent *aContent, nsAString& aID);
   221   /**
   222    * Convert attribute value of the given node to positive integer. If no
   223    * attribute or wrong value then false is returned.
   224    */
   225   static bool GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr,
   226                             int32_t *aUInt);
   228   /**
   229    * Returns language for the given node.
   230    *
   231    * @param aContent     [in] the given node
   232    * @param aRootContent [in] container of the given node
   233    * @param aLanguage    [out] language
   234    */
   235   static void GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
   236                              nsAString& aLanguage);
   238   /**
   239    * Return box object for XUL treechildren element by tree box object.
   240    */
   241   static already_AddRefed<nsIBoxObject>
   242     GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj);
   244   /**
   245    * Return tree box object from any levels DOMNode under the XUL tree.
   246    */
   247   static already_AddRefed<nsITreeBoxObject>
   248     GetTreeBoxObject(nsIContent* aContent);
   250   /**
   251    * Return first sensible column for the given tree box object.
   252    */
   253   static already_AddRefed<nsITreeColumn>
   254     GetFirstSensibleColumn(nsITreeBoxObject *aTree);
   256   /**
   257    * Return sensible columns count for the given tree box object.
   258    */
   259   static uint32_t GetSensibleColumnCount(nsITreeBoxObject *aTree);
   261   /**
   262    * Return sensible column at the given index for the given tree box object.
   263    */
   264   static already_AddRefed<nsITreeColumn>
   265     GetSensibleColumnAt(nsITreeBoxObject *aTree, uint32_t aIndex);
   267   /**
   268    * Return next sensible column for the given column.
   269    */
   270   static already_AddRefed<nsITreeColumn>
   271     GetNextSensibleColumn(nsITreeColumn *aColumn);
   273   /**
   274    * Return previous sensible column for the given column.
   275    */
   276   static already_AddRefed<nsITreeColumn>
   277     GetPreviousSensibleColumn(nsITreeColumn *aColumn);
   279   /**
   280    * Return true if the given column is hidden (i.e. not sensible).
   281    */
   282   static bool IsColumnHidden(nsITreeColumn *aColumn);
   284   /**
   285    * Scroll content into view.
   286    */
   287   static void ScrollTo(nsIPresShell* aPresShell, nsIContent* aContent,
   288                        uint32_t aScrollType);
   290   /**
   291    * Return true if the given node is table header element.
   292    */
   293   static bool IsHTMLTableHeader(nsIContent *aContent)
   294   {
   295     return aContent->NodeInfo()->Equals(nsGkAtoms::th) ||
   296       aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::scope);
   297   }
   299   /**
   300    * Returns true if the given string is empty or contains whitespace symbols
   301    * only. In contrast to nsWhitespaceTokenizer class it takes into account
   302    * non-breaking space (0xa0).
   303    */
   304   static bool IsWhitespaceString(const nsSubstring& aString);
   306   /**
   307    * Returns true if the given character is whitespace symbol.
   308    */
   309   static bool IsWhitespace(char16_t aChar)
   310   {
   311     return aChar == ' ' || aChar == '\n' ||
   312       aChar == '\r' || aChar == '\t' || aChar == 0xa0;
   313   }
   314 };
   316 #endif

mercurial