tor-browser

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

ServoStyleRuleMap.h (2021B)


      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 mozilla_ServoStyleRuleMap_h
      8 #define mozilla_ServoStyleRuleMap_h
      9 
     10 #include "mozilla/StyleSheet.h"
     11 #include "mozilla/css/Rule.h"
     12 #include "nsTHashMap.h"
     13 
     14 struct StyleLockedStyleRule;
     15 
     16 namespace mozilla {
     17 class ServoCSSRuleList;
     18 class ServoStyleSet;
     19 namespace css {
     20 class Rule;
     21 }  // namespace css
     22 namespace dom {
     23 class ShadowRoot;
     24 }
     25 class ServoStyleRuleMap final {
     26 public:
     27  ServoStyleRuleMap() = default;
     28 
     29  void EnsureTable(ServoStyleSet&);
     30  void EnsureTable(dom::ShadowRoot&);
     31 
     32  css::Rule* Lookup(const StyleLockedDeclarationBlock* aDecls) const {
     33    return mTable.Get(aDecls);
     34  }
     35 
     36  void SheetAdded(StyleSheet&);
     37  void SheetRemoved(StyleSheet&);
     38  void SheetCloned(StyleSheet&);
     39 
     40  void RuleAdded(StyleSheet& aStyleSheet, css::Rule&);
     41  void RuleRemoved(StyleSheet& aStyleSheet, css::Rule&);
     42  void RuleDeclarationsChanged(css::Rule&,
     43                               const StyleLockedDeclarationBlock* aOld,
     44                               const StyleLockedDeclarationBlock* aNew);
     45 
     46  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
     47 
     48  ~ServoStyleRuleMap() = default;
     49 
     50 private:
     51  // Since we would never have a document which contains no style rule,
     52  // we use IsEmpty as an indication whether we need to walk through
     53  // all stylesheets to fill the table.
     54  bool IsEmpty() const { return mTable.IsEmpty(); }
     55 
     56  void FillTableFromRule(css::Rule&);
     57  void FillTableFromRuleList(ServoCSSRuleList&);
     58  void FillTableFromStyleSheet(StyleSheet&);
     59 
     60  using Hashtable = nsTHashMap<nsPtrHashKey<const StyleLockedDeclarationBlock>,
     61                               WeakPtr<css::Rule>>;
     62  Hashtable mTable;
     63 };
     64 
     65 }  // namespace mozilla
     66 
     67 #endif  // mozilla_ServoStyleRuleMap_h