Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 | #include "nsTreeStyleCache.h" |
michael@0 | 7 | #include "nsStyleSet.h" |
michael@0 | 8 | #include "mozilla/dom/Element.h" |
michael@0 | 9 | |
michael@0 | 10 | // The style context cache impl |
michael@0 | 11 | nsStyleContext* |
michael@0 | 12 | nsTreeStyleCache::GetStyleContext(nsICSSPseudoComparator* aComparator, |
michael@0 | 13 | nsPresContext* aPresContext, |
michael@0 | 14 | nsIContent* aContent, |
michael@0 | 15 | nsStyleContext* aContext, |
michael@0 | 16 | nsIAtom* aPseudoElement, |
michael@0 | 17 | const AtomArray & aInputWord) |
michael@0 | 18 | { |
michael@0 | 19 | uint32_t count = aInputWord.Length(); |
michael@0 | 20 | nsDFAState startState(0); |
michael@0 | 21 | nsDFAState* currState = &startState; |
michael@0 | 22 | |
michael@0 | 23 | // Go ahead and init the transition table. |
michael@0 | 24 | if (!mTransitionTable) { |
michael@0 | 25 | // Automatic miss. Build the table |
michael@0 | 26 | mTransitionTable = |
michael@0 | 27 | new nsObjectHashtable(nullptr, nullptr, DeleteDFAState, nullptr); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | // The first transition is always made off the supplied pseudo-element. |
michael@0 | 31 | nsTransitionKey key(currState->GetStateID(), aPseudoElement); |
michael@0 | 32 | currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key)); |
michael@0 | 33 | |
michael@0 | 34 | if (!currState) { |
michael@0 | 35 | // We had a miss. Make a new state and add it to our hash. |
michael@0 | 36 | currState = new nsDFAState(mNextState); |
michael@0 | 37 | mNextState++; |
michael@0 | 38 | mTransitionTable->Put(&key, currState); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | for (uint32_t i = 0; i < count; i++) { |
michael@0 | 42 | nsTransitionKey key(currState->GetStateID(), aInputWord[i]); |
michael@0 | 43 | currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key)); |
michael@0 | 44 | |
michael@0 | 45 | if (!currState) { |
michael@0 | 46 | // We had a miss. Make a new state and add it to our hash. |
michael@0 | 47 | currState = new nsDFAState(mNextState); |
michael@0 | 48 | mNextState++; |
michael@0 | 49 | mTransitionTable->Put(&key, currState); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | // We're in a final state. |
michael@0 | 54 | // Look up our style context for this state. |
michael@0 | 55 | nsStyleContext* result = nullptr; |
michael@0 | 56 | if (mCache) |
michael@0 | 57 | result = static_cast<nsStyleContext*>(mCache->Get(currState)); |
michael@0 | 58 | if (!result) { |
michael@0 | 59 | // We missed the cache. Resolve this pseudo-style. |
michael@0 | 60 | result = aPresContext->StyleSet()-> |
michael@0 | 61 | ResolveXULTreePseudoStyle(aContent->AsElement(), aPseudoElement, |
michael@0 | 62 | aContext, aComparator).take(); |
michael@0 | 63 | |
michael@0 | 64 | // Put the style context in our table, transferring the owning reference to the table. |
michael@0 | 65 | if (!mCache) { |
michael@0 | 66 | mCache = new nsObjectHashtable(nullptr, nullptr, ReleaseStyleContext, nullptr); |
michael@0 | 67 | } |
michael@0 | 68 | mCache->Put(currState, result); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | return result; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | bool |
michael@0 | 75 | nsTreeStyleCache::DeleteDFAState(nsHashKey *aKey, |
michael@0 | 76 | void *aData, |
michael@0 | 77 | void *closure) |
michael@0 | 78 | { |
michael@0 | 79 | nsDFAState* entry = static_cast<nsDFAState*>(aData); |
michael@0 | 80 | delete entry; |
michael@0 | 81 | return true; |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | bool |
michael@0 | 85 | nsTreeStyleCache::ReleaseStyleContext(nsHashKey *aKey, |
michael@0 | 86 | void *aData, |
michael@0 | 87 | void *closure) |
michael@0 | 88 | { |
michael@0 | 89 | nsStyleContext* context = static_cast<nsStyleContext*>(aData); |
michael@0 | 90 | context->Release(); |
michael@0 | 91 | return true; |
michael@0 | 92 | } |