GroupRule.h (2672B)
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 /* 8 * internal interface representing CSS style rules that contain other 9 * rules, such as @media rules 10 */ 11 12 #ifndef mozilla_css_GroupRule_h__ 13 #define mozilla_css_GroupRule_h__ 14 15 #include "mozilla/MemoryReporting.h" 16 #include "mozilla/ServoCSSRuleList.h" 17 #include "mozilla/css/Rule.h" 18 #include "nsCycleCollectionParticipant.h" 19 20 namespace mozilla { 21 22 class ErrorResult; 23 class StyleSheet; 24 25 namespace dom { 26 class CSSRuleList; 27 } // namespace dom 28 29 namespace css { 30 31 // Inherits from Rule so it can be shared between MediaRule and DocumentRule 32 class GroupRule : public Rule { 33 protected: 34 GroupRule(StyleSheet* aSheet, Rule* aParentRule, uint32_t aLineNumber, 35 uint32_t aColumnNumber); 36 virtual ~GroupRule(); 37 virtual already_AddRefed<StyleLockedCssRules> GetOrCreateRawRules() = 0; 38 39 public: 40 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule) 41 NS_DECL_ISUPPORTS_INHERITED 42 43 GroupRule(const GroupRule&) = delete; 44 bool IsCCLeaf() const override; 45 46 bool IsGroupRule() const final { return true; } 47 48 #ifdef DEBUG 49 void List(FILE* out = stdout, int32_t aIndent = 0) const override; 50 #endif 51 void DropSheetReference() override; 52 uint32_t StyleRuleCount() { return CssRules()->Length(); } 53 Rule* GetStyleRuleAt(int32_t aIndex) { return CssRules()->GetRule(aIndex); } 54 55 void DidSetRawAfterClone() { 56 if (mRuleList) { 57 mRuleList->SetRawAfterClone(GetOrCreateRawRules()); 58 } 59 } 60 61 /* 62 * The next method should never be called unless you have first called 63 * WillDirty() on the parent stylesheet. 64 */ 65 nsresult DeleteStyleRuleAt(uint32_t aIndex) { 66 return CssRules()->DeleteRule(aIndex); 67 } 68 69 // non-virtual -- it is only called by subclasses 70 size_t SizeOfExcludingThis(MallocSizeOf) const; 71 size_t SizeOfIncludingThis(MallocSizeOf) const override = 0; 72 73 // WebIDL API 74 ServoCSSRuleList* CssRules(); 75 uint32_t InsertRule(const nsACString& aRule, uint32_t aIndex, 76 ErrorResult& aRv); 77 void DeleteRule(uint32_t aIndex, ErrorResult& aRv); 78 79 private: 80 RefPtr<ServoCSSRuleList> mRuleList; 81 }; 82 83 // Implementation of WebIDL CSSConditionRule. 84 class ConditionRule : public GroupRule { 85 protected: 86 using GroupRule::GroupRule; 87 88 public: 89 virtual void GetConditionText(nsACString& aConditionText) = 0; 90 }; 91 92 } // namespace css 93 } // namespace mozilla 94 95 #endif /* mozilla_css_GroupRule_h__ */