/src/mozilla-central/layout/style/CSSPageRule.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 | | #include "mozilla/dom/CSSPageRule.h" |
8 | | #include "mozilla/dom/CSSPageRuleBinding.h" |
9 | | |
10 | | #include "mozilla/DeclarationBlock.h" |
11 | | #include "mozilla/ServoBindings.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace dom { |
15 | | |
16 | | // -- CSSPageRuleDeclaration --------------------------------------- |
17 | | |
18 | | CSSPageRuleDeclaration::CSSPageRuleDeclaration( |
19 | | already_AddRefed<RawServoDeclarationBlock> aDecls) |
20 | | : mDecls(new DeclarationBlock(std::move(aDecls))) |
21 | 0 | { |
22 | 0 | } |
23 | | |
24 | | CSSPageRuleDeclaration::~CSSPageRuleDeclaration() |
25 | 0 | { |
26 | 0 | mDecls->SetOwningRule(nullptr); |
27 | 0 | } |
28 | | |
29 | | // QueryInterface implementation for CSSPageRuleDeclaration |
30 | 0 | NS_INTERFACE_MAP_BEGIN(CSSPageRuleDeclaration) |
31 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
32 | 0 | // We forward the cycle collection interfaces to Rule(), which is |
33 | 0 | // never null (in fact, we're part of that object!) |
34 | 0 | if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) || |
35 | 0 | aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { |
36 | 0 | return Rule()->QueryInterface(aIID, aInstancePtr); |
37 | 0 | } |
38 | 0 | else |
39 | 0 | NS_IMPL_QUERY_TAIL_INHERITING(nsDOMCSSDeclaration) |
40 | | |
41 | | NS_IMPL_ADDREF_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule()) |
42 | | NS_IMPL_RELEASE_USING_AGGREGATOR(CSSPageRuleDeclaration, Rule()) |
43 | | |
44 | | /* nsDOMCSSDeclaration implementation */ |
45 | | |
46 | | css::Rule* |
47 | | CSSPageRuleDeclaration::GetParentRule() |
48 | 0 | { |
49 | 0 | return Rule(); |
50 | 0 | } |
51 | | |
52 | | nsINode* |
53 | | CSSPageRuleDeclaration::GetParentObject() |
54 | 0 | { |
55 | 0 | return Rule()->GetParentObject(); |
56 | 0 | } |
57 | | |
58 | | DeclarationBlock* |
59 | | CSSPageRuleDeclaration::GetOrCreateCSSDeclaration(Operation aOperation, |
60 | | DeclarationBlock** aCreated) |
61 | 0 | { |
62 | 0 | return mDecls; |
63 | 0 | } |
64 | | |
65 | | nsresult |
66 | | CSSPageRuleDeclaration::SetCSSDeclaration(DeclarationBlock* aDecl, |
67 | | MutationClosureData* aClosureData) |
68 | 0 | { |
69 | 0 | MOZ_ASSERT(aDecl, "must be non-null"); |
70 | 0 | CSSPageRule* rule = Rule(); |
71 | 0 |
|
72 | 0 | if (aDecl != mDecls) { |
73 | 0 | mDecls->SetOwningRule(nullptr); |
74 | 0 | RefPtr<DeclarationBlock> decls = aDecl; |
75 | 0 | Servo_PageRule_SetStyle(rule->Raw(), decls->Raw()); |
76 | 0 | mDecls = decls.forget(); |
77 | 0 | mDecls->SetOwningRule(rule); |
78 | 0 | } |
79 | 0 |
|
80 | 0 | return NS_OK; |
81 | 0 | } |
82 | | |
83 | | nsIDocument* |
84 | | CSSPageRuleDeclaration::DocToUpdate() |
85 | 0 | { |
86 | 0 | return nullptr; |
87 | 0 | } |
88 | | |
89 | | nsDOMCSSDeclaration::ParsingEnvironment |
90 | | CSSPageRuleDeclaration::GetParsingEnvironment( |
91 | | nsIPrincipal* aSubjectPrincipal) const |
92 | 0 | { |
93 | 0 | return GetParsingEnvironmentForRule(Rule()); |
94 | 0 | } |
95 | | |
96 | | // -- CSSPageRule -------------------------------------------------- |
97 | | |
98 | | CSSPageRule::CSSPageRule(RefPtr<RawServoPageRule> aRawRule, |
99 | | StyleSheet* aSheet, |
100 | | css::Rule* aParentRule, |
101 | | uint32_t aLine, |
102 | | uint32_t aColumn) |
103 | | : css::Rule(aSheet, aParentRule, aLine, aColumn) |
104 | | , mRawRule(std::move(aRawRule)) |
105 | | , mDecls(Servo_PageRule_GetStyle(mRawRule).Consume()) |
106 | 0 | { |
107 | 0 | } |
108 | | |
109 | | NS_IMPL_ADDREF_INHERITED(CSSPageRule, css::Rule) |
110 | | NS_IMPL_RELEASE_INHERITED(CSSPageRule, css::Rule) |
111 | | |
112 | | // QueryInterface implementation for PageRule |
113 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSPageRule) |
114 | 0 | NS_INTERFACE_MAP_END_INHERITING(css::Rule) |
115 | | |
116 | | NS_IMPL_CYCLE_COLLECTION_CLASS(CSSPageRule) |
117 | | |
118 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSPageRule, css::Rule) |
119 | 0 | // Keep this in sync with IsCCLeaf. |
120 | 0 |
|
121 | 0 | // Trace the wrapper for our declaration. This just expands out |
122 | 0 | // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use |
123 | 0 | // directly because the wrapper is on the declaration, not on us. |
124 | 0 | tmp->mDecls.TraceWrapper(aCallbacks, aClosure); |
125 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
126 | | |
127 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSPageRule, css::Rule) |
128 | 0 | // Keep this in sync with IsCCLeaf. |
129 | 0 |
|
130 | 0 | // Unlink the wrapper for our declaraton. This just expands out |
131 | 0 | // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use |
132 | 0 | // directly because the wrapper is on the declaration, not on us. |
133 | 0 | tmp->mDecls.ReleaseWrapper(static_cast<nsISupports*>(p)); |
134 | 0 | tmp->mDecls.mDecls->SetOwningRule(nullptr); |
135 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
136 | | |
137 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSPageRule, css::Rule) |
138 | 0 | // Keep this in sync with IsCCLeaf. |
139 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
140 | | |
141 | | bool |
142 | | CSSPageRule::IsCCLeaf() const |
143 | 0 | { |
144 | 0 | if (!Rule::IsCCLeaf()) { |
145 | 0 | return false; |
146 | 0 | } |
147 | 0 | |
148 | 0 | return !mDecls.PreservingWrapper(); |
149 | 0 | } |
150 | | |
151 | | size_t |
152 | | CSSPageRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const |
153 | 0 | { |
154 | 0 | // TODO Implement this! |
155 | 0 | return aMallocSizeOf(this); |
156 | 0 | } |
157 | | |
158 | | #ifdef DEBUG |
159 | | void |
160 | | CSSPageRule::List(FILE* out, int32_t aIndent) const |
161 | | { |
162 | | nsAutoCString str; |
163 | | for (int32_t i = 0; i < aIndent; i++) { |
164 | | str.AppendLiteral(" "); |
165 | | } |
166 | | Servo_PageRule_Debug(mRawRule, &str); |
167 | | fprintf_stderr(out, "%s\n", str.get()); |
168 | | } |
169 | | #endif |
170 | | |
171 | | /* CSSRule implementation */ |
172 | | |
173 | | void |
174 | | CSSPageRule::GetCssText(nsAString& aCssText) const |
175 | 0 | { |
176 | 0 | Servo_PageRule_GetCssText(mRawRule, &aCssText); |
177 | 0 | } |
178 | | |
179 | | /* CSSPageRule implementation */ |
180 | | |
181 | | nsICSSDeclaration* |
182 | | CSSPageRule::Style() |
183 | 0 | { |
184 | 0 | return &mDecls; |
185 | 0 | } |
186 | | |
187 | | JSObject* |
188 | | CSSPageRule::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
189 | 0 | { |
190 | 0 | return CSSPageRule_Binding::Wrap(aCx, this, aGivenProto); |
191 | 0 | } |
192 | | |
193 | | } // namespace dom |
194 | | } // namespace mozilla |