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
|
|
|
|
|
|
|
#ifndef nsTreeStyleCache_h__
|
|
|
|
#define nsTreeStyleCache_h__
|
|
|
|
|
2017-10-13 03:59:23 +03:00
|
|
|
#include "mozilla/AtomArray.h"
|
2013-05-29 23:37:49 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2013-03-19 19:46:20 +04:00
|
|
|
#include "nsCOMArray.h"
|
2014-05-09 20:49:53 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2004-04-17 09:53:38 +04:00
|
|
|
#include "nsStyleContext.h"
|
|
|
|
|
2014-05-09 20:49:53 +04:00
|
|
|
class nsTreeStyleCache
|
2004-04-17 09:53:38 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-05-09 20:49:53 +04:00
|
|
|
nsTreeStyleCache()
|
|
|
|
: mNextState(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~nsTreeStyleCache()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
2004-04-17 09:53:38 +04:00
|
|
|
|
2014-05-09 20:49:53 +04:00
|
|
|
void Clear()
|
|
|
|
{
|
|
|
|
mTransitionTable = nullptr;
|
|
|
|
mCache = nullptr;
|
|
|
|
mNextState = 0;
|
|
|
|
}
|
2004-04-17 09:53:38 +04:00
|
|
|
|
2017-10-13 05:50:04 +03:00
|
|
|
nsStyleContext* GetStyleContext(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,
|
2017-10-13 03:59:23 +03:00
|
|
|
const mozilla::AtomArray& aInputWord);
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
protected:
|
2014-05-09 20:49:54 +04:00
|
|
|
typedef uint32_t DFAState;
|
2014-05-09 20:49:53 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class Transition final
|
2014-05-09 20:49:53 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-10-03 01:05:19 +03:00
|
|
|
Transition(DFAState aState, nsAtom* aSymbol);
|
2014-05-09 20:49:53 +04:00
|
|
|
bool operator==(const Transition& aOther) const;
|
|
|
|
uint32_t Hash() const;
|
|
|
|
|
|
|
|
private:
|
2014-05-09 20:49:54 +04:00
|
|
|
DFAState mState;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> mInputSymbol;
|
2014-05-09 20:49:53 +04:00
|
|
|
};
|
|
|
|
|
2014-05-09 20:49:54 +04:00
|
|
|
typedef nsDataHashtable<nsGenericHashKey<Transition>, DFAState> TransitionTable;
|
2014-05-09 20:49:53 +04:00
|
|
|
|
2004-04-17 09:53:38 +04:00
|
|
|
// A transition table for a deterministic finite automaton. The DFA
|
2014-05-09 20:49:53 +04:00
|
|
|
// takes as its input a single pseudoelement and an ordered set of properties.
|
2004-04-17 09:53:38 +04:00
|
|
|
// It transitions on an input word that is the concatenation of the pseudoelement supplied
|
|
|
|
// with the properties in the array.
|
2014-05-09 20:49:53 +04:00
|
|
|
//
|
2004-04-17 09:53:38 +04: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 20:49:53 +04:00
|
|
|
nsAutoPtr<TransitionTable> mTransitionTable;
|
2004-04-17 09:53:38 +04:00
|
|
|
|
2014-05-09 20:49:53 +04:00
|
|
|
// The cache of all active style contexts. This is a hash from
|
2004-04-17 09:53:38 +04:00
|
|
|
// a final state in the DFA, Sf, to the resultant style context.
|
2014-05-09 20:49:53 +04:00
|
|
|
typedef nsRefPtrHashtable<nsUint32HashKey, nsStyleContext> StyleContextCache;
|
|
|
|
nsAutoPtr<StyleContextCache> mCache;
|
2004-04-17 09:53:38 +04:00
|
|
|
|
|
|
|
// An integer counter that is used when we need to make new states in the
|
|
|
|
// DFA.
|
2014-05-09 20:49:54 +04:00
|
|
|
DFAState mNextState;
|
2004-04-17 09:53:38 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsTreeStyleCache_h__
|