OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
15 * | 15 * |
16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
20 */ | 20 */ |
21 | 21 |
22 #ifndef CSSPrimitiveValue_h | 22 #ifndef CSSPrimitiveValue_h |
23 #define CSSPrimitiveValue_h | 23 #define CSSPrimitiveValue_h |
24 | 24 |
25 #include "core/CSSPropertyNames.h" | 25 #include "core/CSSPropertyNames.h" |
26 #include "core/CSSValueKeywords.h" | 26 #include "core/CSSValueKeywords.h" |
27 #include "core/CoreExport.h" | 27 #include "core/CoreExport.h" |
28 #include "core/css/CSSValue.h" | 28 #include "core/css/CSSValueObject.h" |
29 #include "platform/graphics/Color.h" | 29 #include "platform/graphics/Color.h" |
30 #include "wtf/BitVector.h" | 30 #include "wtf/BitVector.h" |
31 #include "wtf/Forward.h" | 31 #include "wtf/Forward.h" |
32 #include "wtf/MathExtras.h" | 32 #include "wtf/MathExtras.h" |
33 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
34 #include "wtf/text/StringHash.h" | 34 #include "wtf/text/StringHash.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 class CSSBasicShape; | 38 class CSSBasicShape; |
(...skipping 21 matching lines...) Expand all Loading... |
60 { | 60 { |
61 double ceiledValue = ceil(value); | 61 double ceiledValue = ceil(value); |
62 double proximityToNextInt = ceiledValue - value; | 62 double proximityToNextInt = ceiledValue - value; |
63 if (proximityToNextInt <= 0.01 && value > 0) | 63 if (proximityToNextInt <= 0.01 && value > 0) |
64 return static_cast<float>(ceiledValue); | 64 return static_cast<float>(ceiledValue); |
65 if (proximityToNextInt >= 0.99 && value < 0) | 65 if (proximityToNextInt >= 0.99 && value < 0) |
66 return static_cast<float>(floor(value)); | 66 return static_cast<float>(floor(value)); |
67 return static_cast<float>(value); | 67 return static_cast<float>(value); |
68 } | 68 } |
69 | 69 |
70 // CSSPrimitiveValues are immutable. This class has manual ref-counting | 70 // A type of unpacked CSSValue for CSSPrimitiveValue objects. Can only be stack-
allocated; |
71 // of unioned types and does not have the code necessary | 71 // pass these around by value. |
72 // to handle any kind of mutations. | 72 // Currently only supports CSSLargePrimitiveValues, but will later support tagge
d pointers |
73 class CORE_EXPORT CSSPrimitiveValue : public CSSValueObject { | 73 // stored as immediates in CSSValues. |
| 74 // TODO(sashab): Add tagged pointer support. |
| 75 class CORE_EXPORT CSSPrimitiveValue { |
| 76 STACK_ALLOCATED(); |
74 public: | 77 public: |
| 78 typedef union { |
| 79 CSSPropertyID propertyID; |
| 80 CSSValueID valueID; |
| 81 double num; |
| 82 StringImpl* string; |
| 83 RGBA32 rgbcolor; |
| 84 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. |
| 85 CSSBasicShape* shape; |
| 86 CSSCalcValue* calc; |
| 87 Counter* counter; |
| 88 Pair* pair; |
| 89 Rect* rect; |
| 90 Quad* quad; |
| 91 } CSSPrimitiveValueData; |
| 92 |
75 enum UnitType { | 93 enum UnitType { |
76 CSS_UNKNOWN = 0, | 94 CSS_UNKNOWN = 0, |
77 CSS_NUMBER = 1, | 95 CSS_NUMBER = 1, |
78 CSS_PERCENTAGE = 2, | 96 CSS_PERCENTAGE = 2, |
79 CSS_EMS = 3, | 97 CSS_EMS = 3, |
80 CSS_EXS = 4, | 98 CSS_EXS = 4, |
81 CSS_PX = 5, | 99 CSS_PX = 5, |
82 CSS_CM = 6, | 100 CSS_CM = 6, |
83 CSS_MM = 7, | 101 CSS_MM = 7, |
84 CSS_IN = 8, | 102 CSS_IN = 8, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 UnitTypeViewportMin, | 152 UnitTypeViewportMin, |
135 UnitTypeViewportMax, | 153 UnitTypeViewportMax, |
136 | 154 |
137 // This value must come after the last length unit type to enable iterat
ion over the length unit types. | 155 // This value must come after the last length unit type to enable iterat
ion over the length unit types. |
138 LengthUnitTypeCount, | 156 LengthUnitTypeCount, |
139 }; | 157 }; |
140 | 158 |
141 typedef Vector<double, CSSPrimitiveValue::LengthUnitTypeCount> CSSLengthArra
y; | 159 typedef Vector<double, CSSPrimitiveValue::LengthUnitTypeCount> CSSLengthArra
y; |
142 typedef BitVector CSSLengthTypeArray; | 160 typedef BitVector CSSLengthTypeArray; |
143 | 161 |
| 162 // No methods here, don't use this. It's just for large value storage. |
| 163 // IMPORTANT: You should never actually make one of these outside the parser
. |
| 164 class CSSLargePrimitiveValue final : public CSSValueObject { |
| 165 friend class CSSPrimitiveValue; |
| 166 public: |
| 167 CSSLargePrimitiveValue(CSSValueID); |
| 168 CSSLargePrimitiveValue(CSSPropertyID); |
| 169 CSSLargePrimitiveValue(RGBA32 color); |
| 170 CSSLargePrimitiveValue(const Length&, float zoom); |
| 171 CSSLargePrimitiveValue(const LengthSize&, const ComputedStyle&); |
| 172 CSSLargePrimitiveValue(const String&, UnitType); |
| 173 CSSLargePrimitiveValue(double, UnitType); |
| 174 CSSLargePrimitiveValue(double, UnitType, bool isQuirkValue); |
| 175 |
| 176 template<typename T> CSSLargePrimitiveValue(T); // Defined in CSSPrimiti
veValueMappings.h |
| 177 template<typename T> CSSLargePrimitiveValue(T* val) |
| 178 : CSSValueObject(PrimitiveClass) |
| 179 { |
| 180 init(PassRefPtrWillBeRawPtr<T>(val)); |
| 181 } |
| 182 |
| 183 template<typename T> CSSLargePrimitiveValue(PassRefPtrWillBeRawPtr<T> va
l) |
| 184 : CSSValueObject(PrimitiveClass) |
| 185 { |
| 186 init(val); |
| 187 } |
| 188 |
| 189 |
| 190 ~CSSLargePrimitiveValue(); |
| 191 |
| 192 void cleanup(); |
| 193 |
| 194 DECLARE_TRACE_AFTER_DISPATCH(); |
| 195 |
| 196 private: |
| 197 void init(const Length&); |
| 198 void init(const LengthSize&, const ComputedStyle&); |
| 199 void init(PassRefPtrWillBeRawPtr<Counter>); |
| 200 void init(PassRefPtrWillBeRawPtr<Rect>); |
| 201 void init(PassRefPtrWillBeRawPtr<Pair>); |
| 202 void init(PassRefPtrWillBeRawPtr<Quad>); |
| 203 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); |
| 204 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); |
| 205 |
| 206 CSSPrimitiveValueData m_value; |
| 207 }; |
| 208 |
| 209 explicit CSSPrimitiveValue(const CSSLargePrimitiveValue* object) |
| 210 : m_rawValue(const_cast<CSSLargePrimitiveValue*>(object)) |
| 211 { |
| 212 ref(); |
| 213 } |
| 214 |
| 215 CSSPrimitiveValue(PassRefPtrWillBeRawPtr<CSSLargePrimitiveValue> cssValue) |
| 216 : m_rawValue(cssValue.leakRef()) |
| 217 { |
| 218 } |
| 219 |
| 220 |
| 221 CSSPrimitiveValue(const CSSPrimitiveValue& other) |
| 222 : m_rawValue(other.m_rawValue) |
| 223 { |
| 224 ref(); |
| 225 } |
| 226 |
| 227 CSSPrimitiveValue& operator=(const CSSPrimitiveValue& rhs) |
| 228 { |
| 229 rhs.ref(); |
| 230 deref(); |
| 231 m_rawValue = rhs.m_rawValue; |
| 232 return *this; |
| 233 } |
| 234 |
| 235 ~CSSPrimitiveValue() |
| 236 { |
| 237 deref(); |
| 238 } |
| 239 |
| 240 |
| 241 CSSLargePrimitiveValue* get() const |
| 242 { |
| 243 return m_rawValue; |
| 244 } |
| 245 |
144 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const; | 246 void accumulateLengthArray(CSSLengthArray&, double multiplier = 1) const; |
145 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult
iplier = 1) const; | 247 void accumulateLengthArray(CSSLengthArray&, CSSLengthTypeArray&, double mult
iplier = 1) const; |
146 | 248 |
147 enum UnitCategory { | 249 enum UnitCategory { |
148 UNumber, | 250 UNumber, |
149 UPercent, | 251 UPercent, |
150 ULength, | 252 ULength, |
151 UAngle, | 253 UAngle, |
152 UTime, | 254 UTime, |
153 UFrequency, | 255 UFrequency, |
154 UResolution, | 256 UResolution, |
155 UOther | 257 UOther |
156 }; | 258 }; |
157 static UnitCategory unitCategory(UnitType); | 259 static UnitCategory unitCategory(UnitType); |
158 static float clampToCSSLengthRange(double); | 260 static float clampToCSSLengthRange(double); |
159 | 261 |
160 static void initUnitTable(); | 262 static void initUnitTable(); |
161 | 263 |
162 static UnitType fromName(const String& unit); | 264 static UnitType fromName(const String& unit); |
163 | 265 |
164 bool isAngle() const | 266 bool isAngle() const |
165 { | 267 { |
166 return m_primitiveUnitType == CSS_DEG | 268 return type() == CSS_DEG |
167 || m_primitiveUnitType == CSS_RAD | 269 || type() == CSS_RAD |
168 || m_primitiveUnitType == CSS_GRAD | 270 || type() == CSS_GRAD |
169 || m_primitiveUnitType == CSS_TURN; | 271 || type() == CSS_TURN; |
170 } | 272 } |
171 bool isAttr() const { return m_primitiveUnitType == CSS_ATTR; } | 273 bool isAttr() const { return type() == CSS_ATTR; } |
172 bool isCounter() const { return m_primitiveUnitType == CSS_COUNTER; } | 274 bool isCounter() const { return type() == CSS_COUNTER; } |
173 bool isCustomIdent() const { return m_primitiveUnitType == CSS_CUSTOM_IDENT;
} | 275 bool isCustomIdent() const { return type() == CSS_CUSTOM_IDENT; } |
174 bool isFontRelativeLength() const | 276 bool isFontRelativeLength() const |
175 { | 277 { |
176 return m_primitiveUnitType == CSS_EMS | 278 return type() == CSS_EMS |
177 || m_primitiveUnitType == CSS_EXS | 279 || type() == CSS_EXS |
178 || m_primitiveUnitType == CSS_REMS | 280 || type() == CSS_REMS |
179 || m_primitiveUnitType == CSS_CHS; | 281 || type() == CSS_CHS; |
180 } | 282 } |
181 bool isViewportPercentageLength() const { return isViewportPercentageLength(
static_cast<UnitType>(m_primitiveUnitType)); } | 283 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } |
182 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V
W && type <= CSS_VMAX; } | 284 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V
W && type <= CSS_VMAX; } |
183 static bool isLength(UnitType type) | 285 static bool isLength(UnitType type) |
184 { | 286 { |
185 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type =
= CSS_CHS || isViewportPercentageLength(type); | 287 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type =
= CSS_CHS || isViewportPercentageLength(type); |
186 } | 288 } |
187 bool isLength() const { return isLength(primitiveType()); } | 289 bool isLength() const { return isLength(primitiveType()); } |
188 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp
e() == CSS_INTEGER; } | 290 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp
e() == CSS_INTEGER; } |
189 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } | 291 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } |
190 bool isPx() const { return primitiveType() == CSS_PX; } | 292 bool isPx() const { return primitiveType() == CSS_PX; } |
191 bool isRect() const { return m_primitiveUnitType == CSS_RECT; } | 293 bool isRect() const { return type() == CSS_RECT; } |
192 bool isRGBColor() const { return m_primitiveUnitType == CSS_RGBCOLOR; } | 294 bool isRGBColor() const { return type() == CSS_RGBCOLOR; } |
193 bool isShape() const { return m_primitiveUnitType == CSS_SHAPE; } | 295 bool isShape() const { return type() == CSS_SHAPE; } |
194 bool isString() const { return m_primitiveUnitType == CSS_STRING; } | 296 bool isString() const { return type() == CSS_STRING; } |
195 bool isTime() const { return m_primitiveUnitType == CSS_S || m_primitiveUnit
Type == CSS_MS; } | 297 bool isTime() const { return type() == CSS_S || type() == CSS_MS; } |
196 bool isURI() const { return m_primitiveUnitType == CSS_URI; } | 298 bool isURI() const { return type() == CSS_URI; } |
197 bool isCalculated() const { return m_primitiveUnitType == CSS_CALC; } | 299 bool isCalculated() const { return type() == CSS_CALC; } |
198 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_NUMBER; } | 300 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_NUMBER; } |
199 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_LENGTH; } | 301 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_LENGTH; } |
200 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } | 302 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } |
201 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } | 303 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } |
202 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } | 304 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } |
203 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } | 305 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } |
204 bool isFlex() const { return primitiveType() == CSS_FR; } | 306 bool isFlex() const { return primitiveType() == CSS_FR; } |
205 bool isValueID() const { return m_primitiveUnitType == CSS_VALUE_ID; } | 307 bool isValueID() const { return type() == CSS_VALUE_ID; } |
206 bool colorIsDerivedFromElement() const; | 308 bool colorIsDerivedFromElement() const; |
207 | 309 |
208 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) | 310 static CSSPrimitiveValue createIdentifier(CSSValueID valueID) |
209 { | 311 { |
210 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); | 312 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alueID))); |
211 } | 313 } |
212 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert
yID propertyID) | 314 static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID) |
213 { | 315 { |
214 return adoptRefWillBeNoop(new CSSPrimitiveValue(propertyID)); | 316 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(p
ropertyID))); |
215 } | 317 } |
216 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue
) | 318 static CSSPrimitiveValue createColor(RGBA32 rgbValue) |
217 { | 319 { |
218 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue)); | 320 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(r
gbValue))); |
219 } | 321 } |
220 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pe type) | 322 static CSSPrimitiveValue create(double value, UnitType type) |
221 { | 323 { |
222 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 324 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); |
223 } | 325 } |
224 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitType type) | 326 static CSSPrimitiveValue create(const String& value, UnitType type) |
225 { | 327 { |
226 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 328 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); |
227 } | 329 } |
228 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) | 330 static CSSPrimitiveValue create(const Length& value, float zoom) |
229 { | 331 { |
230 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); | 332 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, zoom))); |
231 } | 333 } |
232 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va
lue, const ComputedStyle& style) | 334 static CSSPrimitiveValue create(const LengthSize& value, const ComputedStyle
& style) |
233 { | 335 { |
234 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style)); | 336 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, style))); |
235 } | 337 } |
236 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) | 338 template<typename T> static CSSPrimitiveValue create(T value) |
237 { | 339 { |
238 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); | 340 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue))); |
239 } | 341 } |
240 | 342 |
241 // This value is used to handle quirky margins in reflow roots (body, td, an
d th) like WinIE. | 343 // This value is used to handle quirky margins in reflow roots (body, td, an
d th) like WinIE. |
242 // The basic idea is that a stylesheet can use the value __qem (for quirky e
m) instead of em. | 344 // The basic idea is that a stylesheet can use the value __qem (for quirky e
m) instead of em. |
243 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away | 345 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away |
244 // inside a table cell. | 346 // inside a table cell. |
245 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d
ouble value, UnitType type) | 347 static CSSPrimitiveValue createAllowingMarginQuirk(double value, UnitType ty
pe) |
246 { | 348 { |
247 CSSPrimitiveValue* quirkValue = new CSSPrimitiveValue(value, type); | 349 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type, true))); |
248 quirkValue->m_isQuirkValue = true; | |
249 return adoptRefWillBeNoop(quirkValue); | |
250 } | 350 } |
251 | 351 |
252 ~CSSPrimitiveValue(); | |
253 | |
254 void cleanup(); | |
255 | |
256 UnitType primitiveType() const; | 352 UnitType primitiveType() const; |
257 | 353 |
258 double computeDegrees() const; | 354 double computeDegrees() const; |
259 double computeSeconds(); | 355 double computeSeconds(); |
260 | 356 |
261 // Computes a length in pixels, resolving relative lengths | 357 // Computes a length in pixels, resolving relative lengths |
262 template<typename T> T computeLength(const CSSToLengthConversionData&); | 358 template<typename T> T computeLength(const CSSToLengthConversionData&); |
263 | 359 |
264 // Converts to a Length (Fixed, Percent or Calculated) | 360 // Converts to a Length (Fixed, Percent or Calculated) |
265 Length convertToLength(const CSSToLengthConversionData&); | 361 Length convertToLength(const CSSToLengthConversionData&); |
266 | 362 |
267 double getDoubleValue() const; | 363 double getDoubleValue() const; |
268 float getFloatValue() const { return getValue<float>(); } | 364 float getFloatValue() const { return getValue<float>(); } |
269 int getIntValue() const { return getValue<int>(); } | 365 int getIntValue() const { return getValue<int>(); } |
270 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 366 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
271 | 367 |
272 String getStringValue() const; | 368 String getStringValue() const; |
273 | 369 |
274 Counter* getCounterValue() const { return m_primitiveUnitType != CSS_COUNTER
? 0 : m_value.counter; } | 370 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value(
).counter; } |
275 | 371 |
276 Rect* getRectValue() const { return m_primitiveUnitType != CSS_RECT ? 0 : m_
value.rect; } | 372 Rect* getRectValue() const { return type() != CSS_RECT ? 0 : value().rect; } |
277 | 373 |
278 Quad* getQuadValue() const { return m_primitiveUnitType != CSS_QUAD ? 0 : m_
value.quad; } | 374 Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : value().quad; } |
279 | 375 |
280 RGBA32 getRGBA32Value() const { return m_primitiveUnitType != CSS_RGBCOLOR ?
0 : m_value.rgbcolor; } | 376 RGBA32 getRGBA32Value() const { return type() != CSS_RGBCOLOR ? 0 : value().
rgbcolor; } |
281 | 377 |
282 Pair* getPairValue() const { return m_primitiveUnitType != CSS_PAIR ? 0 : m_
value.pair; } | 378 Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : value().pair; } |
283 | 379 |
284 CSSBasicShape* getShapeValue() const { return m_primitiveUnitType != CSS_SHA
PE ? 0 : m_value.shape; } | 380 CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : valu
e().shape; } |
285 | 381 |
286 CSSCalcValue* cssCalcValue() const { return m_primitiveUnitType != CSS_CALC
? 0 : m_value.calc; } | 382 CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : value()
.calc; } |
287 | 383 |
288 CSSPropertyID getPropertyID() const { return m_primitiveUnitType == CSS_PROP
ERTY_ID ? m_value.propertyID : CSSPropertyInvalid; } | 384 CSSPropertyID getPropertyID() const { return type() == CSS_PROPERTY_ID ? val
ue().propertyID : CSSPropertyInvalid; } |
289 CSSValueID getValueID() const { return m_primitiveUnitType == CSS_VALUE_ID ?
m_value.valueID : CSSValueInvalid; } | 385 CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valu
eID : CSSValueInvalid; } |
290 | 386 |
291 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h | 387 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h |
292 | 388 |
293 static const char* unitTypeToString(UnitType); | 389 static const char* unitTypeToString(UnitType); |
| 390 // TODO(sashab): Remove customCSSText() once CSSValueObject uses vtables pro
perly. |
294 String customCSSText() const; | 391 String customCSSText() const; |
| 392 String cssText() const { return customCSSText(); } |
295 | 393 |
296 bool isQuirkValue() { return m_isQuirkValue; } | 394 bool isQuirkValue() const { return m_rawValue->m_isQuirkValue; } |
297 | 395 |
298 bool equals(const CSSPrimitiveValue&) const; | 396 bool equals(const CSSPrimitiveValue) const; |
299 | |
300 DECLARE_TRACE_AFTER_DISPATCH(); | |
301 | 397 |
302 static UnitType canonicalUnitTypeForCategory(UnitCategory); | 398 static UnitType canonicalUnitTypeForCategory(UnitCategory); |
303 static double conversionToCanonicalUnitsScaleFactor(UnitType); | 399 static double conversionToCanonicalUnitsScaleFactor(UnitType); |
304 | 400 |
305 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. | 401 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. |
306 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); | 402 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); |
307 static UnitType lengthUnitTypeToUnitType(LengthUnitType); | 403 static UnitType lengthUnitTypeToUnitType(LengthUnitType); |
308 | 404 |
309 private: | 405 DEFINE_INLINE_TRACE() |
310 CSSPrimitiveValue(CSSValueID); | |
311 CSSPrimitiveValue(CSSPropertyID); | |
312 CSSPrimitiveValue(RGBA32 color); | |
313 CSSPrimitiveValue(const Length&, float zoom); | |
314 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&); | |
315 CSSPrimitiveValue(const String&, UnitType); | |
316 CSSPrimitiveValue(double, UnitType); | |
317 | |
318 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h | |
319 template<typename T> CSSPrimitiveValue(T* val) | |
320 : CSSValueObject(PrimitiveClass) | |
321 { | 406 { |
322 init(PassRefPtrWillBeRawPtr<T>(val)); | 407 visitor->trace(m_rawValue); |
| 408 m_rawValue->traceAfterDispatch(visitor); |
323 } | 409 } |
324 | 410 |
325 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) | 411 private: |
326 : CSSValueObject(PrimitiveClass) | 412 void ref() const |
327 { | 413 { |
328 init(val); | 414 #if !ENABLE(OILPAN) |
| 415 m_rawValue->ref(); |
| 416 #endif |
| 417 } |
| 418 |
| 419 void deref() const |
| 420 { |
| 421 #if !ENABLE(OILPAN) |
| 422 m_rawValue->deref(); |
| 423 #endif |
329 } | 424 } |
330 | 425 |
331 static void create(int); // compile-time guard | 426 static void create(int); // compile-time guard |
332 static void create(unsigned); // compile-time guard | 427 static void create(unsigned); // compile-time guard |
333 template<typename T> operator T*(); // compile-time guard | 428 template<typename T> operator T*(); // compile-time guard |
334 | 429 |
335 void init(const Length&); | |
336 void init(const LengthSize&, const ComputedStyle&); | |
337 void init(PassRefPtrWillBeRawPtr<Counter>); | |
338 void init(PassRefPtrWillBeRawPtr<Rect>); | |
339 void init(PassRefPtrWillBeRawPtr<Pair>); | |
340 void init(PassRefPtrWillBeRawPtr<Quad>); | |
341 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); | |
342 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); | |
343 | |
344 double computeLengthDouble(const CSSToLengthConversionData&); | 430 double computeLengthDouble(const CSSToLengthConversionData&); |
345 | 431 |
346 union { | 432 RawPtrWillBeMember<CSSLargePrimitiveValue> m_rawValue; |
347 CSSPropertyID propertyID; | 433 |
348 CSSValueID valueID; | 434 // Getters/setters for inner class. |
349 double num; | 435 CSSPrimitiveValueData value() const { return m_rawValue->m_value; } |
350 StringImpl* string; | 436 UnitType type() const { return static_cast<UnitType>(m_rawValue->m_primitive
UnitType); } |
351 RGBA32 rgbcolor; | 437 bool hasCachedCSSText() const { return m_rawValue->m_hasCachedCSSText; } |
352 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. | 438 |
353 CSSBasicShape* shape; | 439 void setValue(CSSPrimitiveValueData value) { m_rawValue->m_value = value; } |
354 CSSCalcValue* calc; | 440 void setType(UnitType primitiveUnitType) { m_rawValue->m_primitiveUnitType =
static_cast<unsigned>(primitiveUnitType); } |
355 Counter* counter; | 441 void setHasCachedCSSText(bool hasCachedCSSText) const { m_rawValue->m_hasCac
hedCSSText = hasCachedCSSText; } |
356 Pair* pair; | 442 void setIsQuirkValue(bool isQuirkValue) { m_rawValue->m_isQuirkValue = isQui
rkValue; } |
357 Rect* rect; | |
358 Quad* quad; | |
359 } m_value; | |
360 }; | 443 }; |
361 | 444 |
362 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; | 445 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; |
363 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; | 446 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; |
364 | 447 |
365 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | |
366 | |
367 } // namespace blink | 448 } // namespace blink |
368 | 449 |
369 #endif // CSSPrimitiveValue_h | 450 #endif // CSSPrimitiveValue_h |
OLD | NEW |