nsRuleData.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * temporary (expanded) representation of property-value pairs used to
  7. * hold data from matched rules during style data computation.
  8. */
  9. #ifndef nsRuleData_h_
  10. #define nsRuleData_h_
  11. #include "mozilla/CSSVariableDeclarations.h"
  12. #include "mozilla/RuleNodeCacheConditions.h"
  13. #include "mozilla/SheetType.h"
  14. #include "nsAutoPtr.h"
  15. #include "nsCSSProps.h"
  16. #include "nsCSSValue.h"
  17. #include "nsStyleStructFwd.h"
  18. class nsPresContext;
  19. class nsStyleContext;
  20. struct nsRuleData;
  21. typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData);
  22. struct nsRuleData
  23. {
  24. const uint32_t mSIDs;
  25. mozilla::RuleNodeCacheConditions mConditions;
  26. bool mIsImportantRule;
  27. mozilla::SheetType mLevel;
  28. nsPresContext* const mPresContext;
  29. nsStyleContext* const mStyleContext;
  30. // We store nsCSSValues needed to compute the data for one or more
  31. // style structs (specified by the bitfield mSIDs). These are stored
  32. // in a single array allocation (which our caller allocates; see
  33. // AutoCSSValueArray) The offset of each property |prop| in
  34. // mValueStorage is the sum of
  35. // mValueOffsets[nsCSSProps::kSIDTable[prop]] and
  36. // nsCSSProps::PropertyIndexInStruct(prop). The only place we gather
  37. // more than one style struct's data at a time is
  38. // nsRuleNode::HasAuthorSpecifiedRules; therefore some code that we
  39. // know is not called from HasAuthorSpecifiedRules assumes that the
  40. // mValueOffsets for the one struct in mSIDs is zero.
  41. nsCSSValue* const mValueStorage; // our user owns this array
  42. size_t mValueOffsets[nsStyleStructID_Length];
  43. nsAutoPtr<mozilla::CSSVariableDeclarations> mVariables;
  44. nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage,
  45. nsPresContext* aContext, nsStyleContext* aStyleContext);
  46. #ifdef DEBUG
  47. ~nsRuleData();
  48. #else
  49. ~nsRuleData() {}
  50. #endif
  51. /**
  52. * Return a pointer to the value object within |this| corresponding
  53. * to property |aProperty|.
  54. *
  55. * This function must only be called if the given property is in
  56. * mSIDs.
  57. */
  58. nsCSSValue* ValueFor(nsCSSPropertyID aProperty)
  59. {
  60. MOZ_ASSERT(aProperty < eCSSProperty_COUNT_no_shorthands,
  61. "invalid or shorthand property");
  62. nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty];
  63. size_t indexInStruct = nsCSSProps::PropertyIndexInStruct(aProperty);
  64. // This should really be nsCachedStyleData::GetBitForSID, but we can't
  65. // include that here since it includes us.
  66. MOZ_ASSERT(mSIDs & (1 << sid),
  67. "calling nsRuleData::ValueFor on property not in mSIDs");
  68. MOZ_ASSERT(indexInStruct != size_t(-1),
  69. "logical property");
  70. return mValueStorage + mValueOffsets[sid] + indexInStruct;
  71. }
  72. const nsCSSValue* ValueFor(nsCSSPropertyID aProperty) const {
  73. return const_cast<nsRuleData*>(this)->ValueFor(aProperty);
  74. }
  75. /**
  76. * Getters like ValueFor(aProperty), but for each property by name
  77. * (ValueForBackgroundColor, etc.), and more efficient than ValueFor.
  78. * These use the names used for the property on DOM interfaces (the
  79. * 'method' field in nsCSSPropList.h).
  80. *
  81. * Like ValueFor(), the caller must check that the property is within
  82. * mSIDs.
  83. */
  84. #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) privatename_
  85. #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
  86. kwtable_, stylestruct_, stylestructoffset_, animtype_) \
  87. nsCSSValue* ValueFor##method_() { \
  88. MOZ_ASSERT(mSIDs & NS_STYLE_INHERIT_BIT(stylestruct_), \
  89. "Calling nsRuleData::ValueFor" #method_ " without " \
  90. "NS_STYLE_INHERIT_BIT(" #stylestruct_ " in mSIDs."); \
  91. nsStyleStructID sid = eStyleStruct_##stylestruct_; \
  92. size_t indexInStruct = \
  93. nsCSSProps::PropertyIndexInStruct(eCSSProperty_##id_); \
  94. MOZ_ASSERT(indexInStruct != size_t(-1), \
  95. "logical property"); \
  96. return mValueStorage + mValueOffsets[sid] + indexInStruct; \
  97. } \
  98. const nsCSSValue* ValueFor##method_() const { \
  99. return const_cast<nsRuleData*>(this)->ValueFor##method_(); \
  100. }
  101. #define CSS_PROP_LIST_EXCLUDE_LOGICAL
  102. #include "nsCSSPropList.h"
  103. #undef CSS_PROP_LIST_EXCLUDE_LOGICAL
  104. #undef CSS_PROP
  105. #undef CSS_PROP_PUBLIC_OR_PRIVATE
  106. private:
  107. inline size_t GetPoisonOffset();
  108. };
  109. #endif