nsIStyleRule.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 abstract interface for objects providing immutable style
  7. * information
  8. */
  9. #ifndef nsIStyleRule_h___
  10. #define nsIStyleRule_h___
  11. #include <stdio.h>
  12. #include "nsCSSPropertyID.h"
  13. #include "nsISupports.h"
  14. class nsCSSValue;
  15. struct nsRuleData;
  16. // IID for the nsIStyleRule interface {f75f3f70-435d-43a6-a01b-65970489ca26}
  17. #define NS_ISTYLE_RULE_IID \
  18. { 0xf75f3f70, 0x435d, 0x43a6, \
  19. { 0xa0, 0x1b, 0x65, 0x97, 0x04, 0x89, 0xca, 0x26 } }
  20. /**
  21. * An object implementing |nsIStyleRule| (henceforth, a rule) represents
  22. * immutable stylistic information that either applies or does not apply
  23. * to a given element. It belongs to an object or group of objects that
  24. * implement |nsIStyleSheet| and |nsIStyleRuleProcessor| (henceforth, a
  25. * sheet).
  26. *
  27. * A rule becomes relevant to the computation of style data when
  28. * |nsIStyleRuleProcessor::RulesMatching| creates a rule node that
  29. * points to the rule. (A rule node, |nsRuleNode|, is a node in the
  30. * rule tree, which is a lexicographic tree indexed by rules. The path
  31. * from the root of the rule tree to the |nsRuleNode| for a given
  32. * |nsStyleContext| contains exactly the rules that match the element
  33. * that the style context is for, in priority (weight, origin,
  34. * specificity) order.)
  35. *
  36. * The computation of style data uses the rule tree, which calls
  37. * |nsIStyleRule::MapRuleInfoInto| below.
  38. *
  39. * It is worth emphasizing that the data represented by a rule
  40. * implementation are immutable. When the data need to be changed, a
  41. * new rule object must be created. Failing to do this will lead to
  42. * bugs in the handling of dynamic style changes, since the rule tree
  43. * caches the results of |MapRuleInfoInto|.
  44. *
  45. * |nsIStyleRule| objects are owned by |nsRuleNode| objects (in addition
  46. * to typically being owned by their sheet), which are in turn garbage
  47. * collected (with the garbage collection roots being style contexts).
  48. */
  49. class nsIStyleRule : public nsISupports {
  50. public:
  51. NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_IID)
  52. /**
  53. * |nsIStyleRule::MapRuleInfoInto| is a request to copy all stylistic
  54. * data represented by the rule that:
  55. * + are relevant for any structs in |aRuleData->mSIDs| (style
  56. * struct ID bits)
  57. * + are not already filled into the data struct
  58. * into the appropriate data struct in |aRuleData|. It is important
  59. * that only empty data are filled in, since the rule tree is walked
  60. * from highest priority rule to least, so that the walk can stop if
  61. * all needed data are found. Thus overwriting non-empty data will
  62. * break CSS cascading rules.
  63. */
  64. virtual void MapRuleInfoInto(nsRuleData* aRuleData)=0;
  65. /**
  66. * Returns whether this style rule has any style data for inherited
  67. * properties.
  68. */
  69. virtual bool MightMapInheritedStyleData() = 0;
  70. /**
  71. * Gets and sets given aProperty's value to aValue.
  72. * Returns true, if aValue is filled in this rule.
  73. */
  74. virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
  75. nsCSSValue* aValue) = 0;
  76. #ifdef DEBUG
  77. virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
  78. #endif
  79. };
  80. NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRule, NS_ISTYLE_RULE_IID)
  81. #endif /* nsIStyleRule_h___ */