Bug 1856663 - Add more chunks for Android mochitest-plain. r=jmaher,taskgraph-reviewe...
[gecko.git] / layout / inspector / ServoStyleRuleMap.h
blob09d5dae260afda33232ca3ee66349550e2199172
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/. */
7 #ifndef mozilla_ServoStyleRuleMap_h
8 #define mozilla_ServoStyleRuleMap_h
10 #include "mozilla/dom/CSSStyleRule.h"
11 #include "mozilla/StyleSheet.h"
13 #include "nsTHashMap.h"
15 struct StyleLockedStyleRule;
17 namespace mozilla {
18 class ServoCSSRuleList;
19 class ServoStyleSet;
20 namespace css {
21 class Rule;
22 } // namespace css
23 namespace dom {
24 class ShadowRoot;
26 class ServoStyleRuleMap {
27 public:
28 ServoStyleRuleMap() = default;
30 void EnsureTable(ServoStyleSet&);
31 void EnsureTable(dom::ShadowRoot&);
33 dom::CSSStyleRule* Lookup(const StyleLockedStyleRule* aRawRule) const {
34 return mTable.Get(aRawRule);
37 void SheetAdded(StyleSheet&);
38 void SheetRemoved(StyleSheet&);
39 void SheetCloned(StyleSheet&);
41 void RuleAdded(StyleSheet& aStyleSheet, css::Rule&);
42 void RuleRemoved(StyleSheet& aStyleSheet, css::Rule&);
44 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
46 ~ServoStyleRuleMap() = default;
48 private:
49 // Since we would never have a document which contains no style rule,
50 // we use IsEmpty as an indication whether we need to walk through
51 // all stylesheets to fill the table.
52 bool IsEmpty() const { return mTable.Count() == 0; }
54 void FillTableFromRule(css::Rule&);
55 void FillTableFromRuleList(ServoCSSRuleList&);
56 void FillTableFromStyleSheet(StyleSheet&);
58 using Hashtable = nsTHashMap<nsPtrHashKey<const StyleLockedStyleRule>,
59 WeakPtr<dom::CSSStyleRule>>;
60 Hashtable mTable;
63 } // namespace mozilla
65 #endif // mozilla_ServoStyleRuleMap_h