1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_a11_DocManager_h_
6 #define mozilla_a11_DocManager_h_
8 #include "nsIDocument.h"
9 #include "nsIDOMEventListener.h"
10 #include "nsRefPtrHashtable.h"
11 #include "nsIWebProgressListener.h"
12 #include "nsWeakReference.h"
13 #include "nsIPresShell.h"
22 * Manage the document accessible life cycle.
24 class DocManager
: public nsIWebProgressListener
,
25 public nsIDOMEventListener
,
26 public nsSupportsWeakReference
29 NS_DECL_THREADSAFE_ISUPPORTS
30 NS_DECL_NSIWEBPROGRESSLISTENER
31 NS_DECL_NSIDOMEVENTLISTENER
34 * Return document accessible for the given DOM node.
36 DocAccessible
* GetDocAccessible(nsIDocument
* aDocument
);
39 * Return document accessible for the given presshell.
41 DocAccessible
* GetDocAccessible(const nsIPresShell
* aPresShell
)
46 DocAccessible
* doc
= aPresShell
->GetDocAccessible();
50 return GetDocAccessible(aPresShell
->GetDocument());
54 * Search through all document accessibles for an accessible with the given
57 Accessible
* FindAccessibleInCache(nsINode
* aNode
) const;
60 * Called by document accessible when it gets shutdown.
62 inline void NotifyOfDocumentShutdown(nsIDocument
* aDocument
)
64 mDocAccessibleCache
.Remove(aDocument
);
65 RemoveListeners(aDocument
);
69 bool IsProcessingRefreshDriverNotification() const;
74 virtual ~DocManager() { }
77 * Initialize the manager.
82 * Shutdown the manager.
87 DocManager(const DocManager
&);
88 DocManager
& operator =(const DocManager
&);
92 * Create an accessible document if it was't created and fire accessibility
95 * @param aDocument [in] loaded DOM document
96 * @param aLoadEventType [in] specifies the event type to fire load event,
97 * if 0 then no event is fired
99 void HandleDOMDocumentLoad(nsIDocument
* aDocument
,
100 uint32_t aLoadEventType
);
103 * Add/remove 'pagehide' and 'DOMContentLoaded' event listeners.
105 void AddListeners(nsIDocument
*aDocument
, bool aAddPageShowListener
);
106 void RemoveListeners(nsIDocument
* aDocument
);
109 * Create document or root accessible.
111 DocAccessible
* CreateDocOrRootAccessible(nsIDocument
* aDocument
);
113 typedef nsRefPtrHashtable
<nsPtrHashKey
<const nsIDocument
>, DocAccessible
>
114 DocAccessibleHashtable
;
117 * Get first entry of the document accessible from cache.
119 static PLDHashOperator
120 GetFirstEntryInDocCache(const nsIDocument
* aKey
,
121 DocAccessible
* aDocAccessible
,
125 * Clear the cache and shutdown the document accessibles.
127 void ClearDocCache();
129 struct nsSearchAccessibleInCacheArg
131 Accessible
* mAccessible
;
135 static PLDHashOperator
136 SearchAccessibleInDocCache(const nsIDocument
* aKey
,
137 DocAccessible
* aDocAccessible
,
141 static PLDHashOperator
142 SearchIfDocIsRefreshing(const nsIDocument
* aKey
,
143 DocAccessible
* aDocAccessible
, void* aUserArg
);
146 DocAccessibleHashtable mDocAccessibleCache
;
150 * Return the existing document accessible for the document if any.
151 * Note this returns the doc accessible for the primary pres shell if there is
154 inline DocAccessible
*
155 GetExistingDocAccessible(const nsIDocument
* aDocument
)
157 nsIPresShell
* ps
= aDocument
->GetShell();
158 return ps
? ps
->GetDocAccessible() : nullptr;
162 } // namespace mozilla
164 #endif // mozilla_a11_DocManager_h_