Bumping manifests a=b2g-bump
[gecko.git] / accessible / base / DocManager.h
blob13e80a602372ed2477333e4bbb69d7f37ec1adf2
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"
15 namespace mozilla {
16 namespace a11y {
18 class Accessible;
19 class DocAccessible;
21 /**
22 * Manage the document accessible life cycle.
24 class DocManager : public nsIWebProgressListener,
25 public nsIDOMEventListener,
26 public nsSupportsWeakReference
28 public:
29 NS_DECL_THREADSAFE_ISUPPORTS
30 NS_DECL_NSIWEBPROGRESSLISTENER
31 NS_DECL_NSIDOMEVENTLISTENER
33 /**
34 * Return document accessible for the given DOM node.
36 DocAccessible* GetDocAccessible(nsIDocument* aDocument);
38 /**
39 * Return document accessible for the given presshell.
41 DocAccessible* GetDocAccessible(const nsIPresShell* aPresShell)
43 if (!aPresShell)
44 return nullptr;
46 DocAccessible* doc = aPresShell->GetDocAccessible();
47 if (doc)
48 return doc;
50 return GetDocAccessible(aPresShell->GetDocument());
53 /**
54 * Search through all document accessibles for an accessible with the given
55 * unique id.
57 Accessible* FindAccessibleInCache(nsINode* aNode) const;
59 /**
60 * Called by document accessible when it gets shutdown.
62 inline void NotifyOfDocumentShutdown(nsIDocument* aDocument)
64 mDocAccessibleCache.Remove(aDocument);
65 RemoveListeners(aDocument);
68 #ifdef DEBUG
69 bool IsProcessingRefreshDriverNotification() const;
70 #endif
72 protected:
73 DocManager();
74 virtual ~DocManager() { }
76 /**
77 * Initialize the manager.
79 bool Init();
81 /**
82 * Shutdown the manager.
84 void Shutdown();
86 private:
87 DocManager(const DocManager&);
88 DocManager& operator =(const DocManager&);
90 private:
91 /**
92 * Create an accessible document if it was't created and fire accessibility
93 * events if needed.
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,
122 void* aUserArg);
125 * Clear the cache and shutdown the document accessibles.
127 void ClearDocCache();
129 struct nsSearchAccessibleInCacheArg
131 Accessible* mAccessible;
132 nsINode* mNode;
135 static PLDHashOperator
136 SearchAccessibleInDocCache(const nsIDocument* aKey,
137 DocAccessible* aDocAccessible,
138 void* aUserArg);
140 #ifdef DEBUG
141 static PLDHashOperator
142 SearchIfDocIsRefreshing(const nsIDocument* aKey,
143 DocAccessible* aDocAccessible, void* aUserArg);
144 #endif
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
152 * more than one.
154 inline DocAccessible*
155 GetExistingDocAccessible(const nsIDocument* aDocument)
157 nsIPresShell* ps = aDocument->GetShell();
158 return ps ? ps->GetDocAccessible() : nullptr;
161 } // namespace a11y
162 } // namespace mozilla
164 #endif // mozilla_a11_DocManager_h_