Line data Source code
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 : /* representation of CSSStyleRule for stylo */
8 :
9 : #ifndef mozilla_ServoStyleRule_h
10 : #define mozilla_ServoStyleRule_h
11 :
12 : #include "mozilla/BindingStyleRule.h"
13 : #include "mozilla/ServoBindingTypes.h"
14 : #include "mozilla/WeakPtr.h"
15 :
16 : #include "nsICSSStyleRuleDOMWrapper.h"
17 : #include "nsIDOMCSSStyleRule.h"
18 : #include "nsICSSStyleRuleDOMWrapper.h"
19 : #include "nsDOMCSSDeclaration.h"
20 :
21 : namespace mozilla {
22 :
23 : class ServoDeclarationBlock;
24 : class ServoStyleRule;
25 :
26 : class ServoStyleRuleDeclaration final : public nsDOMCSSDeclaration
27 : {
28 : public:
29 : NS_DECL_ISUPPORTS_INHERITED
30 :
31 : NS_IMETHOD GetParentRule(nsIDOMCSSRule** aParent) final;
32 : nsINode* GetParentObject() final;
33 :
34 : protected:
35 : DeclarationBlock* GetCSSDeclaration(Operation aOperation) final;
36 : nsresult SetCSSDeclaration(DeclarationBlock* aDecl) final;
37 : nsIDocument* DocToUpdate() final;
38 : void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) final;
39 : ServoCSSParsingEnvironment GetServoCSSParsingEnvironment() const final;
40 :
41 : private:
42 : // For accessing the constructor.
43 : friend class ServoStyleRule;
44 :
45 : explicit ServoStyleRuleDeclaration(
46 : already_AddRefed<RawServoDeclarationBlock> aDecls);
47 : ~ServoStyleRuleDeclaration();
48 :
49 : inline ServoStyleRule* Rule();
50 : inline const ServoStyleRule* Rule() const;
51 :
52 : RefPtr<ServoDeclarationBlock> mDecls;
53 : };
54 :
55 : class ServoStyleRule final : public BindingStyleRule
56 : , public nsICSSStyleRuleDOMWrapper
57 : , public SupportsWeakPtr<ServoStyleRule>
58 : {
59 : public:
60 : ServoStyleRule(already_AddRefed<RawServoStyleRule> aRawRule,
61 : uint32_t aLine, uint32_t aColumn);
62 :
63 : NS_DECL_ISUPPORTS_INHERITED
64 0 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(ServoStyleRule,
65 : css::Rule)
66 : bool IsCCLeaf() const final MOZ_MUST_OVERRIDE;
67 : NS_DECL_NSIDOMCSSSTYLERULE
68 :
69 0 : MOZ_DECLARE_WEAKREFERENCE_TYPENAME(ServoStyleRule)
70 :
71 : // nsICSSStyleRuleDOMWrapper
72 : NS_IMETHOD GetCSSStyleRule(BindingStyleRule **aResult) override;
73 :
74 : uint32_t GetSelectorCount() override;
75 : nsresult GetSelectorText(uint32_t aSelectorIndex,
76 : nsAString& aText) override;
77 : nsresult GetSpecificity(uint32_t aSelectorIndex,
78 : uint64_t* aSpecificity) override;
79 : nsresult SelectorMatchesElement(dom::Element* aElement,
80 : uint32_t aSelectorIndex,
81 : const nsAString& aPseudo,
82 : bool* aMatches) override;
83 :
84 : // WebIDL interface
85 : uint16_t Type() const final;
86 : void GetCssTextImpl(nsAString& aCssText) const final;
87 : nsICSSDeclaration* Style() final;
88 :
89 0 : RawServoStyleRule* Raw() const { return mRawRule; }
90 :
91 : // Methods of mozilla::css::Rule
92 0 : int32_t GetType() const final { return css::Rule::STYLE_RULE; }
93 : using Rule::GetType;
94 : already_AddRefed<Rule> Clone() const final;
95 : size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const final;
96 : #ifdef DEBUG
97 : void List(FILE* out = stdout, int32_t aIndent = 0) const final;
98 : #endif
99 :
100 : private:
101 0 : ~ServoStyleRule() {}
102 :
103 : // For computing the offset of mDecls.
104 : friend class ServoStyleRuleDeclaration;
105 :
106 : RefPtr<RawServoStyleRule> mRawRule;
107 : ServoStyleRuleDeclaration mDecls;
108 : };
109 :
110 : ServoStyleRule*
111 0 : ServoStyleRuleDeclaration::Rule()
112 : {
113 : return reinterpret_cast<ServoStyleRule*>(
114 0 : reinterpret_cast<uint8_t*>(this) - offsetof(ServoStyleRule, mDecls));
115 : }
116 :
117 : const ServoStyleRule*
118 0 : ServoStyleRuleDeclaration::Rule() const
119 : {
120 : return reinterpret_cast<const ServoStyleRule*>(
121 0 : reinterpret_cast<const uint8_t*>(this) - offsetof(ServoStyleRule, mDecls));
122 : }
123 :
124 : } // namespace mozilla
125 :
126 : #endif // mozilla_ServoStyleRule_h
|