Bug 1730256 [wpt PR 30555] - Move getWindowSegments to visualViewport.segments, a...
[gecko.git] / layout / style / GroupRule.h
blob6e8b785fd576239b7fc50131f34ffe5b2c913ff3
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 /*
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"
21 namespace mozilla {
23 class ErrorResult;
24 class StyleSheet;
26 namespace dom {
27 class CSSRuleList;
28 } // namespace dom
30 namespace css {
32 // inherits from Rule so it can be shared between
33 // MediaRule and DocumentRule
34 class GroupRule : public Rule {
35 protected:
36 GroupRule(already_AddRefed<ServoCssRules> aRules, StyleSheet* aSheet,
37 Rule* aParentRule, uint32_t aLineNumber, uint32_t aColumnNumber);
38 GroupRule(const GroupRule& aCopy) = delete;
39 virtual ~GroupRule();
41 public:
42 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule)
43 NS_DECL_ISUPPORTS_INHERITED
44 virtual bool IsCCLeaf() const override;
46 #ifdef DEBUG
47 void List(FILE* out = stdout, int32_t aIndent = 0) const override;
48 #endif
49 void DropSheetReference() override;
51 public:
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) {
59 if (mRuleList) {
60 mRuleList->SetRawAfterClone(std::move(aRules));
61 } else {
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) {
71 if (!mRuleList) {
72 return NS_OK;
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;
81 // WebIDL API
82 ServoCSSRuleList* GetCssRules() { return mRuleList; }
83 uint32_t InsertRule(const nsACString& aRule, uint32_t aIndex,
84 ErrorResult& aRv);
85 void DeleteRule(uint32_t aIndex, ErrorResult& aRv);
87 private:
88 RefPtr<ServoCSSRuleList> mRuleList;
91 // Implementation of WebIDL CSSConditionRule.
92 class ConditionRule : public GroupRule {
93 protected:
94 using GroupRule::GroupRule;
96 public:
97 virtual void GetConditionText(nsACString& aConditionText) = 0;
98 virtual void SetConditionText(const nsACString& aConditionText,
99 ErrorResult& aRv) = 0;
102 } // namespace css
103 } // namespace mozilla
105 #endif /* mozilla_css_GroupRule_h__ */