CSSPageRule.h (3676B)
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/ServoBindingTypes.h" 11 #include "mozilla/css/GroupRule.h" 12 #include "nsDOMCSSDeclaration.h" 13 #include "nsICSSDeclaration.h" 14 // The following include provides nsCSSProps::PropertyIDLName(), used by 15 // generated CSSPageDescriptorsBinding.cpp 16 // TODO alaskanemily: Ideally it would only be included from there. 17 #include "nsCSSProps.h" 18 19 namespace mozilla { 20 class DeclarationBlock; 21 22 namespace dom { 23 class DocGroup; 24 class CSSPageRule; 25 26 class CSSPageRuleDeclaration final : public nsDOMCSSDeclaration { 27 public: 28 NS_DECL_ISUPPORTS_INHERITED 29 30 css::Rule* GetParentRule() final; 31 nsINode* GetAssociatedNode() const final; 32 nsISupports* GetParentObject() const final; 33 34 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final; 35 36 protected: 37 DeclarationBlock* GetOrCreateCSSDeclaration( 38 Operation aOperation, DeclarationBlock** aCreated) final; 39 nsresult SetCSSDeclaration(DeclarationBlock* aDecl, 40 MutationClosureData* aClosureData) final; 41 nsDOMCSSDeclaration::ParsingEnvironment GetParsingEnvironment( 42 nsIPrincipal* aSubjectPrincipal) const final; 43 44 private: 45 // For accessing the constructor. 46 friend class CSSPageRule; 47 48 explicit CSSPageRuleDeclaration( 49 already_AddRefed<StyleLockedDeclarationBlock> aDecls); 50 void SetRawAfterClone(RefPtr<StyleLockedDeclarationBlock>); 51 52 ~CSSPageRuleDeclaration(); 53 54 inline CSSPageRule* Rule(); 55 inline const CSSPageRule* Rule() const; 56 57 RefPtr<DeclarationBlock> mDecls; 58 }; 59 60 class CSSPageRule final : public css::GroupRule { 61 public: 62 CSSPageRule(RefPtr<StyleLockedPageRule> aRawRule, StyleSheet* aSheet, 63 css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn); 64 65 NS_DECL_ISUPPORTS_INHERITED 66 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(CSSPageRule, 67 css::GroupRule) 68 69 bool IsCCLeaf() const final; 70 71 StyleLockedPageRule* Raw() const { return mRawRule; } 72 void SetRawAfterClone(RefPtr<StyleLockedPageRule>); 73 74 // WebIDL interfaces 75 StyleCssRuleType Type() const final; 76 void GetCssText(nsACString& aCssText) const final; 77 CSSPageRuleDeclaration* Style() { return &mDecls; } 78 79 void GetSelectorText(nsACString& aSelectorText) const; 80 void SetSelectorText(const nsACString& aSelectorText); 81 82 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final; 83 84 already_AddRefed<StyleLockedCssRules> GetOrCreateRawRules() final; 85 86 #ifdef DEBUG 87 void List(FILE* out = stdout, int32_t aIndent = 0) const final; 88 #endif 89 90 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final; 91 92 private: 93 ~CSSPageRule() = default; 94 95 // For computing the offset of mDecls. 96 friend class CSSPageRuleDeclaration; 97 98 RefPtr<StyleLockedPageRule> mRawRule; 99 CSSPageRuleDeclaration mDecls; 100 }; 101 102 CSSPageRule* CSSPageRuleDeclaration::Rule() { 103 return reinterpret_cast<CSSPageRule*>(reinterpret_cast<uint8_t*>(this) - 104 offsetof(CSSPageRule, mDecls)); 105 } 106 107 const CSSPageRule* CSSPageRuleDeclaration::Rule() const { 108 return reinterpret_cast<const CSSPageRule*>( 109 reinterpret_cast<const uint8_t*>(this) - offsetof(CSSPageRule, mDecls)); 110 } 111 112 } // namespace dom 113 } // namespace mozilla 114 115 #endif // mozilla_dom_CSSPageRule_h