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
);
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
,
57 if (ContainingRule()->IsReadOnly()) {
61 aRv
.ThrowNotSupportedError(
62 "Can't set cssText on CSSFontFaceRule declarations");
65 void CSSFontFaceRuleDecl::GetPropertyValue(const nsACString
& aPropName
,
66 nsACString
& aResult
) {
68 nsCSSFontDesc descID
= nsCSSProps::LookupFontDesc(aPropName
);
69 if (descID
!= eCSSFontDesc_UNKNOWN
) {
70 GetPropertyValue(descID
, aResult
);
74 void CSSFontFaceRuleDecl::RemoveProperty(const nsACString
& aPropName
,
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()) {
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
98 void CSSFontFaceRuleDecl::SetProperty(const nsACString
& aPropName
,
99 const nsACString
& aValue
,
100 const nsACString
& aPriority
,
101 nsIPrincipal
* aSubjectPrincipal
,
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()) {
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
) {
124 aResult
.Assign(nsCSSProps::GetStringValue(id
));
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 // -------------------------------------------
151 NS_IMPL_CYCLE_COLLECTION_CLASS(CSSFontFaceRule
)
153 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSFontFaceRule
,
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
,
174 // Keep this in sync with IsCCLeaf.
175 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
177 bool CSSFontFaceRule::IsCCLeaf() const {
178 if (!Rule::IsCCLeaf()) {
182 return !mDecl
.PreservingWrapper();
185 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(CSSFontFaceRule
,
189 void CSSFontFaceRule::List(FILE* out
, int32_t aIndent
) const {
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());
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 {
209 Servo_FontFaceRule_GetCssText(Raw(), &aCssText
);
212 nsICSSDeclaration
* CSSFontFaceRule::Style() { return &mDecl
; }
215 size_t CSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const {
216 return aMallocSizeOf(this);
220 JSObject
* CSSFontFaceRule::WrapObject(JSContext
* aCx
,
221 JS::Handle
<JSObject
*> aGivenProto
) {
222 return CSSFontFaceRule_Binding::Wrap(aCx
, this, aGivenProto
);