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/. */
6
7 #ifndef mozilla_CSSFontFaceRule_h
8 #define mozilla_CSSFontFaceRule_h
9
10 #include "mozilla/ServoBindingTypes.h"
11 #include "mozilla/css/Rule.h"
12 #include "nsICSSDeclaration.h"
13
14 namespace mozilla::dom {
15
16 // A CSSFontFaceRuleDecl is always embeded in a CSSFontFaceRule.
17 class CSSFontFaceRule;
18 class CSSFontFaceRuleDecl final : public nsICSSDeclaration {
19 public:
20 NS_DECL_ISUPPORTS_INHERITED
21 NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER
22
23 nsINode* GetAssociatedNode() const final;
24 nsISupports* GetParentObject() const final;
25 void IndexedGetter(uint32_t aIndex, bool& aFound,
26 nsACString& aPropName) final;
27
28 void GetPropertyValue(nsCSSFontDesc aFontDescID, nsACString& aResult) const;
29
30 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
31
32 protected:
33 // For accessing the constructor.
34 friend class CSSFontFaceRule;
35
CSSFontFaceRuleDecl(already_AddRefed<RawServoFontFaceRule> aDecl)36 explicit CSSFontFaceRuleDecl(already_AddRefed<RawServoFontFaceRule> aDecl)
37 : mRawRule(std::move(aDecl)) {}
38
39 ~CSSFontFaceRuleDecl() = default;
40
41 inline CSSFontFaceRule* ContainingRule();
42 inline const CSSFontFaceRule* ContainingRule() const;
43
44 RefPtr<RawServoFontFaceRule> mRawRule;
45 void SetRawAfterClone(RefPtr<RawServoFontFaceRule>);
46
47 private:
48 void* operator new(size_t size) noexcept(true) = delete;
49 };
50
51 class CSSFontFaceRule final : public css::Rule {
52 public:
CSSFontFaceRule(already_AddRefed<RawServoFontFaceRule> aRawRule,StyleSheet * aSheet,css::Rule * aParentRule,uint32_t aLine,uint32_t aColumn)53 CSSFontFaceRule(already_AddRefed<RawServoFontFaceRule> aRawRule,
54 StyleSheet* aSheet, css::Rule* aParentRule, uint32_t aLine,
55 uint32_t aColumn)
56 : css::Rule(aSheet, aParentRule, aLine, aColumn),
57 mDecl(std::move(aRawRule)) {}
58
59 CSSFontFaceRule(const CSSFontFaceRule&) = delete;
60
61 NS_DECL_ISUPPORTS_INHERITED
62 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSFontFaceRule,
63 css::Rule)
64 bool IsCCLeaf() const final;
65
Raw()66 RawServoFontFaceRule* Raw() const { return mDecl.mRawRule; }
67 void SetRawAfterClone(RefPtr<RawServoFontFaceRule>);
68
69 // WebIDL interface
70 StyleCssRuleType Type() const final;
71 void GetCssText(nsACString& aCssText) const final;
72 nsICSSDeclaration* Style();
73
74 // Methods of mozilla::css::Rule
75 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const final;
76
77 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
78
79 #ifdef DEBUG
80 void List(FILE* out = stdout, int32_t aIndent = 0) const final;
81 #endif
82
83 private:
84 virtual ~CSSFontFaceRule() = default;
85
86 // For computing the offset of mDecl.
87 friend class CSSFontFaceRuleDecl;
88
89 CSSFontFaceRuleDecl mDecl;
90 };
91
ContainingRule()92 inline CSSFontFaceRule* CSSFontFaceRuleDecl::ContainingRule() {
93 return reinterpret_cast<CSSFontFaceRule*>(reinterpret_cast<char*>(this) -
94 offsetof(CSSFontFaceRule, mDecl));
95 }
96
ContainingRule()97 inline const CSSFontFaceRule* CSSFontFaceRuleDecl::ContainingRule() const {
98 return reinterpret_cast<const CSSFontFaceRule*>(
99 reinterpret_cast<const char*>(this) - offsetof(CSSFontFaceRule, mDecl));
100 }
101
102 } // namespace mozilla::dom
103
104 #endif // mozilla_CSSFontFaceRule_h
105