Back to index

lightning-sunbird  0.9+nobinonly
nsAccessNode.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) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Original Author: Aaron Leventhal (aaronl@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 /* For documentation of the accessibility architecture, 
00040  * see http://lxr.mozilla.org/seamonkey/source/accessible/accessible-docs.html
00041  */
00042 
00043 #ifndef _nsAccessNode_H_
00044 #define _nsAccessNode_H_
00045 
00046 #include "nsCOMPtr.h"
00047 #include "nsAccessibilityAtoms.h"
00048 #include "nsIAccessNode.h"
00049 #include "nsIContent.h"
00050 #include "nsPIAccessNode.h"
00051 #include "nsIDocShellTreeItem.h"
00052 #include "nsIDOMNode.h"
00053 #include "nsINameSpaceManager.h"
00054 #include "nsIStringBundle.h"
00055 #include "nsWeakReference.h"
00056 #include "nsInterfaceHashtable.h"
00057 
00058 class nsIPresShell;
00059 class nsPresContext;
00060 class nsIAccessibleDocument;
00061 class nsIFrame;
00062 class nsIDOMNodeList;
00063 class nsITimer;
00064 
00065 #define ACCESSIBLE_BUNDLE_URL "chrome://global-platform/locale/accessible.properties"
00066 #define PLATFORM_KEYS_BUNDLE_URL "chrome://global-platform/locale/platformKeys.properties"
00067 
00068 /* hashkey wrapper using void* KeyType
00069  *
00070  * @see nsTHashtable::EntryType for specification
00071  */
00072 class nsVoidHashKey : public PLDHashEntryHdr
00073 {
00074 public:
00075   typedef const void* KeyType;
00076   typedef const void* KeyTypePointer;
00077   
00078   nsVoidHashKey(KeyTypePointer aKey) : mValue(aKey) { }
00079   nsVoidHashKey(const nsVoidHashKey& toCopy) : mValue(toCopy.mValue) { }
00080   ~nsVoidHashKey() { }
00081 
00082   KeyType GetKey() const { return mValue; }
00083   KeyTypePointer GetKeyPointer() const { return mValue; }
00084   PRBool KeyEquals(KeyTypePointer aKey) const { return aKey == mValue; }
00085 
00086   static KeyTypePointer KeyToPointer(KeyType aKey) { return aKey; }
00087   static PLDHashNumber HashKey(KeyTypePointer aKey) { return NS_PTR_TO_INT32(aKey) >> 2; }
00088   enum { ALLOW_MEMMOVE = PR_TRUE };
00089 
00090 private:
00091   const void* mValue;
00092 };
00093 
00094 class nsAccessNode: public nsIAccessNode, public nsPIAccessNode
00095 {
00096   public: // construction, destruction
00097     nsAccessNode(nsIDOMNode *, nsIWeakReference* aShell);
00098     virtual ~nsAccessNode();
00099 
00100     NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
00101     NS_IMETHOD_(nsrefcnt) AddRef(void);
00102     NS_IMETHOD_(nsrefcnt) Release(void);
00103     NS_DECL_NSIACCESSNODE
00104     NS_DECL_NSPIACCESSNODE
00105 
00106     static void InitXPAccessibility();
00107     static void ShutdownXPAccessibility();
00108 
00109     // Static methods for handling per-document cache
00110     static void PutCacheEntry(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>& aCache, 
00111                               void* aUniqueID, nsIAccessNode *aAccessNode);
00112     static void GetCacheEntry(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>& aCache, void* aUniqueID, 
00113                               nsIAccessNode **aAccessNode);
00114     static void ClearCache(nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode>& aCache);
00115 
00116     static PLDHashOperator PR_CALLBACK ClearCacheEntry(const void* aKey, nsCOMPtr<nsIAccessNode>& aAccessNode, void* aUserArg);
00117 
00118     // Static cache methods for global document cache
00119     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIWeakReference *aPresShell);
00120     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsISupports *aContainer);
00121     static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDOMNode *aNode);
00122 
00123     static already_AddRefed<nsIDocShellTreeItem> GetDocShellTreeItemFor(nsIDOMNode *aStartNode);
00124     static already_AddRefed<nsIPresShell> GetPresShellFor(nsIDOMNode *aStartNode);
00125     
00126     // Return PR_TRUE if there is a role attribute
00127     static PRBool HasRoleAttribute(nsIContent *aContent)
00128     {
00129       return (aContent->IsContentOfType(nsIContent::eHTML) && aContent->HasAttr(kNameSpaceID_None, nsAccessibilityAtoms::role)) ||
00130               aContent->HasAttr(kNameSpaceID_XHTML, nsAccessibilityAtoms::role) ||
00131               aContent->HasAttr(kNameSpaceID_XHTML2_Unofficial, nsAccessibilityAtoms::role);
00132     }
00133 
00134     // Return PR_TRUE if there is a role attribute, and fill it into aRole
00135     static PRBool GetRoleAttribute(nsIContent *aContent, nsAString& aRole)
00136     {
00137       aRole.Truncate();
00138       return (aContent->IsContentOfType(nsIContent::eHTML) && aContent->GetAttr(kNameSpaceID_None, nsAccessibilityAtoms::role, aRole) != NS_CONTENT_ATTR_NOT_THERE) ||
00139               aContent->GetAttr(kNameSpaceID_XHTML, nsAccessibilityAtoms::role, aRole) != NS_CONTENT_ATTR_NOT_THERE ||
00140               aContent->GetAttr(kNameSpaceID_XHTML2_Unofficial, nsAccessibilityAtoms::role, aRole) != NS_CONTENT_ATTR_NOT_THERE;
00141     }
00142 
00143     static nsIDOMNode *gLastFocusedNode;
00144 
00145 protected:
00146     nsresult MakeAccessNode(nsIDOMNode *aNode, nsIAccessNode **aAccessNode);
00147     already_AddRefed<nsIPresShell> GetPresShell();
00148     nsPresContext* GetPresContext();
00149     already_AddRefed<nsIAccessibleDocument> GetDocAccessible();
00150 
00151     nsCOMPtr<nsIDOMNode> mDOMNode;
00152     nsCOMPtr<nsIWeakReference> mWeakShell;
00153 
00154     PRInt32 mRefCnt;
00155     NS_DECL_OWNINGTHREAD
00156 
00157 #ifdef DEBUG
00158     PRBool mIsInitialized;
00159 #endif
00160 
00161     // Static data, we do our own refcounting for our static data
00162     static nsIStringBundle *gStringBundle;
00163     static nsIStringBundle *gKeyStringBundle;
00164     static nsITimer *gDoCommandTimer;
00165     static PRBool gIsAccessibilityActive;
00166     static PRBool gIsCacheDisabled;
00167 
00168     static nsInterfaceHashtable<nsVoidHashKey, nsIAccessNode> gGlobalDocAccessibleCache;
00169 };
00170 
00171 #endif
00172