michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _nsAccCache_H_ michael@0: #define _nsAccCache_H_ michael@0: michael@0: #include "nsIAccessible.h" michael@0: #include "nsRefPtrHashtable.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: // Accessible cache utils michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: /** michael@0: * Shutdown and removes the accessible from cache. michael@0: */ michael@0: template michael@0: static PLDHashOperator michael@0: ClearCacheEntry(const void* aKey, nsRefPtr& aAccessible, void* aUserArg) michael@0: { michael@0: NS_ASSERTION(aAccessible, "Calling ClearCacheEntry with a nullptr pointer!"); michael@0: if (aAccessible) michael@0: aAccessible->Shutdown(); michael@0: michael@0: return PL_DHASH_REMOVE; michael@0: } michael@0: michael@0: /** michael@0: * Clear the cache and shutdown the accessibles. michael@0: */ michael@0: michael@0: static void michael@0: ClearCache(mozilla::a11y::AccessibleHashtable& aCache) michael@0: { michael@0: aCache.Enumerate(ClearCacheEntry, nullptr); michael@0: } michael@0: michael@0: /** michael@0: * Traverse the accessible cache entry for cycle collector. michael@0: */ michael@0: template michael@0: static PLDHashOperator michael@0: CycleCollectorTraverseCacheEntry(const void *aKey, T *aAccessible, michael@0: void *aUserArg) michael@0: { michael@0: nsCycleCollectionTraversalCallback *cb = michael@0: static_cast(aUserArg); michael@0: michael@0: NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "accessible cache entry"); michael@0: michael@0: nsISupports *supports = static_cast(aAccessible); michael@0: cb->NoteXPCOMChild(supports); michael@0: return PL_DHASH_NEXT; michael@0: } michael@0: michael@0: /** michael@0: * Unlink the accessible cache for the cycle collector. michael@0: */ michael@0: inline void michael@0: ImplCycleCollectionUnlink(mozilla::a11y::AccessibleHashtable& aCache) michael@0: { michael@0: ClearCache(aCache); michael@0: } michael@0: michael@0: /** michael@0: * Traverse the accessible cache for cycle collector. michael@0: */ michael@0: inline void michael@0: ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, michael@0: mozilla::a11y::AccessibleHashtable& aCache, michael@0: const char* aName, michael@0: uint32_t aFlags = 0) michael@0: { michael@0: aCache.EnumerateRead(CycleCollectorTraverseCacheEntry, michael@0: &aCallback); michael@0: } michael@0: michael@0: #endif