-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathCSSNestedDeclarations.cpp
175 lines (145 loc) · 6.07 KB
/
CSSNestedDeclarations.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/CSSNestedDeclarations.h"
#include "mozilla/dom/CSSNestedDeclarationsBinding.h"
#include "mozilla/DeclarationBlock.h"
namespace mozilla::dom {
CSSNestedDeclarationsDeclaration::CSSNestedDeclarationsDeclaration(
already_AddRefed<StyleLockedDeclarationBlock> aDecls)
: mDecls(new DeclarationBlock(std::move(aDecls))) {
mDecls->SetOwningRule(Rule());
}
CSSNestedDeclarationsDeclaration::~CSSNestedDeclarationsDeclaration() {
mDecls->SetOwningRule(nullptr);
}
// QueryInterface implementation for CSSNestedDeclarationsDeclaration
NS_INTERFACE_MAP_BEGIN(CSSNestedDeclarationsDeclaration)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
// We forward the cycle collection interfaces to Rule(), which is
// never null (in fact, we're part of that object!)
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
return Rule()->QueryInterface(aIID, aInstancePtr);
}
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
NS_IMPL_ADDREF_USING_AGGREGATOR(CSSNestedDeclarationsDeclaration, Rule())
NS_IMPL_RELEASE_USING_AGGREGATOR(CSSNestedDeclarationsDeclaration, Rule())
css::Rule* CSSNestedDeclarationsDeclaration::GetParentRule() { return Rule(); }
nsINode* CSSNestedDeclarationsDeclaration::GetAssociatedNode() const {
return Rule()->GetAssociatedDocumentOrShadowRoot();
}
nsISupports* CSSNestedDeclarationsDeclaration::GetParentObject() const {
return Rule()->GetParentObject();
}
DeclarationBlock* CSSNestedDeclarationsDeclaration::GetOrCreateCSSDeclaration(
Operation aOperation, DeclarationBlock** aCreated) {
if (aOperation != Operation::Read) {
if (StyleSheet* sheet = Rule()->GetStyleSheet()) {
sheet->WillDirty();
}
}
return mDecls;
}
void CSSNestedDeclarationsDeclaration::SetRawAfterClone(
RefPtr<StyleLockedDeclarationBlock> aRaw) {
auto block = MakeRefPtr<DeclarationBlock>(aRaw.forget());
mDecls->SetOwningRule(nullptr);
mDecls = std::move(block);
mDecls->SetOwningRule(Rule());
}
nsresult CSSNestedDeclarationsDeclaration::SetCSSDeclaration(
DeclarationBlock* aDecl, MutationClosureData* aClosureData) {
CSSNestedDeclarations* rule = Rule();
RefPtr<DeclarationBlock> oldDecls;
if (StyleSheet* sheet = rule->GetStyleSheet()) {
if (aDecl != mDecls) {
oldDecls = std::move(mDecls);
oldDecls->SetOwningRule(nullptr);
Servo_NestedDeclarationsRule_SetStyle(rule->Raw(), aDecl->Raw());
mDecls = aDecl;
mDecls->SetOwningRule(rule);
}
sheet->RuleChanged(rule, {StyleRuleChangeKind::StyleRuleDeclarations,
oldDecls ? oldDecls.get() : aDecl, aDecl});
}
return NS_OK;
}
nsDOMCSSDeclaration::ParsingEnvironment
CSSNestedDeclarationsDeclaration::GetParsingEnvironment(nsIPrincipal*) const {
return GetParsingEnvironmentForRule(Rule(),
StyleCssRuleType::NestedDeclarations);
}
CSSNestedDeclarations::CSSNestedDeclarations(
already_AddRefed<StyleLockedNestedDeclarationsRule> aRawRule,
StyleSheet* aSheet, css::Rule* aParentRule, uint32_t aLine,
uint32_t aColumn)
: css::Rule(aSheet, aParentRule, aLine, aColumn),
mRawRule(aRawRule),
mDecls(Servo_NestedDeclarationsRule_GetStyle(mRawRule).Consume()) {}
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(CSSNestedDeclarations, css::Rule)
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSNestedDeclarations)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSNestedDeclarations, css::Rule)
// Keep this in sync with IsCCLeaf.
// Trace the wrapper for our declaration. This just expands out
// NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
// directly because the wrapper is on the declaration, not on us.
tmp->mDecls.TraceWrapper(aCallbacks, aClosure);
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSNestedDeclarations)
// Keep this in sync with IsCCLeaf.
// Unlink the wrapper for our declaration.
// Note that this has to happen before unlinking css::Rule.
tmp->UnlinkDeclarationWrapper(tmp->mDecls);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(css::Rule)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSNestedDeclarations,
css::Rule)
// Keep this in sync with IsCCLeaf.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
StyleLockedDeclarationBlock* CSSNestedDeclarations::RawStyle() const {
return mDecls.mDecls->Raw();
}
bool CSSNestedDeclarations::IsCCLeaf() const {
if (!css::Rule::IsCCLeaf()) {
return false;
}
return !mDecls.PreservingWrapper();
}
void CSSNestedDeclarations::GetCssText(nsACString& aCssText) const {
Servo_NestedDeclarationsRule_GetCssText(mRawRule, &aCssText);
}
#ifdef DEBUG
void CSSNestedDeclarations::List(FILE* out, int32_t aIndent) const {
nsAutoCString str;
for (int32_t i = 0; i < aIndent; i++) {
str.AppendLiteral(" ");
}
Servo_NestedDeclarationsRule_Debug(mRawRule, &str);
fprintf_stderr(out, "%s\n", str.get());
}
#endif
StyleCssRuleType CSSNestedDeclarations::Type() const {
return StyleCssRuleType::NestedDeclarations;
}
size_t CSSNestedDeclarations::SizeOfIncludingThis(
MallocSizeOf aMallocSizeOf) const {
size_t n = aMallocSizeOf(this);
// Measurement of the following members may be added later if DMD finds it
// is worthwhile:
// - mRawRule
// - mDecls
return n;
}
void CSSNestedDeclarations::SetRawAfterClone(
RefPtr<StyleLockedNestedDeclarationsRule> aRaw) {
mRawRule = std::move(aRaw);
mDecls.SetRawAfterClone(
Servo_NestedDeclarationsRule_GetStyle(mRawRule).Consume());
}
JSObject* CSSNestedDeclarations::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return CSSNestedDeclarations_Binding::Wrap(aCx, this, aGivenProto);
}
} // namespace mozilla::dom