|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef _nsAccCache_H_ |
|
7 #define _nsAccCache_H_ |
|
8 |
|
9 #include "nsIAccessible.h" |
|
10 #include "nsRefPtrHashtable.h" |
|
11 #include "nsCycleCollectionParticipant.h" |
|
12 |
|
13 //////////////////////////////////////////////////////////////////////////////// |
|
14 // Accessible cache utils |
|
15 //////////////////////////////////////////////////////////////////////////////// |
|
16 |
|
17 /** |
|
18 * Shutdown and removes the accessible from cache. |
|
19 */ |
|
20 template <class T> |
|
21 static PLDHashOperator |
|
22 ClearCacheEntry(const void* aKey, nsRefPtr<T>& aAccessible, void* aUserArg) |
|
23 { |
|
24 NS_ASSERTION(aAccessible, "Calling ClearCacheEntry with a nullptr pointer!"); |
|
25 if (aAccessible) |
|
26 aAccessible->Shutdown(); |
|
27 |
|
28 return PL_DHASH_REMOVE; |
|
29 } |
|
30 |
|
31 /** |
|
32 * Clear the cache and shutdown the accessibles. |
|
33 */ |
|
34 |
|
35 static void |
|
36 ClearCache(mozilla::a11y::AccessibleHashtable& aCache) |
|
37 { |
|
38 aCache.Enumerate(ClearCacheEntry<mozilla::a11y::Accessible>, nullptr); |
|
39 } |
|
40 |
|
41 /** |
|
42 * Traverse the accessible cache entry for cycle collector. |
|
43 */ |
|
44 template <class T> |
|
45 static PLDHashOperator |
|
46 CycleCollectorTraverseCacheEntry(const void *aKey, T *aAccessible, |
|
47 void *aUserArg) |
|
48 { |
|
49 nsCycleCollectionTraversalCallback *cb = |
|
50 static_cast<nsCycleCollectionTraversalCallback*>(aUserArg); |
|
51 |
|
52 NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "accessible cache entry"); |
|
53 |
|
54 nsISupports *supports = static_cast<nsIAccessible*>(aAccessible); |
|
55 cb->NoteXPCOMChild(supports); |
|
56 return PL_DHASH_NEXT; |
|
57 } |
|
58 |
|
59 /** |
|
60 * Unlink the accessible cache for the cycle collector. |
|
61 */ |
|
62 inline void |
|
63 ImplCycleCollectionUnlink(mozilla::a11y::AccessibleHashtable& aCache) |
|
64 { |
|
65 ClearCache(aCache); |
|
66 } |
|
67 |
|
68 /** |
|
69 * Traverse the accessible cache for cycle collector. |
|
70 */ |
|
71 inline void |
|
72 ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, |
|
73 mozilla::a11y::AccessibleHashtable& aCache, |
|
74 const char* aName, |
|
75 uint32_t aFlags = 0) |
|
76 { |
|
77 aCache.EnumerateRead(CycleCollectorTraverseCacheEntry<mozilla::a11y::Accessible>, |
|
78 &aCallback); |
|
79 } |
|
80 |
|
81 #endif |