Bug 867089 - Validate the playbackRate before using it. r=ehsan
[gecko.git] / layout / style / Rule.h
blob3ba96accd4f20eac45496bf8a1612cf70b9ced68
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"
15 class nsIStyleSheet;
16 class nsIDocument;
17 struct nsRuleData;
18 template<class T> struct already_AddRefed;
19 class nsHTMLCSSStyleSheet;
21 namespace mozilla {
22 namespace css {
23 class GroupRule;
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 {
34 protected:
35 Rule()
36 : mSheet(0),
37 mParentRule(nullptr)
41 Rule(const Rule& aCopy)
42 : mSheet(aCopy.mSheet),
43 mParentRule(aCopy.mParentRule)
47 virtual ~Rule() {}
49 public:
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
53 // then N < M
54 // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
55 // rules can come between two rules of type IMPORT_RULE.
56 enum {
57 UNKNOWN_RULE = 0,
58 CHARSET_RULE,
59 IMPORT_RULE,
60 NAMESPACE_RULE,
61 STYLE_RULE,
62 MEDIA_RULE,
63 FONT_FACE_RULE,
64 PAGE_RULE,
65 KEYFRAME_RULE,
66 KEYFRAMES_RULE,
67 DOCUMENT_RULE,
68 SUPPORTS_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
91 // it.
92 mParentRule = aRule;
95 /**
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,
119 void* aData);
121 protected:
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.
124 uintptr_t mSheet;
125 GroupRule* mParentRule;
128 } // namespace css
129 } // namespace mozilla
131 #endif /* mozilla_css_Rule_h___ */