1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/DocManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,165 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_a11_DocManager_h_ 1.9 +#define mozilla_a11_DocManager_h_ 1.10 + 1.11 +#include "nsIDocument.h" 1.12 +#include "nsIDOMEventListener.h" 1.13 +#include "nsRefPtrHashtable.h" 1.14 +#include "nsIWebProgressListener.h" 1.15 +#include "nsWeakReference.h" 1.16 +#include "nsIPresShell.h" 1.17 + 1.18 +namespace mozilla { 1.19 +namespace a11y { 1.20 + 1.21 +class Accessible; 1.22 +class DocAccessible; 1.23 + 1.24 +/** 1.25 + * Manage the document accessible life cycle. 1.26 + */ 1.27 +class DocManager : public nsIWebProgressListener, 1.28 + public nsIDOMEventListener, 1.29 + public nsSupportsWeakReference 1.30 +{ 1.31 +public: 1.32 + virtual ~DocManager() { } 1.33 + 1.34 + NS_DECL_THREADSAFE_ISUPPORTS 1.35 + NS_DECL_NSIWEBPROGRESSLISTENER 1.36 + NS_DECL_NSIDOMEVENTLISTENER 1.37 + 1.38 + /** 1.39 + * Return document accessible for the given DOM node. 1.40 + */ 1.41 + DocAccessible* GetDocAccessible(nsIDocument* aDocument); 1.42 + 1.43 + /** 1.44 + * Return document accessible for the given presshell. 1.45 + */ 1.46 + DocAccessible* GetDocAccessible(const nsIPresShell* aPresShell) 1.47 + { 1.48 + if (!aPresShell) 1.49 + return nullptr; 1.50 + 1.51 + DocAccessible* doc = aPresShell->GetDocAccessible(); 1.52 + if (doc) 1.53 + return doc; 1.54 + 1.55 + return GetDocAccessible(aPresShell->GetDocument()); 1.56 + } 1.57 + 1.58 + /** 1.59 + * Search through all document accessibles for an accessible with the given 1.60 + * unique id. 1.61 + */ 1.62 + Accessible* FindAccessibleInCache(nsINode* aNode) const; 1.63 + 1.64 + /** 1.65 + * Called by document accessible when it gets shutdown. 1.66 + */ 1.67 + inline void NotifyOfDocumentShutdown(nsIDocument* aDocument) 1.68 + { 1.69 + mDocAccessibleCache.Remove(aDocument); 1.70 + RemoveListeners(aDocument); 1.71 + } 1.72 + 1.73 +#ifdef DEBUG 1.74 + bool IsProcessingRefreshDriverNotification() const; 1.75 +#endif 1.76 + 1.77 +protected: 1.78 + DocManager(); 1.79 + 1.80 + /** 1.81 + * Initialize the manager. 1.82 + */ 1.83 + bool Init(); 1.84 + 1.85 + /** 1.86 + * Shutdown the manager. 1.87 + */ 1.88 + void Shutdown(); 1.89 + 1.90 +private: 1.91 + DocManager(const DocManager&); 1.92 + DocManager& operator =(const DocManager&); 1.93 + 1.94 +private: 1.95 + /** 1.96 + * Create an accessible document if it was't created and fire accessibility 1.97 + * events if needed. 1.98 + * 1.99 + * @param aDocument [in] loaded DOM document 1.100 + * @param aLoadEventType [in] specifies the event type to fire load event, 1.101 + * if 0 then no event is fired 1.102 + */ 1.103 + void HandleDOMDocumentLoad(nsIDocument* aDocument, 1.104 + uint32_t aLoadEventType); 1.105 + 1.106 + /** 1.107 + * Add/remove 'pagehide' and 'DOMContentLoaded' event listeners. 1.108 + */ 1.109 + void AddListeners(nsIDocument *aDocument, bool aAddPageShowListener); 1.110 + void RemoveListeners(nsIDocument* aDocument); 1.111 + 1.112 + /** 1.113 + * Create document or root accessible. 1.114 + */ 1.115 + DocAccessible* CreateDocOrRootAccessible(nsIDocument* aDocument); 1.116 + 1.117 + typedef nsRefPtrHashtable<nsPtrHashKey<const nsIDocument>, DocAccessible> 1.118 + DocAccessibleHashtable; 1.119 + 1.120 + /** 1.121 + * Get first entry of the document accessible from cache. 1.122 + */ 1.123 + static PLDHashOperator 1.124 + GetFirstEntryInDocCache(const nsIDocument* aKey, 1.125 + DocAccessible* aDocAccessible, 1.126 + void* aUserArg); 1.127 + 1.128 + /** 1.129 + * Clear the cache and shutdown the document accessibles. 1.130 + */ 1.131 + void ClearDocCache(); 1.132 + 1.133 + struct nsSearchAccessibleInCacheArg 1.134 + { 1.135 + Accessible* mAccessible; 1.136 + nsINode* mNode; 1.137 + }; 1.138 + 1.139 + static PLDHashOperator 1.140 + SearchAccessibleInDocCache(const nsIDocument* aKey, 1.141 + DocAccessible* aDocAccessible, 1.142 + void* aUserArg); 1.143 + 1.144 +#ifdef DEBUG 1.145 + static PLDHashOperator 1.146 + SearchIfDocIsRefreshing(const nsIDocument* aKey, 1.147 + DocAccessible* aDocAccessible, void* aUserArg); 1.148 +#endif 1.149 + 1.150 + DocAccessibleHashtable mDocAccessibleCache; 1.151 +}; 1.152 + 1.153 +/** 1.154 + * Return the existing document accessible for the document if any. 1.155 + * Note this returns the doc accessible for the primary pres shell if there is 1.156 + * more than one. 1.157 + */ 1.158 +inline DocAccessible* 1.159 +GetExistingDocAccessible(const nsIDocument* aDocument) 1.160 +{ 1.161 + nsIPresShell* ps = aDocument->GetShell(); 1.162 + return ps ? ps->GetDocAccessible() : nullptr; 1.163 +} 1.164 + 1.165 +} // namespace a11y 1.166 +} // namespace mozilla 1.167 + 1.168 +#endif // mozilla_a11_DocManager_h_