layout/style/Rule.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:32790c4aebd0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /* base class for all rule types in a CSS style sheet */
7
8 #ifndef mozilla_css_Rule_h___
9 #define mozilla_css_Rule_h___
10
11 #include "mozilla/MemoryReporting.h"
12 #include "nsIStyleRule.h"
13 #include "nsIDOMCSSRule.h"
14 #include "nsCSSStyleSheet.h"
15
16 class nsIStyleSheet;
17 class nsIDocument;
18 struct nsRuleData;
19 template<class T> struct already_AddRefed;
20 class nsHTMLCSSStyleSheet;
21
22 namespace mozilla {
23 namespace css {
24 class GroupRule;
25
26 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
27 virtual void MapRuleInfoInto(nsRuleData* aRuleData);
28
29 #define DECL_STYLE_RULE_INHERIT \
30 DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
31 virtual nsIDOMCSSRule* GetDOMRule(); \
32 virtual nsIDOMCSSRule* GetExistingDOMRule();
33
34 class Rule : public nsIStyleRule {
35 protected:
36 Rule()
37 : mSheet(0),
38 mParentRule(nullptr)
39 {
40 }
41
42 Rule(const Rule& aCopy)
43 : mSheet(aCopy.mSheet),
44 mParentRule(aCopy.mParentRule)
45 {
46 }
47
48 virtual ~Rule() {}
49
50 public:
51
52 // The constants in this list must maintain the following invariants:
53 // If a rule of type N must appear before a rule of type M in stylesheets
54 // then N < M
55 // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
56 // rules can come between two rules of type IMPORT_RULE.
57 enum {
58 UNKNOWN_RULE = 0,
59 CHARSET_RULE,
60 IMPORT_RULE,
61 NAMESPACE_RULE,
62 STYLE_RULE,
63 MEDIA_RULE,
64 FONT_FACE_RULE,
65 PAGE_RULE,
66 KEYFRAME_RULE,
67 KEYFRAMES_RULE,
68 DOCUMENT_RULE,
69 SUPPORTS_RULE,
70 FONT_FEATURE_VALUES_RULE
71 };
72
73 virtual int32_t GetType() const = 0;
74
75 nsCSSStyleSheet* GetStyleSheet() const;
76 nsHTMLCSSStyleSheet* GetHTMLCSSStyleSheet() const;
77
78 // Return the document the rule lives in, if any
79 nsIDocument* GetDocument() const
80 {
81 nsCSSStyleSheet* sheet = GetStyleSheet();
82 return sheet ? sheet->GetDocument() : nullptr;
83 }
84
85 virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
86 // This does not need to be virtual, because GroupRule and MediaRule are not
87 // used for inline style.
88 void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet);
89
90 void SetParentRule(GroupRule* aRule) {
91 // We don't reference count this up reference. The group rule
92 // will tell us when it's going away or when we're detached from
93 // it.
94 mParentRule = aRule;
95 }
96
97 /**
98 * Clones |this|. Never returns nullptr.
99 */
100 virtual already_AddRefed<Rule> Clone() const = 0;
101
102 // Note that this returns null for inline style rules since they aren't
103 // supposed to have a DOM rule representation (and our code wouldn't work).
104 virtual nsIDOMCSSRule* GetDOMRule() = 0;
105
106 // Like GetDOMRule(), but won't create one if we don't have one yet
107 virtual nsIDOMCSSRule* GetExistingDOMRule() = 0;
108
109 // to implement methods on nsIDOMCSSRule
110 nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
111 nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
112
113 // This is pure virtual because all of Rule's data members are non-owning and
114 // thus measured elsewhere.
115 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
116 const MOZ_MUST_OVERRIDE = 0;
117
118 // This is used to measure nsCOMArray<Rule>s.
119 static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
120 mozilla::MallocSizeOf aMallocSizeOf,
121 void* aData);
122
123 protected:
124 // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*. The former
125 // if the low bit is 0, the latter if the low bit is 1.
126 uintptr_t mSheet;
127 GroupRule* mParentRule;
128 };
129
130 } // namespace css
131 } // namespace mozilla
132
133 #endif /* mozilla_css_Rule_h___ */

mercurial