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