| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 unsigned red : 8; | 183 unsigned red : 8; |
| 184 unsigned green : 8; | 184 unsigned green : 8; |
| 185 unsigned blue : 8; | 185 unsigned blue : 8; |
| 186 #if CPU(32BIT) | 186 #if CPU(32BIT) |
| 187 unsigned alpha : 1; | 187 unsigned alpha : 1; |
| 188 #elif CPU(64BIT) | 188 #elif CPU(64BIT) |
| 189 unsigned alpha : 8; | 189 unsigned alpha : 8; |
| 190 #endif | 190 #endif |
| 191 } packedColor; | 191 } packedColor; |
| 192 | 192 |
| 193 | |
| 194 // Returns true if value can be stored in the value field of the tagged
pointer | 193 // Returns true if value can be stored in the value field of the tagged
pointer |
| 195 // without losing information. | 194 // without losing information. |
| 196 inline static bool fitsWithoutDataLoss(double value) | 195 inline static bool canFitWithoutDataLoss(CSSPrimitiveValueData data, Uni
tType type) |
| 197 { | 196 { |
| 198 union { | 197 switch (type) { |
| 199 double asDouble; | 198 case CSS_PROPERTY_ID: |
| 200 uint64_t asBits; | 199 return true; |
| 201 } interpretableValue; | 200 case CSS_VALUE_ID: |
| 202 interpretableValue.asDouble = value; | 201 return true; |
| 203 return (interpretableValue.asBits & mantissaTruncationMask) == 0; | 202 case CSS_RGBCOLOR: |
| 203 #if CPU(32BIT) |
| 204 if (alphaChannel(data.rgbcolor) != 0 && alphaChannel(data.rgbcol
or) != 255) |
| 205 return false; |
| 206 #endif |
| 207 return true; |
| 208 default: |
| 209 union { |
| 210 double asDouble; |
| 211 uint64_t asBits; |
| 212 } interpretableValue; |
| 213 interpretableValue.asDouble = data.num; |
| 214 if ((interpretableValue.asBits & mantissaTruncationMask) != 0) |
| 215 return false; |
| 216 return true; |
| 217 } |
| 204 } | 218 } |
| 205 | 219 |
| 206 inline static bool fitsWithoutDataLoss(RGBA32 color) | 220 inline void setValue(CSSPrimitiveValueData data, UnitType type) |
| 207 { | 221 { |
| 222 this->flag = 1; |
| 223 this->type = static_cast<uintptr_t>(type); |
| 224 switch (type) { |
| 225 case CSS_PROPERTY_ID: |
| 226 valueRaw = static_cast<uintptr_t>(data.propertyID); |
| 227 return; |
| 228 case CSS_VALUE_ID: |
| 229 valueRaw = static_cast<uintptr_t>(data.valueID); |
| 230 return; |
| 231 case CSS_RGBCOLOR: |
| 232 packedColor color; |
| 233 color.red = static_cast<uintptr_t>(redChannel(data.rgbcolor)); |
| 234 color.green = static_cast<uintptr_t>(greenChannel(data.rgbcolor)
); |
| 235 color.blue = static_cast<uintptr_t>(blueChannel(data.rgbcolor)); |
| 208 #if CPU(32BIT) | 236 #if CPU(32BIT) |
| 209 return alphaChannel(color) == 0 || alphaChannel(color) == 255; | 237 color.alpha = static_cast<uintptr_t>(alphaChannel(data.rgbcolor)
== 255 ? 1 : 0); |
| 210 #elif CPU(64BIT) | 238 #elif CPU(64BIT) |
| 211 return true; | 239 color.alpha = static_cast<uintptr_t>(alphaChannel(data.rgbcolor)
); |
| 212 #endif | 240 #endif |
| 241 valueRaw = *reinterpret_cast<uintptr_t*>(&color); |
| 242 return; |
| 243 default: |
| 244 union { |
| 245 double asDouble; |
| 246 uint64_t asBits; |
| 247 } interpretableValue; |
| 248 interpretableValue.asDouble = data.num; |
| 249 valueRaw = interpretableValue.asBits >> doubleShiftAmount; |
| 250 return; |
| 251 } |
| 252 } |
| 253 |
| 254 inline CSSPrimitiveValueData getValue() const |
| 255 { |
| 256 CSSPrimitiveValueData data; |
| 257 switch (type) { |
| 258 case CSS_PROPERTY_ID: |
| 259 data.propertyID = getPropertyIDValue(); |
| 260 break; |
| 261 case CSS_VALUE_ID: |
| 262 data.valueID = getValueIDValue(); |
| 263 break; |
| 264 case CSS_RGBCOLOR: |
| 265 data.rgbcolor = getColorValue(); |
| 266 break; |
| 267 default: |
| 268 data.num = getDoubleValue(); |
| 269 break; |
| 270 } |
| 271 return data; |
| 213 } | 272 } |
| 214 | 273 |
| 215 // Convenience methods for getting/setting the value field, which is tru
ncated. | 274 // Convenience methods for getting/setting the value field, which is tru
ncated. |
| 216 inline double getValue() const | 275 inline double getDoubleValue() const |
| 217 { | 276 { |
| 218 uint64_t shiftedValue = valueRaw; | 277 uint64_t shiftedValue = valueRaw; |
| 219 shiftedValue = shiftedValue << doubleShiftAmount; | 278 shiftedValue = shiftedValue << doubleShiftAmount; |
| 220 return *reinterpret_cast<double*>(&shiftedValue); | 279 return *reinterpret_cast<double*>(&shiftedValue); |
| 221 } | 280 } |
| 222 | 281 |
| 223 inline RGBA32 getColorValue() const | 282 inline RGBA32 getColorValue() const |
| 224 { | 283 { |
| 225 uintptr_t valueRawVar = valueRaw; | 284 uintptr_t valueRawVar = valueRaw; |
| 226 packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar); | 285 packedColor color = *reinterpret_cast<packedColor*>(&valueRawVar); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } | 484 static bool isDotsPerInch(UnitType type) { return type == CSS_DPI; } |
| 426 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } | 485 static bool isDotsPerPixel(UnitType type) { return type == CSS_DPPX; } |
| 427 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } | 486 static bool isDotsPerCentimeter(UnitType type) { return type == CSS_DPCM; } |
| 428 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } | 487 static bool isResolution(UnitType type) { return type >= CSS_DPPX && type <=
CSS_DPCM; } |
| 429 bool isFlex() const { return primitiveType() == CSS_FR; } | 488 bool isFlex() const { return primitiveType() == CSS_FR; } |
| 430 bool isValueID() const { return type() == CSS_VALUE_ID; } | 489 bool isValueID() const { return type() == CSS_VALUE_ID; } |
| 431 bool colorIsDerivedFromElement() const; | 490 bool colorIsDerivedFromElement() const; |
| 432 | 491 |
| 433 static CSSPrimitiveValue createIdentifier(CSSValueID valueID) | 492 static CSSPrimitiveValue createIdentifier(CSSValueID valueID) |
| 434 { | 493 { |
| 435 CSSTaggedPtrValue taggedPointer; | 494 CSSPrimitiveValueData data; |
| 436 taggedPointer.flag = 1; | 495 data.valueID = valueID; |
| 437 taggedPointer.type = CSS_VALUE_ID; | 496 CSSTaggedPtrValue taggedPtr; |
| 438 taggedPointer.setValue(valueID); | 497 taggedPtr.setValue(data, CSS_VALUE_ID); |
| 439 return CSSPrimitiveValue(taggedPointer); | 498 return CSSPrimitiveValue(taggedPtr); |
| 440 } | 499 } |
| 441 | 500 |
| 442 static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID) | 501 static CSSPrimitiveValue createIdentifier(CSSPropertyID propertyID) |
| 443 { | 502 { |
| 444 CSSTaggedPtrValue taggedPointer; | 503 CSSPrimitiveValueData data; |
| 445 taggedPointer.flag = 1; | 504 data.propertyID = propertyID; |
| 446 taggedPointer.type = CSS_PROPERTY_ID; | 505 CSSTaggedPtrValue taggedPtr; |
| 447 taggedPointer.setValue(propertyID); | 506 taggedPtr.setValue(data, CSS_PROPERTY_ID); |
| 448 return CSSPrimitiveValue(taggedPointer); | 507 return CSSPrimitiveValue(taggedPtr); |
| 449 } | 508 } |
| 450 static CSSPrimitiveValue createColor(RGBA32 rgbValue) | 509 static CSSPrimitiveValue createColor(RGBA32 rgbValue) |
| 451 { | 510 { |
| 452 if (CSSTaggedPtrValue::fitsWithoutDataLoss(rgbValue)) { | 511 CSSPrimitiveValueData data; |
| 453 CSSTaggedPtrValue taggedPointer; | 512 data.rgbcolor = rgbValue; |
| 454 taggedPointer.flag = 1; | 513 if (CSSTaggedPtrValue::canFitWithoutDataLoss(data, CSS_RGBCOLOR)) { |
| 455 taggedPointer.type = CSS_RGBCOLOR; | 514 CSSTaggedPtrValue taggedPtr; |
| 456 taggedPointer.setValue(rgbValue); | 515 taggedPtr.setValue(data, CSS_RGBCOLOR); |
| 457 return CSSPrimitiveValue(taggedPointer); | 516 return CSSPrimitiveValue(taggedPtr); |
| 458 } | 517 } |
| 459 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(r
gbValue))); | 518 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(r
gbValue))); |
| 460 } | 519 } |
| 461 static CSSPrimitiveValue create(double value, UnitType type) | 520 static CSSPrimitiveValue create(double value, UnitType type) |
| 462 { | 521 { |
| 463 if (CSSTaggedPtrValue::fitsWithoutDataLoss(value)) { | 522 CSSPrimitiveValueData data; |
| 464 CSSTaggedPtrValue taggedPointer; | 523 data.num = value; |
| 465 taggedPointer.flag = 1; | 524 if (CSSTaggedPtrValue::canFitWithoutDataLoss(data, type)) { |
| 466 taggedPointer.type = type; | 525 CSSTaggedPtrValue taggedPtr; |
| 467 taggedPointer.setValue(value); | 526 taggedPtr.setValue(data, type); |
| 468 return CSSPrimitiveValue(taggedPointer); | 527 return CSSPrimitiveValue(taggedPtr); |
| 469 } | 528 } |
| 470 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); | 529 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); |
| 471 } | 530 } |
| 472 static CSSPrimitiveValue create(const String& value, UnitType type) | 531 static CSSPrimitiveValue create(const String& value, UnitType type) |
| 473 { | 532 { |
| 474 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); | 533 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type))); |
| 475 } | 534 } |
| 476 static CSSPrimitiveValue create(const Length& value, float zoom) | 535 static CSSPrimitiveValue create(const Length& value, float zoom) |
| 477 { | 536 { |
| 478 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, zoom))); | 537 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, zoom))); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 491 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away | 550 // When the quirky value is used, if you're in quirks mode, the margin will
collapse away |
| 492 // inside a table cell. | 551 // inside a table cell. |
| 493 static CSSPrimitiveValue createAllowingMarginQuirk(double value, UnitType ty
pe) | 552 static CSSPrimitiveValue createAllowingMarginQuirk(double value, UnitType ty
pe) |
| 494 { | 553 { |
| 495 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type, true))); | 554 return CSSPrimitiveValue(adoptRefWillBeNoop(new CSSLargePrimitiveValue(v
alue, type, true))); |
| 496 } | 555 } |
| 497 | 556 |
| 498 UnitType primitiveType() const; | 557 UnitType primitiveType() const; |
| 499 | 558 |
| 500 double computeDegrees() const; | 559 double computeDegrees() const; |
| 501 double computeSeconds(); | 560 double computeSeconds() const; |
| 502 | 561 |
| 503 // Computes a length in pixels, resolving relative lengths | 562 // Computes a length in pixels, resolving relative lengths |
| 504 template<typename T> T computeLength(const CSSToLengthConversionData&); | 563 template<typename T> T computeLength(const CSSToLengthConversionData&) const
; |
| 505 | 564 |
| 506 // Converts to a Length (Fixed, Percent or Calculated) | 565 // Converts to a Length (Fixed, Percent or Calculated) |
| 507 Length convertToLength(const CSSToLengthConversionData&); | 566 Length convertToLength(const CSSToLengthConversionData&) const; |
| 508 | 567 |
| 509 double getDoubleValue() const; | 568 double getDoubleValue() const; |
| 510 float getFloatValue() const { return getValue<float>(); } | 569 float getFloatValue() const { return getValue<float>(); } |
| 511 int getIntValue() const { return getValue<int>(); } | 570 int getIntValue() const { return getValue<int>(); } |
| 512 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } | 571 template<typename T> inline T getValue() const { return clampTo<T>(getDouble
Value()); } |
| 513 | 572 |
| 514 String getStringValue() const; | 573 String getStringValue() const; |
| 515 | 574 |
| 516 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value(
).counter; } | 575 Counter* getCounterValue() const { return type() != CSS_COUNTER ? 0 : value(
).counter; } |
| 517 | 576 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 #if !ENABLE(OILPAN) | 631 #if !ENABLE(OILPAN) |
| 573 if (isObject()) | 632 if (isObject()) |
| 574 m_rawValue.asPtr->deref(); | 633 m_rawValue.asPtr->deref(); |
| 575 #endif | 634 #endif |
| 576 } | 635 } |
| 577 | 636 |
| 578 static void create(int); // compile-time guard | 637 static void create(int); // compile-time guard |
| 579 static void create(unsigned); // compile-time guard | 638 static void create(unsigned); // compile-time guard |
| 580 template<typename T> operator T*(); // compile-time guard | 639 template<typename T> operator T*(); // compile-time guard |
| 581 | 640 |
| 582 double computeLengthDouble(const CSSToLengthConversionData&); | 641 double computeLengthDouble(const CSSToLengthConversionData&) const; |
| 583 | 642 |
| 584 union CSSPrimitivePointerValue { | 643 union CSSPrimitivePointerValue { |
| 585 CSSTaggedPtrValue asTaggedPtr; | 644 CSSTaggedPtrValue asTaggedPtr; |
| 586 RawPtrWillBeMember<CSSLargePrimitiveValue> asPtr; | 645 RawPtrWillBeMember<CSSLargePrimitiveValue> asPtr; |
| 587 | 646 |
| 588 CSSPrimitivePointerValue(CSSLargePrimitiveValue* ptr) : asPtr(ptr) { } | 647 CSSPrimitivePointerValue(CSSLargePrimitiveValue* ptr) : asPtr(ptr) { } |
| 589 CSSPrimitivePointerValue(CSSTaggedPtrValue taggedPtr) : asTaggedPtr(tagg
edPtr) { } | 648 CSSPrimitivePointerValue(CSSTaggedPtrValue taggedPtr) : asTaggedPtr(tagg
edPtr) { } |
| 590 | 649 |
| 591 DEFINE_INLINE_TRACE() | 650 DEFINE_INLINE_TRACE() |
| 592 { | 651 { |
| 593 if (!(reinterpret_cast<uintptr_t>(asPtr.get()) & 1)) { | 652 if (!(reinterpret_cast<uintptr_t>(asPtr.get()) & 1)) { |
| 594 visitor->trace(asPtr); | 653 visitor->trace(asPtr); |
| 595 asPtr->traceAfterDispatch(visitor); | 654 asPtr->traceAfterDispatch(visitor); |
| 596 } | 655 } |
| 597 } | 656 } |
| 598 } m_rawValue; | 657 } m_rawValue; |
| 599 static_assert(sizeof(m_rawValue) == sizeof(void*), "The tagged pointer field
in CSSPrimitiveValue must be the size of a pointer"); | 658 static_assert(sizeof(m_rawValue) == sizeof(void*), "The tagged pointer field
in CSSPrimitiveValue must be the size of a pointer"); |
| 600 | 659 |
| 601 bool isObject() const | 660 bool isObject() const |
| 602 { | 661 { |
| 603 return m_rawValue.asTaggedPtr.flag == 0; | 662 return m_rawValue.asTaggedPtr.flag == 0; |
| 604 } | 663 } |
| 605 | 664 |
| 606 // Getters/setters for inner class. | 665 // Getters/setters for inner class. |
| 607 CSSPrimitiveValueData value() const | 666 CSSPrimitiveValueData value() const |
| 608 { | 667 { |
| 609 if (isObject()) | 668 if (isObject()) |
| 610 return m_rawValue.asPtr->m_value; | 669 return m_rawValue.asPtr->m_value; |
| 611 | 670 |
| 612 CSSPrimitiveValueData result; | 671 |
| 613 if (m_rawValue.asTaggedPtr.type == CSS_RGBCOLOR) | 672 return m_rawValue.asTaggedPtr.getValue(); |
| 614 result.rgbcolor = m_rawValue.asTaggedPtr.getColorValue(); | |
| 615 else if (m_rawValue.asTaggedPtr.type == CSS_PROPERTY_ID) | |
| 616 result.propertyID = m_rawValue.asTaggedPtr.getPropertyIDValue(); | |
| 617 else if (m_rawValue.asTaggedPtr.type == CSS_VALUE_ID) | |
| 618 result.valueID = m_rawValue.asTaggedPtr.getValueIDValue(); | |
| 619 else | |
| 620 result.num = m_rawValue.asTaggedPtr.getValue(); | |
| 621 return result; | |
| 622 } | 673 } |
| 623 | 674 |
| 624 UnitType type() const | 675 UnitType type() const |
| 625 { | 676 { |
| 626 if (isObject()) | 677 if (isObject()) |
| 627 return static_cast<UnitType>(m_rawValue.asPtr->m_primitiveUnitType); | 678 return static_cast<UnitType>(m_rawValue.asPtr->m_primitiveUnitType); |
| 628 return static_cast<UnitType>(m_rawValue.asTaggedPtr.type); | 679 return static_cast<UnitType>(m_rawValue.asTaggedPtr.type); |
| 629 } | 680 } |
| 630 }; | 681 }; |
| 631 | 682 |
| 632 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; | 683 typedef CSSPrimitiveValue::CSSLengthArray CSSLengthArray; |
| 633 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; | 684 typedef CSSPrimitiveValue::CSSLengthTypeArray CSSLengthTypeArray; |
| 634 | 685 |
| 635 static_assert(sizeof(CSSPrimitiveValue) == sizeof(void*), "CSSPrimitiveValue mus
t be the size of a pointer"); | 686 static_assert(sizeof(CSSPrimitiveValue) == sizeof(void*), "CSSPrimitiveValue mus
t be the size of a pointer"); |
| 636 | 687 |
| 637 } // namespace blink | 688 } // namespace blink |
| 638 | 689 |
| 639 #endif // CSSPrimitiveValue_h | 690 #endif // CSSPrimitiveValue_h |
| OLD | NEW |