| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 }; | 174 }; |
| 175 static UnitCategory unitCategory(UnitType); | 175 static UnitCategory unitCategory(UnitType); |
| 176 static float clampToCSSLengthRange(double); | 176 static float clampToCSSLengthRange(double); |
| 177 | 177 |
| 178 static void initUnitTable(); | 178 static void initUnitTable(); |
| 179 | 179 |
| 180 static UnitType fromName(const String& unit); | 180 static UnitType fromName(const String& unit); |
| 181 | 181 |
| 182 bool isAngle() const | 182 bool isAngle() const |
| 183 { | 183 { |
| 184 return type() == CSS_DEG | 184 UnitType unitType = type(); |
| 185 || type() == CSS_RAD | 185 return unitType == CSS_DEG |
| 186 || type() == CSS_GRAD | 186 || unitType == CSS_RAD |
| 187 || type() == CSS_TURN; | 187 || unitType == CSS_GRAD |
| 188 || unitType == CSS_TURN; |
| 188 } | 189 } |
| 189 bool isAttr() const { return type() == CSS_ATTR; } | 190 bool isAttr() const { return type() == CSS_ATTR; } |
| 190 bool isCounter() const { return type() == CSS_COUNTER; } | 191 bool isCounter() const { return type() == CSS_COUNTER; } |
| 191 bool isCustomIdent() const { return type() == CSS_CUSTOM_IDENT; } | 192 bool isCustomIdent() const { return type() == CSS_CUSTOM_IDENT; } |
| 192 bool isFontRelativeLength() const | 193 bool isFontRelativeLength() const |
| 193 { | 194 { |
| 194 return type() == CSS_EMS | 195 UnitType unitType = type(); |
| 195 || type() == CSS_EXS | 196 return unitType == CSS_EMS |
| 196 || type() == CSS_REMS | 197 || unitType == CSS_EXS |
| 197 || type() == CSS_CHS; | 198 || unitType == CSS_REMS |
| 199 || unitType == CSS_CHS; |
| 198 } | 200 } |
| 199 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } | 201 bool isViewportPercentageLength() const { return isViewportPercentageLength(
type()); } |
| 200 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V
W && type <= CSS_VMAX; } | 202 static bool isViewportPercentageLength(UnitType type) { return type >= CSS_V
W && type <= CSS_VMAX; } |
| 201 static bool isLength(UnitType type) | 203 static bool isLength(UnitType type) |
| 202 { | 204 { |
| 203 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type =
= CSS_CHS || isViewportPercentageLength(type); | 205 return (type >= CSS_EMS && type <= CSS_PC) || type == CSS_REMS || type =
= CSS_CHS || isViewportPercentageLength(type); |
| 204 } | 206 } |
| 205 bool isLength() const { return isLength(primitiveType()); } | 207 bool isLength() const { return isLength(primitiveType()); } |
| 206 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp
e() == CSS_INTEGER; } | 208 bool isNumber() const { return primitiveType() == CSS_NUMBER || primitiveTyp
e() == CSS_INTEGER; } |
| 207 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } | 209 bool isPercentage() const { return primitiveType() == CSS_PERCENTAGE; } |
| 208 bool isPx() const { return primitiveType() == CSS_PX; } | 210 bool isPx() const { return primitiveType() == CSS_PX; } |
| 209 bool isRect() const { return type() == CSS_RECT; } | 211 bool isRect() const { return type() == CSS_RECT; } |
| 210 bool isRGBColor() const { return type() == CSS_RGBCOLOR; } | 212 bool isRGBColor() const { return type() == CSS_RGBCOLOR; } |
| 211 bool isShape() const { return type() == CSS_SHAPE; } | 213 bool isShape() const { return type() == CSS_SHAPE; } |
| 212 bool isString() const { return type() == CSS_STRING; } | 214 bool isString() const { return type() == CSS_STRING; } |
| 213 bool isTime() const { return type() == CSS_S || type() == CSS_MS; } | 215 bool isTime() const { UnitType unitType = type(); return unitType == CSS_S |
| unitType == CSS_MS; } |
| 214 bool isURI() const { return type() == CSS_URI; } | 216 bool isURI() const { return type() == CSS_URI; } |
| 215 bool isCalculated() const { return type() == CSS_CALC; } | 217 bool isCalculated() const { return type() == CSS_CALC; } |
| 216 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_NUMBER; } | 218 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_NUMBER; } |
| 217 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_LENGTH; } | 219 bool isCalculatedPercentageWithLength() const { return primitiveType() == CS
S_CALC_PERCENTAGE_WITH_LENGTH; } |
| 218 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } | 220 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } |
| 219 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } | 221 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } |
| 220 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } | 222 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } |
| 221 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } | 223 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } |
| 222 bool isFlex() const { return primitiveType() == CSS_FR; } | 224 bool isFlex() const { return primitiveType() == CSS_FR; } |
| 223 bool isValueID() const { return type() == CSS_VALUE_ID; } | 225 bool isValueID() const { return type() == CSS_VALUE_ID; } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 double computeSeconds(); | 318 double computeSeconds(); |
| 317 | 319 |
| 318 // Computes a length in pixels, resolving relative lengths | 320 // Computes a length in pixels, resolving relative lengths |
| 319 template<typename T> T computeLength(const CSSToLengthConversionData&); | 321 template<typename T> T computeLength(const CSSToLengthConversionData&); |
| 320 | 322 |
| 321 // Converts to a Length (Fixed, Percent or Calculated) | 323 // Converts to a Length (Fixed, Percent or Calculated) |
| 322 Length convertToLength(const CSSToLengthConversionData&); | 324 Length convertToLength(const CSSToLengthConversionData&); |
| 323 | 325 |
| 324 double getDoubleValue() const | 326 double getDoubleValue() const |
| 325 { | 327 { |
| 326 if (type() == CSS_CALC) | 328 if (isTaggedPtr()) |
| 329 return numTaggedValue(); |
| 330 if (m_primitiveUnitType == CSS_CALC) |
| 327 return getCalcDoubleValue(); | 331 return getCalcDoubleValue(); |
| 328 return value().num; | 332 return m_value.num; |
| 329 } | 333 } |
| 330 | 334 |
| 331 double getCalcDoubleValue() const; | 335 double getCalcDoubleValue() const; |
| 332 | 336 |
| 333 float getFloatValue() const { return getValue<float>(); } | 337 float getFloatValue() const { return getValue<float>(); } |
| 334 int getIntValue() const { return getValue<int>(); } | 338 int getIntValue() const { return getValue<int>(); } |
| 335 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 339 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
| 336 | 340 |
| 337 String getStringValue() const; | 341 String getStringValue() const; |
| 338 | 342 |
| 339 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value(
).counter; } | 343 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : m_valu
e.counter; } |
| 340 | 344 |
| 341 Rect* getRectValue() const { return type() != CSS_RECT ? 0 : value().rect; } | 345 Rect* getRectValue() const { return type() != CSS_RECT ? 0 : m_value.rect; } |
| 342 | 346 |
| 343 Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : value().quad; } | 347 Quad* getQuadValue() const { return type() != CSS_QUAD ? 0 : m_value.quad; } |
| 344 | 348 |
| 345 RGBA32 getRGBA32Value() const { return type() != CSS_RGBCOLOR ? 0 : value().
rgbcolor; } | 349 RGBA32 getRGBA32Value() const |
| 350 { |
| 351 if (isTaggedPtr()) |
| 352 return taggedType() != CSS_RGBCOLOR ? 0 : rgbcolorTaggedValue(); |
| 353 return m_primitiveUnitType != CSS_RGBCOLOR ? 0 : m_value.rgbcolor; |
| 354 } |
| 346 | 355 |
| 347 Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : value().pair; } | 356 Pair* getPairValue() const { return type() != CSS_PAIR ? 0 : m_value.pair; } |
| 348 | 357 |
| 349 CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : valu
e().shape; } | 358 CSSBasicShape* getShapeValue() const { return type() != CSS_SHAPE ? 0 : m_va
lue.shape; } |
| 350 | 359 |
| 351 CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : value()
.calc; } | 360 CSSCalcValue* cssCalcValue() const { return type() != CSS_CALC ? 0 : m_value
.calc; } |
| 352 | 361 |
| 353 CSSPropertyID getPropertyID() const { return type() == CSS_PROPERTY_ID ? val
ue().propertyID : CSSPropertyInvalid; } | 362 CSSPropertyID getPropertyID() const |
| 354 CSSValueID getValueID() const { return type() == CSS_VALUE_ID ? value().valu
eID : CSSValueInvalid; } | 363 { |
| 364 if (isTaggedPtr()) |
| 365 return taggedType() == CSS_PROPERTY_ID ? propertyIDTaggedValue() : C
SSPropertyInvalid; |
| 366 return m_primitiveUnitType == CSS_PROPERTY_ID ? m_value.propertyID : CSS
PropertyInvalid; |
| 367 } |
| 368 |
| 369 CSSValueID getValueID() const |
| 370 { |
| 371 if (isTaggedPtr()) |
| 372 return taggedType() == CSS_VALUE_ID ? valueIDTaggedValue() : CSSValu
eInvalid; |
| 373 return m_primitiveUnitType == CSS_VALUE_ID ? m_value.valueID : CSSValueI
nvalid; |
| 374 } |
| 355 | 375 |
| 356 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h | 376 template<typename T> inline operator T() const; // Defined in CSSPrimitiveVa
lueMappings.h |
| 357 | 377 |
| 358 static const char* unitTypeToString(UnitType); | 378 static const char* unitTypeToString(UnitType); |
| 359 String customCSSText() const; | 379 String customCSSText() const; |
| 360 | 380 |
| 361 inline bool isQuirkValue() const | 381 inline bool isQuirkValue() const |
| 362 { | 382 { |
| 363 if (isTaggedPtr()) | 383 if (isTaggedPtr()) |
| 364 return false; | 384 return false; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 return reinterpret_cast<CSSTaggedPtrValue&&>(nonConstThis); | 471 return reinterpret_cast<CSSTaggedPtrValue&&>(nonConstThis); |
| 452 } | 472 } |
| 453 | 473 |
| 454 inline UnitType type() const | 474 inline UnitType type() const |
| 455 { | 475 { |
| 456 if (!isTaggedPtr()) | 476 if (!isTaggedPtr()) |
| 457 return static_cast<UnitType>(m_primitiveUnitType); | 477 return static_cast<UnitType>(m_primitiveUnitType); |
| 458 return static_cast<UnitType>(toTaggedPtr().type); | 478 return static_cast<UnitType>(toTaggedPtr().type); |
| 459 } | 479 } |
| 460 | 480 |
| 461 inline CSSPrimitiveValueData value() const | 481 inline double taggedType() const |
| 462 { | 482 { |
| 463 if (!isTaggedPtr()) | 483 ASSERT(isTaggedPtr()); |
| 464 return m_value; | 484 return static_cast<UnitType>(toTaggedPtr().type); |
| 485 } |
| 465 | 486 |
| 466 CSSPrimitiveValueData data; | 487 inline CSSPropertyID propertyIDValue() const |
| 467 switch (type()) { | 488 { |
| 468 case CSSPrimitiveValue::CSS_PROPERTY_ID: | 489 if (isTaggedPtr()) |
| 469 data.propertyID = static_cast<CSSPropertyID>(toTaggedPtr().value); | 490 return propertyIDTaggedValue(); |
| 470 break; | 491 return m_value.propertyID; |
| 471 case CSSPrimitiveValue::CSS_VALUE_ID: | 492 } |
| 472 data.valueID = static_cast<CSSValueID>(toTaggedPtr().value); | 493 |
| 473 break; | 494 inline CSSValueID valueIDValue() const |
| 474 case CSSPrimitiveValue::CSS_RGBCOLOR: { | 495 { |
| 475 uintptr_t valueRawVar = toTaggedPtr().value; | 496 if (isTaggedPtr()) |
| 476 packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar); | 497 return valueIDTaggedValue(); |
| 477 unsigned alpha; | 498 return m_value.valueID; |
| 499 } |
| 500 |
| 501 |
| 502 inline double numValue() const |
| 503 { |
| 504 if (isTaggedPtr()) |
| 505 return numTaggedValue(); |
| 506 return m_value.num; |
| 507 } |
| 508 |
| 509 |
| 510 inline RGBA32 rgbcolorValue() const |
| 511 { |
| 512 if (isTaggedPtr()) |
| 513 return rgbcolorTaggedValue(); |
| 514 return m_value.rgbcolor; |
| 515 } |
| 516 |
| 517 inline CSSPropertyID propertyIDTaggedValue() const |
| 518 { |
| 519 ASSERT(isTaggedPtr()); |
| 520 return static_cast<CSSPropertyID>(toTaggedPtr().value); |
| 521 } |
| 522 |
| 523 inline CSSValueID valueIDTaggedValue() const |
| 524 { |
| 525 ASSERT(isTaggedPtr()); |
| 526 return static_cast<CSSValueID>(toTaggedPtr().value); |
| 527 } |
| 528 |
| 529 inline double numTaggedValue() const |
| 530 { |
| 531 ASSERT(isTaggedPtr()); |
| 532 uint64_t shiftedValue = toTaggedPtr().value; |
| 533 shiftedValue = shiftedValue << doubleShiftAmount; |
| 534 return *reinterpret_cast<double*>(&shiftedValue); |
| 535 } |
| 536 |
| 537 inline RGBA32 rgbcolorTaggedValue() const |
| 538 { |
| 539 ASSERT(isTaggedPtr()); |
| 540 uintptr_t valueRawVar = toTaggedPtr().value; |
| 541 packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar); |
| 542 unsigned alpha; |
| 478 #if CPU(32BIT) | 543 #if CPU(32BIT) |
| 479 alpha = color.alpha == 1 ? 255 : 0; | 544 alpha = color.alpha == 1 ? 255 : 0; |
| 480 #elif CPU(64BIT) | 545 #elif CPU(64BIT) |
| 481 alpha = color.alpha; | 546 alpha = color.alpha; |
| 482 #endif | 547 #endif |
| 483 data.rgbcolor = makeRGBA(color.red, color.green, color.blue, alpha); | 548 return makeRGBA(color.red, color.green, color.blue, alpha); |
| 484 break; | |
| 485 } | |
| 486 default: | |
| 487 uint64_t shiftedValue = toTaggedPtr().value; | |
| 488 shiftedValue = shiftedValue << doubleShiftAmount; | |
| 489 data.num = *reinterpret_cast<double*>(&shiftedValue); | |
| 490 break; | |
| 491 } | |
| 492 return data; | |
| 493 } | 549 } |
| 494 | 550 |
| 551 |
| 495 CSSPrimitiveValueData m_value; | 552 CSSPrimitiveValueData m_value; |
| 496 }; | 553 }; |
| 497 | 554 |
| 498 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; | 555 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; |
| 499 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; | 556 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; |
| 500 | 557 |
| 501 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); | 558 DEFINE_CSS_VALUE_TYPE_CASTS(CSSPrimitiveValue, isPrimitiveValue()); |
| 502 | 559 |
| 503 } // namespace blink | 560 } // namespace blink |
| 504 | 561 |
| 505 namespace WTF { | 562 namespace WTF { |
| 506 | 563 |
| 507 #if !ENABLE(OILPAN) | 564 #if !ENABLE(OILPAN) |
| 508 // Must be defined *after* CSSPrimitiveValue to compile with the correct adopted
() method. | 565 // Must be defined *after* CSSPrimitiveValue to compile with the correct adopted
() method. |
| 509 template<> inline PassRefPtr<blink::CSSPrimitiveValue> adoptRef<blink::CSSPrimit
iveValue>(blink::CSSPrimitiveValue* p) | 566 template<> inline PassRefPtr<blink::CSSPrimitiveValue> adoptRef<blink::CSSPrimit
iveValue>(blink::CSSPrimitiveValue* p) |
| 510 { | 567 { |
| 511 // Immediates (non-pointers) end in a 1. | 568 // Immediates (non-pointers) end in a 1. |
| 512 if (!(reinterpret_cast<uintptr_t>(p) & 1)) | 569 if (!(reinterpret_cast<uintptr_t>(p) & 1)) |
| 513 adopted(p); | 570 adopted(p); |
| 514 return PassRefPtr<blink::CSSPrimitiveValue>(p, PassRefPtr<blink::CSSPrimitiv
eValue>::AdoptRef); | 571 return PassRefPtr<blink::CSSPrimitiveValue>(p, PassRefPtr<blink::CSSPrimitiv
eValue>::AdoptRef); |
| 515 } | 572 } |
| 516 #endif | 573 #endif |
| 517 | 574 |
| 518 } // namespace WTF | 575 } // namespace WTF |
| 519 | 576 |
| 520 #endif // CSSPrimitiveValue_h | 577 #endif // CSSPrimitiveValue_h |
| OLD | NEW |