/src/mozilla-central/layout/style/GroupRule.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "mozilla/css/GroupRule.h" |
13 | | |
14 | | #include "mozilla/dom/CSSRuleList.h" |
15 | | |
16 | | using namespace mozilla::dom; |
17 | | |
18 | | namespace mozilla { |
19 | | namespace css { |
20 | | |
21 | | GroupRule::GroupRule(already_AddRefed<ServoCssRules> aRules, |
22 | | StyleSheet* aSheet, |
23 | | Rule* aParentRule, |
24 | | uint32_t aLineNumber, |
25 | | uint32_t aColumnNumber) |
26 | | : Rule(aSheet, aParentRule, aLineNumber, aColumnNumber) |
27 | | , mRuleList(new ServoCSSRuleList(std::move(aRules), aSheet, this)) |
28 | 0 | { |
29 | 0 | } |
30 | | |
31 | | GroupRule::~GroupRule() |
32 | 0 | { |
33 | 0 | MOZ_ASSERT(!mSheet, "SetStyleSheet should have been called"); |
34 | 0 | if (mRuleList) { |
35 | 0 | mRuleList->DropReferences(); |
36 | 0 | } |
37 | 0 | } |
38 | | |
39 | | NS_IMPL_ADDREF_INHERITED(GroupRule, Rule) |
40 | | NS_IMPL_RELEASE_INHERITED(GroupRule, Rule) |
41 | | |
42 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule) |
43 | 0 | NS_INTERFACE_MAP_END_INHERITING(Rule) |
44 | | |
45 | | bool |
46 | | GroupRule::IsCCLeaf() const |
47 | 0 | { |
48 | 0 | // Let's not worry for now about sorting out whether we're a leaf or not. |
49 | 0 | return false; |
50 | 0 | } |
51 | | |
52 | | NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule) |
53 | | |
54 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GroupRule, Rule) |
55 | 0 | if (tmp->mRuleList) { |
56 | 0 | // If tmp has a style sheet (which can happen if it gets unlinked |
57 | 0 | // earlier than its owning style sheet), then we need to null out the |
58 | 0 | // style sheet pointer on descendants now, before we clear mRuleList. |
59 | 0 | tmp->mRuleList->DropReferences(); |
60 | 0 | tmp->mRuleList = nullptr; |
61 | 0 | } |
62 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
63 | | |
64 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GroupRule, Rule) |
65 | 0 | ImplCycleCollectionTraverse(cb, tmp->mRuleList, "mRuleList"); |
66 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
67 | | |
68 | | #ifdef DEBUG |
69 | | void |
70 | | GroupRule::List(FILE* out, int32_t aIndent) const |
71 | | { |
72 | | // TODO list something reasonable? |
73 | | } |
74 | | #endif |
75 | | |
76 | | /* virtual */ void |
77 | | GroupRule::DropSheetReference() |
78 | 0 | { |
79 | 0 | if (mRuleList) { |
80 | 0 | mRuleList->DropSheetReference(); |
81 | 0 | } |
82 | 0 | Rule::DropSheetReference(); |
83 | 0 | } |
84 | | |
85 | | uint32_t |
86 | | GroupRule::InsertRule(const nsAString& aRule, uint32_t aIndex, ErrorResult& aRv) |
87 | 0 | { |
88 | 0 | StyleSheet* sheet = GetStyleSheet(); |
89 | 0 | if (NS_WARN_IF(!sheet)) { |
90 | 0 | aRv.Throw(NS_ERROR_FAILURE); |
91 | 0 | return 0; |
92 | 0 | } |
93 | 0 | |
94 | 0 | uint32_t count = StyleRuleCount(); |
95 | 0 | if (aIndex > count) { |
96 | 0 | aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); |
97 | 0 | return 0; |
98 | 0 | } |
99 | 0 | |
100 | 0 | NS_ASSERTION(count <= INT32_MAX, "Too many style rules!"); |
101 | 0 |
|
102 | 0 | nsresult rv = sheet->InsertRuleIntoGroup(aRule, this, aIndex); |
103 | 0 | if (NS_FAILED(rv)) { |
104 | 0 | aRv.Throw(rv); |
105 | 0 | return 0; |
106 | 0 | } |
107 | 0 | return aIndex; |
108 | 0 | } |
109 | | |
110 | | void |
111 | | GroupRule::DeleteRule(uint32_t aIndex, ErrorResult& aRv) |
112 | 0 | { |
113 | 0 | StyleSheet* sheet = GetStyleSheet(); |
114 | 0 | if (NS_WARN_IF(!sheet)) { |
115 | 0 | aRv.Throw(NS_ERROR_FAILURE); |
116 | 0 | return; |
117 | 0 | } |
118 | 0 | |
119 | 0 | uint32_t count = StyleRuleCount(); |
120 | 0 | if (aIndex >= count) { |
121 | 0 | aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR); |
122 | 0 | return; |
123 | 0 | } |
124 | 0 | |
125 | 0 | NS_ASSERTION(count <= INT32_MAX, "Too many style rules!"); |
126 | 0 |
|
127 | 0 | nsresult rv = sheet->DeleteRuleFromGroup(this, aIndex); |
128 | 0 | if (NS_FAILED(rv)) { |
129 | 0 | aRv.Throw(rv); |
130 | 0 | } |
131 | 0 | } |
132 | | |
133 | | size_t |
134 | | GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const |
135 | 0 | { |
136 | 0 | // TODO how to implement? |
137 | 0 | return 0; |
138 | 0 | } |
139 | | |
140 | | } // namespace css |
141 | | } // namespace mozilla |