nsCSSRules.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. // vim:cindent:ts=2:et:sw=2:
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. /* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
  7. #ifndef nsCSSRules_h_
  8. #define nsCSSRules_h_
  9. #include "Declaration.h"
  10. #include "StyleRule.h"
  11. #include "gfxFontFeatures.h"
  12. #include "mozilla/Attributes.h"
  13. #include "mozilla/MemoryReporting.h"
  14. #include "mozilla/Move.h"
  15. #include "mozilla/SheetType.h"
  16. #include "mozilla/css/GroupRule.h"
  17. #include "mozilla/dom/FontFace.h"
  18. #include "nsAutoPtr.h"
  19. #include "nsCSSPropertyID.h"
  20. #include "nsCSSValue.h"
  21. #include "nsDOMCSSDeclaration.h"
  22. #include "nsIDOMCSSConditionRule.h"
  23. #include "nsIDOMCSSCounterStyleRule.h"
  24. #include "nsIDOMCSSFontFaceRule.h"
  25. #include "nsIDOMCSSFontFeatureValuesRule.h"
  26. #include "nsIDOMCSSGroupingRule.h"
  27. #include "nsIDOMCSSMediaRule.h"
  28. #include "nsIDOMCSSMozDocumentRule.h"
  29. #include "nsIDOMCSSPageRule.h"
  30. #include "nsIDOMCSSSupportsRule.h"
  31. #include "nsIDOMCSSKeyframeRule.h"
  32. #include "nsIDOMCSSKeyframesRule.h"
  33. #include "nsTArray.h"
  34. class nsMediaList;
  35. namespace mozilla {
  36. namespace dom {
  37. class DocGroup;
  38. } // namespace dom
  39. class ErrorResult;
  40. namespace css {
  41. class MediaRule final : public GroupRule,
  42. public nsIDOMCSSMediaRule
  43. {
  44. public:
  45. MediaRule(uint32_t aLineNumber, uint32_t aColumnNumber);
  46. private:
  47. MediaRule(const MediaRule& aCopy);
  48. ~MediaRule();
  49. public:
  50. NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRule, GroupRule)
  51. NS_DECL_ISUPPORTS_INHERITED
  52. // Rule methods
  53. #ifdef DEBUG
  54. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  55. #endif
  56. virtual void SetStyleSheet(mozilla::CSSStyleSheet* aSheet) override; //override GroupRule
  57. virtual int32_t GetType() const override;
  58. virtual already_AddRefed<Rule> Clone() const override;
  59. virtual nsIDOMCSSRule* GetDOMRule() override
  60. {
  61. return this;
  62. }
  63. virtual nsIDOMCSSRule* GetExistingDOMRule() override
  64. {
  65. return this;
  66. }
  67. // nsIDOMCSSRule interface
  68. NS_DECL_NSIDOMCSSRULE
  69. // nsIDOMCSSGroupingRule interface
  70. NS_DECL_NSIDOMCSSGROUPINGRULE
  71. // nsIDOMCSSConditionRule interface
  72. NS_DECL_NSIDOMCSSCONDITIONRULE
  73. // nsIDOMCSSMediaRule interface
  74. NS_DECL_NSIDOMCSSMEDIARULE
  75. // rest of GroupRule
  76. virtual bool UseForPresentation(nsPresContext* aPresContext,
  77. nsMediaQueryResultCacheKey& aKey) override;
  78. // @media rule methods
  79. nsresult SetMedia(nsMediaList* aMedia);
  80. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
  81. const override MOZ_MUST_OVERRIDE;
  82. protected:
  83. void AppendConditionText(nsAString& aOutput);
  84. RefPtr<nsMediaList> mMedia;
  85. };
  86. class DocumentRule final : public GroupRule,
  87. public nsIDOMCSSMozDocumentRule
  88. {
  89. public:
  90. DocumentRule(uint32_t aLineNumber, uint32_t aColumnNumber);
  91. private:
  92. DocumentRule(const DocumentRule& aCopy);
  93. ~DocumentRule();
  94. public:
  95. NS_DECL_ISUPPORTS_INHERITED
  96. // Rule methods
  97. #ifdef DEBUG
  98. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  99. #endif
  100. virtual int32_t GetType() const override;
  101. virtual already_AddRefed<Rule> Clone() const override;
  102. virtual nsIDOMCSSRule* GetDOMRule() override
  103. {
  104. return this;
  105. }
  106. virtual nsIDOMCSSRule* GetExistingDOMRule() override
  107. {
  108. return this;
  109. }
  110. // nsIDOMCSSRule interface
  111. NS_DECL_NSIDOMCSSRULE
  112. // nsIDOMCSSGroupingRule interface
  113. NS_DECL_NSIDOMCSSGROUPINGRULE
  114. // nsIDOMCSSConditionRule interface
  115. NS_DECL_NSIDOMCSSCONDITIONRULE
  116. // nsIDOMCSSMozDocumentRule interface
  117. NS_DECL_NSIDOMCSSMOZDOCUMENTRULE
  118. // rest of GroupRule
  119. virtual bool UseForPresentation(nsPresContext* aPresContext,
  120. nsMediaQueryResultCacheKey& aKey) override;
  121. bool UseForPresentation(nsPresContext* aPresContext);
  122. enum Function {
  123. eURL,
  124. eURLPrefix,
  125. eDomain,
  126. eRegExp
  127. };
  128. struct URL {
  129. Function func;
  130. nsCString url;
  131. URL *next;
  132. URL() : next(nullptr) {}
  133. URL(const URL& aOther)
  134. : func(aOther.func)
  135. , url(aOther.url)
  136. , next(aOther.next ? new URL(*aOther.next) : nullptr)
  137. {
  138. }
  139. ~URL();
  140. };
  141. void SetURLs(URL *aURLs) { mURLs = aURLs; }
  142. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
  143. const override MOZ_MUST_OVERRIDE;
  144. protected:
  145. void AppendConditionText(nsAString& aOutput);
  146. nsAutoPtr<URL> mURLs; // linked list of |struct URL| above.
  147. };
  148. } // namespace css
  149. struct CSSFontFaceDescriptors
  150. {
  151. #define CSS_FONT_DESC(name_, method_) nsCSSValue m##method_;
  152. #include "nsCSSFontDescList.h"
  153. #undef CSS_FONT_DESC
  154. const nsCSSValue& Get(nsCSSFontDesc aFontDescID) const;
  155. nsCSSValue& Get(nsCSSFontDesc aFontDescID);
  156. private:
  157. static nsCSSValue CSSFontFaceDescriptors::* const Fields[];
  158. };
  159. } // namespace mozilla
  160. // A nsCSSFontFaceStyleDecl is always embedded in a nsCSSFontFaceRule.
  161. class nsCSSFontFaceRule;
  162. class nsCSSFontFaceStyleDecl final : public nsICSSDeclaration
  163. {
  164. public:
  165. NS_DECL_ISUPPORTS_INHERITED
  166. NS_DECL_NSIDOMCSSSTYLEDECLARATION_HELPER
  167. NS_DECL_NSICSSDECLARATION
  168. virtual already_AddRefed<mozilla::dom::CSSValue>
  169. GetPropertyCSSValue(const nsAString& aProp, mozilla::ErrorResult& aRv)
  170. override;
  171. using nsICSSDeclaration::GetPropertyCSSValue;
  172. virtual nsINode *GetParentObject() override;
  173. virtual mozilla::dom::DocGroup* GetDocGroup() const override;
  174. virtual void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName) override;
  175. nsresult GetPropertyValue(nsCSSFontDesc aFontDescID,
  176. nsAString & aResult) const;
  177. virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
  178. protected:
  179. ~nsCSSFontFaceStyleDecl() {}
  180. friend class nsCSSFontFaceRule;
  181. inline nsCSSFontFaceRule* ContainingRule();
  182. inline const nsCSSFontFaceRule* ContainingRule() const;
  183. mozilla::CSSFontFaceDescriptors mDescriptors;
  184. private:
  185. // NOT TO BE IMPLEMENTED
  186. // This object cannot be allocated on its own, only as part of
  187. // nsCSSFontFaceRule.
  188. void* operator new(size_t size) CPP_THROW_NEW;
  189. };
  190. class nsCSSFontFaceRule final : public mozilla::css::Rule,
  191. public nsIDOMCSSFontFaceRule
  192. {
  193. public:
  194. nsCSSFontFaceRule(uint32_t aLineNumber, uint32_t aColumnNumber)
  195. : mozilla::css::Rule(aLineNumber, aColumnNumber) {}
  196. nsCSSFontFaceRule(const nsCSSFontFaceRule& aCopy)
  197. // copy everything except our reference count
  198. : mozilla::css::Rule(aCopy), mDecl(aCopy.mDecl) {}
  199. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  200. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsCSSFontFaceRule,
  201. mozilla::css::Rule)
  202. // Rule methods
  203. DECL_STYLE_RULE_INHERIT
  204. #ifdef DEBUG
  205. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  206. #endif
  207. virtual int32_t GetType() const override;
  208. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  209. // nsIDOMCSSRule interface
  210. NS_DECL_NSIDOMCSSRULE
  211. // nsIDOMCSSFontFaceRule interface
  212. NS_DECL_NSIDOMCSSFONTFACERULE
  213. void SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue);
  214. void GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue);
  215. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  216. void GetDescriptors(mozilla::CSSFontFaceDescriptors& aDescriptors) const
  217. { aDescriptors = mDecl.mDescriptors; }
  218. protected:
  219. ~nsCSSFontFaceRule() {}
  220. friend class nsCSSFontFaceStyleDecl;
  221. nsCSSFontFaceStyleDecl mDecl;
  222. };
  223. // nsFontFaceRuleContainer - used for associating sheet type with
  224. // specific @font-face rules
  225. struct nsFontFaceRuleContainer {
  226. RefPtr<nsCSSFontFaceRule> mRule;
  227. mozilla::SheetType mSheetType;
  228. };
  229. inline nsCSSFontFaceRule*
  230. nsCSSFontFaceStyleDecl::ContainingRule()
  231. {
  232. return reinterpret_cast<nsCSSFontFaceRule*>
  233. (reinterpret_cast<char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
  234. }
  235. inline const nsCSSFontFaceRule*
  236. nsCSSFontFaceStyleDecl::ContainingRule() const
  237. {
  238. return reinterpret_cast<const nsCSSFontFaceRule*>
  239. (reinterpret_cast<const char*>(this) - offsetof(nsCSSFontFaceRule, mDecl));
  240. }
  241. class nsCSSFontFeatureValuesRule final : public mozilla::css::Rule,
  242. public nsIDOMCSSFontFeatureValuesRule
  243. {
  244. public:
  245. nsCSSFontFeatureValuesRule(uint32_t aLineNumber, uint32_t aColumnNumber)
  246. : mozilla::css::Rule(aLineNumber, aColumnNumber) {}
  247. nsCSSFontFeatureValuesRule(const nsCSSFontFeatureValuesRule& aCopy)
  248. // copy everything except our reference count
  249. : mozilla::css::Rule(aCopy),
  250. mFamilyList(aCopy.mFamilyList),
  251. mFeatureValues(aCopy.mFeatureValues) {}
  252. NS_DECL_ISUPPORTS
  253. // Rule methods
  254. DECL_STYLE_RULE_INHERIT
  255. #ifdef DEBUG
  256. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  257. #endif
  258. virtual int32_t GetType() const override;
  259. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  260. // nsIDOMCSSRule interface
  261. NS_DECL_NSIDOMCSSRULE
  262. // nsIDOMCSSFontFaceRule interface
  263. NS_DECL_NSIDOMCSSFONTFEATUREVALUESRULE
  264. const mozilla::FontFamilyList& GetFamilyList() { return mFamilyList; }
  265. void SetFamilyList(const mozilla::FontFamilyList& aFamilyList);
  266. void AddValueList(int32_t aVariantAlternate,
  267. nsTArray<gfxFontFeatureValueSet::ValueList>& aValueList);
  268. const nsTArray<gfxFontFeatureValueSet::FeatureValues>& GetFeatureValues()
  269. {
  270. return mFeatureValues;
  271. }
  272. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  273. protected:
  274. ~nsCSSFontFeatureValuesRule() {}
  275. mozilla::FontFamilyList mFamilyList;
  276. nsTArray<gfxFontFeatureValueSet::FeatureValues> mFeatureValues;
  277. };
  278. class nsCSSKeyframeRule;
  279. class nsCSSKeyframeStyleDeclaration final : public nsDOMCSSDeclaration
  280. {
  281. public:
  282. explicit nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule *aRule);
  283. NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override;
  284. void DropReference() { mRule = nullptr; }
  285. virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
  286. virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) override;
  287. virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
  288. virtual nsIDocument* DocToUpdate() override;
  289. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  290. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsCSSKeyframeStyleDeclaration,
  291. nsICSSDeclaration)
  292. virtual nsINode* GetParentObject() override;
  293. virtual mozilla::dom::DocGroup* GetDocGroup() const override;
  294. protected:
  295. virtual ~nsCSSKeyframeStyleDeclaration();
  296. // This reference is not reference-counted. The rule object tells us
  297. // when it's about to go away.
  298. nsCSSKeyframeRule* MOZ_NON_OWNING_REF mRule;
  299. };
  300. class nsCSSKeyframeRule final : public mozilla::css::Rule,
  301. public nsIDOMCSSKeyframeRule
  302. {
  303. public:
  304. // Steals the contents of aKeys, and takes the reference in Declaration
  305. nsCSSKeyframeRule(InfallibleTArray<float>&& aKeys,
  306. already_AddRefed<mozilla::css::Declaration>&& aDeclaration,
  307. uint32_t aLineNumber, uint32_t aColumnNumber)
  308. : mozilla::css::Rule(aLineNumber, aColumnNumber)
  309. , mKeys(mozilla::Move(aKeys))
  310. , mDeclaration(mozilla::Move(aDeclaration))
  311. {
  312. mDeclaration->SetOwningRule(this);
  313. }
  314. private:
  315. nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy);
  316. ~nsCSSKeyframeRule();
  317. public:
  318. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  319. NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSKeyframeRule, mozilla::css::Rule)
  320. // Rule methods
  321. DECL_STYLE_RULE_INHERIT
  322. #ifdef DEBUG
  323. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  324. #endif
  325. virtual int32_t GetType() const override;
  326. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  327. // nsIDOMCSSRule interface
  328. NS_DECL_NSIDOMCSSRULE
  329. // nsIDOMCSSKeyframeRule interface
  330. NS_DECL_NSIDOMCSSKEYFRAMERULE
  331. const nsTArray<float>& GetKeys() const { return mKeys; }
  332. mozilla::css::Declaration* Declaration() { return mDeclaration; }
  333. void ChangeDeclaration(mozilla::css::Declaration* aDeclaration);
  334. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  335. void DoGetKeyText(nsAString &aKeyText) const;
  336. private:
  337. nsTArray<float> mKeys;
  338. RefPtr<mozilla::css::Declaration> mDeclaration;
  339. // lazily created when needed:
  340. RefPtr<nsCSSKeyframeStyleDeclaration> mDOMDeclaration;
  341. };
  342. class nsCSSKeyframesRule final : public mozilla::css::GroupRule,
  343. public nsIDOMCSSKeyframesRule
  344. {
  345. public:
  346. nsCSSKeyframesRule(const nsSubstring& aName,
  347. uint32_t aLineNumber, uint32_t aColumnNumber)
  348. : mozilla::css::GroupRule(aLineNumber, aColumnNumber)
  349. , mName(aName)
  350. {
  351. }
  352. private:
  353. nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy);
  354. ~nsCSSKeyframesRule();
  355. public:
  356. NS_DECL_ISUPPORTS_INHERITED
  357. // Rule methods
  358. #ifdef DEBUG
  359. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  360. #endif
  361. virtual int32_t GetType() const override;
  362. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  363. virtual nsIDOMCSSRule* GetDOMRule() override
  364. {
  365. return this;
  366. }
  367. virtual nsIDOMCSSRule* GetExistingDOMRule() override
  368. {
  369. return this;
  370. }
  371. // nsIDOMCSSRule interface
  372. NS_DECL_NSIDOMCSSRULE
  373. // nsIDOMCSSKeyframesRule interface
  374. NS_DECL_NSIDOMCSSKEYFRAMESRULE
  375. // rest of GroupRule
  376. virtual bool UseForPresentation(nsPresContext* aPresContext,
  377. nsMediaQueryResultCacheKey& aKey) override;
  378. const nsString& GetName() { return mName; }
  379. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  380. private:
  381. uint32_t FindRuleIndexForKey(const nsAString& aKey);
  382. nsString mName;
  383. };
  384. class nsCSSPageRule;
  385. class nsCSSPageStyleDeclaration final : public nsDOMCSSDeclaration
  386. {
  387. public:
  388. explicit nsCSSPageStyleDeclaration(nsCSSPageRule *aRule);
  389. NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent) override;
  390. void DropReference() { mRule = nullptr; }
  391. virtual mozilla::DeclarationBlock* GetCSSDeclaration(Operation aOperation) override;
  392. virtual nsresult SetCSSDeclaration(mozilla::DeclarationBlock* aDecl) override;
  393. virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) override;
  394. virtual nsIDocument* DocToUpdate() override;
  395. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  396. NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsCSSPageStyleDeclaration,
  397. nsICSSDeclaration)
  398. virtual nsINode *GetParentObject() override;
  399. virtual mozilla::dom::DocGroup* GetDocGroup() const override;
  400. protected:
  401. virtual ~nsCSSPageStyleDeclaration();
  402. // This reference is not reference-counted. The rule object tells us
  403. // when it's about to go away.
  404. nsCSSPageRule* MOZ_NON_OWNING_REF mRule;
  405. };
  406. class nsCSSPageRule final : public mozilla::css::Rule,
  407. public nsIDOMCSSPageRule
  408. {
  409. public:
  410. nsCSSPageRule(mozilla::css::Declaration* aDeclaration,
  411. uint32_t aLineNumber, uint32_t aColumnNumber)
  412. : mozilla::css::Rule(aLineNumber, aColumnNumber)
  413. , mDeclaration(aDeclaration)
  414. {
  415. mDeclaration->SetOwningRule(this);
  416. }
  417. private:
  418. nsCSSPageRule(const nsCSSPageRule& aCopy);
  419. ~nsCSSPageRule();
  420. public:
  421. NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  422. NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCSSPageRule, nsIDOMCSSPageRule)
  423. // Rule methods
  424. DECL_STYLE_RULE_INHERIT
  425. #ifdef DEBUG
  426. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  427. #endif
  428. virtual int32_t GetType() const override;
  429. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  430. // nsIDOMCSSRule interface
  431. NS_DECL_NSIDOMCSSRULE
  432. // nsIDOMCSSPageRule interface
  433. NS_DECL_NSIDOMCSSPAGERULE
  434. mozilla::css::Declaration* Declaration() { return mDeclaration; }
  435. void ChangeDeclaration(mozilla::css::Declaration* aDeclaration);
  436. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  437. private:
  438. RefPtr<mozilla::css::Declaration> mDeclaration;
  439. // lazily created when needed:
  440. RefPtr<nsCSSPageStyleDeclaration> mDOMDeclaration;
  441. };
  442. namespace mozilla {
  443. class CSSSupportsRule : public css::GroupRule,
  444. public nsIDOMCSSSupportsRule
  445. {
  446. public:
  447. CSSSupportsRule(bool aConditionMet, const nsString& aCondition,
  448. uint32_t aLineNumber, uint32_t aColumnNumber);
  449. CSSSupportsRule(const CSSSupportsRule& aCopy);
  450. // Rule methods
  451. #ifdef DEBUG
  452. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  453. #endif
  454. virtual int32_t GetType() const override;
  455. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  456. virtual bool UseForPresentation(nsPresContext* aPresContext,
  457. nsMediaQueryResultCacheKey& aKey) override;
  458. virtual nsIDOMCSSRule* GetDOMRule() override
  459. {
  460. return this;
  461. }
  462. virtual nsIDOMCSSRule* GetExistingDOMRule() override
  463. {
  464. return this;
  465. }
  466. NS_DECL_ISUPPORTS_INHERITED
  467. // nsIDOMCSSRule interface
  468. NS_DECL_NSIDOMCSSRULE
  469. // nsIDOMCSSGroupingRule interface
  470. NS_DECL_NSIDOMCSSGROUPINGRULE
  471. // nsIDOMCSSConditionRule interface
  472. NS_DECL_NSIDOMCSSCONDITIONRULE
  473. // nsIDOMCSSSupportsRule interface
  474. NS_DECL_NSIDOMCSSSUPPORTSRULE
  475. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  476. protected:
  477. virtual ~CSSSupportsRule();
  478. bool mUseGroup;
  479. nsString mCondition;
  480. };
  481. } // namespace mozilla
  482. class nsCSSCounterStyleRule final : public mozilla::css::Rule,
  483. public nsIDOMCSSCounterStyleRule
  484. {
  485. public:
  486. explicit nsCSSCounterStyleRule(const nsAString& aName,
  487. uint32_t aLineNumber, uint32_t aColumnNumber)
  488. : mozilla::css::Rule(aLineNumber, aColumnNumber)
  489. , mName(aName)
  490. , mGeneration(0)
  491. {
  492. }
  493. private:
  494. nsCSSCounterStyleRule(const nsCSSCounterStyleRule& aCopy);
  495. ~nsCSSCounterStyleRule();
  496. public:
  497. NS_DECL_ISUPPORTS
  498. // Rule methods
  499. DECL_STYLE_RULE_INHERIT
  500. #ifdef DEBUG
  501. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
  502. #endif
  503. virtual int32_t GetType() const override;
  504. virtual already_AddRefed<mozilla::css::Rule> Clone() const override;
  505. // nsIDOMCSSRule interface
  506. NS_DECL_NSIDOMCSSRULE
  507. // nsIDOMCSSCounterStyleRule
  508. NS_DECL_NSIDOMCSSCOUNTERSTYLERULE
  509. // This function is only used to check whether a non-empty value, which has
  510. // been accepted by parser, is valid for the given system and descriptor.
  511. static bool CheckDescValue(int32_t aSystem,
  512. nsCSSCounterDesc aDescID,
  513. const nsCSSValue& aValue);
  514. const nsString& GetName() const { return mName; }
  515. uint32_t GetGeneration() const { return mGeneration; }
  516. int32_t GetSystem() const;
  517. const nsCSSValue& GetSystemArgument() const;
  518. const nsCSSValue& GetDesc(nsCSSCounterDesc aDescID) const
  519. {
  520. MOZ_ASSERT(aDescID >= 0 && aDescID < eCSSCounterDesc_COUNT,
  521. "descriptor ID out of range");
  522. return mValues[aDescID];
  523. }
  524. void SetDesc(nsCSSCounterDesc aDescID, const nsCSSValue& aValue);
  525. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override;
  526. private:
  527. typedef NS_STDCALL_FUNCPROTO(nsresult, Getter, nsCSSCounterStyleRule,
  528. GetSymbols, (nsAString&));
  529. static const Getter kGetters[];
  530. nsresult GetDescriptor(nsCSSCounterDesc aDescID, nsAString& aValue);
  531. nsresult SetDescriptor(nsCSSCounterDesc aDescID, const nsAString& aValue);
  532. nsString mName;
  533. nsCSSValue mValues[eCSSCounterDesc_COUNT];
  534. uint32_t mGeneration;
  535. };
  536. #endif /* !defined(nsCSSRules_h_) */