LCOV - code coverage report
Current view: top level - accessible/base - nsCoreUtils.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 9 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13