1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1999
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : /* base class for all rule types in a CSS style sheet */
39 :
40 : #ifndef mozilla_css_Rule_h___
41 : #define mozilla_css_Rule_h___
42 :
43 : #include "nsIStyleRule.h"
44 : #include "nsIDOMCSSRule.h"
45 :
46 : class nsIStyleSheet;
47 : class nsCSSStyleSheet;
48 : struct nsRuleData;
49 : template<class T> struct already_AddRefed;
50 :
51 : namespace mozilla {
52 : namespace css {
53 : class GroupRule;
54 :
55 : #define DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
56 : virtual void MapRuleInfoInto(nsRuleData* aRuleData);
57 :
58 : #define DECL_STYLE_RULE_INHERIT \
59 : DECL_STYLE_RULE_INHERIT_NO_DOMRULE \
60 : virtual nsIDOMCSSRule* GetDOMRule();
61 :
62 : class Rule : public nsIStyleRule {
63 : protected:
64 0 : Rule()
65 : : mSheet(nsnull),
66 0 : mParentRule(nsnull)
67 : {
68 0 : }
69 :
70 0 : Rule(const Rule& aCopy)
71 : : mSheet(aCopy.mSheet),
72 0 : mParentRule(aCopy.mParentRule)
73 : {
74 0 : }
75 :
76 0 : virtual ~Rule() {}
77 :
78 : public:
79 : // for implementing nsISupports
80 : NS_IMETHOD_(nsrefcnt) AddRef();
81 : NS_IMETHOD_(nsrefcnt) Release();
82 : protected:
83 : nsAutoRefCnt mRefCnt;
84 : NS_DECL_OWNINGTHREAD
85 : public:
86 :
87 : // The constants in this list must maintain the following invariants:
88 : // If a rule of type N must appear before a rule of type M in stylesheets
89 : // then N < M
90 : // Note that nsCSSStyleSheet::RebuildChildList assumes that no other kinds of
91 : // rules can come between two rules of type IMPORT_RULE.
92 : enum {
93 : UNKNOWN_RULE = 0,
94 : CHARSET_RULE,
95 : IMPORT_RULE,
96 : NAMESPACE_RULE,
97 : STYLE_RULE,
98 : MEDIA_RULE,
99 : FONT_FACE_RULE,
100 : PAGE_RULE,
101 : KEYFRAME_RULE,
102 : KEYFRAMES_RULE,
103 : DOCUMENT_RULE
104 : };
105 :
106 : virtual PRInt32 GetType() const = 0;
107 :
108 0 : nsCSSStyleSheet* GetStyleSheet() const { return mSheet; }
109 :
110 : virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
111 :
112 0 : void SetParentRule(GroupRule* aRule) {
113 : // We don't reference count this up reference. The group rule
114 : // will tell us when it's going away or when we're detached from
115 : // it.
116 0 : mParentRule = aRule;
117 0 : }
118 :
119 : /**
120 : * Clones |this|. Never returns NULL.
121 : */
122 : virtual already_AddRefed<Rule> Clone() const = 0;
123 :
124 : // Note that this returns null for inline style rules since they aren't
125 : // supposed to have a DOM rule representation (and our code wouldn't work).
126 : virtual nsIDOMCSSRule* GetDOMRule() = 0;
127 :
128 : // to implement methods on nsIDOMCSSRule
129 : nsresult GetParentRule(nsIDOMCSSRule** aParentRule);
130 : nsresult GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet);
131 :
132 : // This is pure virtual because all of Rule's data members are non-owning and
133 : // thus measured elsewhere.
134 : virtual NS_MUST_OVERRIDE size_t
135 : SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const = 0;
136 :
137 : // This is used to measure nsCOMArray<Rule>s.
138 : static size_t SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
139 : nsMallocSizeOfFun aMallocSizeOf,
140 : void* aData);
141 :
142 : protected:
143 : nsCSSStyleSheet* mSheet;
144 : GroupRule* mParentRule;
145 : };
146 :
147 : } // namespace css
148 : } // namespace mozilla
149 :
150 : #endif /* mozilla_css_Rule_h___ */
|