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_dom_CSSPageRule_h
8 #define mozilla_dom_CSSPageRule_h
9
10 #include "mozilla/css/Rule.h"
11 #include "mozilla/ServoBindingTypes.h"
12
13 #include "nsDOMCSSDeclaration.h"
14 #include "nsICSSDeclaration.h"
15
16 namespace mozilla {
17 class DeclarationBlock;
18
19 namespace dom {
20 class DocGroup;
21 class CSSPageRule;
22
23 class CSSPageRuleDeclaration final : public nsDOMCSSDeclaration {
24 public:
25 NS_DECL_ISUPPORTS_INHERITED
26
27 css::Rule* GetParentRule() final;
28 nsINode* GetParentObject() final;
29
30 protected:
31 DeclarationBlock* GetOrCreateCSSDeclaration(
32 Operation aOperation, DeclarationBlock** aCreated) final;
33 nsresult SetCSSDeclaration(DeclarationBlock* aDecl,
34 MutationClosureData* aClosureData) final;
DocToUpdate()35 Document* DocToUpdate() final { return nullptr; }
36 nsDOMCSSDeclaration::ParsingEnvironment GetParsingEnvironment(
37 nsIPrincipal* aSubjectPrincipal) const final;
38
39 private:
40 // For accessing the constructor.
41 friend class CSSPageRule;
42
43 explicit CSSPageRuleDeclaration(
44 already_AddRefed<RawServoDeclarationBlock> aDecls);
45 ~CSSPageRuleDeclaration();
46
47 inline CSSPageRule* Rule();
48 inline const CSSPageRule* Rule() const;
49
50 RefPtr<DeclarationBlock> mDecls;
51 };
52
53 class CSSPageRule final : public css::Rule {
54 public:
55 CSSPageRule(RefPtr<RawServoPageRule> aRawRule, StyleSheet* aSheet,
56 css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn);
57
58 NS_DECL_ISUPPORTS_INHERITED
59 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSPageRule, css::Rule)
60
61 bool IsCCLeaf() const final;
62
Raw()63 RawServoPageRule* Raw() const { return mRawRule; }
64
65 // WebIDL interfaces
Type()66 uint16_t Type() const final { return CSSRule_Binding::PAGE_RULE; }
67 void GetCssText(nsAString& aCssText) const final;
68 nsICSSDeclaration* Style();
69
70 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
71
72 #ifdef DEBUG
73 void List(FILE* out = stdout, int32_t aIndent = 0) const final;
74 #endif
75
76 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
77
78 private:
79 ~CSSPageRule() = default;
80
81 // For computing the offset of mDecls.
82 friend class CSSPageRuleDeclaration;
83
84 RefPtr<RawServoPageRule> mRawRule;
85 CSSPageRuleDeclaration mDecls;
86 };
87
Rule()88 CSSPageRule* CSSPageRuleDeclaration::Rule() {
89 return reinterpret_cast<CSSPageRule*>(reinterpret_cast<uint8_t*>(this) -
90 offsetof(CSSPageRule, mDecls));
91 }
92
Rule()93 const CSSPageRule* CSSPageRuleDeclaration::Rule() const {
94 return reinterpret_cast<const CSSPageRule*>(
95 reinterpret_cast<const uint8_t*>(this) - offsetof(CSSPageRule, mDecls));
96 }
97
98 } // namespace dom
99 } // namespace mozilla
100
101 #endif // mozilla_dom_CSSPageRule_h
102