Changeset 138952 in webkit
- Timestamp:
- Jan 7, 2013 9:25:37 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r138948 r138952 1 2013-01-07 Julien Chaffraix <jchaffraix@webkit.org> 2 3 Support size_t multiplication and division operators on LayoutUnit 4 https://bugs.webkit.org/show_bug.cgi?id=83848 5 6 Reviewed by Emil A Eklund. 7 8 Per Darin's suggestion, adding a version of the operator for most unsigned types (excluding 9 only unsigned char). This should automatically cover size_t as it should be one of these. 10 11 Test: TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp 12 13 * platform/LayoutUnit.h: 14 (WebCore::LayoutUnit::LayoutUnit): 15 (WebCore::operator*): 16 (WebCore::operator/): 17 Added the operators and (possibly saturating) constructors for unsigned short, unsigned long, 18 unsigned long long. 19 1 20 2013-01-07 Sheriff Bot <webkit.review.bot@gmail.com> 2 21 -
trunk/Source/WebCore/platform/LayoutUnit.h
r138736 r138952 67 67 class LayoutUnit { 68 68 public: 69 // FIXME: Ideally we would have size_t versions of the constructor and operators.70 // However due to compiler and platform differences adding those are non-trivial.71 // See https://bugs.webkit.org/show_bug.cgi?id=83848 for details.72 73 69 LayoutUnit() : m_value(0) { } 74 70 #if ENABLE(SUBPIXEL_LAYOUT) … … 76 72 LayoutUnit(unsigned short value) { setValue(value); } 77 73 LayoutUnit(unsigned value) { setValue(value); } 74 LayoutUnit(unsigned long value) 75 { 76 #if ENABLE(SATURATED_LAYOUT_ARITHMETIC) 77 m_value = clampTo<int>(value * kEffectiveFixedPointDenominator); 78 #else 79 REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value))); 80 m_value = value * kEffectiveFixedPointDenominator; 81 #endif 82 } 83 LayoutUnit(unsigned long long value) 84 { 85 #if ENABLE(SATURATED_LAYOUT_ARITHMETIC) 86 m_value = clampTo<int>(value * kEffectiveFixedPointDenominator); 87 #else 88 REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value))); 89 m_value = value * kEffectiveFixedPointDenominator; 90 #endif 91 } 78 92 LayoutUnit(float value) 79 93 { … … 98 112 LayoutUnit(unsigned short value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; } 99 113 LayoutUnit(unsigned value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; } 114 LayoutUnit(unsigned long long value) { REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value))); m_value = value; } 115 LayoutUnit(unsigned long value) { REPORT_OVERFLOW(isInBounds(static_cast<unsigned>(value))); m_value = value; } 100 116 LayoutUnit(float value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; } 101 117 LayoutUnit(double value) { REPORT_OVERFLOW(isInBounds(value)); m_value = value; } … … 538 554 } 539 555 556 inline LayoutUnit operator*(const LayoutUnit& a, unsigned short b) 557 { 558 return a * LayoutUnit(b); 559 } 560 540 561 inline LayoutUnit operator*(const LayoutUnit& a, unsigned b) 541 562 { … … 543 564 } 544 565 566 inline LayoutUnit operator*(const LayoutUnit& a, unsigned long b) 567 { 568 return a * LayoutUnit(b); 569 } 570 571 inline LayoutUnit operator*(const LayoutUnit& a, unsigned long long b) 572 { 573 return a * LayoutUnit(b); 574 } 575 576 inline LayoutUnit operator*(unsigned short a, const LayoutUnit& b) 577 { 578 return LayoutUnit(a) * b; 579 } 580 545 581 inline LayoutUnit operator*(unsigned a, const LayoutUnit& b) 582 { 583 return LayoutUnit(a) * b; 584 } 585 586 inline LayoutUnit operator*(unsigned long a, const LayoutUnit& b) 587 { 588 return LayoutUnit(a) * b; 589 } 590 591 inline LayoutUnit operator*(unsigned long long a, const LayoutUnit& b) 546 592 { 547 593 return LayoutUnit(a) * b; … … 594 640 } 595 641 642 inline LayoutUnit operator/(const LayoutUnit& a, unsigned short b) 643 { 644 return a / LayoutUnit(b); 645 } 646 596 647 inline LayoutUnit operator/(const LayoutUnit& a, unsigned b) 597 648 { … … 599 650 } 600 651 652 inline LayoutUnit operator/(const LayoutUnit& a, unsigned long b) 653 { 654 return a / LayoutUnit(b); 655 } 656 657 inline LayoutUnit operator/(const LayoutUnit& a, unsigned long long b) 658 { 659 return a / LayoutUnit(b); 660 } 661 601 662 inline float operator/(const float a, const LayoutUnit& b) 602 663 { … … 614 675 } 615 676 677 inline LayoutUnit operator/(unsigned short a, const LayoutUnit& b) 678 { 679 return LayoutUnit(a) / b; 680 } 681 616 682 inline LayoutUnit operator/(unsigned a, const LayoutUnit& b) 683 { 684 return LayoutUnit(a) / b; 685 } 686 687 inline LayoutUnit operator/(unsigned long a, const LayoutUnit& b) 688 { 689 return LayoutUnit(a) / b; 690 } 691 692 inline LayoutUnit operator/(unsigned long long a, const LayoutUnit& b) 617 693 { 618 694 return LayoutUnit(a) / b; -
trunk/Tools/ChangeLog
r138951 r138952 1 2013-01-07 Julien Chaffraix <jchaffraix@webkit.org> 2 3 Support size_t multiplication and division operators on LayoutUnit 4 https://bugs.webkit.org/show_bug.cgi?id=83848 5 6 Reviewed by Emil A Eklund. 7 8 * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp: 9 Added some simple tests for the new operators using size_t. 10 1 11 2013-01-07 Csaba Osztrogonác <ossy@webkit.org> 2 12 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp
r138736 r138952 147 147 ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(3.33)).round(), -333); 148 148 ASSERT_EQ((LayoutUnit(-100) * LayoutUnit(-3.33)).round(), 333); 149 149 150 size_t aHundredSizeT = 100; 151 ASSERT_EQ((LayoutUnit(aHundredSizeT) * LayoutUnit(1)).toInt(), 100); 152 ASSERT_EQ((aHundredSizeT * LayoutUnit(4)).toInt(), 400); 153 ASSERT_EQ((LayoutUnit(4) * aHundredSizeT).toInt(), 400); 154 150 155 int quarterMax = intMaxForLayoutUnit / 4; 151 156 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(2)).toInt(), quarterMax * 2); … … 153 158 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(4)).toInt(), quarterMax * 4); 154 159 ASSERT_EQ((LayoutUnit(quarterMax) * LayoutUnit(5)).toInt(), intMaxForLayoutUnit); 160 161 size_t overflowIntSizeT = intMaxForLayoutUnit * 4; 162 ASSERT_EQ((LayoutUnit(overflowIntSizeT) * LayoutUnit(2)).toInt(), intMaxForLayoutUnit); 163 ASSERT_EQ((overflowIntSizeT * LayoutUnit(4)).toInt(), intMaxForLayoutUnit); 164 ASSERT_EQ((LayoutUnit(4) * overflowIntSizeT).toInt(), intMaxForLayoutUnit); 155 165 } 156 166 … … 184 194 ASSERT_FLOAT_EQ((LayoutUnit(-0.5) / LayoutUnit(-2)).toFloat(), 0.25f); 185 195 196 size_t aHundredSizeT = 100; 197 ASSERT_EQ((LayoutUnit(aHundredSizeT) / LayoutUnit(2)).toInt(), 50); 198 ASSERT_EQ((aHundredSizeT / LayoutUnit(4)).toInt(), 25); 199 ASSERT_EQ((LayoutUnit(400) / aHundredSizeT).toInt(), 4); 200 186 201 ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(2)).toInt(), intMaxForLayoutUnit / 2); 187 202 ASSERT_EQ((LayoutUnit(intMaxForLayoutUnit) / LayoutUnit(0.5)).toInt(), intMaxForLayoutUnit);
Note: See TracChangeset
for help on using the changeset viewer.