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/. */
8 * internal interface representing CSS style rules that contain other
9 * rules, such as @media rules
12 #ifndef mozilla_css_GroupRule_h__
13 #define mozilla_css_GroupRule_h__
15 #include "mozilla/Attributes.h"
16 #include "mozilla/MemoryReporting.h"
17 #include "mozilla/ServoCSSRuleList.h"
18 #include "mozilla/css/Rule.h"
19 #include "nsCycleCollectionParticipant.h"
32 // Inherits from Rule so it can be shared between MediaRule and DocumentRule
33 class GroupRule
: public Rule
{
35 GroupRule(StyleSheet
* aSheet
, Rule
* aParentRule
, uint32_t aLineNumber
,
36 uint32_t aColumnNumber
);
38 virtual already_AddRefed
<StyleLockedCssRules
> GetOrCreateRawRules() = 0;
41 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule
, Rule
)
42 NS_DECL_ISUPPORTS_INHERITED
44 GroupRule(const GroupRule
&) = delete;
45 bool IsCCLeaf() const override
;
47 bool IsGroupRule() const final
{ return true; }
50 void List(FILE* out
= stdout
, int32_t aIndent
= 0) const override
;
52 void DropSheetReference() override
;
53 uint32_t StyleRuleCount() { return CssRules()->Length(); }
54 Rule
* GetStyleRuleAt(int32_t aIndex
) { return CssRules()->GetRule(aIndex
); }
56 void DidSetRawAfterClone() {
58 mRuleList
->SetRawAfterClone(GetOrCreateRawRules());
63 * The next method should never be called unless you have first called
64 * WillDirty() on the parent stylesheet.
66 nsresult
DeleteStyleRuleAt(uint32_t aIndex
) {
67 return CssRules()->DeleteRule(aIndex
);
70 // non-virtual -- it is only called by subclasses
71 size_t SizeOfExcludingThis(MallocSizeOf
) const;
72 size_t SizeOfIncludingThis(MallocSizeOf
) const override
= 0;
75 ServoCSSRuleList
* CssRules();
76 uint32_t InsertRule(const nsACString
& aRule
, uint32_t aIndex
,
78 void DeleteRule(uint32_t aIndex
, ErrorResult
& aRv
);
81 RefPtr
<ServoCSSRuleList
> mRuleList
;
84 // Implementation of WebIDL CSSConditionRule.
85 class ConditionRule
: public GroupRule
{
87 using GroupRule::GroupRule
;
90 virtual void GetConditionText(nsACString
& aConditionText
) = 0;
94 } // namespace mozilla
96 #endif /* mozilla_css_GroupRule_h__ */