OLD | NEW |
---|---|
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 17 matching lines...) Expand all Loading... | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef LayoutUnit_h | 31 #ifndef LayoutUnit_h |
32 #define LayoutUnit_h | 32 #define LayoutUnit_h |
33 | 33 |
34 #include "wtf/Allocator.h" | 34 #include "wtf/Allocator.h" |
35 #include "wtf/Assertions.h" | 35 #include "wtf/Assertions.h" |
36 #include "wtf/MathExtras.h" | 36 #include "wtf/MathExtras.h" |
37 #include "wtf/SaturatedArithmetic.h" | 37 #include "wtf/SaturatedArithmetic.h" |
38 #include "wtf/text/WTFString.h" | |
38 #include <algorithm> | 39 #include <algorithm> |
39 #include <limits.h> | 40 #include <limits.h> |
40 #include <limits> | 41 #include <limits> |
41 #include <stdlib.h> | 42 #include <stdlib.h> |
42 | 43 |
43 namespace blink { | 44 namespace blink { |
44 | 45 |
45 #if DCHECK_IS_ON() | 46 #if DCHECK_IS_ON() |
46 #define REPORT_OVERFLOW(doesOverflow) DLOG_IF(ERROR, !(doesOverflow)) << "Layout Unit overflow !(" << #doesOverflow << ") in " << WTF_PRETTY_FUNCTION | 47 #define REPORT_OVERFLOW(doesOverflow) DLOG_IF(ERROR, !(doesOverflow)) << "Layout Unit overflow !(" << #doesOverflow << ") in " << WTF_PRETTY_FUNCTION |
47 #else | 48 #else |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
205 LayoutUnit m; | 206 LayoutUnit m; |
206 m.m_value = std::numeric_limits<int>::min() + kFixedPointDenominator / 2 ; | 207 m.m_value = std::numeric_limits<int>::min() + kFixedPointDenominator / 2 ; |
207 return m; | 208 return m; |
208 } | 209 } |
209 | 210 |
210 static LayoutUnit clamp(double value) | 211 static LayoutUnit clamp(double value) |
211 { | 212 { |
212 return clampTo<LayoutUnit>(value, LayoutUnit::min(), LayoutUnit::max()); | 213 return clampTo<LayoutUnit>(value, LayoutUnit::min(), LayoutUnit::max()); |
213 } | 214 } |
214 | 215 |
216 String toString() const | |
217 { | |
218 if (m_value == LayoutUnit::max().rawValue()) | |
esprehn
2016/08/19 17:58:52
can we make this out of line?
| |
219 return String::format("LayoutUnit::max(%f)", toDouble()); | |
esprehn
2016/08/19 17:58:53
fwiw this is slow, doing "LayoutUnit::max(" + Stri
| |
220 if (m_value == LayoutUnit::min().rawValue()) | |
221 return String::format("LayoutUnit::min(%f)", toDouble()); | |
222 if (m_value == LayoutUnit::nearlyMax().rawValue()) | |
223 return String::format("LayoutUnit::nearlyMax(%f)", toDouble()); | |
224 if (m_value == LayoutUnit::nearlyMin().rawValue()) | |
225 return String::format("LayoutUnit::nearlyMin(%f)", toDouble()); | |
226 return String::number(toDouble()); | |
227 } | |
228 | |
215 private: | 229 private: |
216 static bool isInBounds(int value) | 230 static bool isInBounds(int value) |
217 { | 231 { |
218 return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDeno minator; | 232 return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDeno minator; |
219 } | 233 } |
220 static bool isInBounds(unsigned value) | 234 static bool isInBounds(unsigned value) |
221 { | 235 { |
222 return value <= static_cast<unsigned>(std::numeric_limits<int>::max()) / kFixedPointDenominator; | 236 return value <= static_cast<unsigned>(std::numeric_limits<int>::max()) / kFixedPointDenominator; |
223 } | 237 } |
224 static bool isInBounds(double value) | 238 static bool isInBounds(double value) |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 { | 815 { |
802 if (value >= max) | 816 if (value >= max) |
803 return max; | 817 return max; |
804 if (value <= min) | 818 if (value <= min) |
805 return min; | 819 return min; |
806 return value; | 820 return value; |
807 } | 821 } |
808 | 822 |
809 inline std::ostream& operator<<(std::ostream& stream, const LayoutUnit& value) | 823 inline std::ostream& operator<<(std::ostream& stream, const LayoutUnit& value) |
810 { | 824 { |
811 return stream << value.toDouble(); | 825 return stream << value.toString(); |
812 } | 826 } |
813 | 827 |
814 } // namespace blink | 828 } // namespace blink |
815 | 829 |
816 #endif // LayoutUnit_h | 830 #endif // LayoutUnit_h |
OLD | NEW |