GroupRule.h 3.0 KB

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