/src/mozilla-central/layout/style/CSSFontFaceRule.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/CSSFontFaceRule.h" |
8 | | |
9 | | #include "mozilla/dom/CSSFontFaceRuleBinding.h" |
10 | | #include "mozilla/dom/CSSStyleDeclarationBinding.h" |
11 | | #include "mozilla/ServoBindings.h" |
12 | | #include "nsCSSProps.h" |
13 | | |
14 | | using namespace mozilla; |
15 | | using namespace mozilla::dom; |
16 | | |
17 | | // ------------------------------------------- |
18 | | // CSSFontFaceRuleDecl and related routines |
19 | | // |
20 | | |
21 | | // QueryInterface implementation for CSSFontFaceRuleDecl |
22 | 0 | NS_INTERFACE_MAP_BEGIN(CSSFontFaceRuleDecl) |
23 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
24 | 0 | NS_INTERFACE_MAP_ENTRY(nsICSSDeclaration) |
25 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
26 | 0 | // We forward the cycle collection interfaces to ContainingRule(), which is |
27 | 0 | // never null (in fact, we're part of that object!) |
28 | 0 | if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) || |
29 | 0 | aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) { |
30 | 0 | return ContainingRule()->QueryInterface(aIID, aInstancePtr); |
31 | 0 | } |
32 | 0 | else |
33 | 0 | NS_INTERFACE_MAP_END |
34 | | |
35 | | NS_IMPL_ADDREF_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule()) |
36 | | NS_IMPL_RELEASE_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule()) |
37 | | |
38 | | // helper for string GetPropertyValue and RemovePropertyValue |
39 | | void |
40 | | CSSFontFaceRuleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID, |
41 | | nsAString& aResult) const |
42 | 0 | { |
43 | 0 | MOZ_ASSERT(aResult.IsEmpty()); |
44 | 0 | Servo_FontFaceRule_GetDescriptorCssText(mRawRule, aFontDescID, &aResult); |
45 | 0 | } |
46 | | |
47 | | void |
48 | | CSSFontFaceRuleDecl::GetCssText(nsAString& aCssText) |
49 | 0 | { |
50 | 0 | aCssText.Truncate(); |
51 | 0 | Servo_FontFaceRule_GetDeclCssText(mRawRule, &aCssText); |
52 | 0 | } |
53 | | |
54 | | void |
55 | | CSSFontFaceRuleDecl::SetCssText(const nsAString& aCssText, |
56 | | nsIPrincipal* aSubjectPrincipal, |
57 | | ErrorResult& aRv) |
58 | 0 | { |
59 | 0 | aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); // bug 443978 |
60 | 0 | } |
61 | | |
62 | | NS_IMETHODIMP |
63 | | CSSFontFaceRuleDecl::GetPropertyValue(const nsAString& aPropName, |
64 | | nsAString& aResult) |
65 | 0 | { |
66 | 0 | aResult.Truncate(); |
67 | 0 | GetPropertyValue(nsCSSProps::LookupFontDesc(aPropName), aResult); |
68 | 0 | return NS_OK; |
69 | 0 | } |
70 | | |
71 | | NS_IMETHODIMP |
72 | | CSSFontFaceRuleDecl::RemoveProperty(const nsAString& aPropName, |
73 | | nsAString& aResult) |
74 | 0 | { |
75 | 0 | nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(aPropName); |
76 | 0 | NS_ASSERTION(descID >= eCSSFontDesc_UNKNOWN && |
77 | 0 | descID < eCSSFontDesc_COUNT, |
78 | 0 | "LookupFontDesc returned value out of range"); |
79 | 0 |
|
80 | 0 | aResult.Truncate(); |
81 | 0 | if (descID != eCSSFontDesc_UNKNOWN) { |
82 | 0 | GetPropertyValue(descID, aResult); |
83 | 0 | Servo_FontFaceRule_ResetDescriptor(mRawRule, descID); |
84 | 0 | } |
85 | 0 | return NS_OK; |
86 | 0 | } |
87 | | |
88 | | void |
89 | | CSSFontFaceRuleDecl::GetPropertyPriority(const nsAString& aPropName, |
90 | | nsAString& aResult) |
91 | 0 | { |
92 | 0 | // font descriptors do not have priorities at present |
93 | 0 | aResult.Truncate(); |
94 | 0 | } |
95 | | |
96 | | NS_IMETHODIMP |
97 | | CSSFontFaceRuleDecl::SetProperty(const nsAString& aPropName, |
98 | | const nsAString& aValue, |
99 | | const nsAString& aPriority, |
100 | | nsIPrincipal* aSubjectPrincipal) |
101 | 0 | { |
102 | 0 | // FIXME(heycam): If we are changing unicode-range, then a FontFace object |
103 | 0 | // representing this rule must have its mUnicodeRange value invalidated. |
104 | 0 |
|
105 | 0 | return NS_ERROR_NOT_IMPLEMENTED; // bug 443978 |
106 | 0 | } |
107 | | |
108 | | uint32_t |
109 | | CSSFontFaceRuleDecl::Length() |
110 | 0 | { |
111 | 0 | return Servo_FontFaceRule_Length(mRawRule); |
112 | 0 | } |
113 | | |
114 | | void |
115 | | CSSFontFaceRuleDecl::IndexedGetter(uint32_t aIndex, bool& aFound, |
116 | | nsAString& aResult) |
117 | 0 | { |
118 | 0 | nsCSSFontDesc id = Servo_FontFaceRule_IndexGetter(mRawRule, aIndex); |
119 | 0 | if (id != eCSSFontDesc_UNKNOWN) { |
120 | 0 | aFound = true; |
121 | 0 | aResult.AssignASCII(nsCSSProps::GetStringValue(id).get()); |
122 | 0 | } else { |
123 | 0 | aFound = false; |
124 | 0 | } |
125 | 0 | } |
126 | | |
127 | | css::Rule* |
128 | | CSSFontFaceRuleDecl::GetParentRule() |
129 | 0 | { |
130 | 0 | return ContainingRule(); |
131 | 0 | } |
132 | | |
133 | | nsINode* |
134 | | CSSFontFaceRuleDecl::GetParentObject() |
135 | 0 | { |
136 | 0 | return ContainingRule()->GetParentObject(); |
137 | 0 | } |
138 | | |
139 | | JSObject* |
140 | | CSSFontFaceRuleDecl::WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) |
141 | 0 | { |
142 | 0 | return CSSStyleDeclaration_Binding::Wrap(cx, this, aGivenProto); |
143 | 0 | } |
144 | | |
145 | | // ------------------------------------------- |
146 | | // CSSFontFaceRule |
147 | | // |
148 | | |
149 | | NS_IMPL_CYCLE_COLLECTION_CLASS(CSSFontFaceRule) |
150 | | |
151 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSFontFaceRule, |
152 | 0 | mozilla::css::Rule) |
153 | 0 | // Keep this in sync with IsCCLeaf. |
154 | 0 |
|
155 | 0 | // Trace the wrapper for our declaration. This just expands out |
156 | 0 | // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use |
157 | 0 | // directly because the wrapper is on the declaration, not on us. |
158 | 0 | tmp->mDecl.TraceWrapper(aCallbacks, aClosure); |
159 | 0 | NS_IMPL_CYCLE_COLLECTION_TRACE_END |
160 | | |
161 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(CSSFontFaceRule, |
162 | 0 | mozilla::css::Rule) |
163 | 0 | // Keep this in sync with IsCCLeaf. |
164 | 0 |
|
165 | 0 | // Unlink the wrapper for our declaraton. This just expands out |
166 | 0 | // NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use |
167 | 0 | // directly because the wrapper is on the declaration, not on us. |
168 | 0 | tmp->mDecl.ReleaseWrapper(static_cast<nsISupports*>(p)); |
169 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
170 | | |
171 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSFontFaceRule, |
172 | 0 | mozilla::css::Rule) |
173 | 0 | // Keep this in sync with IsCCLeaf. |
174 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
175 | | |
176 | | bool |
177 | | CSSFontFaceRule::IsCCLeaf() const |
178 | 0 | { |
179 | 0 | if (!Rule::IsCCLeaf()) { |
180 | 0 | return false; |
181 | 0 | } |
182 | 0 | |
183 | 0 | return !mDecl.PreservingWrapper(); |
184 | 0 | } |
185 | | |
186 | | NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(CSSFontFaceRule, mozilla::css::Rule) |
187 | | |
188 | | #ifdef DEBUG |
189 | | void |
190 | | CSSFontFaceRule::List(FILE* out, int32_t aIndent) const |
191 | | { |
192 | | nsAutoCString str; |
193 | | for (int32_t i = 0; i < aIndent; i++) { |
194 | | str.AppendLiteral(" "); |
195 | | } |
196 | | Servo_FontFaceRule_Debug(Raw(), &str); |
197 | | fprintf_stderr(out, "%s\n", str.get()); |
198 | | } |
199 | | #endif |
200 | | |
201 | | uint16_t |
202 | | CSSFontFaceRule::Type() const |
203 | 0 | { |
204 | 0 | return CSSRule_Binding::FONT_FACE_RULE; |
205 | 0 | } |
206 | | |
207 | | void |
208 | | CSSFontFaceRule::GetCssText(nsAString& aCssText) const |
209 | 0 | { |
210 | 0 | aCssText.Truncate(); |
211 | 0 | Servo_FontFaceRule_GetCssText(Raw(), &aCssText); |
212 | 0 | } |
213 | | |
214 | | nsICSSDeclaration* |
215 | | CSSFontFaceRule::Style() |
216 | 0 | { |
217 | 0 | return &mDecl; |
218 | 0 | } |
219 | | |
220 | | /* virtual */ size_t |
221 | | CSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const |
222 | 0 | { |
223 | 0 | return aMallocSizeOf(this); |
224 | 0 | } |
225 | | |
226 | | /* virtual */ JSObject* |
227 | | CSSFontFaceRule::WrapObject(JSContext* aCx, |
228 | | JS::Handle<JSObject*> aGivenProto) |
229 | 0 | { |
230 | 0 | return CSSFontFaceRule_Binding::Wrap(aCx, this, aGivenProto); |
231 | 0 | } |