1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/GroupRule.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * internal interface representing CSS style rules that contain other 1.11 + * rules, such as @media rules 1.12 + */ 1.13 + 1.14 +#ifndef mozilla_css_GroupRule_h__ 1.15 +#define mozilla_css_GroupRule_h__ 1.16 + 1.17 +#include "mozilla/Attributes.h" 1.18 +#include "mozilla/MemoryReporting.h" 1.19 +#include "mozilla/css/Rule.h" 1.20 +#include "nsCOMArray.h" 1.21 +#include "nsAutoPtr.h" 1.22 +#include "nsCycleCollectionParticipant.h" 1.23 + 1.24 +class nsPresContext; 1.25 +class nsMediaQueryResultCacheKey; 1.26 + 1.27 +namespace mozilla { 1.28 +namespace css { 1.29 + 1.30 +class GroupRuleRuleList; 1.31 + 1.32 +// inherits from Rule so it can be shared between 1.33 +// MediaRule and DocumentRule 1.34 +class GroupRule : public Rule 1.35 +{ 1.36 +protected: 1.37 + GroupRule(); 1.38 + GroupRule(const GroupRule& aCopy); 1.39 + virtual ~GroupRule(); 1.40 +public: 1.41 + 1.42 + NS_DECL_CYCLE_COLLECTION_CLASS(GroupRule) 1.43 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.44 + 1.45 + // implement part of nsIStyleRule and Rule 1.46 + DECL_STYLE_RULE_INHERIT_NO_DOMRULE 1.47 + virtual void SetStyleSheet(nsCSSStyleSheet* aSheet); 1.48 + 1.49 + // to help implement nsIStyleRule 1.50 +#ifdef DEBUG 1.51 + virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; 1.52 +#endif 1.53 + 1.54 +public: 1.55 + void AppendStyleRule(Rule* aRule); 1.56 + 1.57 + int32_t StyleRuleCount() const { return mRules.Count(); } 1.58 + Rule* GetStyleRuleAt(int32_t aIndex) const; 1.59 + 1.60 + typedef nsCOMArray<Rule>::nsCOMArrayEnumFunc RuleEnumFunc; 1.61 + bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const; 1.62 + 1.63 + /* 1.64 + * The next three methods should never be called unless you have first 1.65 + * called WillDirty() on the parent stylesheet. After they are 1.66 + * called, DidDirty() needs to be called on the sheet. 1.67 + */ 1.68 + nsresult DeleteStyleRuleAt(uint32_t aIndex); 1.69 + nsresult InsertStyleRuleAt(uint32_t aIndex, Rule* aRule); 1.70 + nsresult ReplaceStyleRule(Rule *aOld, Rule *aNew); 1.71 + 1.72 + virtual bool UseForPresentation(nsPresContext* aPresContext, 1.73 + nsMediaQueryResultCacheKey& aKey) = 0; 1.74 + 1.75 + // non-virtual -- it is only called by subclasses 1.76 + size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 1.77 + virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const = 0; 1.78 + 1.79 + static bool 1.80 + CloneRuleInto(Rule* aRule, void* aArray) 1.81 + { 1.82 + nsRefPtr<Rule> clone = aRule->Clone(); 1.83 + static_cast<nsCOMArray<Rule>*>(aArray)->AppendObject(clone); 1.84 + return true; 1.85 + } 1.86 + 1.87 +protected: 1.88 + // to help implement nsIDOMCSSRule 1.89 + void AppendRulesToCssText(nsAString& aCssText); 1.90 + 1.91 + // to implement common methods on nsIDOMCSSMediaRule and 1.92 + // nsIDOMCSSMozDocumentRule 1.93 + nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList); 1.94 + nsresult InsertRule(const nsAString & aRule, uint32_t aIndex, 1.95 + uint32_t* _retval); 1.96 + nsresult DeleteRule(uint32_t aIndex); 1.97 + 1.98 + nsCOMArray<Rule> mRules; 1.99 + nsRefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed 1.100 +}; 1.101 + 1.102 +} // namespace css 1.103 +} // namespace mozilla 1.104 + 1.105 +#endif /* mozilla_css_GroupRule_h__ */