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 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef nsContentSupportMap_h__ |
michael@0 | 7 | #define nsContentSupportMap_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "pldhash.h" |
michael@0 | 10 | #include "nsTemplateMatch.h" |
michael@0 | 11 | |
michael@0 | 12 | /** |
michael@0 | 13 | * The nsContentSupportMap maintains a mapping from a "resource element" |
michael@0 | 14 | * in the content tree to the nsTemplateMatch that was used to instantiate it. This |
michael@0 | 15 | * is necessary to allow the XUL content to be built lazily. Specifically, |
michael@0 | 16 | * when building "resumes" on a partially-built content element, the builder |
michael@0 | 17 | * will walk upwards in the content tree to find the first element with an |
michael@0 | 18 | * 'id' attribute. This element is assumed to be the "resource element", |
michael@0 | 19 | * and allows the content builder to access the nsTemplateMatch (variable assignments |
michael@0 | 20 | * and rule information). |
michael@0 | 21 | */ |
michael@0 | 22 | class nsContentSupportMap { |
michael@0 | 23 | public: |
michael@0 | 24 | nsContentSupportMap() { Init(); } |
michael@0 | 25 | ~nsContentSupportMap() { Finish(); } |
michael@0 | 26 | |
michael@0 | 27 | nsresult Put(nsIContent* aElement, nsTemplateMatch* aMatch) { |
michael@0 | 28 | if (!mMap.ops) |
michael@0 | 29 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 30 | |
michael@0 | 31 | PLDHashEntryHdr* hdr = PL_DHashTableOperate(&mMap, aElement, PL_DHASH_ADD); |
michael@0 | 32 | if (!hdr) |
michael@0 | 33 | return NS_ERROR_OUT_OF_MEMORY; |
michael@0 | 34 | |
michael@0 | 35 | Entry* entry = reinterpret_cast<Entry*>(hdr); |
michael@0 | 36 | NS_ASSERTION(entry->mMatch == nullptr, "over-writing entry"); |
michael@0 | 37 | entry->mContent = aElement; |
michael@0 | 38 | entry->mMatch = aMatch; |
michael@0 | 39 | return NS_OK; } |
michael@0 | 40 | |
michael@0 | 41 | bool Get(nsIContent* aElement, nsTemplateMatch** aMatch) { |
michael@0 | 42 | if (!mMap.ops) |
michael@0 | 43 | return false; |
michael@0 | 44 | |
michael@0 | 45 | PLDHashEntryHdr* hdr = PL_DHashTableOperate(&mMap, aElement, PL_DHASH_LOOKUP); |
michael@0 | 46 | if (PL_DHASH_ENTRY_IS_FREE(hdr)) |
michael@0 | 47 | return false; |
michael@0 | 48 | |
michael@0 | 49 | Entry* entry = reinterpret_cast<Entry*>(hdr); |
michael@0 | 50 | *aMatch = entry->mMatch; |
michael@0 | 51 | return true; } |
michael@0 | 52 | |
michael@0 | 53 | nsresult Remove(nsIContent* aElement); |
michael@0 | 54 | |
michael@0 | 55 | void Clear() { Finish(); Init(); } |
michael@0 | 56 | |
michael@0 | 57 | protected: |
michael@0 | 58 | PLDHashTable mMap; |
michael@0 | 59 | |
michael@0 | 60 | void Init(); |
michael@0 | 61 | void Finish(); |
michael@0 | 62 | |
michael@0 | 63 | struct Entry { |
michael@0 | 64 | PLDHashEntryHdr mHdr; |
michael@0 | 65 | nsIContent* mContent; |
michael@0 | 66 | nsTemplateMatch* mMatch; |
michael@0 | 67 | }; |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | #endif |