Line data Source code
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 : /*
7 : * temporary (expanded) representation of property-value pairs used to
8 : * hold data from matched rules during style data computation.
9 : */
10 :
11 : #ifndef nsRuleData_h_
12 : #define nsRuleData_h_
13 :
14 : #include "mozilla/CSSVariableDeclarations.h"
15 : #include "mozilla/GenericSpecifiedValues.h"
16 : #include "mozilla/RuleNodeCacheConditions.h"
17 : #include "mozilla/SheetType.h"
18 : #include "nsAutoPtr.h"
19 : #include "nsCSSProps.h"
20 : #include "nsCSSValue.h"
21 : #include "nsStyleStructFwd.h"
22 :
23 : class nsPresContext;
24 : class nsStyleContext;
25 : struct nsRuleData;
26 :
27 : typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData);
28 :
29 : struct nsRuleData final : mozilla::GenericSpecifiedValues
30 : {
31 : mozilla::RuleNodeCacheConditions mConditions;
32 : bool mIsImportantRule;
33 : mozilla::SheetType mLevel;
34 : nsStyleContext* const mStyleContext;
35 :
36 : // We store nsCSSValues needed to compute the data for one or more
37 : // style structs (specified by the bitfield mSIDs). These are stored
38 : // in a single array allocation (which our caller allocates; see
39 : // AutoCSSValueArray) The offset of each property |prop| in
40 : // mValueStorage is the sum of
41 : // mValueOffsets[nsCSSProps::kSIDTable[prop]] and
42 : // nsCSSProps::PropertyIndexInStruct(prop). The only place we gather
43 : // more than one style struct's data at a time is
44 : // nsRuleNode::HasAuthorSpecifiedRules; therefore some code that we
45 : // know is not called from HasAuthorSpecifiedRules assumes that the
46 : // mValueOffsets for the one struct in mSIDs is zero.
47 : nsCSSValue* const mValueStorage; // our user owns this array
48 : size_t mValueOffsets[nsStyleStructID_Length];
49 :
50 : nsAutoPtr<mozilla::CSSVariableDeclarations> mVariables;
51 :
52 : nsRuleData(uint32_t aSIDs,
53 : nsCSSValue* aValueStorage,
54 : nsPresContext* aContext,
55 : nsStyleContext* aStyleContext);
56 :
57 : #ifdef DEBUG
58 : ~nsRuleData();
59 : #else
60 : ~nsRuleData() {}
61 : #endif
62 :
63 : /**
64 : * Return a pointer to the value object within |this| corresponding
65 : * to property |aProperty|.
66 : *
67 : * This function must only be called if the given property is in
68 : * mSIDs.
69 : */
70 25635 : nsCSSValue* ValueFor(nsCSSPropertyID aProperty)
71 : {
72 25635 : MOZ_ASSERT(aProperty < eCSSProperty_COUNT_no_shorthands,
73 : "invalid or shorthand property");
74 :
75 25635 : nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty];
76 25635 : size_t indexInStruct = nsCSSProps::PropertyIndexInStruct(aProperty);
77 :
78 : // This should really be nsCachedStyleData::GetBitForSID, but we can't
79 : // include that here since it includes us.
80 25635 : MOZ_ASSERT(mSIDs & (1 << sid),
81 : "calling nsRuleData::ValueFor on property not in mSIDs");
82 25635 : MOZ_ASSERT(indexInStruct != size_t(-1), "logical property");
83 :
84 25635 : return mValueStorage + mValueOffsets[sid] + indexInStruct;
85 : }
86 :
87 14218 : const nsCSSValue* ValueFor(nsCSSPropertyID aProperty) const
88 : {
89 14218 : return const_cast<nsRuleData*>(this)->ValueFor(aProperty);
90 : }
91 :
92 : /**
93 : * Getters like ValueFor(aProperty), but for each property by name
94 : * (ValueForBackgroundColor, etc.), and more efficient than ValueFor.
95 : * These use the names used for the property on DOM interfaces (the
96 : * 'method' field in nsCSSPropList.h).
97 : *
98 : * Like ValueFor(), the caller must check that the property is within
99 : * mSIDs.
100 : */
101 : #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) privatename_
102 : #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \
103 : kwtable_, stylestruct_, stylestructoffset_, animtype_) \
104 : nsCSSValue* ValueFor##method_() { \
105 : MOZ_ASSERT(mSIDs & NS_STYLE_INHERIT_BIT(stylestruct_), \
106 : "Calling nsRuleData::ValueFor" #method_ " without " \
107 : "NS_STYLE_INHERIT_BIT(" #stylestruct_ " in mSIDs."); \
108 : nsStyleStructID sid = eStyleStruct_##stylestruct_; \
109 : size_t indexInStruct = \
110 : nsCSSProps::PropertyIndexInStruct(eCSSProperty_##id_); \
111 : MOZ_ASSERT(indexInStruct != size_t(-1), \
112 : "logical property"); \
113 : return mValueStorage + mValueOffsets[sid] + indexInStruct; \
114 : } \
115 : const nsCSSValue* ValueFor##method_() const { \
116 : return const_cast<nsRuleData*>(this)->ValueFor##method_(); \
117 : }
118 : #define CSS_PROP_LIST_EXCLUDE_LOGICAL
119 : #include "nsCSSPropList.h"
120 : #undef CSS_PROP_LIST_EXCLUDE_LOGICAL
121 : #undef CSS_PROP
122 : #undef CSS_PROP_PUBLIC_OR_PRIVATE
123 :
124 : // GenericSpecifiedValues overrides
125 80 : bool PropertyIsSet(nsCSSPropertyID aId)
126 : {
127 80 : return ValueFor(aId)->GetUnit() != eCSSUnit_Null;
128 : }
129 :
130 : void SetIdentStringValue(nsCSSPropertyID aId, const nsString& aValue)
131 : {
132 : ValueFor(aId)->SetStringValue(aValue, eCSSUnit_Ident);
133 : }
134 :
135 0 : void SetIdentAtomValue(nsCSSPropertyID aId, nsIAtom* aValue)
136 : {
137 0 : nsCOMPtr<nsIAtom> atom = aValue;
138 0 : ValueFor(aId)->SetAtomIdentValue(atom.forget());
139 0 : }
140 :
141 28 : void SetKeywordValue(nsCSSPropertyID aId, int32_t aValue)
142 : {
143 28 : ValueFor(aId)->SetIntValue(aValue, eCSSUnit_Enumerated);
144 28 : }
145 :
146 0 : void SetIntValue(nsCSSPropertyID aId, int32_t aValue)
147 : {
148 0 : ValueFor(aId)->SetIntValue(aValue, eCSSUnit_Integer);
149 0 : }
150 :
151 0 : void SetPixelValue(nsCSSPropertyID aId, float aValue)
152 : {
153 0 : ValueFor(aId)->SetFloatValue(aValue, eCSSUnit_Pixel);
154 0 : }
155 :
156 0 : void SetLengthValue(nsCSSPropertyID aId, nsCSSValue aValue)
157 : {
158 0 : nsCSSValue* val = ValueFor(aId);
159 0 : *val = aValue;
160 0 : }
161 :
162 0 : void SetNumberValue(nsCSSPropertyID aId, float aValue)
163 : {
164 0 : ValueFor(aId)->SetFloatValue(aValue, eCSSUnit_Number);
165 0 : }
166 :
167 0 : void SetPercentValue(nsCSSPropertyID aId, float aValue)
168 : {
169 0 : ValueFor(aId)->SetPercentValue(aValue);
170 0 : }
171 :
172 0 : void SetAutoValue(nsCSSPropertyID aId) {
173 0 : ValueFor(aId)->SetAutoValue();
174 0 : }
175 :
176 0 : void SetCurrentColor(nsCSSPropertyID aId)
177 : {
178 0 : ValueFor(aId)->SetIntValue(NS_COLOR_CURRENTCOLOR, eCSSUnit_EnumColor);
179 0 : }
180 :
181 0 : void SetColorValue(nsCSSPropertyID aId, nscolor aValue)
182 : {
183 0 : ValueFor(aId)->SetColorValue(aValue);
184 0 : }
185 :
186 : void SetFontFamily(const nsString& aValue);
187 : void SetTextDecorationColorOverride();
188 : void SetBackgroundImage(nsAttrValue& aValue);
189 :
190 : private:
191 : inline size_t GetPoisonOffset();
192 : };
193 :
194 : #endif
|