Bug 1890793: Assert CallArgs::newTarget is not gray. r=spidermonkey-reviewers,sfink...
[gecko.git] / layout / style / GroupRule.cpp
blobff3cd11f8c3c5ab7f88a4c22597021fc065cba27
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 #include "mozilla/css/GroupRule.h"
14 #include "mozilla/dom/CSSRuleList.h"
16 #include "nsPrintfCString.h"
18 using namespace mozilla::dom;
20 namespace mozilla::css {
22 GroupRule::GroupRule(StyleSheet* aSheet, Rule* aParentRule,
23 uint32_t aLineNumber, uint32_t aColumnNumber)
24 : Rule(aSheet, aParentRule, aLineNumber, aColumnNumber) {}
26 GroupRule::~GroupRule() {
27 MOZ_ASSERT(!mSheet, "SetStyleSheet should have been called");
28 if (mRuleList) {
29 mRuleList->DropReferences();
33 NS_IMPL_ADDREF_INHERITED(GroupRule, Rule)
34 NS_IMPL_RELEASE_INHERITED(GroupRule, Rule)
36 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule)
37 NS_INTERFACE_MAP_END_INHERITING(Rule)
39 bool GroupRule::IsCCLeaf() const {
40 if (!Rule::IsCCLeaf()) {
41 return false;
43 return !mRuleList;
46 ServoCSSRuleList* GroupRule::CssRules() {
47 if (!mRuleList) {
48 // Lazily create the rule list since most style rules won't have child
49 // rules.
50 mRuleList =
51 new ServoCSSRuleList(GetOrCreateRawRules(), GetStyleSheet(), this);
53 return mRuleList;
56 NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule)
58 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GroupRule, Rule)
59 if (tmp->mRuleList) {
60 // If tmp has a style sheet (which can happen if it gets unlinked
61 // earlier than its owning style sheet), then we need to null out the
62 // style sheet pointer on descendants now, before we clear mRuleList.
63 tmp->mRuleList->DropReferences();
64 tmp->mRuleList = nullptr;
66 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
68 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GroupRule, Rule)
69 ImplCycleCollectionTraverse(cb, tmp->mRuleList, "mRuleList");
70 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
72 #ifdef DEBUG
73 void GroupRule::List(FILE* out, int32_t aIndent) const {
74 // TODO list something reasonable?
76 #endif
78 /* virtual */
79 void GroupRule::DropSheetReference() {
80 if (mRuleList) {
81 mRuleList->DropSheetReference();
83 Rule::DropSheetReference();
86 uint32_t GroupRule::InsertRule(const nsACString& aRule, uint32_t aIndex,
87 ErrorResult& aRv) {
88 if (IsReadOnly()) {
89 return 0;
92 StyleSheet* sheet = GetStyleSheet();
93 if (NS_WARN_IF(!sheet)) {
94 aRv.Throw(NS_ERROR_FAILURE);
95 return 0;
98 uint32_t count = StyleRuleCount();
99 if (aIndex > count) {
100 aRv.ThrowIndexSizeError(nsPrintfCString(
101 "Can't insert rule at index %u because rule list length is %u", aIndex,
102 count));
103 return 0;
106 NS_ASSERTION(count <= INT32_MAX, "Too many style rules!");
108 nsresult rv = sheet->InsertRuleIntoGroup(aRule, this, aIndex);
109 if (NS_FAILED(rv)) {
110 aRv.Throw(rv);
111 return 0;
113 return aIndex;
116 void GroupRule::DeleteRule(uint32_t aIndex, ErrorResult& aRv) {
117 if (IsReadOnly()) {
118 return;
121 StyleSheet* sheet = GetStyleSheet();
122 if (NS_WARN_IF(!sheet)) {
123 aRv.Throw(NS_ERROR_FAILURE);
124 return;
127 uint32_t count = StyleRuleCount();
128 if (aIndex >= count) {
129 aRv.ThrowIndexSizeError(nsPrintfCString(
130 "Index %u is too large for list of length %u", aIndex, count));
131 return;
134 NS_ASSERTION(count <= INT32_MAX, "Too many style rules!");
136 nsresult rv = sheet->DeleteRuleFromGroup(this, aIndex);
137 if (NS_FAILED(rv)) {
138 aRv.Throw(rv);
142 size_t GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
143 // TODO how to implement?
144 return 0;
147 } // namespace mozilla::css