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/. */
6 /* base class for all rule types in a CSS style sheet */
8 #ifndef mozilla_css_Rule_h___
9 #define mozilla_css_Rule_h___
11 #include "nsIStyleRule.h"
12 #include "nsIDOMCSSRule.h"
13 #include "nsCSSStyleSheet.h"
18 template<class T
> struct already_AddRefed
;
19 class nsHTMLCSSStyleSheet
;
25 #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
26 virtual void MapRuleInfoInto(nsRuleData* aRuleData);
28 #define DECL_STYLE_RULE_INHERIT \
29 DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
30 virtual nsIDOMCSSRule* GetDOMRule(); \
31 virtual nsIDOMCSSRule* GetExistingDOMRule();
33 class Rule
: public nsIStyleRule
{
41 Rule(const Rule
& aCopy
)
42 : mSheet(aCopy
.mSheet
),
43 mParentRule(aCopy
.mParentRule
)
51 // The constants in this list must maintain the following invariants:
52 // If a rule of type N must appear before a rule of type M in stylesheets
54 // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
55 // rules can come between two rules of type IMPORT_RULE.
71 virtual int32_t GetType() const = 0;
73 nsCSSStyleSheet
* GetStyleSheet() const;
74 nsHTMLCSSStyleSheet
* GetHTMLCSSStyleSheet() const;
76 // Return the document the rule lives in, if any
77 nsIDocument
* GetDocument() const
79 nsCSSStyleSheet
* sheet
= GetStyleSheet();
80 return sheet
? sheet
->GetDocument() : nullptr;
83 virtual void SetStyleSheet(nsCSSStyleSheet
* aSheet
);
84 // This does not need to be virtual, because GroupRule and MediaRule are not
85 // used for inline style.
86 void SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet
* aSheet
);
88 void SetParentRule(GroupRule
* aRule
) {
89 // We don't reference count this up reference. The group rule
90 // will tell us when it's going away or when we're detached from
96 * Clones |this|. Never returns NULL.
98 virtual already_AddRefed
<Rule
> Clone() const = 0;
100 // Note that this returns null for inline style rules since they aren't
101 // supposed to have a DOM rule representation (and our code wouldn't work).
102 virtual nsIDOMCSSRule
* GetDOMRule() = 0;
104 // Like GetDOMRule(), but won't create one if we don't have one yet
105 virtual nsIDOMCSSRule
* GetExistingDOMRule() = 0;
107 // to implement methods on nsIDOMCSSRule
108 nsresult
GetParentRule(nsIDOMCSSRule
** aParentRule
);
109 nsresult
GetParentStyleSheet(nsIDOMCSSStyleSheet
** aSheet
);
111 // This is pure virtual because all of Rule's data members are non-owning and
112 // thus measured elsewhere.
113 virtual size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf
)
114 const MOZ_MUST_OVERRIDE
= 0;
116 // This is used to measure nsCOMArray<Rule>s.
117 static size_t SizeOfCOMArrayElementIncludingThis(css::Rule
* aElement
,
118 nsMallocSizeOfFun aMallocSizeOf
,
122 // This is either an nsCSSStyleSheet* or a nsHTMLStyleSheet*. The former
123 // if the low bit is 0, the latter if the low bit is 1.
125 GroupRule
* mParentRule
;
129 } // namespace mozilla
131 #endif /* mozilla_css_Rule_h___ */