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/ServoStyleRule.h" 11 12 #include "nsDataHashtable.h" 13 14 struct RawServoStyleRule; 15 class nsXBLPrototypeResources; 16 17 namespace mozilla { 18 class ServoCSSRuleList; 19 class ServoStyleSet; 20 namespace css { 21 class Rule; 22 } // namespace css 23 namespace dom { 24 class ShadowRoot; 25 } 26 class ServoStyleRuleMap { 27 public: 28 ServoStyleRuleMap() = default; 29 30 void EnsureTable(ServoStyleSet&); 31 void EnsureTable(nsXBLPrototypeResources&); 32 void EnsureTable(dom::ShadowRoot&); 33 Lookup(const RawServoStyleRule * aRawRule)34 ServoStyleRule* Lookup(const RawServoStyleRule* aRawRule) const { 35 return mTable.Get(aRawRule); 36 } 37 38 void SheetAdded(ServoStyleSheet&); 39 void SheetRemoved(ServoStyleSheet&); 40 41 void RuleAdded(ServoStyleSheet& aStyleSheet, css::Rule&); 42 void RuleRemoved(ServoStyleSheet& aStyleSheet, css::Rule&); 43 44 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const; 45 46 ~ServoStyleRuleMap() = default; 47 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. IsEmpty()52 bool IsEmpty() const { return mTable.Count() == 0; } 53 54 void FillTableFromRule(css::Rule& aRule); 55 void FillTableFromRuleList(ServoCSSRuleList& aRuleList); 56 void FillTableFromStyleSheet(ServoStyleSheet& aSheet); 57 58 typedef nsDataHashtable<nsPtrHashKey<const RawServoStyleRule>, 59 WeakPtr<ServoStyleRule>> 60 Hashtable; 61 Hashtable mTable; 62 }; 63 64 } // namespace mozilla 65 66 #endif // mozilla_ServoStyleRuleMap_h 67