| 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 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 "platform/PlatformExport.h" |
| 34 #include "wtf/Allocator.h" | 35 #include "wtf/Allocator.h" |
| 35 #include "wtf/Assertions.h" | 36 #include "wtf/Assertions.h" |
| 36 #include "wtf/MathExtras.h" | 37 #include "wtf/MathExtras.h" |
| 37 #include "wtf/SaturatedArithmetic.h" | 38 #include "wtf/SaturatedArithmetic.h" |
| 39 #include "wtf/text/WTFString.h" |
| 38 #include <algorithm> | 40 #include <algorithm> |
| 39 #include <limits.h> | 41 #include <limits.h> |
| 40 #include <limits> | 42 #include <limits> |
| 41 #include <stdlib.h> | 43 #include <stdlib.h> |
| 42 | 44 |
| 43 namespace blink { | 45 namespace blink { |
| 44 | 46 |
| 45 #if DCHECK_IS_ON() | 47 #if DCHECK_IS_ON() |
| 46 #define REPORT_OVERFLOW(doesOverflow) DLOG_IF(ERROR, !(doesOverflow)) << "Layout
Unit overflow !(" << #doesOverflow << ") in " << WTF_PRETTY_FUNCTION | 48 #define REPORT_OVERFLOW(doesOverflow) DLOG_IF(ERROR, !(doesOverflow)) << "Layout
Unit overflow !(" << #doesOverflow << ") in " << WTF_PRETTY_FUNCTION |
| 47 #else | 49 #else |
| 48 #define REPORT_OVERFLOW(doesOverflow) ((void)0) | 50 #define REPORT_OVERFLOW(doesOverflow) ((void)0) |
| 49 #endif | 51 #endif |
| 50 | 52 |
| 51 static const int kLayoutUnitFractionalBits = 6; | 53 static const int kLayoutUnitFractionalBits = 6; |
| 52 static const int kFixedPointDenominator = 1 << kLayoutUnitFractionalBits; | 54 static const int kFixedPointDenominator = 1 << kLayoutUnitFractionalBits; |
| 53 | 55 |
| 54 const int intMaxForLayoutUnit = INT_MAX / kFixedPointDenominator; | 56 const int intMaxForLayoutUnit = INT_MAX / kFixedPointDenominator; |
| 55 const int intMinForLayoutUnit = INT_MIN / kFixedPointDenominator; | 57 const int intMinForLayoutUnit = INT_MIN / kFixedPointDenominator; |
| 56 | 58 |
| 57 // TODO(thakis): Remove these two lines once http://llvm.org/PR26504 is resolved | 59 // TODO(thakis): Remove these two lines once http://llvm.org/PR26504 is resolved |
| 58 class LayoutUnit; | 60 class PLATFORM_EXPORT LayoutUnit; |
| 59 inline bool operator<(const LayoutUnit&, const LayoutUnit&); | 61 inline bool operator<(const LayoutUnit&, const LayoutUnit&); |
| 60 | 62 |
| 61 class LayoutUnit { | 63 class LayoutUnit { |
| 62 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 64 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 63 public: | 65 public: |
| 64 LayoutUnit() : m_value(0) { } | 66 LayoutUnit() : m_value(0) { } |
| 65 explicit LayoutUnit(int value) { setValue(value); } | 67 explicit LayoutUnit(int value) { setValue(value); } |
| 66 explicit LayoutUnit(unsigned short value) { setValue(value); } | 68 explicit LayoutUnit(unsigned short value) { setValue(value); } |
| 67 explicit LayoutUnit(unsigned value) { setValue(value); } | 69 explicit LayoutUnit(unsigned value) { setValue(value); } |
| 68 explicit LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kF
ixedPointDenominator); } | 70 explicit LayoutUnit(unsigned long value) { m_value = clampTo<int>(value * kF
ixedPointDenominator); } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 LayoutUnit m; | 207 LayoutUnit m; |
| 206 m.m_value = std::numeric_limits<int>::min() + kFixedPointDenominator / 2
; | 208 m.m_value = std::numeric_limits<int>::min() + kFixedPointDenominator / 2
; |
| 207 return m; | 209 return m; |
| 208 } | 210 } |
| 209 | 211 |
| 210 static LayoutUnit clamp(double value) | 212 static LayoutUnit clamp(double value) |
| 211 { | 213 { |
| 212 return clampTo<LayoutUnit>(value, LayoutUnit::min(), LayoutUnit::max()); | 214 return clampTo<LayoutUnit>(value, LayoutUnit::min(), LayoutUnit::max()); |
| 213 } | 215 } |
| 214 | 216 |
| 217 String toString() const; |
| 218 |
| 215 private: | 219 private: |
| 216 static bool isInBounds(int value) | 220 static bool isInBounds(int value) |
| 217 { | 221 { |
| 218 return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDeno
minator; | 222 return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDeno
minator; |
| 219 } | 223 } |
| 220 static bool isInBounds(unsigned value) | 224 static bool isInBounds(unsigned value) |
| 221 { | 225 { |
| 222 return value <= static_cast<unsigned>(std::numeric_limits<int>::max()) /
kFixedPointDenominator; | 226 return value <= static_cast<unsigned>(std::numeric_limits<int>::max()) /
kFixedPointDenominator; |
| 223 } | 227 } |
| 224 static bool isInBounds(double value) | 228 static bool isInBounds(double value) |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 { | 805 { |
| 802 if (value >= max) | 806 if (value >= max) |
| 803 return max; | 807 return max; |
| 804 if (value <= min) | 808 if (value <= min) |
| 805 return min; | 809 return min; |
| 806 return value; | 810 return value; |
| 807 } | 811 } |
| 808 | 812 |
| 809 inline std::ostream& operator<<(std::ostream& stream, const LayoutUnit& value) | 813 inline std::ostream& operator<<(std::ostream& stream, const LayoutUnit& value) |
| 810 { | 814 { |
| 811 return stream << value.toDouble(); | 815 return stream << value.toString(); |
| 812 } | 816 } |
| 813 | 817 |
| 814 } // namespace blink | 818 } // namespace blink |
| 815 | 819 |
| 816 #endif // LayoutUnit_h | 820 #endif // LayoutUnit_h |
| OLD | NEW |