Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #ifndef mozilla_a11_DocManager_h_ |
michael@0 | 6 | #define mozilla_a11_DocManager_h_ |
michael@0 | 7 | |
michael@0 | 8 | #include "nsIDocument.h" |
michael@0 | 9 | #include "nsIDOMEventListener.h" |
michael@0 | 10 | #include "nsRefPtrHashtable.h" |
michael@0 | 11 | #include "nsIWebProgressListener.h" |
michael@0 | 12 | #include "nsWeakReference.h" |
michael@0 | 13 | #include "nsIPresShell.h" |
michael@0 | 14 | |
michael@0 | 15 | namespace mozilla { |
michael@0 | 16 | namespace a11y { |
michael@0 | 17 | |
michael@0 | 18 | class Accessible; |
michael@0 | 19 | class DocAccessible; |
michael@0 | 20 | |
michael@0 | 21 | /** |
michael@0 | 22 | * Manage the document accessible life cycle. |
michael@0 | 23 | */ |
michael@0 | 24 | class DocManager : public nsIWebProgressListener, |
michael@0 | 25 | public nsIDOMEventListener, |
michael@0 | 26 | public nsSupportsWeakReference |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | virtual ~DocManager() { } |
michael@0 | 30 | |
michael@0 | 31 | NS_DECL_THREADSAFE_ISUPPORTS |
michael@0 | 32 | NS_DECL_NSIWEBPROGRESSLISTENER |
michael@0 | 33 | NS_DECL_NSIDOMEVENTLISTENER |
michael@0 | 34 | |
michael@0 | 35 | /** |
michael@0 | 36 | * Return document accessible for the given DOM node. |
michael@0 | 37 | */ |
michael@0 | 38 | DocAccessible* GetDocAccessible(nsIDocument* aDocument); |
michael@0 | 39 | |
michael@0 | 40 | /** |
michael@0 | 41 | * Return document accessible for the given presshell. |
michael@0 | 42 | */ |
michael@0 | 43 | DocAccessible* GetDocAccessible(const nsIPresShell* aPresShell) |
michael@0 | 44 | { |
michael@0 | 45 | if (!aPresShell) |
michael@0 | 46 | return nullptr; |
michael@0 | 47 | |
michael@0 | 48 | DocAccessible* doc = aPresShell->GetDocAccessible(); |
michael@0 | 49 | if (doc) |
michael@0 | 50 | return doc; |
michael@0 | 51 | |
michael@0 | 52 | return GetDocAccessible(aPresShell->GetDocument()); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | /** |
michael@0 | 56 | * Search through all document accessibles for an accessible with the given |
michael@0 | 57 | * unique id. |
michael@0 | 58 | */ |
michael@0 | 59 | Accessible* FindAccessibleInCache(nsINode* aNode) const; |
michael@0 | 60 | |
michael@0 | 61 | /** |
michael@0 | 62 | * Called by document accessible when it gets shutdown. |
michael@0 | 63 | */ |
michael@0 | 64 | inline void NotifyOfDocumentShutdown(nsIDocument* aDocument) |
michael@0 | 65 | { |
michael@0 | 66 | mDocAccessibleCache.Remove(aDocument); |
michael@0 | 67 | RemoveListeners(aDocument); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | #ifdef DEBUG |
michael@0 | 71 | bool IsProcessingRefreshDriverNotification() const; |
michael@0 | 72 | #endif |
michael@0 | 73 | |
michael@0 | 74 | protected: |
michael@0 | 75 | DocManager(); |
michael@0 | 76 | |
michael@0 | 77 | /** |
michael@0 | 78 | * Initialize the manager. |
michael@0 | 79 | */ |
michael@0 | 80 | bool Init(); |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Shutdown the manager. |
michael@0 | 84 | */ |
michael@0 | 85 | void Shutdown(); |
michael@0 | 86 | |
michael@0 | 87 | private: |
michael@0 | 88 | DocManager(const DocManager&); |
michael@0 | 89 | DocManager& operator =(const DocManager&); |
michael@0 | 90 | |
michael@0 | 91 | private: |
michael@0 | 92 | /** |
michael@0 | 93 | * Create an accessible document if it was't created and fire accessibility |
michael@0 | 94 | * events if needed. |
michael@0 | 95 | * |
michael@0 | 96 | * @param aDocument [in] loaded DOM document |
michael@0 | 97 | * @param aLoadEventType [in] specifies the event type to fire load event, |
michael@0 | 98 | * if 0 then no event is fired |
michael@0 | 99 | */ |
michael@0 | 100 | void HandleDOMDocumentLoad(nsIDocument* aDocument, |
michael@0 | 101 | uint32_t aLoadEventType); |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * Add/remove 'pagehide' and 'DOMContentLoaded' event listeners. |
michael@0 | 105 | */ |
michael@0 | 106 | void AddListeners(nsIDocument *aDocument, bool aAddPageShowListener); |
michael@0 | 107 | void RemoveListeners(nsIDocument* aDocument); |
michael@0 | 108 | |
michael@0 | 109 | /** |
michael@0 | 110 | * Create document or root accessible. |
michael@0 | 111 | */ |
michael@0 | 112 | DocAccessible* CreateDocOrRootAccessible(nsIDocument* aDocument); |
michael@0 | 113 | |
michael@0 | 114 | typedef nsRefPtrHashtable<nsPtrHashKey<const nsIDocument>, DocAccessible> |
michael@0 | 115 | DocAccessibleHashtable; |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Get first entry of the document accessible from cache. |
michael@0 | 119 | */ |
michael@0 | 120 | static PLDHashOperator |
michael@0 | 121 | GetFirstEntryInDocCache(const nsIDocument* aKey, |
michael@0 | 122 | DocAccessible* aDocAccessible, |
michael@0 | 123 | void* aUserArg); |
michael@0 | 124 | |
michael@0 | 125 | /** |
michael@0 | 126 | * Clear the cache and shutdown the document accessibles. |
michael@0 | 127 | */ |
michael@0 | 128 | void ClearDocCache(); |
michael@0 | 129 | |
michael@0 | 130 | struct nsSearchAccessibleInCacheArg |
michael@0 | 131 | { |
michael@0 | 132 | Accessible* mAccessible; |
michael@0 | 133 | nsINode* mNode; |
michael@0 | 134 | }; |
michael@0 | 135 | |
michael@0 | 136 | static PLDHashOperator |
michael@0 | 137 | SearchAccessibleInDocCache(const nsIDocument* aKey, |
michael@0 | 138 | DocAccessible* aDocAccessible, |
michael@0 | 139 | void* aUserArg); |
michael@0 | 140 | |
michael@0 | 141 | #ifdef DEBUG |
michael@0 | 142 | static PLDHashOperator |
michael@0 | 143 | SearchIfDocIsRefreshing(const nsIDocument* aKey, |
michael@0 | 144 | DocAccessible* aDocAccessible, void* aUserArg); |
michael@0 | 145 | #endif |
michael@0 | 146 | |
michael@0 | 147 | DocAccessibleHashtable mDocAccessibleCache; |
michael@0 | 148 | }; |
michael@0 | 149 | |
michael@0 | 150 | /** |
michael@0 | 151 | * Return the existing document accessible for the document if any. |
michael@0 | 152 | * Note this returns the doc accessible for the primary pres shell if there is |
michael@0 | 153 | * more than one. |
michael@0 | 154 | */ |
michael@0 | 155 | inline DocAccessible* |
michael@0 | 156 | GetExistingDocAccessible(const nsIDocument* aDocument) |
michael@0 | 157 | { |
michael@0 | 158 | nsIPresShell* ps = aDocument->GetShell(); |
michael@0 | 159 | return ps ? ps->GetDocAccessible() : nullptr; |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | } // namespace a11y |
michael@0 | 163 | } // namespace mozilla |
michael@0 | 164 | |
michael@0 | 165 | #endif // mozilla_a11_DocManager_h_ |