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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 { | 58 { |
59 double ceiledValue = ceil(value); | 59 double ceiledValue = ceil(value); |
60 double proximityToNextInt = ceiledValue - value; | 60 double proximityToNextInt = ceiledValue - value; |
61 if (proximityToNextInt <= 0.01 && value > 0) | 61 if (proximityToNextInt <= 0.01 && value > 0) |
62 return static_cast<float>(ceiledValue); | 62 return static_cast<float>(ceiledValue); |
63 if (proximityToNextInt >= 0.99 && value < 0) | 63 if (proximityToNextInt >= 0.99 && value < 0) |
64 return static_cast<float>(floor(value)); | 64 return static_cast<float>(floor(value)); |
65 return static_cast<float>(value); | 65 return static_cast<float>(value); |
66 } | 66 } |
67 | 67 |
| 68 // CSSPrimitiveValues are immutable. This class has manual ref-counting |
| 69 // of unioned types and does not have the code necessary |
| 70 // to handle any kind of mutations. All DOM-exposed "setters" just throw |
| 71 // exceptions. |
68 class CSSPrimitiveValue : public CSSValue { | 72 class CSSPrimitiveValue : public CSSValue { |
69 public: | 73 public: |
70 enum UnitTypes { | 74 enum UnitTypes { |
71 CSS_UNKNOWN = 0, | 75 CSS_UNKNOWN = 0, |
72 CSS_NUMBER = 1, | 76 CSS_NUMBER = 1, |
73 CSS_PERCENTAGE = 2, | 77 CSS_PERCENTAGE = 2, |
74 CSS_EMS = 3, | 78 CSS_EMS = 3, |
75 CSS_EXS = 4, | 79 CSS_EXS = 4, |
76 CSS_PX = 5, | 80 CSS_PX = 5, |
77 CSS_CM = 6, | 81 CSS_CM = 6, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) | 206 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSValueID
valueID) |
203 { | 207 { |
204 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(va
lueID)); | 208 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(va
lueID)); |
205 } | 209 } |
206 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert
yID propertyID) | 210 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createIdentifier(CSSPropert
yID propertyID) |
207 { | 211 { |
208 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(pr
opertyID)); | 212 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(pr
opertyID)); |
209 } | 213 } |
210 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createParserOperator(int pa
rserOperator) | 214 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createParserOperator(int pa
rserOperator) |
211 { | 215 { |
212 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(pa
rserOperator)); | 216 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(pa
rserOperator, CSS_PARSER_OPERATOR)); |
213 } | 217 } |
214 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(unsigned rgbVal
ue) | 218 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> createColor(unsigned rgbVal
ue) |
215 { | 219 { |
216 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(rg
bValue)); | 220 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(rg
bValue, CSS_RGBCOLOR)); |
217 } | 221 } |
218 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pes type) | 222 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(double value, UnitTy
pes type) |
219 { | 223 { |
220 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(va
lue, type)); | 224 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(va
lue, type)); |
221 } | 225 } |
222 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitTypes type) | 226 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const String& value,
UnitTypes type) |
223 { | 227 { |
224 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(va
lue, type)); | 228 return adoptRefWillBeRefCountedGarbageCollected(new CSSPrimitiveValue(va
lue, type)); |
225 } | 229 } |
226 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) | 230 static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> create(const Length& value,
float zoom) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dp
i | 281 * For screen output we assume 1 inch == 72 px, for printer we assume 300 dp
i |
278 * | 282 * |
279 * this is screen/printer dependent, so we probably need a config option for
this, | 283 * this is screen/printer dependent, so we probably need a config option for
this, |
280 * and some tool to calibrate. | 284 * and some tool to calibrate. |
281 */ | 285 */ |
282 template<typename T> T computeLength(const CSSToLengthConversionData&); | 286 template<typename T> T computeLength(const CSSToLengthConversionData&); |
283 | 287 |
284 // Converts to a Length, mapping various unit types appropriately. | 288 // Converts to a Length, mapping various unit types appropriately. |
285 template<int> Length convertToLength(const CSSToLengthConversionData&); | 289 template<int> Length convertToLength(const CSSToLengthConversionData&); |
286 | 290 |
287 // use with care!!! | |
288 void setPrimitiveType(unsigned short type) { m_primitiveUnitType = type; } | |
289 | |
290 double getDoubleValue(unsigned short unitType, ExceptionState&) const; | 291 double getDoubleValue(unsigned short unitType, ExceptionState&) const; |
291 double getDoubleValue(unsigned short unitType) const; | 292 double getDoubleValue(unsigned short unitType) const; |
292 double getDoubleValue() const; | 293 double getDoubleValue() const; |
293 | 294 |
294 void setFloatValue(unsigned short unitType, double floatValue, ExceptionStat
e&); | 295 void setFloatValue(unsigned short unitType, double floatValue, ExceptionStat
e&); |
295 float getFloatValue(unsigned short unitType, ExceptionState& exceptionState)
const { return getValue<float>(unitType, exceptionState); } | 296 float getFloatValue(unsigned short unitType, ExceptionState& exceptionState)
const { return getValue<float>(unitType, exceptionState); } |
296 float getFloatValue(unsigned short unitType) const { return getValue<float>(
unitType); } | 297 float getFloatValue(unsigned short unitType) const { return getValue<float>(
unitType); } |
297 float getFloatValue() const { return getValue<float>(); } | 298 float getFloatValue() const { return getValue<float>(); } |
298 | 299 |
299 int getIntValue(unsigned short unitType, ExceptionState& exceptionState) con
st { return getValue<int>(unitType, exceptionState); } | 300 int getIntValue(unsigned short unitType, ExceptionState& exceptionState) con
st { return getValue<int>(unitType, exceptionState); } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 bool equals(const CSSPrimitiveValue&) const; | 343 bool equals(const CSSPrimitiveValue&) const; |
343 | 344 |
344 void traceAfterDispatch(Visitor*); | 345 void traceAfterDispatch(Visitor*); |
345 | 346 |
346 static UnitTypes canonicalUnitTypeForCategory(UnitCategory); | 347 static UnitTypes canonicalUnitTypeForCategory(UnitCategory); |
347 static double conversionToCanonicalUnitsScaleFactor(unsigned short unitType)
; | 348 static double conversionToCanonicalUnitsScaleFactor(unsigned short unitType)
; |
348 | 349 |
349 private: | 350 private: |
350 CSSPrimitiveValue(CSSValueID); | 351 CSSPrimitiveValue(CSSValueID); |
351 CSSPrimitiveValue(CSSPropertyID); | 352 CSSPrimitiveValue(CSSPropertyID); |
352 // FIXME: int vs. unsigned overloading is too subtle to distinguish the colo
r and operator cases. | 353 // int vs. unsigned is too subtle to distinguish types, so require a UnitTyp
e. |
353 CSSPrimitiveValue(int parserOperator); | 354 CSSPrimitiveValue(int parserOperator, UnitTypes); |
354 CSSPrimitiveValue(unsigned color); // RGB value | 355 CSSPrimitiveValue(unsigned color, UnitTypes); // RGB value |
355 CSSPrimitiveValue(const Length& length) | 356 CSSPrimitiveValue(const Length& length) |
356 : CSSValue(PrimitiveClass) | 357 : CSSValue(PrimitiveClass) |
357 { | 358 { |
358 init(length); | 359 init(length); |
359 } | 360 } |
360 CSSPrimitiveValue(const Length&, float zoom); | 361 CSSPrimitiveValue(const Length&, float zoom); |
361 CSSPrimitiveValue(const LengthSize&); | 362 CSSPrimitiveValue(const LengthSize&); |
362 CSSPrimitiveValue(const String&, UnitTypes); | 363 CSSPrimitiveValue(const String&, UnitTypes); |
363 CSSPrimitiveValue(double, UnitTypes); | 364 CSSPrimitiveValue(double, UnitTypes); |
364 | 365 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 Rect* rect; | 407 Rect* rect; |
407 Quad* quad; | 408 Quad* quad; |
408 } m_value; | 409 } m_value; |
409 }; | 410 }; |
410 | 411 |
411 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 412 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
412 | 413 |
413 } // namespace WebCore | 414 } // namespace WebCore |
414 | 415 |
415 #endif // CSSPrimitiveValue_h | 416 #endif // CSSPrimitiveValue_h |
OLD | NEW |