2004-04-17 09:53:38 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
#include "nsTreeStyleCache.h"
|
|
|
|
#include "nsStyleSet.h"
|
2011-07-20 23:18:54 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2016-02-24 10:01:11 +03:00
|
|
|
#include "mozilla/StyleSetHandle.h"
|
|
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
2004-04-17 09:53:38 +04:00
|
|
|
|
2014-05-09 20:49:54 +04:00
|
|
|
nsTreeStyleCache::Transition::Transition(DFAState aState, nsIAtom* aSymbol)
|
2014-05-09 20:49:53 +04:00
|
|
|
: mState(aState), mInputSymbol(aSymbol)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsTreeStyleCache::Transition::operator==(const Transition& aOther) const
|
|
|
|
{
|
|
|
|
return aOther.mState == mState && aOther.mInputSymbol == mInputSymbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsTreeStyleCache::Transition::Hash() const
|
|
|
|
{
|
|
|
|
// Make a 32-bit integer that combines the low-order 16 bits of the state and the input symbol.
|
|
|
|
uint32_t hb = mState << 16;
|
|
|
|
uint32_t lb = (NS_PTR_TO_UINT32(mInputSymbol.get()) << 16) >> 16;
|
|
|
|
return hb+lb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-04-17 09:53:38 +04:00
|
|
|
// The style context cache impl
|
|
|
|
nsStyleContext*
|
|
|
|
nsTreeStyleCache::GetStyleContext(nsICSSPseudoComparator* aComparator,
|
2004-08-01 03:15:21 +04:00
|
|
|
nsPresContext* aPresContext,
|
2014-05-09 20:49:53 +04:00
|
|
|
nsIContent* aContent,
|
2004-04-17 09:53:38 +04:00
|
|
|
nsStyleContext* aContext,
|
2017-04-26 18:54:43 +03:00
|
|
|
nsICSSAnonBoxPseudo* aPseudoElement,
|
2013-03-19 19:46:20 +04:00
|
|
|
const AtomArray & aInputWord)
|
2004-04-17 09:53:38 +04:00
|
|
|
{
|
2017-04-26 18:54:43 +03:00
|
|
|
MOZ_ASSERT(nsCSSAnonBoxes::IsTreePseudoElement(aPseudoElement));
|
|
|
|
|
2013-03-19 19:46:20 +04:00
|
|
|
uint32_t count = aInputWord.Length();
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
// Go ahead and init the transition table.
|
|
|
|
if (!mTransitionTable) {
|
|
|
|
// Automatic miss. Build the table
|
2014-05-09 20:49:53 +04:00
|
|
|
mTransitionTable = new TransitionTable();
|
2004-04-17 09:53:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// The first transition is always made off the supplied pseudo-element.
|
2014-05-09 20:49:53 +04:00
|
|
|
Transition transition(0, aPseudoElement);
|
2014-05-09 20:49:54 +04:00
|
|
|
DFAState currState = mTransitionTable->Get(transition);
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
if (!currState) {
|
|
|
|
// We had a miss. Make a new state and add it to our hash.
|
2014-05-09 20:49:54 +04:00
|
|
|
currState = mNextState;
|
2004-04-17 09:53:38 +04:00
|
|
|
mNextState++;
|
2014-05-09 20:49:53 +04:00
|
|
|
mTransitionTable->Put(transition, currState);
|
2004-04-17 09:53:38 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2014-05-09 20:49:54 +04:00
|
|
|
Transition transition(currState, aInputWord[i]);
|
2014-05-09 20:49:53 +04:00
|
|
|
currState = mTransitionTable->Get(transition);
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
if (!currState) {
|
|
|
|
// We had a miss. Make a new state and add it to our hash.
|
2014-05-09 20:49:54 +04:00
|
|
|
currState = mNextState;
|
2004-04-17 09:53:38 +04:00
|
|
|
mNextState++;
|
2014-05-09 20:49:53 +04:00
|
|
|
mTransitionTable->Put(transition, currState);
|
2004-04-17 09:53:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're in a final state.
|
|
|
|
// Look up our style context for this state.
|
2012-07-30 18:20:58 +04:00
|
|
|
nsStyleContext* result = nullptr;
|
2014-05-09 20:49:53 +04:00
|
|
|
if (mCache) {
|
2014-05-09 20:49:54 +04:00
|
|
|
result = mCache->GetWeak(currState);
|
2014-05-09 20:49:53 +04:00
|
|
|
}
|
2004-04-17 09:53:38 +04:00
|
|
|
if (!result) {
|
|
|
|
// We missed the cache. Resolve this pseudo-style.
|
2016-02-24 10:01:11 +03:00
|
|
|
// XXXheycam ServoStyleSets do not support XUL tree styles.
|
2016-11-29 07:31:32 +03:00
|
|
|
RefPtr<nsStyleContext> newResult;
|
2016-02-24 10:01:11 +03:00
|
|
|
if (aPresContext->StyleSet()->IsServo()) {
|
2016-11-29 07:31:32 +03:00
|
|
|
NS_ERROR("stylo: ServoStyleSets should not support XUL tree styles yet");
|
|
|
|
newResult = aPresContext->StyleSet()->
|
2017-03-08 08:18:40 +03:00
|
|
|
ResolveStyleForPlaceholder();
|
2016-11-29 07:31:32 +03:00
|
|
|
} else {
|
|
|
|
newResult = aPresContext->StyleSet()->AsGecko()->
|
|
|
|
ResolveXULTreePseudoStyle(aContent->AsElement(), aPseudoElement,
|
|
|
|
aContext, aComparator);
|
2016-02-24 10:01:11 +03:00
|
|
|
}
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
// Put the style context in our table, transferring the owning reference to the table.
|
|
|
|
if (!mCache) {
|
2014-05-09 20:49:53 +04:00
|
|
|
mCache = new StyleContextCache();
|
2004-04-17 09:53:38 +04:00
|
|
|
}
|
2014-05-09 20:49:53 +04:00
|
|
|
result = newResult.get();
|
2014-05-09 20:49:54 +04:00
|
|
|
mCache->Put(currState, newResult.forget());
|
2004-04-17 09:53:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|