2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsTreeStyleCache.h"
|
|
|
|
#include "nsStyleSet.h"
|
2011-07-20 12:18:54 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The style context cache impl
|
|
|
|
nsStyleContext*
|
|
|
|
nsTreeStyleCache::GetStyleContext(nsICSSPseudoComparator* aComparator,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsIAtom* aPseudoElement,
|
2013-03-19 08:46:20 -07:00
|
|
|
const AtomArray & aInputWord)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-03-19 08:46:20 -07:00
|
|
|
uint32_t count = aInputWord.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsDFAState startState(0);
|
|
|
|
nsDFAState* currState = &startState;
|
|
|
|
|
|
|
|
// Go ahead and init the transition table.
|
|
|
|
if (!mTransitionTable) {
|
|
|
|
// Automatic miss. Build the table
|
|
|
|
mTransitionTable =
|
2012-07-30 07:20:58 -07:00
|
|
|
new nsObjectHashtable(nullptr, nullptr, DeleteDFAState, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// The first transition is always made off the supplied pseudo-element.
|
|
|
|
nsTransitionKey key(currState->GetStateID(), aPseudoElement);
|
2007-07-08 00:08:04 -07:00
|
|
|
currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!currState) {
|
|
|
|
// We had a miss. Make a new state and add it to our hash.
|
|
|
|
currState = new nsDFAState(mNextState);
|
|
|
|
mNextState++;
|
|
|
|
mTransitionTable->Put(&key, currState);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2013-03-19 08:46:20 -07:00
|
|
|
nsTransitionKey key(currState->GetStateID(), aInputWord[i]);
|
2007-07-08 00:08:04 -07:00
|
|
|
currState = static_cast<nsDFAState*>(mTransitionTable->Get(&key));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (!currState) {
|
|
|
|
// We had a miss. Make a new state and add it to our hash.
|
|
|
|
currState = new nsDFAState(mNextState);
|
|
|
|
mNextState++;
|
|
|
|
mTransitionTable->Put(&key, currState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're in a final state.
|
|
|
|
// Look up our style context for this state.
|
2012-07-30 07:20:58 -07:00
|
|
|
nsStyleContext* result = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mCache)
|
2007-07-08 00:08:04 -07:00
|
|
|
result = static_cast<nsStyleContext*>(mCache->Get(currState));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!result) {
|
|
|
|
// We missed the cache. Resolve this pseudo-style.
|
|
|
|
result = aPresContext->StyleSet()->
|
2010-04-30 06:12:06 -07:00
|
|
|
ResolveXULTreePseudoStyle(aContent->AsElement(), aPseudoElement,
|
2009-12-10 23:37:40 -08:00
|
|
|
aContext, aComparator).get();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Put the style context in our table, transferring the owning reference to the table.
|
|
|
|
if (!mCache) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mCache = new nsObjectHashtable(nullptr, nullptr, ReleaseStyleContext, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
mCache->Put(currState, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTreeStyleCache::DeleteDFAState(nsHashKey *aKey,
|
|
|
|
void *aData,
|
|
|
|
void *closure)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsDFAState* entry = static_cast<nsDFAState*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
delete entry;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsTreeStyleCache::ReleaseStyleContext(nsHashKey *aKey,
|
|
|
|
void *aData,
|
|
|
|
void *closure)
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
nsStyleContext* context = static_cast<nsStyleContext*>(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
context->Release();
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|