Back to index

lightning-sunbird  0.9+nobinonly
nsAccessible.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   John Gaunt (jgaunt@netscape.com)
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef _nsAccessible_H_
00040 #define _nsAccessible_H_
00041 
00042 #include "nsAccessNodeWrap.h"
00043 #include "nsAccessibilityAtoms.h"
00044 #include "nsIAccessible.h"
00045 #include "nsPIAccessible.h"
00046 #include "nsIAccessibleSelectable.h"
00047 #include "nsIDOMNodeList.h"
00048 #include "nsINameSpaceManager.h"
00049 #include "nsWeakReference.h"
00050 #include "nsString.h"
00051 
00052 struct nsRect;
00053 class nsIContent;
00054 class nsIFrame;
00055 class nsIPresShell;
00056 class nsIDOMNode;
00057 class nsIAtom;
00058 
00059 // When mNextSibling is set to this, it indicates there ar eno more siblings
00060 #define DEAD_END_ACCESSIBLE NS_STATIC_CAST(nsIAccessible*, (void*)1)
00061 
00062 // Saves a data member -- if child count equals this value we haven't
00063 // cached children or child count yet
00064 enum { eChildCountUninitialized = 0xffffffff };
00065 
00066 struct nsStateMapEntry
00067 {
00068   const char* attributeName;  // magic value of nsnull means last entry in map
00069   const char* attributeValue; // magic value of nsnull means any value
00070   PRUint32 state;       // OR state with this
00071 };
00072 
00073 enum ENameRule {
00074   eNameLabelOrTitle,     // Collect name if explicitly specified from 
00075                          // 1) content subtree pointed to by labelledby
00076                          //    which contains the ID for the label content, or
00077                          // 2) title attribute if specified
00078   eNameOkFromChildren    // Collect name from
00079                          // 1) labelledby attribute if specified, or
00080                          // 2) text & img descendents, or
00081                          // 3) title attribute if specified
00082 };
00083 
00084 enum EValueRule {
00085   eNoValue,
00086   eHasValueMinMax    // Supports value, min and max from waistate:valuenow, valuemin and valuemax
00087 };
00088 
00089 #define eNoReqStates 0
00090 #define END_ENTRY {0, 0, 0}  // To fill in array of state mappings
00091 #define BOOL_STATE 0
00092 
00093 struct nsRoleMapEntry
00094 {
00095   const char *roleString; // such as "button"
00096   PRUint32 role;   // use this role
00097   ENameRule nameRule;  // how to compute name
00098   EValueRule valueRule;  // how to compute name
00099   PRUint32 state;  // always OR state with this
00100   // For this role with a DOM attribute/value match definined in
00101   // nsStateMapEntry.attributeName && .attributeValue, OR accessible state with
00102   // nsStateMapEntry.state
00103   // Currently you can have up to 3 DOM attributes with accessible state mappings.
00104   // A variable sized array would not allow use of C++'s struct initialization feature.
00105   nsStateMapEntry attributeMap1;
00106   nsStateMapEntry attributeMap2;
00107   nsStateMapEntry attributeMap3;
00108   nsStateMapEntry attributeMap4;
00109   nsStateMapEntry attributeMap5;
00110   nsStateMapEntry attributeMap6;
00111   nsStateMapEntry attributeMap7;
00112 };
00113 
00114 class nsAccessible : public nsAccessNodeWrap, 
00115                      public nsIAccessible, 
00116                      public nsPIAccessible,
00117                      public nsIAccessibleSelectable
00118 {
00119 public:
00120   // to eliminate the confusion of "magic numbers" -- if ( 0 ){ foo; }
00121   enum { eAction_Switch=0, eAction_Jump=0, eAction_Click=0, eAction_Select=0, eAction_Expand=1 };
00122   // how many actions
00123   enum { eNo_Action=0, eSingle_Action=1, eDouble_Action=2 }; 
00124 
00125   nsAccessible(nsIDOMNode* aNode, nsIWeakReference* aShell);
00126   virtual ~nsAccessible();
00127 
00128   NS_DECL_ISUPPORTS_INHERITED
00129   NS_DECL_NSIACCESSIBLE
00130   NS_DECL_NSPIACCESSIBLE
00131   NS_DECL_NSIACCESSIBLESELECTABLE
00132 
00133   // nsIAccessNode
00134   NS_IMETHOD Init();
00135   NS_IMETHOD Shutdown();
00136 
00137   // Support GetFinalState(), GetFinalValue()
00138   NS_IMETHOD GetState(PRUint32 *aState);
00139   NS_IMETHOD GetValue(nsAString & aValue);
00140 
00141 #ifdef MOZ_ACCESSIBILITY_ATK
00142   static nsresult GetParentBlockNode(nsIPresShell *aPresShell, nsIDOMNode *aCurrentNode, nsIDOMNode **aBlockNode);
00143   static nsIFrame* GetParentBlockFrame(nsIFrame *aFrame);
00144   static PRBool FindTextFrame(PRInt32 &index, nsPresContext *aPresContext, nsIFrame *aCurFrame, 
00145                                    nsIFrame **aFirstTextFrame, const nsIFrame *aTextFrame);
00146 #endif
00147 
00148   static PRBool IsCorrectFrameType(nsIFrame* aFrame, nsIAtom* aAtom);
00149 
00150 protected:
00151   PRBool MappedAttrState(nsIContent *aContent, PRUint32 *aStateInOut, nsStateMapEntry *aStateMapEntry);
00152   virtual nsIFrame* GetBoundsFrame();
00153   virtual void GetBoundsRect(nsRect& aRect, nsIFrame** aRelativeFrame);
00154   PRBool IsPartiallyVisible(PRBool *aIsOffscreen); 
00155   nsresult GetTextFromRelationID(nsIAtom *aIDAttrib, nsString &aName);
00156 
00157   static nsIContent *GetContentPointingTo(const nsAString *aId,
00158                                           nsIContent *aLookContent,
00159                                           nsIAtom *forAttrib,
00160                                           PRUint32 aForAttribNamespace = kNameSpaceID_None,
00161                                           nsIAtom *aTagType = nsAccessibilityAtoms::label);
00162   static nsIContent *GetXULLabelContent(nsIContent *aForNode,
00163                                         nsIAtom *aLabelType = nsAccessibilityAtoms::label);
00164   static nsIContent *GetHTMLLabelContent(nsIContent *aForNode);
00165   static nsIContent *GetLabelContent(nsIContent *aForNode);
00166   static nsIContent *GetRoleContent(nsIDOMNode *aDOMNode);
00167 
00168   nsresult GetHTMLName(nsAString& _retval, PRBool aCanAggregateSubtree = PR_TRUE);
00169   nsresult GetXULName(nsAString& aName, PRBool aCanAggregateSubtree = PR_TRUE);
00170   // For accessibles that are not lists of choices, the name of the subtree should be the 
00171   // sum of names in the subtree
00172   nsresult AppendFlatStringFromSubtree(nsIContent *aContent, nsAString *aFlatString);
00173   nsresult AppendNameFromAccessibleFor(nsIContent *aContent, nsAString *aFlatString,
00174                                        PRBool aFromValue = PR_FALSE);
00175   nsresult AppendFlatStringFromContentNode(nsIContent *aContent, nsAString *aFlatString);
00176   nsresult AppendStringWithSpaces(nsAString *aFlatString, const nsAString& textEquivalent);
00177 
00178   // helper method to verify frames
00179   static nsresult GetFullKeyName(const nsAString& aModifierName, const nsAString& aKeyName, nsAString& aStringOut);
00180   static nsresult GetTranslatedString(const nsAString& aKey, nsAString& aStringOut);
00181   void GetScreenOrigin(nsPresContext *aPresContext, nsIFrame *aFrame, nsRect *aRect);
00182   nsresult AppendFlatStringFromSubtreeRecurse(nsIContent *aContent, nsAString *aFlatString);
00183   virtual void CacheChildren(PRBool aWalkAnonContent);
00184 
00185   // Selection helpers
00186   already_AddRefed<nsIAccessible> GetNextWithState(nsIAccessible *aStart, PRUint32 matchState);
00187   static already_AddRefed<nsIAccessible> GetMultiSelectFor(nsIDOMNode *aNode);
00188   nsresult SetNonTextSelection(PRBool aSelect);
00189 
00190   // For accessibles that have actions
00191   static void DoCommandCallback(nsITimer *aTimer, void *aClosure);
00192   nsresult DoCommand(nsIContent *aContent = nsnull);
00193 
00194   // Relation helpers
00195   already_AddRefed<nsIDOMNode> GetInverseRelatedNode(nsIAtom *aRelationAttr,
00196                                                      PRUint32 aAncestorLevelsToSearch = 0);
00197 
00198   // Data Members
00199   nsCOMPtr<nsIAccessible> mParent;
00200   nsIAccessible *mFirstChild, *mNextSibling;
00201   nsRoleMapEntry *mRoleMapEntry; // Non-null indicates author-supplied role; possibly state & value as well
00202   PRUint32 mAccChildCount;
00203 
00204   static nsRoleMapEntry gWAIRoleMap[];
00205   static nsStateMapEntry gUnivStateMap[];
00206 };
00207 
00208 
00209 #endif  
00210