tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsTreeStyleCache.h (2646B)


      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/ComputedStyle.h"
     12 #include "mozilla/UniquePtr.h"
     13 #include "nsCOMArray.h"
     14 #include "nsRefPtrHashtable.h"
     15 #include "nsTHashMap.h"
     16 
     17 class nsIContent;
     18 
     19 class nsTreeStyleCache {
     20 public:
     21  nsTreeStyleCache() : mNextState(0) {}
     22 
     23  ~nsTreeStyleCache() { Clear(); }
     24 
     25  void Clear() {
     26    mTransitionTable = nullptr;
     27    mCache = nullptr;
     28    mNextState = 0;
     29  }
     30 
     31  mozilla::ComputedStyle* GetComputedStyle(
     32      nsPresContext* aPresContext, nsIContent* aContent,
     33      mozilla::ComputedStyle* aStyle,
     34      nsCSSAnonBoxPseudoStaticAtom* aPseudoElement,
     35      const mozilla::AtomArray& aInputWord);
     36 
     37 protected:
     38  typedef uint32_t DFAState;
     39 
     40  class Transition final {
     41   public:
     42    Transition(DFAState aState, nsAtom* aSymbol);
     43    bool operator==(const Transition& aOther) const;
     44    uint32_t Hash() const;
     45 
     46   private:
     47    DFAState mState;
     48    RefPtr<nsAtom> mInputSymbol;
     49  };
     50 
     51  typedef nsTHashMap<nsGenericHashKey<Transition>, DFAState> TransitionTable;
     52 
     53  // A transition table for a deterministic finite automaton.  The DFA
     54  // takes as its input a single pseudoelement and an ordered set of properties.
     55  // It transitions on an input word that is the concatenation of the
     56  // pseudoelement supplied with the properties in the array.
     57  //
     58  // It transitions from state to state by looking up entries in the transition
     59  // table (which is a mapping from (S,i)->S', where S is the current state, i
     60  // is the next property in the input word, and S' is the state to transition
     61  // to.
     62  //
     63  // If S' is not found, it is constructed and entered into the hashtable
     64  // under the key (S,i).
     65  //
     66  // Once the entire word has been consumed, the final state is used
     67  // to reference the cache table to locate the ComputedStyle.
     68  mozilla::UniquePtr<TransitionTable> mTransitionTable;
     69 
     70  // The cache of all active ComputedStyles.  This is a hash from
     71  // a final state in the DFA, Sf, to the resultant ComputedStyle.
     72  typedef nsRefPtrHashtable<nsUint32HashKey, mozilla::ComputedStyle>
     73      ComputedStyleCache;
     74  mozilla::UniquePtr<ComputedStyleCache> mCache;
     75 
     76  // An integer counter that is used when we need to make new states in the
     77  // DFA.
     78  DFAState mNextState;
     79 };
     80 
     81 #endif  // nsTreeStyleCache_h__