|
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 /* |
|
7 * internal interface representing CSS style rules that contain other |
|
8 * rules, such as @media rules |
|
9 */ |
|
10 |
|
11 #ifndef mozilla_css_GroupRule_h__ |
|
12 #define mozilla_css_GroupRule_h__ |
|
13 |
|
14 #include "mozilla/Attributes.h" |
|
15 #include "mozilla/MemoryReporting.h" |
|
16 #include "mozilla/css/Rule.h" |
|
17 #include "nsCOMArray.h" |
|
18 #include "nsAutoPtr.h" |
|
19 #include "nsCycleCollectionParticipant.h" |
|
20 |
|
21 class nsPresContext; |
|
22 class nsMediaQueryResultCacheKey; |
|
23 |
|
24 namespace mozilla { |
|
25 namespace css { |
|
26 |
|
27 class GroupRuleRuleList; |
|
28 |
|
29 // inherits from Rule so it can be shared between |
|
30 // MediaRule and DocumentRule |
|
31 class GroupRule : public Rule |
|
32 { |
|
33 protected: |
|
34 GroupRule(); |
|
35 GroupRule(const GroupRule& aCopy); |
|
36 virtual ~GroupRule(); |
|
37 public: |
|
38 |
|
39 NS_DECL_CYCLE_COLLECTION_CLASS(GroupRule) |
|
40 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
41 |
|
42 // implement part of nsIStyleRule and Rule |
|
43 DECL_STYLE_RULE_INHERIT_NO_DOMRULE |
|
44 virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); |
|
45 |
|
46 // to help implement nsIStyleRule |
|
47 #ifdef DEBUG |
|
48 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; |
|
49 #endif |
|
50 |
|
51 public: |
|
52 void AppendStyleRule(Rule* aRule); |
|
53 |
|
54 int32_t StyleRuleCount() const { return mRules.Count(); } |
|
55 Rule* GetStyleRuleAt(int32_t aIndex) const; |
|
56 |
|
57 typedef nsCOMArray<Rule>::nsCOMArrayEnumFunc RuleEnumFunc; |
|
58 bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const; |
|
59 |
|
60 /* |
|
61 * The next three methods should never be called unless you have first |
|
62 * called WillDirty() on the parent stylesheet. After they are |
|
63 * called, DidDirty() needs to be called on the sheet. |
|
64 */ |
|
65 nsresult DeleteStyleRuleAt(uint32_t aIndex); |
|
66 nsresult InsertStyleRuleAt(uint32_t aIndex, Rule* aRule); |
|
67 nsresult ReplaceStyleRule(Rule *aOld, Rule *aNew); |
|
68 |
|
69 virtual bool UseForPresentation(nsPresContext* aPresContext, |
|
70 nsMediaQueryResultCacheKey& aKey) = 0; |
|
71 |
|
72 // non-virtual -- it is only called by subclasses |
|
73 size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
|
74 virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; |
|
75 |
|
76 static bool |
|
77 CloneRuleInto(Rule* aRule, void* aArray) |
|
78 { |
|
79 nsRefPtr<Rule> clone = aRule->Clone(); |
|
80 static_cast<nsCOMArray<Rule>*>(aArray)->AppendObject(clone); |
|
81 return true; |
|
82 } |
|
83 |
|
84 protected: |
|
85 // to help implement nsIDOMCSSRule |
|
86 void AppendRulesToCssText(nsAString& aCssText); |
|
87 |
|
88 // to implement common methods on nsIDOMCSSMediaRule and |
|
89 // nsIDOMCSSMozDocumentRule |
|
90 nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList); |
|
91 nsresult InsertRule(const nsAString & aRule, uint32_t aIndex, |
|
92 uint32_t* _retval); |
|
93 nsresult DeleteRule(uint32_t aIndex); |
|
94 |
|
95 nsCOMArray<Rule> mRules; |
|
96 nsRefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed |
|
97 }; |
|
98 |
|
99 } // namespace css |
|
100 } // namespace mozilla |
|
101 |
|
102 #endif /* mozilla_css_GroupRule_h__ */ |