1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Mozilla Foundation.
19 : * Portions created by the Initial Developer are Copyright (C) 2010
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Alexander Surkov <surkov.alexander@gmail.com> (original author)
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef _nsAccCache_H_
40 : #define _nsAccCache_H_
41 :
42 : #include "nsIAccessible.h"
43 : #include "nsRefPtrHashtable.h"
44 : #include "nsCycleCollectionParticipant.h"
45 :
46 : ////////////////////////////////////////////////////////////////////////////////
47 : // Accessible cache utils
48 : ////////////////////////////////////////////////////////////////////////////////
49 :
50 : /**
51 : * Shutdown and removes the accessible from cache.
52 : */
53 : template <class T>
54 : static PLDHashOperator
55 0 : ClearCacheEntry(const void* aKey, nsRefPtr<T>& aAccessible, void* aUserArg)
56 : {
57 0 : NS_ASSERTION(aAccessible, "Calling ClearCacheEntry with a NULL pointer!");
58 0 : if (aAccessible)
59 0 : aAccessible->Shutdown();
60 :
61 0 : return PL_DHASH_REMOVE;
62 : }
63 :
64 : /**
65 : * Clear the cache and shutdown the accessibles.
66 : */
67 : template <class T>
68 : static void
69 0 : ClearCache(nsRefPtrHashtable<nsVoidPtrHashKey, T> & aCache)
70 : {
71 0 : aCache.Enumerate(ClearCacheEntry<T>, nsnull);
72 0 : }
73 :
74 : /**
75 : * Traverse the accessible cache entry for cycle collector.
76 : */
77 : template <class T>
78 : static PLDHashOperator
79 0 : CycleCollectorTraverseCacheEntry(const void *aKey, T *aAccessible,
80 : void *aUserArg)
81 : {
82 : nsCycleCollectionTraversalCallback *cb =
83 0 : static_cast<nsCycleCollectionTraversalCallback*>(aUserArg);
84 :
85 0 : NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "accessible cache entry");
86 :
87 0 : nsISupports *supports = static_cast<nsIAccessible*>(aAccessible);
88 0 : cb->NoteXPCOMChild(supports);
89 0 : return PL_DHASH_NEXT;
90 : }
91 :
92 : /**
93 : * Traverse the accessible cache for cycle collector.
94 : */
95 : template <class T>
96 : static void
97 0 : CycleCollectorTraverseCache(nsRefPtrHashtable<nsVoidPtrHashKey, T> & aCache,
98 : nsCycleCollectionTraversalCallback *aCallback)
99 : {
100 0 : aCache.EnumerateRead(CycleCollectorTraverseCacheEntry<T>, aCallback);
101 0 : }
102 :
103 : #endif
|