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

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

Issue 1660863002: Force all LayoutUnit construction to be explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also fix LayoutRectTest.cpp 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // TODO(thakis): Remove these two lines once http://llvm.org/PR26504 is resolved 65 // TODO(thakis): Remove these two lines once http://llvm.org/PR26504 is resolved
66 class LayoutUnit; 66 class LayoutUnit;
67 inline bool operator<(const LayoutUnit&, const LayoutUnit&); 67 inline bool operator<(const LayoutUnit&, const LayoutUnit&);
68 68
69 class LayoutUnit { 69 class LayoutUnit {
70 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); 70 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
71 public: 71 public:
72 LayoutUnit() : m_value(0) { } 72 LayoutUnit() : m_value(0) { }
73 // TODO(leviw): All of the below constructors should be explicit. crbug.com/ 581254 73 // TODO(leviw): All of the below constructors should be explicit. crbug.com/ 581254
74 LayoutUnit(int value) { setValue(value); } 74 explicit LayoutUnit(int value) { setValue(value); }
75 LayoutUnit(unsigned short value) { setValue(value); } 75 explicit LayoutUnit(unsigned short value) { setValue(value); }
76 LayoutUnit(unsigned value) { setValue(value); } 76 explicit LayoutUnit(unsigned value) { setValue(value); }
77 LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kFixedPoint Denominator); } 77 explicit LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kF ixedPointDenominator); }
78 LayoutUnit(unsigned long long value) { m_value = clampTo<int>(value * kFixed PointDenominator); } 78 explicit LayoutUnit(unsigned long long value) { m_value = clampTo<int>(value * kFixedPointDenominator); }
79 LayoutUnit(float value) { m_value = clampTo<int>(value * kFixedPointDenomina tor); } 79 explicit LayoutUnit(float value) { m_value = clampTo<int>(value * kFixedPoin tDenominator); }
80 LayoutUnit(double value) { m_value = clampTo<int>(value * kFixedPointDenomin ator); } 80 explicit LayoutUnit(double value) { m_value = clampTo<int>(value * kFixedPoi ntDenominator); }
81 81
82 static LayoutUnit fromFloatCeil(float value) 82 static LayoutUnit fromFloatCeil(float value)
83 { 83 {
84 LayoutUnit v; 84 LayoutUnit v;
85 v.m_value = clampTo<int>(ceilf(value * kFixedPointDenominator)); 85 v.m_value = clampTo<int>(ceilf(value * kFixedPointDenominator));
86 return v; 86 return v;
87 } 87 }
88 88
89 static LayoutUnit fromFloatFloor(float value) 89 static LayoutUnit fromFloatFloor(float value)
90 { 90 {
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 inline LayoutUnit absoluteValue(const LayoutUnit& value) 789 inline LayoutUnit absoluteValue(const LayoutUnit& value)
790 { 790 {
791 return value.abs(); 791 return value.abs();
792 } 792 }
793 793
794 inline LayoutUnit layoutMod(const LayoutUnit& numerator, const LayoutUnit& denom inator) 794 inline LayoutUnit layoutMod(const LayoutUnit& numerator, const LayoutUnit& denom inator)
795 { 795 {
796 return numerator % denominator; 796 return numerator % denominator;
797 } 797 }
798 798
799 inline LayoutUnit layoutMod(const LayoutUnit& numerator, int denominator)
800 {
801 return numerator % LayoutUnit(denominator);
802 }
803
799 inline bool isIntegerValue(const LayoutUnit value) 804 inline bool isIntegerValue(const LayoutUnit value)
800 { 805 {
801 return value.toInt() == value; 806 return value.toInt() == value;
802 } 807 }
803 808
804 inline LayoutUnit clampToLayoutUnit(LayoutUnit value, LayoutUnit min, LayoutUnit max) 809 inline LayoutUnit clampToLayoutUnit(LayoutUnit value, LayoutUnit min, LayoutUnit max)
805 { 810 {
806 if (value >= max) 811 if (value >= max)
807 return max; 812 return max;
808 if (value <= min) 813 if (value <= min)
809 return min; 814 return min;
810 return value; 815 return value;
811 } 816 }
812 817
813 } // namespace blink 818 } // namespace blink
814 819
815 #endif // LayoutUnit_h 820 #endif // LayoutUnit_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/StyleGeneratedImage.cpp ('k') | third_party/WebKit/Source/platform/LengthFunctions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698