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 #ifndef mozilla_CSSFontFaceRule_h
8 #define mozilla_CSSFontFaceRule_h
10 #include "mozilla/ServoBindingTypes.h"
11 #include "mozilla/css/Rule.h"
12 #include "nsICSSDeclaration.h"
17 // A CSSFontFaceRuleDecl is always embeded in a CSSFontFaceRule.
18 class CSSFontFaceRule
;
19 class CSSFontFaceRuleDecl final
: public nsICSSDeclaration
{
21 NS_DECL_ISUPPORTS_INHERITED
22 NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER
24 nsINode
* GetAssociatedNode() const final
;
25 nsISupports
* GetParentObject() const final
;
26 void IndexedGetter(uint32_t aIndex
, bool& aFound
,
27 nsACString
& aPropName
) final
;
29 void GetPropertyValue(nsCSSFontDesc aFontDescID
, nsACString
& aResult
) const;
31 JSObject
* WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) final
;
34 // For accessing the constructor.
35 friend class CSSFontFaceRule
;
37 explicit CSSFontFaceRuleDecl(already_AddRefed
<RawServoFontFaceRule
> aDecl
)
38 : mRawRule(std::move(aDecl
)) {}
40 ~CSSFontFaceRuleDecl() = default;
42 inline CSSFontFaceRule
* ContainingRule();
43 inline const CSSFontFaceRule
* ContainingRule() const;
45 RefPtr
<RawServoFontFaceRule
> mRawRule
;
48 void* operator new(size_t size
) noexcept(true) = delete;
51 class CSSFontFaceRule final
: public css::Rule
{
53 CSSFontFaceRule(already_AddRefed
<RawServoFontFaceRule
> aRawRule
,
54 StyleSheet
* aSheet
, css::Rule
* aParentRule
, uint32_t aLine
,
56 : css::Rule(aSheet
, aParentRule
, aLine
, aColumn
),
57 mDecl(std::move(aRawRule
)) {}
59 CSSFontFaceRule(const CSSFontFaceRule
&) = delete;
61 NS_DECL_ISUPPORTS_INHERITED
62 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSFontFaceRule
,
64 bool IsCCLeaf() const final
;
66 RawServoFontFaceRule
* Raw() const { return mDecl
.mRawRule
; }
69 uint16_t Type() const final
;
70 void GetCssText(nsACString
& aCssText
) const final
;
71 nsICSSDeclaration
* Style();
73 // Methods of mozilla::css::Rule
74 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const final
;
76 JSObject
* WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) final
;
79 void List(FILE* out
= stdout
, int32_t aIndent
= 0) const final
;
83 virtual ~CSSFontFaceRule() = default;
85 // For computing the offset of mDecl.
86 friend class CSSFontFaceRuleDecl
;
88 CSSFontFaceRuleDecl mDecl
;
91 inline CSSFontFaceRule
* CSSFontFaceRuleDecl::ContainingRule() {
92 return reinterpret_cast<CSSFontFaceRule
*>(reinterpret_cast<char*>(this) -
93 offsetof(CSSFontFaceRule
, mDecl
));
96 inline const CSSFontFaceRule
* CSSFontFaceRuleDecl::ContainingRule() const {
97 return reinterpret_cast<const CSSFontFaceRule
*>(
98 reinterpret_cast<const char*>(this) - offsetof(CSSFontFaceRule
, mDecl
));
102 } // namespace mozilla
104 #endif // mozilla_CSSFontFaceRule_h