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 23 matching lines...) Expand all Loading... |
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; | 42 class LengthSize; |
43 class Pair; | 43 class Pair; |
44 class Quad; | |
45 class RGBColor; | 44 class RGBColor; |
46 class Rect; | |
47 class ComputedStyle; | 45 class ComputedStyle; |
48 | 46 |
49 // Dimension calculations are imprecise, often resulting in values of e.g. | 47 // Dimension calculations are imprecise, often resulting in values of e.g. |
50 // 44.99998. We need to go ahead and round if we're really close to the next | 48 // 44.99998. We need to go ahead and round if we're really close to the next |
51 // integer value. | 49 // integer value. |
52 template<typename T> inline T roundForImpreciseConversion(double value) | 50 template<typename T> inline T roundForImpreciseConversion(double value) |
53 { | 51 { |
54 value += (value < 0) ? -0.01 : +0.01; | 52 value += (value < 0) ? -0.01 : +0.01; |
55 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); | 53 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); |
56 } | 54 } |
(...skipping 30 matching lines...) Expand all Loading... |
87 Radians, | 85 Radians, |
88 Gradians, | 86 Gradians, |
89 Turns, | 87 Turns, |
90 Milliseconds, | 88 Milliseconds, |
91 Seconds, | 89 Seconds, |
92 Hertz, | 90 Hertz, |
93 Kilohertz, | 91 Kilohertz, |
94 CustomIdentifier, | 92 CustomIdentifier, |
95 URI, | 93 URI, |
96 Attribute, | 94 Attribute, |
97 Rect, | |
98 RGBColor, | 95 RGBColor, |
99 ViewportWidth, | 96 ViewportWidth, |
100 ViewportHeight, | 97 ViewportHeight, |
101 ViewportMin, | 98 ViewportMin, |
102 ViewportMax, | 99 ViewportMax, |
103 DotsPerPixel, | 100 DotsPerPixel, |
104 DotsPerInch, | 101 DotsPerInch, |
105 DotsPerCentimeter, | 102 DotsPerCentimeter, |
106 Fraction, | 103 Fraction, |
107 Integer, | 104 Integer, |
108 Pair, | 105 Pair, |
109 Rems, | 106 Rems, |
110 Chs, | 107 Chs, |
111 Shape, | 108 Shape, |
112 Quad, | |
113 Calc, | 109 Calc, |
114 CalcPercentageWithNumber, | 110 CalcPercentageWithNumber, |
115 CalcPercentageWithLength, | 111 CalcPercentageWithLength, |
116 String, | 112 String, |
117 PropertyID, | 113 PropertyID, |
118 ValueID, | 114 ValueID, |
119 QuirkyEms, | 115 QuirkyEms, |
120 }; | 116 }; |
121 | 117 |
122 enum LengthUnitType { | 118 enum LengthUnitType { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 static bool isViewportPercentageLength(UnitType type) { return type >= UnitT
ype::ViewportWidth && type <= UnitType::ViewportMax; } | 174 static bool isViewportPercentageLength(UnitType type) { return type >= UnitT
ype::ViewportWidth && type <= UnitType::ViewportMax; } |
179 static bool isLength(UnitType type) | 175 static bool isLength(UnitType type) |
180 { | 176 { |
181 return (type >= UnitType::Ems && type <= UnitType::Picas) || type == Uni
tType::Rems || type == UnitType::Chs || isViewportPercentageLength(type); | 177 return (type >= UnitType::Ems && type <= UnitType::Picas) || type == Uni
tType::Rems || type == UnitType::Chs || isViewportPercentageLength(type); |
182 } | 178 } |
183 bool isLength() const { return isLength(typeWithCalcResolved()); } | 179 bool isLength() const { return isLength(typeWithCalcResolved()); } |
184 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } | 180 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } |
185 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } | 181 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } |
186 bool isPropertyID() const { return type() == UnitType::PropertyID; } | 182 bool isPropertyID() const { return type() == UnitType::PropertyID; } |
187 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } | 183 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } |
188 bool isQuad() const { return type() == UnitType::Quad; } | |
189 bool isRect() const { return type() == UnitType::Rect; } | |
190 bool isRGBColor() const { return type() == UnitType::RGBColor; } | 184 bool isRGBColor() const { return type() == UnitType::RGBColor; } |
191 bool isShape() const { return type() == UnitType::Shape; } | 185 bool isShape() const { return type() == UnitType::Shape; } |
192 bool isString() const { return type() == UnitType::String; } | 186 bool isString() const { return type() == UnitType::String; } |
193 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } | 187 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } |
194 bool isURI() const { return type() == UnitType::URI; } | 188 bool isURI() const { return type() == UnitType::URI; } |
195 bool isCalculated() const { return type() == UnitType::Calc; } | 189 bool isCalculated() const { return type() == UnitType::Calc; } |
196 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } | 190 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } |
197 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } | 191 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } |
198 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI
nch; } | 192 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI
nch; } |
199 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer
Pixel; } | 193 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer
Pixel; } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 255 |
262 // Converts to a Length (Fixed, Percent or Calculated) | 256 // Converts to a Length (Fixed, Percent or Calculated) |
263 Length convertToLength(const CSSToLengthConversionData&); | 257 Length convertToLength(const CSSToLengthConversionData&); |
264 | 258 |
265 double getDoubleValue() const; | 259 double getDoubleValue() const; |
266 float getFloatValue() const { return getValue<float>(); } | 260 float getFloatValue() const { return getValue<float>(); } |
267 int getIntValue() const { return getValue<int>(); } | 261 int getIntValue() const { return getValue<int>(); } |
268 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 262 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
269 | 263 |
270 String getStringValue() const; | 264 String getStringValue() const; |
271 | |
272 Rect* getRectValue() const { ASSERT(isRect()); return m_value.rect; } | |
273 Quad* getQuadValue() const { ASSERT(isQuad()); return m_value.quad; } | |
274 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } | 265 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } |
275 | 266 |
276 // TODO(timloh): Add isPair() and update callers so we can ASSERT(isPair()) | 267 // TODO(timloh): Add isPair() and update callers so we can ASSERT(isPair()) |
277 Pair* getPairValue() const { return type() != UnitType::Pair ? 0 : m_value.p
air; } | 268 Pair* getPairValue() const { return type() != UnitType::Pair ? 0 : m_value.p
air; } |
278 | 269 |
279 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha
pe; } | 270 CSSBasicShape* getShapeValue() const { ASSERT(isShape()); return m_value.sha
pe; } |
280 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } | 271 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } |
281 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value
.propertyID; } | 272 CSSPropertyID getPropertyID() const { ASSERT(isPropertyID()); return m_value
.propertyID; } |
282 | 273 |
283 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } | 274 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 init(val); | 313 init(val); |
323 } | 314 } |
324 | 315 |
325 static void create(int); // compile-time guard | 316 static void create(int); // compile-time guard |
326 static void create(unsigned); // compile-time guard | 317 static void create(unsigned); // compile-time guard |
327 template<typename T> operator T*(); // compile-time guard | 318 template<typename T> operator T*(); // compile-time guard |
328 | 319 |
329 void init(UnitType); | 320 void init(UnitType); |
330 void init(const Length&); | 321 void init(const Length&); |
331 void init(const LengthSize&, const ComputedStyle&); | 322 void init(const LengthSize&, const ComputedStyle&); |
332 void init(PassRefPtrWillBeRawPtr<Rect>); | |
333 void init(PassRefPtrWillBeRawPtr<Pair>); | 323 void init(PassRefPtrWillBeRawPtr<Pair>); |
334 void init(PassRefPtrWillBeRawPtr<Quad>); | |
335 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); | 324 void init(PassRefPtrWillBeRawPtr<CSSBasicShape>); |
336 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); | 325 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); |
337 | 326 |
338 double computeLengthDouble(const CSSToLengthConversionData&); | 327 double computeLengthDouble(const CSSToLengthConversionData&); |
339 | 328 |
340 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } | 329 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } |
341 | 330 |
342 union { | 331 union { |
343 CSSPropertyID propertyID; | 332 CSSPropertyID propertyID; |
344 CSSValueID valueID; | 333 CSSValueID valueID; |
345 double num; | 334 double num; |
346 StringImpl* string; | 335 StringImpl* string; |
347 RGBA32 rgbcolor; | 336 RGBA32 rgbcolor; |
348 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. | 337 // FIXME: oilpan: Should be members, but no support for members in union
s. Just trace the raw ptr for now. |
349 CSSBasicShape* shape; | 338 CSSBasicShape* shape; |
350 CSSCalcValue* calc; | 339 CSSCalcValue* calc; |
351 Pair* pair; | 340 Pair* pair; |
352 Rect* rect; | |
353 Quad* quad; | |
354 } m_value; | 341 } m_value; |
355 }; | 342 }; |
356 | 343 |
357 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; | 344 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; |
358 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; | 345 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; |
359 | 346 |
360 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 347 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
361 | 348 |
362 } // namespace blink | 349 } // namespace blink |
363 | 350 |
364 #endif // CSSPrimitiveValue_h | 351 #endif // CSSPrimitiveValue_h |
OLD | NEW |