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/CSSValue.h" |
29 #include "platform/graphics/Color.h" | |
30 #include "wtf/BitVector.h" | 29 #include "wtf/BitVector.h" |
31 #include "wtf/Forward.h" | 30 #include "wtf/Forward.h" |
32 #include "wtf/MathExtras.h" | 31 #include "wtf/MathExtras.h" |
33 #include "wtf/PassRefPtr.h" | 32 #include "wtf/PassRefPtr.h" |
34 #include "wtf/text/StringHash.h" | 33 #include "wtf/text/StringHash.h" |
35 | 34 |
36 namespace blink { | 35 namespace blink { |
37 | 36 |
38 class CSSCalcValue; | 37 class CSSCalcValue; |
39 class CSSToLengthConversionData; | 38 class CSSToLengthConversionData; |
40 class Length; | 39 class Length; |
41 class RGBColor; | |
42 class ComputedStyle; | 40 class ComputedStyle; |
43 | 41 |
44 // Dimension calculations are imprecise, often resulting in values of e.g. | 42 // Dimension calculations are imprecise, often resulting in values of e.g. |
45 // 44.99998. We need to go ahead and round if we're really close to the next | 43 // 44.99998. We need to go ahead and round if we're really close to the next |
46 // integer value. | 44 // integer value. |
47 template<typename T> inline T roundForImpreciseConversion(double value) | 45 template<typename T> inline T roundForImpreciseConversion(double value) |
48 { | 46 { |
49 value += (value < 0) ? -0.01 : +0.01; | 47 value += (value < 0) ? -0.01 : +0.01; |
50 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); | 48 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim
its<T>::min())) ? 0 : static_cast<T>(value); |
51 } | 49 } |
(...skipping 27 matching lines...) Expand all Loading... |
79 Points, | 77 Points, |
80 Picas, | 78 Picas, |
81 Degrees, | 79 Degrees, |
82 Radians, | 80 Radians, |
83 Gradians, | 81 Gradians, |
84 Turns, | 82 Turns, |
85 Milliseconds, | 83 Milliseconds, |
86 Seconds, | 84 Seconds, |
87 Hertz, | 85 Hertz, |
88 Kilohertz, | 86 Kilohertz, |
89 RGBColor, | |
90 ViewportWidth, | 87 ViewportWidth, |
91 ViewportHeight, | 88 ViewportHeight, |
92 ViewportMin, | 89 ViewportMin, |
93 ViewportMax, | 90 ViewportMax, |
94 DotsPerPixel, | 91 DotsPerPixel, |
95 DotsPerInch, | 92 DotsPerInch, |
96 DotsPerCentimeter, | 93 DotsPerCentimeter, |
97 Fraction, | 94 Fraction, |
98 Integer, | 95 Integer, |
99 Rems, | 96 Rems, |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } | 166 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } |
170 static bool isViewportPercentageLength(UnitType type) { return type >= UnitT
ype::ViewportWidth && type <= UnitType::ViewportMax; } | 167 static bool isViewportPercentageLength(UnitType type) { return type >= UnitT
ype::ViewportWidth && type <= UnitType::ViewportMax; } |
171 static bool isLength(UnitType type) | 168 static bool isLength(UnitType type) |
172 { | 169 { |
173 return (type >= UnitType::Ems && type <= UnitType::Picas) || type == Uni
tType::QuirkyEms || type == UnitType::Rems || type == UnitType::Chs || isViewpor
tPercentageLength(type); | 170 return (type >= UnitType::Ems && type <= UnitType::Picas) || type == Uni
tType::QuirkyEms || type == UnitType::Rems || type == UnitType::Chs || isViewpor
tPercentageLength(type); |
174 } | 171 } |
175 bool isLength() const { return isLength(typeWithCalcResolved()); } | 172 bool isLength() const { return isLength(typeWithCalcResolved()); } |
176 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } | 173 bool isNumber() const { return typeWithCalcResolved() == UnitType::Number ||
typeWithCalcResolved() == UnitType::Integer; } |
177 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } | 174 bool isPercentage() const { return typeWithCalcResolved() == UnitType::Perce
ntage; } |
178 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } | 175 bool isPx() const { return typeWithCalcResolved() == UnitType::Pixels; } |
179 bool isRGBColor() const { return type() == UnitType::RGBColor; } | |
180 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } | 176 bool isTime() const { return type() == UnitType::Seconds || type() == UnitTy
pe::Milliseconds; } |
181 bool isCalculated() const { return type() == UnitType::Calc; } | 177 bool isCalculated() const { return type() == UnitType::Calc; } |
182 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } | 178 bool isCalculatedPercentageWithNumber() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithNumber; } |
183 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } | 179 bool isCalculatedPercentageWithLength() const { return typeWithCalcResolved(
) == UnitType::CalcPercentageWithLength; } |
184 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI
nch; } | 180 static bool isDotsPerInch(UnitType type) { return type == UnitType::DotsPerI
nch; } |
185 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer
Pixel; } | 181 static bool isDotsPerPixel(UnitType type) { return type == UnitType::DotsPer
Pixel; } |
186 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do
tsPerCentimeter; } | 182 static bool isDotsPerCentimeter(UnitType type) { return type == UnitType::Do
tsPerCentimeter; } |
187 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } | 183 static bool isResolution(UnitType type) { return type >= UnitType::DotsPerPi
xel && type <= UnitType::DotsPerCentimeter; } |
188 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } | 184 bool isFlex() const { return typeWithCalcResolved() == UnitType::Fraction; } |
189 bool isValueID() const { return type() == UnitType::ValueID; } | 185 bool isValueID() const { return type() == UnitType::ValueID; } |
190 bool colorIsDerivedFromElement() const; | 186 bool colorIsDerivedFromElement() const; |
191 | 187 |
192 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) | 188 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) |
193 { | 189 { |
194 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); | 190 return adoptRefWillBeNoop(new CSSPrimitiveValue(valueID)); |
195 } | 191 } |
196 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(RGBA32 rgbValue
) | |
197 { | |
198 return adoptRefWillBeNoop(new CSSPrimitiveValue(rgbValue)); | |
199 } | |
200 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pe type) | 192 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pe type) |
201 { | 193 { |
202 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); | 194 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, type)); |
203 } | 195 } |
204 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) | 196 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) |
205 { | 197 { |
206 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); | 198 return adoptRefWillBeNoop(new CSSPrimitiveValue(value, zoom)); |
207 } | 199 } |
208 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) | 200 template<typename T> static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create
(T value) |
209 { | 201 { |
(...skipping 13 matching lines...) Expand all Loading... |
223 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; | 215 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; |
224 | 216 |
225 // Converts to a Length (Fixed, Percent or Calculated) | 217 // Converts to a Length (Fixed, Percent or Calculated) |
226 Length convertToLength(const CSSToLengthConversionData&) const; | 218 Length convertToLength(const CSSToLengthConversionData&) const; |
227 | 219 |
228 double getDoubleValue() const; | 220 double getDoubleValue() const; |
229 float getFloatValue() const { return getValue<float>(); } | 221 float getFloatValue() const { return getValue<float>(); } |
230 int getIntValue() const { return getValue<int>(); } | 222 int getIntValue() const { return getValue<int>(); } |
231 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 223 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
232 | 224 |
233 RGBA32 getRGBA32Value() const { ASSERT(isRGBColor()); return m_value.rgbcolo
r; } | |
234 | |
235 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } | 225 CSSCalcValue* cssCalcValue() const { ASSERT(isCalculated()); return m_value.
calc; } |
236 | 226 |
237 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } | 227 CSSValueID getValueID() const { return type() == UnitType::ValueID ? m_value
.valueID : CSSValueInvalid; } |
238 | 228 |
239 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h | 229 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h |
240 | 230 |
241 static const char* unitTypeToString(UnitType); | 231 static const char* unitTypeToString(UnitType); |
242 String customCSSText() const; | 232 String customCSSText() const; |
243 | 233 |
244 bool equals(const CSSPrimitiveValue&) const; | 234 bool equals(const CSSPrimitiveValue&) const; |
245 | 235 |
246 DECLARE_TRACE_AFTER_DISPATCH(); | 236 DECLARE_TRACE_AFTER_DISPATCH(); |
247 | 237 |
248 static UnitType canonicalUnitTypeForCategory(UnitCategory); | 238 static UnitType canonicalUnitTypeForCategory(UnitCategory); |
249 static double conversionToCanonicalUnitsScaleFactor(UnitType); | 239 static double conversionToCanonicalUnitsScaleFactor(UnitType); |
250 | 240 |
251 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. | 241 // Returns true and populates lengthUnitType, if unitType is a length unit.
Otherwise, returns false. |
252 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); | 242 static bool unitTypeToLengthUnitType(UnitType, LengthUnitType&); |
253 static UnitType lengthUnitTypeToUnitType(LengthUnitType); | 243 static UnitType lengthUnitTypeToUnitType(LengthUnitType); |
254 | 244 |
255 private: | 245 private: |
256 CSSPrimitiveValue(CSSValueID); | 246 CSSPrimitiveValue(CSSValueID); |
257 CSSPrimitiveValue(RGBA32 color); | |
258 CSSPrimitiveValue(const Length&, float zoom); | 247 CSSPrimitiveValue(const Length&, float zoom); |
259 CSSPrimitiveValue(double, UnitType); | 248 CSSPrimitiveValue(double, UnitType); |
260 | 249 |
261 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h | 250 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMa
ppings.h |
262 template<typename T> CSSPrimitiveValue(T* val) | 251 template<typename T> CSSPrimitiveValue(T* val) |
263 : CSSValue(PrimitiveClass) | 252 : CSSValue(PrimitiveClass) |
264 { | 253 { |
265 init(PassRefPtrWillBeRawPtr<T>(val)); | 254 init(PassRefPtrWillBeRawPtr<T>(val)); |
266 } | 255 } |
267 | 256 |
(...skipping 11 matching lines...) Expand all Loading... |
279 void init(const Length&); | 268 void init(const Length&); |
280 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); | 269 void init(PassRefPtrWillBeRawPtr<CSSCalcValue>); |
281 | 270 |
282 double computeLengthDouble(const CSSToLengthConversionData&) const; | 271 double computeLengthDouble(const CSSToLengthConversionData&) const; |
283 | 272 |
284 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } | 273 inline UnitType type() const { return static_cast<UnitType>(m_primitiveUnitT
ype); } |
285 | 274 |
286 union { | 275 union { |
287 CSSValueID valueID; | 276 CSSValueID valueID; |
288 double num; | 277 double num; |
289 RGBA32 rgbcolor; | |
290 // FIXME: oilpan: Should be a member, but no support for members in unio
ns. Just trace the raw ptr for now. | 278 // FIXME: oilpan: Should be a member, but no support for members in unio
ns. Just trace the raw ptr for now. |
291 CSSCalcValue* calc; | 279 CSSCalcValue* calc; |
292 } m_value; | 280 } m_value; |
293 }; | 281 }; |
294 | 282 |
295 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; | 283 using CSSLengthArray = CSSPrimitiveValue::CSSLengthArray; |
296 using CSSLengthTypeArray = CSSPrimitiveValue::CSSLengthTypeArray; | 284 using CSSLengthTypeArray = CSSPrimitiveValue::CSSLengthTypeArray; |
297 | 285 |
298 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 286 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
299 | 287 |
300 } // namespace blink | 288 } // namespace blink |
301 | 289 |
302 #endif // CSSPrimitiveValue_h | 290 #endif // CSSPrimitiveValue_h |
OLD | NEW |