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 * |
(...skipping 21 matching lines...) Expand all Loading... |
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; |
39 class CSSCalcValue; | 39 class CSSCalcValue; |
40 class CSSToLengthConversionData; | 40 class CSSToLengthConversionData; |
41 class Length; | 41 class Length; |
42 class LengthSize; | |
43 class Pair; | |
44 class RGBColor; | 42 class RGBColor; |
45 class ComputedStyle; | 43 class ComputedStyle; |
46 | 44 |
47 // Dimension calculations are imprecise, often resulting in values of e.g. | 45 // Dimension calculations are imprecise, often resulting in values of e.g. |
48 // 44.99998. We need to go ahead and round if we're really close to the next | 46 // 44.99998. We need to go ahead and round if we're really close to the next |
49 // integer value. | 47 // integer value. |
50 template<typename T> inline T roundForImpreciseConversion(double value) | 48 template<typename T> inline T roundForImpreciseConversion(double value) |
51 { | 49 { |
52 value += (value < 0) ? -0.01 : +0.01; | 50 value += (value < 0) ? -0.01 : +0.01; |
53 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); | 51 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 RGBColor, | 93 RGBColor, |
96 ViewportWidth, | 94 ViewportWidth, |
97 ViewportHeight, | 95 ViewportHeight, |
98 ViewportMin, | 96 ViewportMin, |
99 ViewportMax, | 97 ViewportMax, |
100 DotsPerPixel, | 98 DotsPerPixel, |
101 DotsPerInch, | 99 DotsPerInch, |
102 DotsPerCentimeter, | 100 DotsPerCentimeter, |
103 Fraction, | 101 Fraction, |
104 Integer, | 102 Integer, |
105 Pair, | |
106 Rems, | 103 Rems, |
107 Chs, | 104 Chs, |
108 Shape, | 105 Shape, |
109 Calc, | 106 Calc, |
110 CalcPercentageWithNumber, | 107 CalcPercentageWithNumber, |
111 CalcPercentageWithLength, | 108 CalcPercentageWithLength, |
112 String, | 109 String, |
113 PropertyID, | 110 PropertyID, |
114 ValueID, | 111 ValueID, |
115 QuirkyEms, | 112 QuirkyEms, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 211 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); |
215 } | 212 } |
216 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitType type) | 213 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitType type) |
217 { | 214 { |
218 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 215 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); |
219 } | 216 } |
220 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) | 217 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) |
221 { | 218 { |
222 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); | 219 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); |
223 } | 220 } |
224 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const LengthSize& va
lue, const ComputedStyle& style) | |
225 { | |
226 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, style)); | |
227 } | |
228 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) | 221 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) |
229 { | 222 { |
230 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); | 223 return adoptRefWillBeNoop(new CSSPrimitiveValue(value)); |
231 } | 224 } |
232 | 225 |
233 // This value is used to handle quirky margins in reflow roots (body, td, an
d th) like WinIE. | 226 // This value is used to handle quirky margins in reflow roots (body, td, an
d th) like WinIE. |
234 // The basic idea is that a stylesheet can use the value __qem (for quirky e
m) instead of em. | 227 // The basic idea is that a stylesheet can use the value __qem (for quirky e
m) instead of em. |
235 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away | 228 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away |
236 // inside a table cell. | 229 // inside a table cell. |
237 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d
ouble value, UnitType type) | 230 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createAllowingMarginQuirk(d
ouble value, UnitType type) |
(...skipping 19 matching lines...) Expand all Loading... |
257 Length convertToLength(const CSSToLengthConversionData&) const; | 250 Length convertToLength(const CSSToLengthConversionData&) const; |
258 | 251 |
259 double getDoubleValue() const; | 252 double getDoubleValue() const; |
260 float getFloatValue() const { return getValue<float>(); } | 253 float getFloatValue() const { return getValue<float>(); } |
261 int getIntValue() const { return getValue<int>(); } | 254 int getIntValue() const { return getValue<int>(); } |
262 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 255 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
263 | 256 |
264 String getStringValue() const; | 257 String getStringValue() const; |
265 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } | 258 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } |
266 | 259 |
267 // TODO(timloh): Add isPair() and update callers so we can ASSERT(isPair()) | |
268 Pair* getPairValue() const { return type() != UnitType::Pair ? 0 : m_value.p
air; } | |
269 | |
270 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha
pe; } | 260 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha
pe; } |
271 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } | 261 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } |
272 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value
.propertyID; } | 262 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value
.propertyID; } |
273 | 263 |
274 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } | 264 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } |
275 | 265 |
276 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h | 266 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h |
277 | 267 |
278 static const char* unitTypeToString(UnitType); | 268 static const char* unitTypeToString(UnitType); |
279 String customCSSText() const; | 269 String customCSSText() const; |
280 | 270 |
281 bool isQuirkValue() const { return m_isQuirkValue; } | 271 bool isQuirkValue() const { return m_isQuirkValue; } |
282 | 272 |
283 bool equals(const CSSPrimitiveValue&) const; | 273 bool equals(const CSSPrimitiveValue&) const; |
284 | 274 |
285 DECLARE_TRACE_AFTER_DISPATCH(); | 275 DECLARE_TRACE_AFTER_DISPATCH(); |
286 | 276 |
287 static UnitType canonicalUnitTypeForCategory(UnitCategory); | 277 static UnitType canonicalUnitTypeForCategory(UnitCategory); |
288 static double conversionToCanonicalUnitsScaleFactor(UnitType); | 278 static double conversionToCanonicalUnitsScaleFactor(UnitType); |
289 | 279 |
290 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. | 280 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. |
291 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); | 281 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); |
292 static UnitType lengthUnitTypeToUnitType(LengthUnitType); | 282 static UnitType lengthUnitTypeToUnitType(LengthUnitType); |
293 | 283 |
294 private: | 284 private: |
295 CSSPrimitiveValue(CSSValueID); | 285 CSSPrimitiveValue(CSSValueID); |
296 CSSPrimitiveValue(CSSPropertyID); | 286 CSSPrimitiveValue(CSSPropertyID); |
297 CSSPrimitiveValue(RGBA32 color); | 287 CSSPrimitiveValue(RGBA32 color); |
298 CSSPrimitiveValue(const Length&, float zoom); | 288 CSSPrimitiveValue(const Length&, float zoom); |
299 CSSPrimitiveValue(const LengthSize&, const ComputedStyle&); | |
300 CSSPrimitiveValue(const String&, UnitType); | 289 CSSPrimitiveValue(const String&, UnitType); |
301 CSSPrimitiveValue(double, UnitType); | 290 CSSPrimitiveValue(double, UnitType); |
302 | 291 |
303 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h | 292 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h |
304 template<typename T> CSSPrimitiveValue(T* val) | 293 template<typename T> CSSPrimitiveValue(T* val) |
305 : CSSValue(PrimitiveClass) | 294 : CSSValue(PrimitiveClass) |
306 { | 295 { |
307 init(PassRefPtrWillBeRawPtr<T>(val)); | 296 init(PassRefPtrWillBeRawPtr<T>(val)); |
308 } | 297 } |
309 | 298 |
310 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) | 299 template<typename T> CSSPrimitiveValue(PassRefPtrWillBeRawPtr<T> val) |
311 : CSSValue(PrimitiveClass) | 300 : CSSValue(PrimitiveClass) |
312 { | 301 { |
313 init(val); | 302 init(val); |
314 } | 303 } |
315 | 304 |
316 static void create(int); // compile-time guard | 305 static void create(int); // compile-time guard |
317 static void create(unsigned); // compile-time guard | 306 static void create(unsigned); // compile-time guard |
318 template<typename T> operator T*(); // compile-time guard | 307 template<typename T> operator T*(); // compile-time guard |
319 | 308 |
320 void init(UnitType); | 309 void init(UnitType); |
321 void init(const Length&); | 310 void init(const Length&); |
322 void init(const LengthSize&, const ComputedStyle&); | |
323 void init(PassRefPtrWillBeRawPtr<Pair>); | |
324 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); | 311 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); |
325 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); | 312 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); |
326 | 313 |
327 double computeLengthDouble(const CSSToLengthConversionData&) const; | 314 double computeLengthDouble(const CSSToLengthConversionData&) const; |
328 | 315 |
329 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } | 316 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } |
330 | 317 |
331 union { | 318 union { |
332 CSSPropertyID propertyID; | 319 CSSPropertyID propertyID; |
333 CSSValueID valueID; | 320 CSSValueID valueID; |
334 double num; | 321 double num; |
335 StringImpl* string; | 322 StringImpl* string; |
336 RGBA32 rgbcolor; | 323 RGBA32 rgbcolor; |
337 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. | 324 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. |
338 CSSBasicShape* shape; | 325 CSSBasicShape* shape; |
339 CSSCalcValue* calc; | 326 CSSCalcValue* calc; |
340 Pair* pair; | |
341 } m_value; | 327 } m_value; |
342 }; | 328 }; |
343 | 329 |
344 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; | 330 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; |
345 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; | 331 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; |
346 | 332 |
347 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 333 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
348 | 334 |
349 } // namespace blink | 335 } // namespace blink |
350 | 336 |
351 #endif // CSSPrimitiveValue_h | 337 #endif // CSSPrimitiveValue_h |
OLD | NEW |