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 : /*
39 : * internal interface representing CSS style rules that contain other
40 : * rules, such as @media rules
41 : */
42 :
43 : #ifndef mozilla_css_GroupRule_h__
44 : #define mozilla_css_GroupRule_h__
45 :
46 : #include "mozilla/css/Rule.h"
47 : #include "nsCOMArray.h"
48 : #include "nsAutoPtr.h"
49 :
50 : class nsPresContext;
51 : class nsMediaQueryResultCacheKey;
52 :
53 : namespace mozilla {
54 : namespace css {
55 :
56 : class GroupRuleRuleList;
57 :
58 : // inherits from Rule so it can be shared between
59 : // MediaRule and DocumentRule
60 : class GroupRule : public Rule
61 : {
62 : protected:
63 : GroupRule();
64 : GroupRule(const GroupRule& aCopy);
65 : virtual ~GroupRule();
66 : public:
67 :
68 : // implement part of nsIStyleRule and Rule
69 : DECL_STYLE_RULE_INHERIT_NO_DOMRULE
70 : virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
71 :
72 : // to help implement nsIStyleRule
73 : #ifdef DEBUG
74 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
75 : #endif
76 :
77 : public:
78 : void AppendStyleRule(Rule* aRule);
79 :
80 0 : PRInt32 StyleRuleCount() const { return mRules.Count(); }
81 : Rule* GetStyleRuleAt(PRInt32 aIndex) const;
82 :
83 : typedef nsCOMArray<Rule>::nsCOMArrayEnumFunc RuleEnumFunc;
84 : bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const;
85 :
86 : /*
87 : * The next three methods should never be called unless you have first
88 : * called WillDirty() on the parent stylesheet. After they are
89 : * called, DidDirty() needs to be called on the sheet.
90 : */
91 : nsresult DeleteStyleRuleAt(PRUint32 aIndex);
92 : nsresult InsertStyleRulesAt(PRUint32 aIndex,
93 : nsCOMArray<Rule>& aRules);
94 : nsresult ReplaceStyleRule(Rule *aOld, Rule *aNew);
95 :
96 : virtual bool UseForPresentation(nsPresContext* aPresContext,
97 : nsMediaQueryResultCacheKey& aKey) = 0;
98 :
99 : NS_MUST_OVERRIDE size_t // non-virtual -- it is only called by subclasses
100 : SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
101 : virtual size_t
102 : SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const = 0;
103 :
104 : protected:
105 : // to help implement nsIDOMCSSRule
106 : nsresult AppendRulesToCssText(nsAString& aCssText);
107 :
108 : // to implement common methods on nsIDOMCSSMediaRule and
109 : // nsIDOMCSSMozDocumentRule
110 : nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList);
111 : nsresult InsertRule(const nsAString & aRule, PRUint32 aIndex,
112 : PRUint32* _retval);
113 : nsresult DeleteRule(PRUint32 aIndex);
114 :
115 : nsCOMArray<Rule> mRules;
116 : nsRefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
117 : };
118 :
119 : } // namespace css
120 : } // namespace mozilla
121 :
122 : #endif /* mozilla_css_GroupRule_h__ */
|