2004-04-17 05:53:38 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 05:53:38 +00:00
|
|
|
|
|
|
|
#ifndef nsTreeStyleCache_h__
|
|
|
|
#define nsTreeStyleCache_h__
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2004-04-17 05:53:38 +00:00
|
|
|
#include "nsHashtable.h"
|
|
|
|
#include "nsIAtom.h"
|
2013-03-19 15:46:20 +00:00
|
|
|
#include "nsCOMArray.h"
|
2004-04-17 05:53:38 +00:00
|
|
|
#include "nsICSSPseudoComparator.h"
|
2014-05-09 16:49:53 +00:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2004-04-17 05:53:38 +00:00
|
|
|
#include "nsStyleContext.h"
|
|
|
|
|
2013-03-19 15:46:20 +00:00
|
|
|
typedef nsCOMArray<nsIAtom> AtomArray;
|
2009-03-30 18:08:06 +00:00
|
|
|
|
2004-04-17 05:53:38 +00:00
|
|
|
class nsDFAState : public nsHashKey
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mStateID;
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsDFAState(uint32_t aID) :mStateID(aID) {}
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetStateID() { return mStateID; }
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
uint32_t HashCode(void) const MOZ_OVERRIDE {
|
2004-04-17 05:53:38 +00:00
|
|
|
return mStateID;
|
|
|
|
}
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
bool Equals(const nsHashKey *aKey) const MOZ_OVERRIDE {
|
2004-04-17 05:53:38 +00:00
|
|
|
nsDFAState* key = (nsDFAState*)aKey;
|
|
|
|
return key->mStateID == mStateID;
|
|
|
|
}
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
nsHashKey *Clone(void) const MOZ_OVERRIDE {
|
2004-04-17 05:53:38 +00:00
|
|
|
return new nsDFAState(mStateID);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsTransitionKey : public nsHashKey
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mState;
|
2004-04-17 05:53:38 +00:00
|
|
|
nsCOMPtr<nsIAtom> mInputSymbol;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsTransitionKey(uint32_t aState, nsIAtom* aSymbol) :mState(aState), mInputSymbol(aSymbol) {}
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
uint32_t HashCode(void) const MOZ_OVERRIDE {
|
2004-04-17 05:53:38 +00:00
|
|
|
// Make a 32-bit integer that combines the low-order 16 bits of the state and the input symbol.
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t hb = mState << 16;
|
|
|
|
int32_t lb = (NS_PTR_TO_INT32(mInputSymbol.get()) << 16) >> 16;
|
2004-04-17 05:53:38 +00:00
|
|
|
return hb+lb;
|
|
|
|
}
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
bool Equals(const nsHashKey *aKey) const MOZ_OVERRIDE {
|
2004-04-17 05:53:38 +00:00
|
|
|
nsTransitionKey* key = (nsTransitionKey*)aKey;
|
|
|
|
return key->mState == mState && key->mInputSymbol == mInputSymbol;
|
|
|
|
}
|
|
|
|
|
2013-05-29 19:37:49 +00:00
|
|
|
nsHashKey *Clone(void) const MOZ_OVERRIDE {
|
2004-04-17 05:53:38 +00:00
|
|
|
return new nsTransitionKey(mState, mInputSymbol);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-09 16:49:53 +00:00
|
|
|
class nsTreeStyleCache
|
2004-04-17 05:53:38 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-05-09 16:49:53 +00:00
|
|
|
nsTreeStyleCache()
|
|
|
|
: mNextState(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsTreeStyleCache()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2014-05-09 16:49:53 +00:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mTransitionTable = nullptr;
|
|
|
|
mCache = nullptr;
|
|
|
|
mNextState = 0;
|
|
|
|
}
|
2004-04-17 05:53:38 +00:00
|
|
|
|
|
|
|
nsStyleContext* GetStyleContext(nsICSSPseudoComparator* aComparator,
|
2014-05-09 16:49:53 +00:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
nsIContent* aContent,
|
2004-04-17 05:53:38 +00:00
|
|
|
nsStyleContext* aContext,
|
|
|
|
nsIAtom* aPseudoElement,
|
2013-03-19 15:46:20 +00:00
|
|
|
const AtomArray & aInputWord);
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool DeleteDFAState(nsHashKey *aKey, void *aData, void *closure);
|
2004-04-17 05:53:38 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// A transition table for a deterministic finite automaton. The DFA
|
2014-05-09 16:49:53 +00:00
|
|
|
// takes as its input a single pseudoelement and an ordered set of properties.
|
2004-04-17 05:53:38 +00:00
|
|
|
// It transitions on an input word that is the concatenation of the pseudoelement supplied
|
|
|
|
// with the properties in the array.
|
2014-05-09 16:49:53 +00:00
|
|
|
//
|
2004-04-17 05:53:38 +00:00
|
|
|
// It transitions from state to state by looking up entries in the transition table (which is
|
|
|
|
// a mapping from (S,i)->S', where S is the current state, i is the next
|
|
|
|
// property in the input word, and S' is the state to transition to.
|
|
|
|
//
|
|
|
|
// If S' is not found, it is constructed and entered into the hashtable
|
|
|
|
// under the key (S,i).
|
|
|
|
//
|
|
|
|
// Once the entire word has been consumed, the final state is used
|
|
|
|
// to reference the cache table to locate the style context.
|
2014-05-09 16:49:53 +00:00
|
|
|
nsAutoPtr<nsObjectHashtable> mTransitionTable;
|
2004-04-17 05:53:38 +00:00
|
|
|
|
2014-05-09 16:49:53 +00:00
|
|
|
// The cache of all active style contexts. This is a hash from
|
2004-04-17 05:53:38 +00:00
|
|
|
// a final state in the DFA, Sf, to the resultant style context.
|
2014-05-09 16:49:53 +00:00
|
|
|
typedef nsRefPtrHashtable<nsUint32HashKey, nsStyleContext> StyleContextCache;
|
|
|
|
nsAutoPtr<StyleContextCache> mCache;
|
2004-04-17 05:53:38 +00:00
|
|
|
|
|
|
|
// An integer counter that is used when we need to make new states in the
|
|
|
|
// DFA.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mNextState;
|
2004-04-17 05:53:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsTreeStyleCache_h__
|