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 11 matching lines...) Expand all Loading... |
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/CSSValue.h" |
29 #include "wtf/BitVector.h" | 29 #include "wtf/BitVector.h" |
30 #include "wtf/Forward.h" | 30 #include "wtf/Forward.h" |
31 #include "wtf/MathExtras.h" | 31 #include "wtf/MathExtras.h" |
| 32 #include "wtf/PassRefPtr.h" |
32 #include "wtf/TypeTraits.h" | 33 #include "wtf/TypeTraits.h" |
33 #include "wtf/text/StringHash.h" | 34 #include "wtf/text/StringHash.h" |
34 #include "wtf/text/StringView.h" | 35 #include "wtf/text/StringView.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 class CSSCalcValue; | 39 class CSSCalcValue; |
39 class CSSToLengthConversionData; | 40 class CSSToLengthConversionData; |
40 class Length; | 41 class Length; |
| 42 class ComputedStyle; |
41 | 43 |
42 // Dimension calculations are imprecise, often resulting in values of e.g. | 44 // Dimension calculations are imprecise, often resulting in values of e.g. |
43 // 44.99998. We need to go ahead and round if we're really close to the next | 45 // 44.99998. We need to go ahead and round if we're really close to the next |
44 // integer value. | 46 // integer value. |
45 template<typename T> inline T roundForImpreciseConversion(double value) | 47 template<typename T> inline T roundForImpreciseConversion(double value) |
46 { | 48 { |
47 value += (value < 0) ? -0.01 : +0.01; | 49 value += (value < 0) ? -0.01 : +0.01; |
48 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); | 50 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); |
49 } | 51 } |
50 | 52 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 bool isCalculated() const { return type() == UnitType::Calc; } | 202 bool isCalculated() const { return type() == UnitType::Calc; } |
201 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } | 203 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } |
202 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } | 204 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } |
203 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } | 205 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } |
204 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } | 206 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } |
205 bool isValueID() const { return type() == UnitType::ValueID; } | 207 bool isValueID() const { return type() == UnitType::ValueID; } |
206 bool colorIsDerivedFromElement() const; | 208 bool colorIsDerivedFromElement() const; |
207 | 209 |
208 static CSSPrimitiveValue* createIdentifier(CSSValueID); | 210 static CSSPrimitiveValue* createIdentifier(CSSValueID); |
209 static CSSPrimitiveValue* create(double value, UnitType); | 211 static CSSPrimitiveValue* create(double value, UnitType); |
| 212 // TODO(sashab): Remove this create() method, CSSPrimitiveValue should not |
| 213 // reference ComputedStyle. |
| 214 static CSSPrimitiveValue* create(const Length& value, const ComputedStyle&); |
210 static CSSPrimitiveValue* create(const Length& value, float zoom) | 215 static CSSPrimitiveValue* create(const Length& value, float zoom) |
211 { | 216 { |
212 return new CSSPrimitiveValue(value, zoom); | 217 return new CSSPrimitiveValue(value, zoom); |
213 } | 218 } |
214 template<typename T> static CSSPrimitiveValue* create(T value) | 219 template<typename T> static CSSPrimitiveValue* create(T value) |
215 { | 220 { |
216 static_assert(!std::is_same<T, CSSValueID>::value, "Do not call create()
with a CSSValueID; call createIdentifier() instead"); | 221 static_assert(!std::is_same<T, CSSValueID>::value, "Do not call create()
with a CSSValueID; call createIdentifier() instead"); |
217 return new CSSPrimitiveValue(value); | 222 return new CSSPrimitiveValue(value); |
218 } | 223 } |
219 | 224 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } m_value; | 304 } m_value; |
300 }; | 305 }; |
301 | 306 |
302 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; | 307 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; |
303 | 308 |
304 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 309 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
305 | 310 |
306 } // namespace blink | 311 } // namespace blink |
307 | 312 |
308 #endif // CSSPrimitiveValue_h | 313 #endif // CSSPrimitiveValue_h |
OLD | NEW |