Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(243)

Side by Side Diff: third_party/WebKit/Source/platform/LayoutUnit.h

Issue 1648573002: Transition to explicit constructors in LayoutUnit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moar tweaks! Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, Google Inc. All rights reserved. 2 * Copyright (c) 2012, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 static const int kLayoutUnitFractionalBits = 6; 58 static const int kLayoutUnitFractionalBits = 6;
59 static const int kFixedPointDenominator = 1 << kLayoutUnitFractionalBits; 59 static const int kFixedPointDenominator = 1 << kLayoutUnitFractionalBits;
60 60
61 const int intMaxForLayoutUnit = INT_MAX / kFixedPointDenominator; 61 const int intMaxForLayoutUnit = INT_MAX / kFixedPointDenominator;
62 const int intMinForLayoutUnit = INT_MIN / kFixedPointDenominator; 62 const int intMinForLayoutUnit = INT_MIN / kFixedPointDenominator;
63 63
64 class LayoutUnit { 64 class LayoutUnit {
65 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 65 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
66 public: 66 public:
67 LayoutUnit() : m_value(0) { } 67 LayoutUnit() : m_value(0) { }
68 // TODO(leviw): All of the below constructors should be explicit. crbug.com/ 581254
68 LayoutUnit(int value) { setValue(value); } 69 LayoutUnit(int value) { setValue(value); }
69 LayoutUnit(unsigned short value) { setValue(value); } 70 LayoutUnit(unsigned short value) { setValue(value); }
70 LayoutUnit(unsigned value) { setValue(value); } 71 LayoutUnit(unsigned value) { setValue(value); }
71 LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kFixedPoint Denominator); } 72 LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kFixedPoint Denominator); }
72 LayoutUnit(unsigned long long value) { m_value = clampTo<int>(value * kFixed PointDenominator); } 73 LayoutUnit(unsigned long long value) { m_value = clampTo<int>(value * kFixed PointDenominator); }
73 LayoutUnit(float value) { m_value = clampTo<int>(value * kFixedPointDenomina tor); } 74 LayoutUnit(float value) { m_value = clampTo<int>(value * kFixedPointDenomina tor); }
74 LayoutUnit(double value) { m_value = clampTo<int>(value * kFixedPointDenomin ator); } 75 LayoutUnit(double value) { m_value = clampTo<int>(value * kFixedPointDenomin ator); }
75 76
76 static LayoutUnit fromFloatCeil(float value) 77 static LayoutUnit fromFloatCeil(float value)
77 { 78 {
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 672 }
672 673
673 inline LayoutUnit& operator+=(LayoutUnit& a, const LayoutUnit& b) 674 inline LayoutUnit& operator+=(LayoutUnit& a, const LayoutUnit& b)
674 { 675 {
675 a.setRawValue(saturatedAddition(a.rawValue(), b.rawValue())); 676 a.setRawValue(saturatedAddition(a.rawValue(), b.rawValue()));
676 return a; 677 return a;
677 } 678 }
678 679
679 inline LayoutUnit& operator+=(LayoutUnit& a, int b) 680 inline LayoutUnit& operator+=(LayoutUnit& a, int b)
680 { 681 {
681 a = a + b; 682 a = a + LayoutUnit(b);
682 return a; 683 return a;
683 } 684 }
684 685
685 inline LayoutUnit& operator+=(LayoutUnit& a, float b) 686 inline LayoutUnit& operator+=(LayoutUnit& a, float b)
686 { 687 {
687 a = a + b; 688 a = a + LayoutUnit(b);
688 return a; 689 return a;
689 } 690 }
690 691
691 inline float& operator+=(float& a, const LayoutUnit& b) 692 inline float& operator+=(float& a, const LayoutUnit& b)
692 { 693 {
693 a = a + b; 694 a = a + b;
694 return a; 695 return a;
695 } 696 }
696 697
697 inline LayoutUnit& operator-=(LayoutUnit& a, int b) 698 inline LayoutUnit& operator-=(LayoutUnit& a, int b)
698 { 699 {
699 a = a - b; 700 a = a - LayoutUnit(b);
700 return a; 701 return a;
701 } 702 }
702 703
703 inline LayoutUnit& operator-=(LayoutUnit& a, const LayoutUnit& b) 704 inline LayoutUnit& operator-=(LayoutUnit& a, const LayoutUnit& b)
704 { 705 {
705 a.setRawValue(saturatedSubtraction(a.rawValue(), b.rawValue())); 706 a.setRawValue(saturatedSubtraction(a.rawValue(), b.rawValue()));
706 return a; 707 return a;
707 } 708 }
708 709
709 inline LayoutUnit& operator-=(LayoutUnit& a, float b) 710 inline LayoutUnit& operator-=(LayoutUnit& a, float b)
710 { 711 {
711 a = a - b; 712 a = LayoutUnit(a - b);
712 return a; 713 return a;
713 } 714 }
714 715
715 inline float& operator-=(float& a, const LayoutUnit& b) 716 inline float& operator-=(float& a, const LayoutUnit& b)
716 { 717 {
717 a = a - b; 718 a = a - b;
718 return a; 719 return a;
719 } 720 }
720 721
721 inline LayoutUnit& operator*=(LayoutUnit& a, const LayoutUnit& b) 722 inline LayoutUnit& operator*=(LayoutUnit& a, const LayoutUnit& b)
722 { 723 {
723 a = a * b; 724 a = a * b;
724 return a; 725 return a;
725 } 726 }
726 // operator*=(LayoutUnit& a, int b) is supported by the operator above plus Layo utUnit(int).
727
728 inline LayoutUnit& operator*=(LayoutUnit& a, float b)
729 {
730 a = a * b;
731 return a;
732 }
733 727
728 inline LayoutUnit& operator*=(LayoutUnit& a, float b)
729 {
730 a = LayoutUnit(a * b);
731 return a;
732 }
733
734 inline float& operator*=(float& a, const LayoutUnit& b) 734 inline float& operator*=(float& a, const LayoutUnit& b)
735 { 735 {
736 a = a * b; 736 a = a * b;
737 return a; 737 return a;
738 } 738 }
739 739
740 inline LayoutUnit& operator/=(LayoutUnit& a, const LayoutUnit& b) 740 inline LayoutUnit& operator/=(LayoutUnit& a, const LayoutUnit& b)
741 { 741 {
742 a = a / b; 742 a = a / b;
743 return a; 743 return a;
744 } 744 }
745 // operator/=(LayoutUnit& a, int b) is supported by the operator above plus Layo utUnit(int).
746
747 inline LayoutUnit& operator/=(LayoutUnit& a, float b)
748 {
749 a = a / b;
750 return a;
751 }
752 745
746 inline LayoutUnit& operator/=(LayoutUnit& a, float b)
747 {
748 a = LayoutUnit(a / b);
749 return a;
750 }
751
753 inline float& operator/=(float& a, const LayoutUnit& b) 752 inline float& operator/=(float& a, const LayoutUnit& b)
754 { 753 {
755 a = a / b; 754 a = a / b;
756 return a; 755 return a;
757 } 756 }
758 757
759 inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location) 758 inline int snapSizeToPixel(LayoutUnit size, LayoutUnit location)
760 { 759 {
761 LayoutUnit fraction = location.fraction(); 760 LayoutUnit fraction = location.fraction();
762 return (fraction + size).round() - fraction.round(); 761 return (fraction + size).round() - fraction.round();
(...skipping 29 matching lines...) Expand all
792 if (value >= max) 791 if (value >= max)
793 return max; 792 return max;
794 if (value <= min) 793 if (value <= min)
795 return min; 794 return min;
796 return value; 795 return value;
797 } 796 }
798 797
799 } // namespace blink 798 } // namespace blink
800 799
801 #endif // LayoutUnit_h 800 #endif // LayoutUnit_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698