LCOV - code coverage report
Current view: directory - accessible/src/base - nsAccessible.h (source / functions) Found Hit Coverage
Test: app.info Lines: 61 1 1.6 %
Date: 2012-06-02 Functions: 36 1 2.8 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   John Gaunt (jgaunt@netscape.com)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef _nsAccessible_H_
      40                 : #define _nsAccessible_H_
      41                 : 
      42                 : #include "mozilla/a11y/Role.h"
      43                 : #include "mozilla/a11y/States.h"
      44                 : #include "nsAccessNodeWrap.h"
      45                 : 
      46                 : #include "nsIAccessible.h"
      47                 : #include "nsIAccessibleHyperLink.h"
      48                 : #include "nsIAccessibleSelectable.h"
      49                 : #include "nsIAccessibleValue.h"
      50                 : #include "nsIAccessibleRole.h"
      51                 : #include "nsIAccessibleStates.h"
      52                 : 
      53                 : #include "nsARIAMap.h"
      54                 : #include "nsStringGlue.h"
      55                 : #include "nsTArray.h"
      56                 : #include "nsRefPtrHashtable.h"
      57                 : 
      58                 : class AccEvent;
      59                 : class AccGroupInfo;
      60                 : class EmbeddedObjCollector;
      61                 : class KeyBinding;
      62                 : class nsAccessible;
      63                 : class nsHyperTextAccessible;
      64                 : class nsHTMLImageAccessible;
      65                 : class nsHTMLLIAccessible;
      66                 : struct nsRoleMapEntry;
      67                 : class Relation;
      68                 : class nsTextAccessible;
      69                 : 
      70                 : struct nsRect;
      71                 : class nsIContent;
      72                 : class nsIFrame;
      73                 : class nsIAtom;
      74                 : class nsIView;
      75                 : 
      76                 : typedef nsRefPtrHashtable<nsVoidPtrHashKey, nsAccessible>
      77                 :   nsAccessibleHashtable;
      78                 : 
      79                 : // see nsAccessible::GetAttrValue
      80                 : #define NS_OK_NO_ARIA_VALUE \
      81                 : NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 0x21)
      82                 : 
      83                 : // see nsAccessible::GetNameInternal
      84                 : #define NS_OK_EMPTY_NAME \
      85                 : NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 0x23)
      86                 : 
      87                 : // see nsAccessible::GetNameInternal
      88                 : #define NS_OK_NAME_FROM_TOOLTIP \
      89                 : NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 0x25)
      90                 : 
      91                 : 
      92                 : #define NS_ACCESSIBLE_IMPL_IID                          \
      93                 : {  /* 133c8bf4-4913-4355-bd50-426bd1d6e1ad */           \
      94                 :   0x133c8bf4,                                           \
      95                 :   0x4913,                                               \
      96                 :   0x4355,                                               \
      97                 :   { 0xbd, 0x50, 0x42, 0x6b, 0xd1, 0xd6, 0xe1, 0xad }    \
      98                 : }
      99                 : 
     100                 : class nsAccessible : public nsAccessNodeWrap, 
     101                 :                      public nsIAccessible, 
     102                 :                      public nsIAccessibleHyperLink,
     103                 :                      public nsIAccessibleSelectable,
     104                 :                      public nsIAccessibleValue
     105                 : {
     106                 : public:
     107                 :   nsAccessible(nsIContent* aContent, nsDocAccessible* aDoc);
     108                 :   virtual ~nsAccessible();
     109                 : 
     110                 :   NS_DECL_ISUPPORTS_INHERITED
     111           10248 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsAccessible, nsAccessNode)
     112                 : 
     113                 :   NS_DECL_NSIACCESSIBLE
     114                 :   NS_DECL_NSIACCESSIBLEHYPERLINK
     115                 :   NS_DECL_NSIACCESSIBLESELECTABLE
     116                 :   NS_DECL_NSIACCESSIBLEVALUE
     117                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ACCESSIBLE_IMPL_IID)
     118                 : 
     119                 :   //////////////////////////////////////////////////////////////////////////////
     120                 :   // nsAccessNode
     121                 : 
     122                 :   virtual void Shutdown();
     123                 : 
     124                 :   //////////////////////////////////////////////////////////////////////////////
     125                 :   // Public methods
     126                 : 
     127                 :   /**
     128                 :    * get the description of this accessible
     129                 :    */
     130                 :   virtual void Description(nsString& aDescription);
     131                 : 
     132                 :   /**
     133                 :    * Return DOM node associated with this accessible.
     134                 :    */
     135                 :   inline already_AddRefed<nsIDOMNode> DOMNode() const
     136                 :   {
     137                 :     nsIDOMNode *DOMNode = nsnull;
     138                 :     if (GetNode())
     139                 :       CallQueryInterface(GetNode(), &DOMNode);
     140                 :     return DOMNode;
     141                 :   }
     142                 : 
     143                 :   /**
     144                 :    * Returns the accessible name specified by ARIA.
     145                 :    */
     146                 :   nsresult GetARIAName(nsAString& aName);
     147                 : 
     148                 :   /**
     149                 :    * Maps ARIA state attributes to state of accessible. Note the given state
     150                 :    * argument should hold states for accessible before you pass it into this
     151                 :    * method.
     152                 :    *
     153                 :    * @param  [in/out] where to fill the states into.
     154                 :    */
     155                 :   virtual void ApplyARIAState(PRUint64* aState);
     156                 : 
     157                 :   /**
     158                 :    * Returns the accessible name provided by native markup. It doesn't take
     159                 :    * into account ARIA markup used to specify the name.
     160                 :    *
     161                 :    * @param  aName             [out] the accessible name
     162                 :    *
     163                 :    * @return NS_OK_EMPTY_NAME  points empty name was specified by native markup
     164                 :    *                           explicitly (see nsIAccessible::name attribute for
     165                 :    *                           details)
     166                 :    */
     167                 :   virtual nsresult GetNameInternal(nsAString& aName);
     168                 : 
     169                 :   /**
     170                 :    * Return enumerated accessible role (see constants in Role.h).
     171                 :    */
     172               0 :   inline mozilla::a11y::role Role()
     173                 :   {
     174               0 :     if (!mRoleMapEntry || mRoleMapEntry->roleRule != kUseMapRole)
     175               0 :       return NativeRole();
     176                 : 
     177               0 :     return ARIARoleInternal();
     178                 :   }
     179                 : 
     180                 :   /**
     181                 :    * Return true if ARIA role is specified on the element.
     182                 :    */
     183               0 :   inline bool HasARIARole() const
     184                 :   {
     185               0 :     return mRoleMapEntry;
     186                 :   }
     187                 : 
     188                 :   /**
     189                 :    * Return accessible role specified by ARIA (see constants in
     190                 :    * roles).
     191                 :    */
     192               0 :   inline mozilla::a11y::role ARIARole()
     193                 :   {
     194               0 :     if (!mRoleMapEntry || mRoleMapEntry->roleRule != kUseMapRole)
     195               0 :       return mozilla::a11y::roles::NOTHING;
     196                 : 
     197               0 :     return ARIARoleInternal();
     198                 :   }
     199                 : 
     200                 :   /**
     201                 :    * Returns enumerated accessible role from native markup (see constants in
     202                 :    * Role.h). Doesn't take into account ARIA roles.
     203                 :    */
     204                 :   virtual mozilla::a11y::role NativeRole();
     205                 : 
     206                 :   /**
     207                 :    * Return all states of accessible (including ARIA states).
     208                 :    */
     209                 :   virtual PRUint64 State();
     210                 : 
     211                 :   /**
     212                 :    * Return the states of accessible, not taking into account ARIA states.
     213                 :    * Use State() to get complete set of states.
     214                 :    */
     215                 :   virtual PRUint64 NativeState();
     216                 : 
     217                 :   /**
     218                 :    * Return bit set of invisible and offscreen states.
     219                 :    */
     220                 :   PRUint64 VisibilityState();
     221                 : 
     222                 :   /**
     223                 :    * Returns attributes for accessible without explicitly setted ARIA
     224                 :    * attributes.
     225                 :    */
     226                 :   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
     227                 : 
     228                 :   /**
     229                 :    * Used by ChildAtPoint() method to get direct or deepest child at point.
     230                 :    */
     231                 :   enum EWhichChildAtPoint {
     232                 :     eDirectChild,
     233                 :     eDeepestChild
     234                 :   };
     235                 : 
     236                 :   /**
     237                 :    * Return direct or deepest child at the given point.
     238                 :    *
     239                 :    * @param  aX           [in] x coordinate relative screen
     240                 :    * @param  aY           [in] y coordinate relative screen
     241                 :    * @param  aWhichChild  [in] flag points if deepest or direct child
     242                 :    *                        should be returned
     243                 :    */
     244                 :   virtual nsAccessible* ChildAtPoint(PRInt32 aX, PRInt32 aY,
     245                 :                                      EWhichChildAtPoint aWhichChild);
     246                 : 
     247                 :   /**
     248                 :    * Return the focused child if any.
     249                 :    */
     250                 :   virtual nsAccessible* FocusedChild();
     251                 : 
     252                 :   /**
     253                 :    * Return calculated group level based on accessible hierarchy.
     254                 :    */
     255                 :   virtual PRInt32 GetLevelInternal();
     256                 : 
     257                 :   /**
     258                 :    * Calculate position in group and group size ('posinset' and 'setsize') based
     259                 :    * on accessible hierarchy.
     260                 :    *
     261                 :    * @param  aPosInSet  [out] accessible position in the group
     262                 :    * @param  aSetSize   [out] the group size
     263                 :    */
     264                 :   virtual void GetPositionAndSizeInternal(PRInt32 *aPosInSet,
     265                 :                                           PRInt32 *aSetSize);
     266                 : 
     267                 :   /**
     268                 :    * Get the relation of the given type.
     269                 :    */
     270                 :   virtual Relation RelationByType(PRUint32 aType);
     271                 : 
     272                 :   //////////////////////////////////////////////////////////////////////////////
     273                 :   // Initializing methods
     274                 : 
     275                 :   /**
     276                 :    * Set the ARIA role map entry for a new accessible.
     277                 :    * For a newly created accessible, specify which role map entry should be used.
     278                 :    *
     279                 :    * @param aRoleMapEntry The ARIA nsRoleMapEntry* for the accessible, or 
     280                 :    *                      nsnull if none.
     281                 :    */
     282                 :   virtual void SetRoleMapEntry(nsRoleMapEntry *aRoleMapEntry);
     283                 : 
     284                 :   /**
     285                 :    * Update the children cache.
     286                 :    */
     287               0 :   inline bool UpdateChildren()
     288                 :   {
     289               0 :     InvalidateChildren();
     290               0 :     return EnsureChildren();
     291                 :   }
     292                 : 
     293                 :   /**
     294                 :    * Cache children if necessary. Return true if the accessible is defunct.
     295                 :    */
     296                 :   bool EnsureChildren();
     297                 : 
     298                 :   /**
     299                 :    * Set the child count to -1 (unknown) and null out cached child pointers.
     300                 :    * Should be called when accessible tree is changed because document has
     301                 :    * transformed. Note, if accessible cares about its parent relation chain
     302                 :    * itself should override this method to do nothing.
     303                 :    */
     304                 :   virtual void InvalidateChildren();
     305                 : 
     306                 :   /**
     307                 :    * Append/insert/remove a child. Return true if operation was successful.
     308                 :    */
     309                 :   virtual bool AppendChild(nsAccessible* aChild);
     310                 :   virtual bool InsertChildAt(PRUint32 aIndex, nsAccessible* aChild);
     311                 :   virtual bool RemoveChild(nsAccessible* aChild);
     312                 : 
     313                 :   //////////////////////////////////////////////////////////////////////////////
     314                 :   // Accessible tree traverse methods
     315                 : 
     316                 :   /**
     317                 :    * Return parent accessible.
     318                 :    */
     319               0 :   nsAccessible* Parent() const { return mParent; }
     320                 : 
     321                 :   /**
     322                 :    * Return child accessible at the given index.
     323                 :    */
     324                 :   virtual nsAccessible* GetChildAt(PRUint32 aIndex);
     325                 : 
     326                 :   /**
     327                 :    * Return child accessible count.
     328                 :    */
     329                 :   virtual PRInt32 GetChildCount();
     330                 : 
     331                 :   /**
     332                 :    * Return index of the given child accessible.
     333                 :    */
     334                 :   virtual PRInt32 GetIndexOf(nsAccessible* aChild);
     335                 : 
     336                 :   /**
     337                 :    * Return index in parent accessible.
     338                 :    */
     339                 :   virtual PRInt32 IndexInParent() const;
     340                 : 
     341                 :   /**
     342                 :    * Return true if accessible has children;
     343                 :    */
     344               0 :   bool HasChildren() { return !!GetChildAt(0); }
     345                 : 
     346                 :   /**
     347                 :    * Return first/last/next/previous sibling of the accessible.
     348                 :    */
     349               0 :   inline nsAccessible* NextSibling() const
     350               0 :     {  return GetSiblingAtOffset(1); }
     351               0 :   inline nsAccessible* PrevSibling() const
     352               0 :     { return GetSiblingAtOffset(-1); }
     353               0 :   inline nsAccessible* FirstChild()
     354               0 :     { return GetChildCount() != 0 ? GetChildAt(0) : nsnull; }
     355               0 :   inline nsAccessible* LastChild()
     356                 :   {
     357               0 :     PRUint32 childCount = GetChildCount();
     358               0 :     return childCount != 0 ? GetChildAt(childCount - 1) : nsnull;
     359                 :   }
     360                 : 
     361                 : 
     362                 :   /**
     363                 :    * Return embedded accessible children count.
     364                 :    */
     365                 :   PRInt32 GetEmbeddedChildCount();
     366                 : 
     367                 :   /**
     368                 :    * Return embedded accessible child at the given index.
     369                 :    */
     370                 :   nsAccessible* GetEmbeddedChildAt(PRUint32 aIndex);
     371                 : 
     372                 :   /**
     373                 :    * Return index of the given embedded accessible child.
     374                 :    */
     375                 :   PRInt32 GetIndexOfEmbeddedChild(nsAccessible* aChild);
     376                 : 
     377                 :   /**
     378                 :    * Return number of content children/content child at index. The content
     379                 :    * child is created from markup in contrast to it's never constructed by its
     380                 :    * parent accessible (like treeitem accessibles for XUL trees).
     381                 :    */
     382               0 :   PRUint32 ContentChildCount() const { return mChildren.Length(); }
     383               0 :   nsAccessible* ContentChildAt(PRUint32 aIndex) const
     384               0 :     { return mChildren.ElementAt(aIndex); }
     385                 : 
     386                 :   /**
     387                 :    * Return true if children were initialized.
     388                 :    */
     389                 :   inline bool AreChildrenCached() const
     390                 :     { return !IsChildrenFlag(eChildrenUninitialized); }
     391                 : 
     392                 :   /**
     393                 :    * Return true if the accessible is attached to tree.
     394                 :    */
     395               0 :   bool IsBoundToParent() const { return !!mParent; }
     396                 : 
     397                 :   //////////////////////////////////////////////////////////////////////////////
     398                 :   // Miscellaneous methods
     399                 : 
     400                 :   /**
     401                 :    * Handle accessible event, i.e. process it, notifies observers and fires
     402                 :    * platform specific event.
     403                 :    */
     404                 :   virtual nsresult HandleAccEvent(AccEvent* aAccEvent);
     405                 : 
     406                 :   /**
     407                 :    * Return true if this accessible allows accessible children from anonymous subtree.
     408                 :    */
     409                 :   virtual bool CanHaveAnonChildren();
     410                 : 
     411                 :   /**
     412                 :    * Returns text of accessible if accessible has text role otherwise empty
     413                 :    * string.
     414                 :    *
     415                 :    * @param aText         [in] returned text of the accessible
     416                 :    * @param aStartOffset  [in, optional] start offset inside of the accessible,
     417                 :    *                        if missed entire text is appended
     418                 :    * @param aLength       [in, optional] required length of text, if missed
     419                 :    *                        then text form start offset till the end is appended
     420                 :    */
     421                 :   virtual void AppendTextTo(nsAString& aText, PRUint32 aStartOffset = 0,
     422                 :                             PRUint32 aLength = PR_UINT32_MAX);
     423                 : 
     424                 :   /**
     425                 :    * Assert if child not in parent's cache if the cache was initialized at this
     426                 :    * point.
     427                 :    */
     428                 :   void TestChildCache(nsAccessible* aCachedChild) const;
     429                 : 
     430                 :   //////////////////////////////////////////////////////////////////////////////
     431                 :   // Downcasting and types
     432                 : 
     433                 :   inline bool IsAbbreviation() const
     434                 :   {
     435                 :     return mContent->IsHTML() &&
     436                 :       (mContent->Tag() == nsGkAtoms::abbr || mContent->Tag() == nsGkAtoms::acronym);
     437                 :   }
     438                 : 
     439                 :   inline bool IsApplication() const { return mFlags & eApplicationAccessible; }
     440                 : 
     441               0 :   bool IsAutoComplete() const { return mFlags & eAutoCompleteAccessible; }
     442                 : 
     443               0 :   inline bool IsAutoCompletePopup() const { return mFlags & eAutoCompletePopupAccessible; }
     444                 : 
     445               0 :   inline bool IsCombobox() const { return mFlags & eComboboxAccessible; }
     446                 : 
     447               0 :   inline bool IsDoc() const { return mFlags & eDocAccessible; }
     448                 :   nsDocAccessible* AsDoc();
     449                 : 
     450               0 :   inline bool IsHyperText() const { return mFlags & eHyperTextAccessible; }
     451                 :   nsHyperTextAccessible* AsHyperText();
     452                 : 
     453                 :   inline bool IsHTMLFileInput() const { return mFlags & eHTMLFileInputAccessible; }
     454                 : 
     455                 :   inline bool IsHTMLListItem() const { return mFlags & eHTMLListItemAccessible; }
     456                 :   nsHTMLLIAccessible* AsHTMLListItem();
     457                 :   
     458               0 :   inline bool IsImageAccessible() const { return mFlags & eImageAccessible; }
     459                 :   nsHTMLImageAccessible* AsImage();
     460                 : 
     461                 :   inline bool IsListControl() const { return mFlags & eListControlAccessible; }
     462                 : 
     463               0 :   inline bool IsMenuButton() const { return mFlags & eMenuButtonAccessible; }
     464                 : 
     465               0 :   inline bool IsMenuPopup() const { return mFlags & eMenuPopupAccessible; }
     466                 : 
     467               0 :   inline bool IsRoot() const { return mFlags & eRootAccessible; }
     468                 :   nsRootAccessible* AsRoot();
     469                 : 
     470                 :   inline bool IsTextLeaf() const { return mFlags & eTextLeafAccessible; }
     471                 :   nsTextAccessible* AsTextLeaf();
     472                 : 
     473                 :   //////////////////////////////////////////////////////////////////////////////
     474                 :   // ActionAccessible
     475                 : 
     476                 :   /**
     477                 :    * Return the number of actions that can be performed on this accessible.
     478                 :    */
     479                 :   virtual PRUint8 ActionCount();
     480                 : 
     481                 :   /**
     482                 :    * Return access key, such as Alt+D.
     483                 :    */
     484                 :   virtual KeyBinding AccessKey() const;
     485                 : 
     486                 :   /**
     487                 :    * Return global keyboard shortcut for default action, such as Ctrl+O for
     488                 :    * Open file menuitem.
     489                 :    */
     490                 :   virtual KeyBinding KeyboardShortcut() const;
     491                 : 
     492                 :   //////////////////////////////////////////////////////////////////////////////
     493                 :   // HyperLinkAccessible
     494                 : 
     495                 :   /**
     496                 :    * Return true if the accessible is hyper link accessible.
     497                 :    */
     498                 :   virtual bool IsLink();
     499                 : 
     500                 :   /**
     501                 :    * Return the start offset of the link within the parent accessible.
     502                 :    */
     503                 :   virtual PRUint32 StartOffset();
     504                 : 
     505                 :   /**
     506                 :    * Return the end offset of the link within the parent accessible.
     507                 :    */
     508                 :   virtual PRUint32 EndOffset();
     509                 : 
     510                 :   /**
     511                 :    * Return true if the link is valid (e. g. points to a valid URL).
     512                 :    */
     513               0 :   inline bool IsLinkValid()
     514                 :   {
     515               0 :     NS_PRECONDITION(IsLink(), "IsLinkValid is called on not hyper link!");
     516                 : 
     517                 :     // XXX In order to implement this we would need to follow every link
     518                 :     // Perhaps we can get information about invalid links from the cache
     519                 :     // In the mean time authors can use role="link" aria-invalid="true"
     520                 :     // to force it for links they internally know to be invalid
     521               0 :     return (0 == (State() & mozilla::a11y::states::INVALID));
     522                 :   }
     523                 : 
     524                 :   /**
     525                 :    * Return true if the link currently has the focus.
     526                 :    */
     527                 :   bool IsLinkSelected();
     528                 : 
     529                 :   /**
     530                 :    * Return the number of anchors within the link.
     531                 :    */
     532                 :   virtual PRUint32 AnchorCount();
     533                 : 
     534                 :   /**
     535                 :    * Returns an anchor accessible at the given index.
     536                 :    */
     537                 :   virtual nsAccessible* AnchorAt(PRUint32 aAnchorIndex);
     538                 : 
     539                 :   /**
     540                 :    * Returns an anchor URI at the given index.
     541                 :    */
     542                 :   virtual already_AddRefed<nsIURI> AnchorURIAt(PRUint32 aAnchorIndex);
     543                 : 
     544                 :   //////////////////////////////////////////////////////////////////////////////
     545                 :   // SelectAccessible
     546                 : 
     547                 :   /**
     548                 :    * Return true if the accessible is a select control containing selectable
     549                 :    * items.
     550                 :    */
     551                 :   virtual bool IsSelect();
     552                 : 
     553                 :   /**
     554                 :    * Return an array of selected items.
     555                 :    */
     556                 :   virtual already_AddRefed<nsIArray> SelectedItems();
     557                 : 
     558                 :   /**
     559                 :    * Return the number of selected items.
     560                 :    */
     561                 :   virtual PRUint32 SelectedItemCount();
     562                 : 
     563                 :   /**
     564                 :    * Return selected item at the given index.
     565                 :    */
     566                 :   virtual nsAccessible* GetSelectedItem(PRUint32 aIndex);
     567                 : 
     568                 :   /**
     569                 :    * Determine if item at the given index is selected.
     570                 :    */
     571                 :   virtual bool IsItemSelected(PRUint32 aIndex);
     572                 : 
     573                 :   /**
     574                 :    * Add item at the given index the selection. Return true if success.
     575                 :    */
     576                 :   virtual bool AddItemToSelection(PRUint32 aIndex);
     577                 : 
     578                 :   /**
     579                 :    * Remove item at the given index from the selection. Return if success.
     580                 :    */
     581                 :   virtual bool RemoveItemFromSelection(PRUint32 aIndex);
     582                 : 
     583                 :   /**
     584                 :    * Select all items. Return true if success.
     585                 :    */
     586                 :   virtual bool SelectAll();
     587                 : 
     588                 :   /**
     589                 :    * Unselect all items. Return true if success.
     590                 :    */
     591                 :   virtual bool UnselectAll();
     592                 : 
     593                 :   //////////////////////////////////////////////////////////////////////////////
     594                 :   // Widgets
     595                 : 
     596                 :   /**
     597                 :    * Return true if accessible is a widget, i.e. control or accessible that
     598                 :    * manages its items. Note, being a widget the accessible may be a part of
     599                 :    * composite widget.
     600                 :    */
     601                 :   virtual bool IsWidget() const;
     602                 : 
     603                 :   /**
     604                 :    * Return true if the widget is active, i.e. has a focus within it.
     605                 :    */
     606                 :   virtual bool IsActiveWidget() const;
     607                 : 
     608                 :   /**
     609                 :    * Return true if the widget has items and items are operable by user and
     610                 :    * can be activated.
     611                 :    */
     612                 :   virtual bool AreItemsOperable() const;
     613                 : 
     614                 :   /**
     615                 :    * Return the current item of the widget, i.e. an item that has or will have
     616                 :    * keyboard focus when widget gets active.
     617                 :    */
     618                 :   virtual nsAccessible* CurrentItem();
     619                 : 
     620                 :   /**
     621                 :    * Set the current item of the widget.
     622                 :    */
     623                 :   virtual void SetCurrentItem(nsAccessible* aItem);
     624                 : 
     625                 :   /**
     626                 :    * Return container widget this accessible belongs to.
     627                 :    */
     628                 :   virtual nsAccessible* ContainerWidget() const;
     629                 : 
     630                 :   /**
     631                 :    * Return the localized string for the given key.
     632                 :    */
     633                 :   static void TranslateString(const nsAString& aKey, nsAString& aStringOut);
     634                 : 
     635                 : protected:
     636                 : 
     637                 :   //////////////////////////////////////////////////////////////////////////////
     638                 :   // Initializing, cache and tree traverse methods
     639                 : 
     640                 :   /**
     641                 :    * Cache accessible children.
     642                 :    */
     643                 :   virtual void CacheChildren();
     644                 : 
     645                 :   /**
     646                 :    * Set accessible parent and index in parent.
     647                 :    */
     648                 :   virtual void BindToParent(nsAccessible* aParent, PRUint32 aIndexInParent);
     649                 :   virtual void UnbindFromParent();
     650                 : 
     651                 :   /**
     652                 :    * Return sibling accessible at the given offset.
     653                 :    */
     654                 :   virtual nsAccessible* GetSiblingAtOffset(PRInt32 aOffset,
     655                 :                                            nsresult *aError = nsnull) const;
     656                 : 
     657                 :   /**
     658                 :    * Flags used to describe the state and type of children.
     659                 :    */
     660                 :   enum ChildrenFlags {
     661                 :     eChildrenUninitialized = 0, // children aren't initialized
     662                 :     eMixedChildren = 1 << 0, // text leaf children are presented
     663                 :     eEmbeddedChildren = 1 << 1 // all children are embedded objects
     664                 :   };
     665                 : 
     666                 :   /**
     667                 :    * Return true if the children flag is set.
     668                 :    */
     669               0 :   inline bool IsChildrenFlag(ChildrenFlags aFlag) const
     670               0 :     { return static_cast<ChildrenFlags> (mFlags & kChildrenFlagsMask) == aFlag; }
     671                 : 
     672                 :   /**
     673                 :    * Set children flag.
     674                 :    */
     675               0 :   inline void SetChildrenFlag(ChildrenFlags aFlag)
     676               0 :     { mFlags = (mFlags & ~kChildrenFlagsMask) | aFlag; }
     677                 : 
     678                 :   /**
     679                 :    * Flags describing the accessible itself.
     680                 :    * @note keep these flags in sync with ChildrenFlags
     681                 :    */
     682                 :   enum AccessibleTypes {
     683                 :     eApplicationAccessible = 1 << 2,
     684                 :     eAutoCompleteAccessible = 1 << 3,
     685                 :     eAutoCompletePopupAccessible = 1 << 4,
     686                 :     eComboboxAccessible = 1 << 5,
     687                 :     eDocAccessible = 1 << 6,
     688                 :     eHyperTextAccessible = 1 << 7,
     689                 :     eHTMLFileInputAccessible = 1 << 8,
     690                 :     eHTMLListItemAccessible = 1 << 9,
     691                 :     eImageAccessible = 1 << 10,
     692                 :     eListControlAccessible = 1 << 11,
     693                 :     eMenuButtonAccessible = 1 << 12,
     694                 :     eMenuPopupAccessible = 1 << 13,
     695                 :     eRootAccessible = 1 << 14,
     696                 :     eTextLeafAccessible = 1 << 15
     697                 :   };
     698                 : 
     699                 :   //////////////////////////////////////////////////////////////////////////////
     700                 :   // Miscellaneous helpers
     701                 : 
     702                 :   /**
     703                 :    * Return ARIA role (helper method).
     704                 :    */
     705                 :   mozilla::a11y::role ARIARoleInternal();
     706                 : 
     707                 :   virtual nsIFrame* GetBoundsFrame();
     708                 :   virtual void GetBoundsRect(nsRect& aRect, nsIFrame** aRelativeFrame);
     709                 : 
     710                 :   //////////////////////////////////////////////////////////////////////////////
     711                 :   // Name helpers
     712                 : 
     713                 :   /**
     714                 :    * Compute the name of HTML node.
     715                 :    */
     716                 :   nsresult GetHTMLName(nsAString& aName);
     717                 : 
     718                 :   /**
     719                 :    * Compute the name for XUL node.
     720                 :    */
     721                 :   nsresult GetXULName(nsAString& aName);
     722                 : 
     723                 :   // helper method to verify frames
     724                 :   static nsresult GetFullKeyName(const nsAString& aModifierName, const nsAString& aKeyName, nsAString& aStringOut);
     725                 : 
     726                 :   /**
     727                 :    * Return an accessible for the given DOM node, or if that node isn't
     728                 :    * accessible, return the accessible for the next DOM node which has one
     729                 :    * (based on forward depth first search).
     730                 :    *
     731                 :    * @param  aStartNode  [in] the DOM node to start from
     732                 :    * @return              the resulting accessible
     733                 :    */
     734                 :   nsAccessible *GetFirstAvailableAccessible(nsINode *aStartNode) const;
     735                 : 
     736                 :   //////////////////////////////////////////////////////////////////////////////
     737                 :   // Action helpers
     738                 : 
     739                 :   /**
     740                 :    * Prepares click action that will be invoked in timeout.
     741                 :    *
     742                 :    * @note  DoCommand() prepares an action in timeout because when action
     743                 :    *  command opens a modal dialog/window, it won't return until the
     744                 :    *  dialog/window is closed. If executing action command directly in
     745                 :    *  nsIAccessible::DoAction() method, it will block AT tools (e.g. GOK) that
     746                 :    *  invoke action of mozilla accessibles direclty (see bug 277888 for details).
     747                 :    *
     748                 :    * @param  aContent      [in, optional] element to click
     749                 :    * @param  aActionIndex  [in, optional] index of accessible action
     750                 :    */
     751                 :   void DoCommand(nsIContent *aContent = nsnull, PRUint32 aActionIndex = 0);
     752                 : 
     753                 :   /**
     754                 :    * Dispatch click event.
     755                 :    */
     756                 :   virtual void DispatchClickEvent(nsIContent *aContent, PRUint32 aActionIndex);
     757                 : 
     758               0 :   NS_DECL_RUNNABLEMETHOD_ARG2(nsAccessible, DispatchClickEvent,
     759               0 :                               nsCOMPtr<nsIContent>, PRUint32)
     760                 : 
     761                 :   //////////////////////////////////////////////////////////////////////////////
     762                 :   // Helpers
     763                 : 
     764                 :   /**
     765                 :    *  Get the container node for an atomic region, defined by aria-atomic="true"
     766                 :    *  @return the container node
     767                 :    */
     768                 :   nsIContent* GetAtomicRegion() const;
     769                 : 
     770                 :   /**
     771                 :    * Get numeric value of the given ARIA attribute.
     772                 :    *
     773                 :    * @param aAriaProperty - the ARIA property we're using
     774                 :    * @param aValue - value of the attribute
     775                 :    *
     776                 :    * @return - NS_OK_NO_ARIA_VALUE if there is no setted ARIA attribute
     777                 :    */
     778                 :   nsresult GetAttrValue(nsIAtom *aAriaProperty, double *aValue);
     779                 : 
     780                 :   /**
     781                 :    * Return the action rule based on ARIA enum constants EActionRule
     782                 :    * (see nsARIAMap.h). Used by ActionCount() and GetActionName().
     783                 :    *
     784                 :    * @param aStates  [in] states of the accessible
     785                 :    */
     786                 :   PRUint32 GetActionRule(PRUint64 aStates);
     787                 : 
     788                 :   /**
     789                 :    * Return group info.
     790                 :    */
     791                 :   AccGroupInfo* GetGroupInfo();
     792                 : 
     793                 :   /**
     794                 :    * Fires platform accessible event. It's notification method only. It does
     795                 :    * change nothing on Gecko side. Don't use it until you're sure what you do
     796                 :    * (see example in XUL tree accessible), use nsEventShell::FireEvent()
     797                 :    * instead. MUST be overridden in wrap classes.
     798                 :    *
     799                 :    * @param aEvent  the accessible event to fire.
     800                 :    */
     801                 :   virtual nsresult FirePlatformEvent(AccEvent* aEvent) = 0;
     802                 : 
     803                 :   // Data Members
     804                 :   nsRefPtr<nsAccessible> mParent;
     805                 :   nsTArray<nsRefPtr<nsAccessible> > mChildren;
     806                 :   PRInt32 mIndexInParent;
     807                 : 
     808                 :   static const PRUint32 kChildrenFlagsMask =
     809                 :     eChildrenUninitialized | eMixedChildren | eEmbeddedChildren;
     810                 : 
     811                 :   PRUint32 mFlags;
     812                 : 
     813                 :   nsAutoPtr<EmbeddedObjCollector> mEmbeddedObjCollector;
     814                 :   PRInt32 mIndexOfEmbeddedChild;
     815                 :   friend class EmbeddedObjCollector;
     816                 : 
     817                 :   nsAutoPtr<AccGroupInfo> mGroupInfo;
     818                 :   friend class AccGroupInfo;
     819                 : 
     820                 :   nsRoleMapEntry *mRoleMapEntry; // Non-null indicates author-supplied role; possibly state & value as well
     821                 : };
     822                 : 
     823                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsAccessible,
     824                 :                               NS_ACCESSIBLE_IMPL_IID)
     825                 : 
     826                 : 
     827                 : /**
     828                 :  * Represent key binding associated with accessible (such as access key and
     829                 :  * global keyboard shortcuts).
     830                 :  */
     831                 : class KeyBinding
     832                 : {
     833                 : public:
     834                 :   /**
     835                 :    * Modifier mask values.
     836                 :    */
     837                 :   static const PRUint32 kShift = 1;
     838                 :   static const PRUint32 kControl = 2;
     839                 :   static const PRUint32 kAlt = 4;
     840                 :   static const PRUint32 kMeta = 8;
     841                 : 
     842               0 :   KeyBinding() : mKey(0), mModifierMask(0) {}
     843               0 :   KeyBinding(PRUint32 aKey, PRUint32 aModifierMask) :
     844               0 :     mKey(aKey), mModifierMask(aModifierMask) {};
     845                 : 
     846               0 :   inline bool IsEmpty() const { return !mKey; }
     847                 :   inline PRUint32 Key() const { return mKey; }
     848                 :   inline PRUint32 ModifierMask() const { return mModifierMask; }
     849                 : 
     850                 :   enum Format {
     851                 :     ePlatformFormat,
     852                 :     eAtkFormat
     853                 :   };
     854                 : 
     855                 :   /**
     856                 :    * Return formatted string for this key binding depending on the given format.
     857                 :    */
     858               0 :   inline void ToString(nsAString& aValue,
     859                 :                        Format aFormat = ePlatformFormat) const
     860                 :   {
     861               0 :     aValue.Truncate();
     862               0 :     AppendToString(aValue, aFormat);
     863               0 :   }
     864               0 :   inline void AppendToString(nsAString& aValue,
     865                 :                              Format aFormat = ePlatformFormat) const
     866                 :   {
     867               0 :     if (mKey) {
     868               0 :       if (aFormat == ePlatformFormat)
     869               0 :         ToPlatformFormat(aValue);
     870                 :       else
     871               0 :         ToAtkFormat(aValue);
     872                 :     }
     873               0 :   }
     874                 : 
     875                 : private:
     876                 :   void ToPlatformFormat(nsAString& aValue) const;
     877                 :   void ToAtkFormat(nsAString& aValue) const;
     878                 : 
     879                 :   PRUint32 mKey;
     880                 :   PRUint32 mModifierMask;
     881                 : };
     882                 : 
     883                 : #endif

Generated by: LCOV version 1.7