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* GetAssociatedNode() const final;
29   nsISupports* GetParentObject() const final;
30 
31  protected:
32   DeclarationBlock* GetOrCreateCSSDeclaration(
33       Operation aOperation, DeclarationBlock** aCreated) final;
34   nsresult SetCSSDeclaration(DeclarationBlock* aDecl,
35                              MutationClosureData* aClosureData) final;
DocToUpdate()36   Document* DocToUpdate() final { return nullptr; }
37   nsDOMCSSDeclaration::ParsingEnvironment GetParsingEnvironment(
38       nsIPrincipal* aSubjectPrincipal) const final;
39 
40  private:
41   // For accessing the constructor.
42   friend class CSSPageRule;
43 
44   explicit CSSPageRuleDeclaration(
45       already_AddRefed<RawServoDeclarationBlock> aDecls);
46   void SetRawAfterClone(RefPtr<RawServoDeclarationBlock>);
47 
48   ~CSSPageRuleDeclaration();
49 
50   inline CSSPageRule* Rule();
51   inline const CSSPageRule* Rule() const;
52 
53   RefPtr<DeclarationBlock> mDecls;
54 };
55 
56 class CSSPageRule final : public css::Rule {
57  public:
58   CSSPageRule(RefPtr<RawServoPageRule> aRawRule, StyleSheet* aSheet,
59               css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn);
60 
61   NS_DECL_ISUPPORTS_INHERITED
62   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSPageRule, css::Rule)
63 
64   bool IsCCLeaf() const final;
65 
Raw()66   RawServoPageRule* Raw() const { return mRawRule; }
67   void SetRawAfterClone(RefPtr<RawServoPageRule>);
68 
69   // WebIDL interfaces
70   StyleCssRuleType Type() const final;
71   void GetCssText(nsACString& aCssText) const final;
72   nsICSSDeclaration* Style();
73 
74   void GetSelectorText(nsACString& aSelectorText) const;
75   void SetSelectorText(const nsACString& aSelectorText);
76 
77   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
78 
79 #ifdef DEBUG
80   void List(FILE* out = stdout, int32_t aIndent = 0) const final;
81 #endif
82 
83   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
84 
85  private:
86   ~CSSPageRule() = default;
87 
88   // For computing the offset of mDecls.
89   friend class CSSPageRuleDeclaration;
90 
91   RefPtr<RawServoPageRule> mRawRule;
92   CSSPageRuleDeclaration mDecls;
93 };
94 
Rule()95 CSSPageRule* CSSPageRuleDeclaration::Rule() {
96   return reinterpret_cast<CSSPageRule*>(reinterpret_cast<uint8_t*>(this) -
97                                         offsetof(CSSPageRule, mDecls));
98 }
99 
Rule()100 const CSSPageRule* CSSPageRuleDeclaration::Rule() const {
101   return reinterpret_cast<const CSSPageRule*>(
102       reinterpret_cast<const uint8_t*>(this) - offsetof(CSSPageRule, mDecls));
103 }
104 
105 }  // namespace dom
106 }  // namespace mozilla
107 
108 #endif  // mozilla_dom_CSSPageRule_h
109