1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/nsAccCache.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef _nsAccCache_H_ 1.10 +#define _nsAccCache_H_ 1.11 + 1.12 +#include "nsIAccessible.h" 1.13 +#include "nsRefPtrHashtable.h" 1.14 +#include "nsCycleCollectionParticipant.h" 1.15 + 1.16 +//////////////////////////////////////////////////////////////////////////////// 1.17 +// Accessible cache utils 1.18 +//////////////////////////////////////////////////////////////////////////////// 1.19 + 1.20 +/** 1.21 + * Shutdown and removes the accessible from cache. 1.22 + */ 1.23 +template <class T> 1.24 +static PLDHashOperator 1.25 +ClearCacheEntry(const void* aKey, nsRefPtr<T>& aAccessible, void* aUserArg) 1.26 +{ 1.27 + NS_ASSERTION(aAccessible, "Calling ClearCacheEntry with a nullptr pointer!"); 1.28 + if (aAccessible) 1.29 + aAccessible->Shutdown(); 1.30 + 1.31 + return PL_DHASH_REMOVE; 1.32 +} 1.33 + 1.34 +/** 1.35 + * Clear the cache and shutdown the accessibles. 1.36 + */ 1.37 + 1.38 +static void 1.39 +ClearCache(mozilla::a11y::AccessibleHashtable& aCache) 1.40 +{ 1.41 + aCache.Enumerate(ClearCacheEntry<mozilla::a11y::Accessible>, nullptr); 1.42 +} 1.43 + 1.44 +/** 1.45 + * Traverse the accessible cache entry for cycle collector. 1.46 + */ 1.47 +template <class T> 1.48 +static PLDHashOperator 1.49 +CycleCollectorTraverseCacheEntry(const void *aKey, T *aAccessible, 1.50 + void *aUserArg) 1.51 +{ 1.52 + nsCycleCollectionTraversalCallback *cb = 1.53 + static_cast<nsCycleCollectionTraversalCallback*>(aUserArg); 1.54 + 1.55 + NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "accessible cache entry"); 1.56 + 1.57 + nsISupports *supports = static_cast<nsIAccessible*>(aAccessible); 1.58 + cb->NoteXPCOMChild(supports); 1.59 + return PL_DHASH_NEXT; 1.60 +} 1.61 + 1.62 +/** 1.63 + * Unlink the accessible cache for the cycle collector. 1.64 + */ 1.65 +inline void 1.66 +ImplCycleCollectionUnlink(mozilla::a11y::AccessibleHashtable& aCache) 1.67 +{ 1.68 + ClearCache(aCache); 1.69 +} 1.70 + 1.71 +/** 1.72 + * Traverse the accessible cache for cycle collector. 1.73 + */ 1.74 +inline void 1.75 +ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, 1.76 + mozilla::a11y::AccessibleHashtable& aCache, 1.77 + const char* aName, 1.78 + uint32_t aFlags = 0) 1.79 +{ 1.80 + aCache.EnumerateRead(CycleCollectorTraverseCacheEntry<mozilla::a11y::Accessible>, 1.81 + &aCallback); 1.82 +} 1.83 + 1.84 +#endif