Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
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 /*
7 * internal interface representing CSS style rules that contain other
8 * rules, such as @media rules
9 */
11 #ifndef mozilla_css_GroupRule_h__
12 #define mozilla_css_GroupRule_h__
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"
21 class nsPresContext;
22 class nsMediaQueryResultCacheKey;
24 namespace mozilla {
25 namespace css {
27 class GroupRuleRuleList;
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:
39 NS_DECL_CYCLE_COLLECTION_CLASS(GroupRule)
40 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
42 // implement part of nsIStyleRule and Rule
43 DECL_STYLE_RULE_INHERIT_NO_DOMRULE
44 virtual void SetStyleSheet(nsCSSStyleSheet* aSheet);
46 // to help implement nsIStyleRule
47 #ifdef DEBUG
48 virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
49 #endif
51 public:
52 void AppendStyleRule(Rule* aRule);
54 int32_t StyleRuleCount() const { return mRules.Count(); }
55 Rule* GetStyleRuleAt(int32_t aIndex) const;
57 typedef nsCOMArray<Rule>::nsCOMArrayEnumFunc RuleEnumFunc;
58 bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const;
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);
69 virtual bool UseForPresentation(nsPresContext* aPresContext,
70 nsMediaQueryResultCacheKey& aKey) = 0;
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;
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 }
84 protected:
85 // to help implement nsIDOMCSSRule
86 void AppendRulesToCssText(nsAString& aCssText);
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);
95 nsCOMArray<Rule> mRules;
96 nsRefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
97 };
99 } // namespace css
100 } // namespace mozilla
102 #endif /* mozilla_css_GroupRule_h__ */