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
33 // MediaRule and DocumentRule
34 class GroupRule
: public Rule
{
36 GroupRule(already_AddRefed
<ServoCssRules
> aRules
, StyleSheet
* aSheet
,
37 Rule
* aParentRule
, uint32_t aLineNumber
, uint32_t aColumnNumber
);
38 GroupRule(const GroupRule
& aCopy
) = delete;
42 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule
, Rule
)
43 NS_DECL_ISUPPORTS_INHERITED
44 virtual bool IsCCLeaf() const override
;
47 void List(FILE* out
= stdout
, int32_t aIndent
= 0) const override
;
49 void DropSheetReference() override
;
52 int32_t StyleRuleCount() const { return mRuleList
? mRuleList
->Length() : 0; }
54 Rule
* GetStyleRuleAt(int32_t aIndex
) const {
55 return mRuleList
? mRuleList
->GetRule(aIndex
) : nullptr;
58 void SetRawAfterClone(RefPtr
<ServoCssRules
> aRules
) {
60 mRuleList
->SetRawAfterClone(std::move(aRules
));
62 MOZ_ASSERT(!aRules
, "Can't move from having no rules to having rules");
67 * The next method should never be called unless you have first called
68 * WillDirty() on the parent stylesheet.
70 nsresult
DeleteStyleRuleAt(uint32_t aIndex
) {
74 return mRuleList
->DeleteRule(aIndex
);
77 // non-virtual -- it is only called by subclasses
78 size_t SizeOfExcludingThis(MallocSizeOf
) const;
79 size_t SizeOfIncludingThis(MallocSizeOf
) const override
= 0;
82 ServoCSSRuleList
* GetCssRules() { return mRuleList
; }
83 uint32_t InsertRule(const nsACString
& aRule
, uint32_t aIndex
,
85 void DeleteRule(uint32_t aIndex
, ErrorResult
& aRv
);
88 RefPtr
<ServoCSSRuleList
> mRuleList
;
91 // Implementation of WebIDL CSSConditionRule.
92 class ConditionRule
: public GroupRule
{
94 using GroupRule::GroupRule
;
97 virtual void GetConditionText(nsACString
& aConditionText
) = 0;
98 virtual void SetConditionText(const nsACString
& aConditionText
,
99 ErrorResult
& aRv
) = 0;
103 } // namespace mozilla
105 #endif /* mozilla_css_GroupRule_h__ */