Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / layout / style / CSSFontFaceRule.cpp
blob1115c9223f5012c235d4e68b56f1fad0aad1f382
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 #include "mozilla/dom/CSSFontFaceRule.h"
9 #include "mozilla/dom/CSSFontFaceRuleBinding.h"
10 #include "mozilla/dom/CSSStyleDeclarationBinding.h"
11 #include "mozilla/ServoBindings.h"
12 #include "nsCSSProps.h"
14 using namespace mozilla;
15 using namespace mozilla::dom;
17 // -------------------------------------------
18 // CSSFontFaceRuleDecl and related routines
21 // QueryInterface implementation for CSSFontFaceRuleDecl
22 NS_INTERFACE_MAP_BEGIN(CSSFontFaceRuleDecl)
23 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
24 NS_INTERFACE_MAP_ENTRY(nsICSSDeclaration)
25 NS_INTERFACE_MAP_ENTRY(nsISupports)
26 // We forward the cycle collection interfaces to ContainingRule(), which is
27 // never null (in fact, we're part of that object!)
28 if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
29 aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
30 return ContainingRule()->QueryInterface(aIID, aInstancePtr);
31 } else
32 NS_INTERFACE_MAP_END
34 NS_IMPL_ADDREF_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule())
35 NS_IMPL_RELEASE_USING_AGGREGATOR(CSSFontFaceRuleDecl, ContainingRule())
37 void CSSFontFaceRuleDecl::SetRawAfterClone(
38 RefPtr<StyleLockedFontFaceRule> aRaw) {
39 mRawRule = std::move(aRaw);
42 // helper for string GetPropertyValue and RemovePropertyValue
43 void CSSFontFaceRuleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID,
44 nsACString& aResult) const {
45 MOZ_ASSERT(aResult.IsEmpty());
46 Servo_FontFaceRule_GetDescriptorCssText(mRawRule, aFontDescID, &aResult);
49 void CSSFontFaceRuleDecl::GetCssText(nsACString& aCssText) {
50 MOZ_ASSERT(aCssText.IsEmpty());
51 Servo_FontFaceRule_GetDeclCssText(mRawRule, &aCssText);
54 void CSSFontFaceRuleDecl::SetCssText(const nsACString& aCssText,
55 nsIPrincipal* aSubjectPrincipal,
56 ErrorResult& aRv) {
57 if (ContainingRule()->IsReadOnly()) {
58 return;
60 // bug 443978
61 aRv.ThrowNotSupportedError(
62 "Can't set cssText on CSSFontFaceRule declarations");
65 void CSSFontFaceRuleDecl::GetPropertyValue(const nsACString& aPropName,
66 nsACString& aResult) {
67 aResult.Truncate();
68 nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(aPropName);
69 if (descID != eCSSFontDesc_UNKNOWN) {
70 GetPropertyValue(descID, aResult);
74 void CSSFontFaceRuleDecl::RemoveProperty(const nsACString& aPropName,
75 nsACString& aResult,
76 ErrorResult& aRv) {
77 nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(aPropName);
78 NS_ASSERTION(descID >= eCSSFontDesc_UNKNOWN && descID < eCSSFontDesc_COUNT,
79 "LookupFontDesc returned value out of range");
81 if (ContainingRule()->IsReadOnly()) {
82 return;
85 aResult.Truncate();
86 if (descID != eCSSFontDesc_UNKNOWN) {
87 GetPropertyValue(descID, aResult);
88 Servo_FontFaceRule_ResetDescriptor(mRawRule, descID);
92 void CSSFontFaceRuleDecl::GetPropertyPriority(const nsACString& aPropName,
93 nsACString& aResult) {
94 // font descriptors do not have priorities at present
95 aResult.Truncate();
98 void CSSFontFaceRuleDecl::SetProperty(const nsACString& aPropName,
99 const nsACString& aValue,
100 const nsACString& aPriority,
101 nsIPrincipal* aSubjectPrincipal,
102 ErrorResult& aRv) {
103 // FIXME(heycam): If we are changing unicode-range, then a FontFace object
104 // representing this rule must have its mUnicodeRange value invalidated.
106 if (ContainingRule()->IsReadOnly()) {
107 return;
110 // bug 443978
111 aRv.ThrowNotSupportedError(
112 "Can't set properties on CSSFontFaceRule declarations");
115 uint32_t CSSFontFaceRuleDecl::Length() {
116 return Servo_FontFaceRule_Length(mRawRule);
119 void CSSFontFaceRuleDecl::IndexedGetter(uint32_t aIndex, bool& aFound,
120 nsACString& aResult) {
121 nsCSSFontDesc id = Servo_FontFaceRule_IndexGetter(mRawRule, aIndex);
122 if (id != eCSSFontDesc_UNKNOWN) {
123 aFound = true;
124 aResult.Assign(nsCSSProps::GetStringValue(id));
125 } else {
126 aFound = false;
130 css::Rule* CSSFontFaceRuleDecl::GetParentRule() { return ContainingRule(); }
132 nsINode* CSSFontFaceRuleDecl::GetAssociatedNode() const {
133 return ContainingRule()->GetAssociatedDocumentOrShadowRoot();
136 nsISupports* CSSFontFaceRuleDecl::GetParentObject() const {
137 return ContainingRule()->GetParentObject();
140 JSObject* CSSFontFaceRuleDecl::WrapObject(JSContext* cx,
141 JS::Handle<JSObject*> aGivenProto) {
142 // If this changes to use a different type, remove the 'concrete'
143 // annotation from CSSStyleDeclaration.
144 return CSSStyleDeclaration_Binding::Wrap(cx, this, aGivenProto);
147 // -------------------------------------------
148 // CSSFontFaceRule
151 NS_IMPL_CYCLE_COLLECTION_CLASS(CSSFontFaceRule)
153 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSFontFaceRule,
154 mozilla::css::Rule)
155 // Keep this in sync with IsCCLeaf.
157 // Trace the wrapper for our declaration. This just expands out
158 // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
159 // directly because the wrapper is on the declaration, not on us.
160 tmp->mDecl.TraceWrapper(aCallbacks, aClosure);
161 NS_IMPL_CYCLE_COLLECTION_TRACE_END
163 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSFontFaceRule)
164 // Keep this in sync with IsCCLeaf.
166 // Unlink the wrapper for our declaration.
168 // Note that this has to happen before unlinking css::Rule.
169 tmp->UnlinkDeclarationWrapper(tmp->mDecl);
170 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(mozilla::css::Rule)
172 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSFontFaceRule,
173 mozilla::css::Rule)
174 // Keep this in sync with IsCCLeaf.
175 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
177 bool CSSFontFaceRule::IsCCLeaf() const {
178 if (!Rule::IsCCLeaf()) {
179 return false;
182 return !mDecl.PreservingWrapper();
185 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(CSSFontFaceRule,
186 mozilla::css::Rule)
188 #ifdef DEBUG
189 void CSSFontFaceRule::List(FILE* out, int32_t aIndent) const {
190 nsAutoCString str;
191 for (int32_t i = 0; i < aIndent; i++) {
192 str.AppendLiteral(" ");
194 Servo_FontFaceRule_Debug(Raw(), &str);
195 fprintf_stderr(out, "%s\n", str.get());
197 #endif
199 StyleCssRuleType CSSFontFaceRule::Type() const {
200 return StyleCssRuleType::FontFace;
203 void CSSFontFaceRule::SetRawAfterClone(RefPtr<StyleLockedFontFaceRule> aRaw) {
204 mDecl.SetRawAfterClone(std::move(aRaw));
207 void CSSFontFaceRule::GetCssText(nsACString& aCssText) const {
208 aCssText.Truncate();
209 Servo_FontFaceRule_GetCssText(Raw(), &aCssText);
212 nsICSSDeclaration* CSSFontFaceRule::Style() { return &mDecl; }
214 /* virtual */
215 size_t CSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
216 return aMallocSizeOf(this);
219 /* virtual */
220 JSObject* CSSFontFaceRule::WrapObject(JSContext* aCx,
221 JS::Handle<JSObject*> aGivenProto) {
222 return CSSFontFaceRule_Binding::Wrap(aCx, this, aGivenProto);