michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * internal interface representing CSS style rules that contain other michael@0: * rules, such as @media rules michael@0: */ michael@0: michael@0: #ifndef mozilla_css_GroupRule_h__ michael@0: #define mozilla_css_GroupRule_h__ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "mozilla/css/Rule.h" michael@0: #include "nsCOMArray.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: michael@0: class nsPresContext; michael@0: class nsMediaQueryResultCacheKey; michael@0: michael@0: namespace mozilla { michael@0: namespace css { michael@0: michael@0: class GroupRuleRuleList; michael@0: michael@0: // inherits from Rule so it can be shared between michael@0: // MediaRule and DocumentRule michael@0: class GroupRule : public Rule michael@0: { michael@0: protected: michael@0: GroupRule(); michael@0: GroupRule(const GroupRule& aCopy); michael@0: virtual ~GroupRule(); michael@0: public: michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS(GroupRule) michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: michael@0: // implement part of nsIStyleRule and Rule michael@0: DECL_STYLE_RULE_INHERIT_NO_DOMRULE michael@0: virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); michael@0: michael@0: // to help implement nsIStyleRule michael@0: #ifdef DEBUG michael@0: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: public: michael@0: void AppendStyleRule(Rule* aRule); michael@0: michael@0: int32_t StyleRuleCount() const { return mRules.Count(); } michael@0: Rule* GetStyleRuleAt(int32_t aIndex) const; michael@0: michael@0: typedef nsCOMArray::nsCOMArrayEnumFunc RuleEnumFunc; michael@0: bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const; michael@0: michael@0: /* michael@0: * The next three methods should never be called unless you have first michael@0: * called WillDirty() on the parent stylesheet. After they are michael@0: * called, DidDirty() needs to be called on the sheet. michael@0: */ michael@0: nsresult DeleteStyleRuleAt(uint32_t aIndex); michael@0: nsresult InsertStyleRuleAt(uint32_t aIndex, Rule* aRule); michael@0: nsresult ReplaceStyleRule(Rule *aOld, Rule *aNew); michael@0: michael@0: virtual bool UseForPresentation(nsPresContext* aPresContext, michael@0: nsMediaQueryResultCacheKey& aKey) = 0; michael@0: michael@0: // non-virtual -- it is only called by subclasses michael@0: size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; michael@0: michael@0: static bool michael@0: CloneRuleInto(Rule* aRule, void* aArray) michael@0: { michael@0: nsRefPtr clone = aRule->Clone(); michael@0: static_cast*>(aArray)->AppendObject(clone); michael@0: return true; michael@0: } michael@0: michael@0: protected: michael@0: // to help implement nsIDOMCSSRule michael@0: void AppendRulesToCssText(nsAString& aCssText); michael@0: michael@0: // to implement common methods on nsIDOMCSSMediaRule and michael@0: // nsIDOMCSSMozDocumentRule michael@0: nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList); michael@0: nsresult InsertRule(const nsAString & aRule, uint32_t aIndex, michael@0: uint32_t* _retval); michael@0: nsresult DeleteRule(uint32_t aIndex); michael@0: michael@0: nsCOMArray mRules; michael@0: nsRefPtr mRuleCollection; // lazily constructed michael@0: }; michael@0: michael@0: } // namespace css michael@0: } // namespace mozilla michael@0: michael@0: #endif /* mozilla_css_GroupRule_h__ */