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 // helper for string GetPropertyValue and RemovePropertyValue
38 void CSSFontFaceRuleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID
,
39 nsACString
& aResult
) const {
40 MOZ_ASSERT(aResult
.IsEmpty());
41 Servo_FontFaceRule_GetDescriptorCssText(mRawRule
, aFontDescID
, &aResult
);
44 void CSSFontFaceRuleDecl::GetCssText(nsACString
& aCssText
) {
45 MOZ_ASSERT(aCssText
.IsEmpty());
46 Servo_FontFaceRule_GetDeclCssText(mRawRule
, &aCssText
);
49 void CSSFontFaceRuleDecl::SetCssText(const nsACString
& aCssText
,
50 nsIPrincipal
* aSubjectPrincipal
,
52 if (ContainingRule()->IsReadOnly()) {
56 aRv
.ThrowNotSupportedError(
57 "Can't set cssText on CSSFontFaceRule declarations");
61 CSSFontFaceRuleDecl::GetPropertyValue(const nsACString
& aPropName
,
62 nsACString
& aResult
) {
64 nsCSSFontDesc descID
= nsCSSProps::LookupFontDesc(aPropName
);
65 if (descID
!= eCSSFontDesc_UNKNOWN
) {
66 GetPropertyValue(descID
, aResult
);
71 void CSSFontFaceRuleDecl::RemoveProperty(const nsACString
& aPropName
,
74 nsCSSFontDesc descID
= nsCSSProps::LookupFontDesc(aPropName
);
75 NS_ASSERTION(descID
>= eCSSFontDesc_UNKNOWN
&& descID
< eCSSFontDesc_COUNT
,
76 "LookupFontDesc returned value out of range");
78 if (ContainingRule()->IsReadOnly()) {
83 if (descID
!= eCSSFontDesc_UNKNOWN
) {
84 GetPropertyValue(descID
, aResult
);
85 Servo_FontFaceRule_ResetDescriptor(mRawRule
, descID
);
89 void CSSFontFaceRuleDecl::GetPropertyPriority(const nsACString
& aPropName
,
90 nsACString
& aResult
) {
91 // font descriptors do not have priorities at present
95 void CSSFontFaceRuleDecl::SetProperty(const nsACString
& aPropName
,
96 const nsACString
& aValue
,
97 const nsACString
& aPriority
,
98 nsIPrincipal
* aSubjectPrincipal
,
100 // FIXME(heycam): If we are changing unicode-range, then a FontFace object
101 // representing this rule must have its mUnicodeRange value invalidated.
103 if (ContainingRule()->IsReadOnly()) {
108 aRv
.ThrowNotSupportedError(
109 "Can't set properties on CSSFontFaceRule declarations");
112 uint32_t CSSFontFaceRuleDecl::Length() {
113 return Servo_FontFaceRule_Length(mRawRule
);
116 void CSSFontFaceRuleDecl::IndexedGetter(uint32_t aIndex
, bool& aFound
,
117 nsACString
& aResult
) {
118 nsCSSFontDesc id
= Servo_FontFaceRule_IndexGetter(mRawRule
, aIndex
);
119 if (id
!= eCSSFontDesc_UNKNOWN
) {
121 aResult
.Assign(nsCSSProps::GetStringValue(id
));
127 css::Rule
* CSSFontFaceRuleDecl::GetParentRule() { return ContainingRule(); }
129 nsINode
* CSSFontFaceRuleDecl::GetAssociatedNode() const {
130 return ContainingRule()->GetAssociatedDocumentOrShadowRoot();
133 nsISupports
* CSSFontFaceRuleDecl::GetParentObject() const {
134 return ContainingRule()->GetParentObject();
137 JSObject
* CSSFontFaceRuleDecl::WrapObject(JSContext
* cx
,
138 JS::Handle
<JSObject
*> aGivenProto
) {
139 // If this changes to use a different type, remove the 'concrete'
140 // annotation from CSSStyleDeclaration.
141 return CSSStyleDeclaration_Binding::Wrap(cx
, this, aGivenProto
);
144 // -------------------------------------------
148 NS_IMPL_CYCLE_COLLECTION_CLASS(CSSFontFaceRule
)
150 NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(CSSFontFaceRule
,
152 // Keep this in sync with IsCCLeaf.
154 // Trace the wrapper for our declaration. This just expands out
155 // NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
156 // directly because the wrapper is on the declaration, not on us.
157 tmp
->mDecl
.TraceWrapper(aCallbacks
, aClosure
);
158 NS_IMPL_CYCLE_COLLECTION_TRACE_END
160 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSFontFaceRule
)
161 // Keep this in sync with IsCCLeaf.
163 // Unlink the wrapper for our declaration.
165 // Note that this has to happen before unlinking css::Rule.
166 tmp
->UnlinkDeclarationWrapper(tmp
->mDecl
);
167 NS_IMPL_CYCLE_COLLECTION_UNLINK_END_INHERITED(mozilla::css::Rule
)
169 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(CSSFontFaceRule
,
171 // Keep this in sync with IsCCLeaf.
172 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
174 bool CSSFontFaceRule::IsCCLeaf() const {
175 if (!Rule::IsCCLeaf()) {
179 return !mDecl
.PreservingWrapper();
182 NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(CSSFontFaceRule
,
186 void CSSFontFaceRule::List(FILE* out
, int32_t aIndent
) const {
188 for (int32_t i
= 0; i
< aIndent
; i
++) {
189 str
.AppendLiteral(" ");
191 Servo_FontFaceRule_Debug(Raw(), &str
);
192 fprintf_stderr(out
, "%s\n", str
.get());
196 uint16_t CSSFontFaceRule::Type() const {
197 return CSSRule_Binding::FONT_FACE_RULE
;
200 void CSSFontFaceRule::GetCssText(nsACString
& aCssText
) const {
202 Servo_FontFaceRule_GetCssText(Raw(), &aCssText
);
205 nsICSSDeclaration
* CSSFontFaceRule::Style() { return &mDecl
; }
208 size_t CSSFontFaceRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf
) const {
209 return aMallocSizeOf(this);
213 JSObject
* CSSFontFaceRule::WrapObject(JSContext
* aCx
,
214 JS::Handle
<JSObject
*> aGivenProto
) {
215 return CSSFontFaceRule_Binding::Wrap(aCx
, this, aGivenProto
);