nsIStyleRuleProcessor.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 containers (roughly origins within
  7. * the CSS cascade) that provide style rules matching an element or
  8. * pseudo-element
  9. */
  10. #ifndef nsIStyleRuleProcessor_h___
  11. #define nsIStyleRuleProcessor_h___
  12. #include "mozilla/MemoryReporting.h"
  13. #include "nsISupports.h"
  14. #include "nsChangeHint.h"
  15. struct RuleProcessorData;
  16. struct ElementRuleProcessorData;
  17. struct PseudoElementRuleProcessorData;
  18. struct AnonBoxRuleProcessorData;
  19. #ifdef MOZ_XUL
  20. struct XULTreeRuleProcessorData;
  21. #endif
  22. struct StateRuleProcessorData;
  23. struct PseudoElementStateRuleProcessorData;
  24. struct AttributeRuleProcessorData;
  25. class nsPresContext;
  26. // IID for the nsIStyleRuleProcessor interface
  27. // {c1d6001e-4fcb-4c40-bce1-5eba80bfd8f3}
  28. #define NS_ISTYLE_RULE_PROCESSOR_IID \
  29. { 0xc1d6001e, 0x4fcb, 0x4c40, \
  30. {0xbc, 0xe1, 0x5e, 0xba, 0x80, 0xbf, 0xd8, 0xf3} }
  31. /* The style rule processor interface is a mechanism to separate the matching
  32. * of style rules from style sheet instances.
  33. * Simple style sheets can and will act as their own processor.
  34. * Sheets where rule ordering interlaces between multiple sheets, will need to
  35. * share a single rule processor between them (CSS sheets do this for cascading order)
  36. *
  37. * @see nsIStyleRule (for significantly more detailed comments)
  38. */
  39. class nsIStyleRuleProcessor : public nsISupports {
  40. public:
  41. NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLE_RULE_PROCESSOR_IID)
  42. // Shorthand for:
  43. // nsCOMArray<nsIStyleRuleProcessor>::nsCOMArrayEnumFunc
  44. typedef bool (* EnumFunc)(nsIStyleRuleProcessor*, void*);
  45. /**
  46. * Find the |nsIStyleRule|s matching the given content node and
  47. * position the given |nsRuleWalker| at the |nsRuleNode| in the rule
  48. * tree representing that ordered list of rules (with higher
  49. * precedence being farther from the root of the lexicographic tree).
  50. */
  51. virtual void RulesMatching(ElementRuleProcessorData* aData) = 0;
  52. /**
  53. * Just like the previous |RulesMatching|, except for a given content
  54. * node <em>and pseudo-element</em>.
  55. */
  56. virtual void RulesMatching(PseudoElementRuleProcessorData* aData) = 0;
  57. /**
  58. * Just like the previous |RulesMatching|, except for a given anonymous box.
  59. */
  60. virtual void RulesMatching(AnonBoxRuleProcessorData* aData) = 0;
  61. #ifdef MOZ_XUL
  62. /**
  63. * Just like the previous |RulesMatching|, except for a given content
  64. * node <em>and tree pseudo</em>.
  65. */
  66. virtual void RulesMatching(XULTreeRuleProcessorData* aData) = 0;
  67. #endif
  68. /**
  69. * Return whether style can depend on a change of the given document state.
  70. *
  71. * Document states are defined in nsIDocument.h.
  72. */
  73. virtual bool
  74. HasDocumentStateDependentStyle(StateRuleProcessorData* aData) = 0;
  75. /**
  76. * Return how (as described by nsRestyleHint) style can depend on a
  77. * change of the given content state on the given content node. This
  78. * test is used for optimization only, and may err on the side of
  79. * reporting more dependencies than really exist.
  80. *
  81. * Event states are defined in mozilla/EventStates.h.
  82. */
  83. virtual nsRestyleHint
  84. HasStateDependentStyle(StateRuleProcessorData* aData) = 0;
  85. virtual nsRestyleHint
  86. HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) = 0;
  87. /**
  88. * This method will be called twice for every attribute change.
  89. * During the first call, aData->mAttrHasChanged will be false and
  90. * the attribute change will not have happened yet. During the
  91. * second call, aData->mAttrHasChanged will be true and the
  92. * change will have already happened. The bitwise OR of the two
  93. * return values must describe the style changes that are needed due
  94. * to the attribute change. It's up to the rule processor
  95. * implementation to decide how to split the bits up amongst the two
  96. * return values. For example, it could return the bits needed by
  97. * rules that might stop matching the node from the first call and
  98. * the bits needed by rules that might have started matching the
  99. * node from the second call. This test is used for optimization
  100. * only, and may err on the side of reporting more dependencies than
  101. * really exist.
  102. */
  103. virtual nsRestyleHint HasAttributeDependentStyle(
  104. AttributeRuleProcessorData* aData,
  105. mozilla::RestyleHintData& aRestyleHintDataResult) = 0;
  106. /**
  107. * Do any processing that needs to happen as a result of a change in
  108. * the characteristics of the medium, and return whether this rule
  109. * processor's rules have changed (e.g., because of media queries).
  110. */
  111. virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) = 0;
  112. /**
  113. * Report the size of this style rule processor to about:memory. A
  114. * processor may return 0.
  115. */
  116. virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const = 0;
  117. virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const = 0;
  118. };
  119. NS_DEFINE_STATIC_IID_ACCESSOR(nsIStyleRuleProcessor,
  120. NS_ISTYLE_RULE_PROCESSOR_IID)
  121. #endif /* nsIStyleRuleProcessor_h___ */