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"
14 namespace mozilla::dom
{
16 // A CSSFontFaceRuleDecl is always embeded in a CSSFontFaceRule.
17 class CSSFontFaceRule
;
18 class CSSFontFaceRuleDecl final
: public nsICSSDeclaration
{
20 NS_DECL_ISUPPORTS_INHERITED
21 NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER
23 nsINode
* GetAssociatedNode() const final
;
24 nsISupports
* GetParentObject() const final
;
25 void IndexedGetter(uint32_t aIndex
, bool& aFound
,
26 nsACString
& aPropName
) final
;
28 void GetPropertyValue(nsCSSFontDesc aFontDescID
, nsACString
& aResult
) const;
30 JSObject
* WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) final
;
33 // For accessing the constructor.
34 friend class CSSFontFaceRule
;
36 explicit CSSFontFaceRuleDecl(already_AddRefed
<StyleLockedFontFaceRule
> aDecl
)
37 : mRawRule(std::move(aDecl
)) {}
39 ~CSSFontFaceRuleDecl() = default;
41 inline CSSFontFaceRule
* ContainingRule();
42 inline const CSSFontFaceRule
* ContainingRule() const;
44 RefPtr
<StyleLockedFontFaceRule
> mRawRule
;
45 void SetRawAfterClone(RefPtr
<StyleLockedFontFaceRule
>);
48 void* operator new(size_t size
) noexcept(true) = delete;
51 class CSSFontFaceRule final
: public css::Rule
{
53 CSSFontFaceRule(already_AddRefed
<StyleLockedFontFaceRule
> 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 StyleLockedFontFaceRule
* Raw() const { return mDecl
.mRawRule
; }
67 void SetRawAfterClone(RefPtr
<StyleLockedFontFaceRule
>);
70 StyleCssRuleType
Type() const final
;
71 void GetCssText(nsACString
& aCssText
) const final
;
72 nsICSSDeclaration
* Style();
74 // Methods of mozilla::css::Rule
75 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const final
;
77 JSObject
* WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) final
;
80 void List(FILE* out
= stdout
, int32_t aIndent
= 0) const final
;
84 virtual ~CSSFontFaceRule() = default;
86 // For computing the offset of mDecl.
87 friend class CSSFontFaceRuleDecl
;
89 CSSFontFaceRuleDecl mDecl
;
92 inline CSSFontFaceRule
* CSSFontFaceRuleDecl::ContainingRule() {
93 return reinterpret_cast<CSSFontFaceRule
*>(reinterpret_cast<char*>(this) -
94 offsetof(CSSFontFaceRule
, mDecl
));
97 inline const CSSFontFaceRule
* CSSFontFaceRuleDecl::ContainingRule() const {
98 return reinterpret_cast<const CSSFontFaceRule
*>(
99 reinterpret_cast<const char*>(this) - offsetof(CSSFontFaceRule
, mDecl
));
102 } // namespace mozilla::dom
104 #endif // mozilla_CSSFontFaceRule_h