Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/xul/tree/nsTreeStyleCache.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef nsTreeStyleCache_h__
8
#define nsTreeStyleCache_h__
9
10
#include "mozilla/AtomArray.h"
11
#include "mozilla/Attributes.h"
12
#include "nsAutoPtr.h"
13
#include "nsCOMArray.h"
14
#include "nsRefPtrHashtable.h"
15
#include "mozilla/ComputedStyle.h"
16
17
class nsTreeStyleCache
18
{
19
public:
20
  nsTreeStyleCache()
21
    : mNextState(0)
22
0
  {
23
0
  }
24
25
  ~nsTreeStyleCache()
26
0
  {
27
0
    Clear();
28
0
  }
29
30
  void Clear()
31
0
  {
32
0
    mTransitionTable = nullptr;
33
0
    mCache = nullptr;
34
0
    mNextState = 0;
35
0
  }
36
37
  mozilla::ComputedStyle* GetComputedStyle(
38
      nsPresContext* aPresContext,
39
      nsIContent* aContent,
40
      mozilla::ComputedStyle* aStyle,
41
      nsICSSAnonBoxPseudo* aPseudoElement,
42
      const mozilla::AtomArray& aInputWord);
43
44
protected:
45
  typedef uint32_t DFAState;
46
47
  class Transition final
48
  {
49
  public:
50
    Transition(DFAState aState, nsAtom* aSymbol);
51
    bool operator==(const Transition& aOther) const;
52
    uint32_t Hash() const;
53
54
  private:
55
    DFAState mState;
56
    RefPtr<nsAtom> mInputSymbol;
57
  };
58
59
  typedef nsDataHashtable<nsGenericHashKey<Transition>, DFAState> TransitionTable;
60
61
  // A transition table for a deterministic finite automaton.  The DFA
62
  // takes as its input a single pseudoelement and an ordered set of properties.
63
  // It transitions on an input word that is the concatenation of the pseudoelement supplied
64
  // with the properties in the array.
65
  //
66
  // It transitions from state to state by looking up entries in the transition table (which is
67
  // a mapping from (S,i)->S', where S is the current state, i is the next
68
  // property in the input word, and S' is the state to transition to.
69
  //
70
  // If S' is not found, it is constructed and entered into the hashtable
71
  // under the key (S,i).
72
  //
73
  // Once the entire word has been consumed, the final state is used
74
  // to reference the cache table to locate the ComputedStyle.
75
  nsAutoPtr<TransitionTable> mTransitionTable;
76
77
  // The cache of all active ComputedStyles.  This is a hash from
78
  // a final state in the DFA, Sf, to the resultant ComputedStyle.
79
  typedef nsRefPtrHashtable<nsUint32HashKey, mozilla::ComputedStyle> ComputedStyleCache;
80
  nsAutoPtr<ComputedStyleCache> mCache;
81
82
  // An integer counter that is used when we need to make new states in the
83
  // DFA.
84
  DFAState mNextState;
85
};
86
87
#endif // nsTreeStyleCache_h__