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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 FractionalLayoutUnit m; | 175 FractionalLayoutUnit m; |
176 m.m_value = std::numeric_limits<int>::max(); | 176 m.m_value = std::numeric_limits<int>::max(); |
177 return m; | 177 return m; |
178 } | 178 } |
179 static const FractionalLayoutUnit min() | 179 static const FractionalLayoutUnit min() |
180 { | 180 { |
181 FractionalLayoutUnit m; | 181 FractionalLayoutUnit m; |
182 m.m_value = std::numeric_limits<int>::min(); | 182 m.m_value = std::numeric_limits<int>::min(); |
183 return m; | 183 return m; |
184 } | 184 } |
| 185 |
| 186 // Versions of max/min that are slightly smaller/larger than max/min() to al
low for roinding without overflowing. |
| 187 static const FractionalLayoutUnit nearlyMax() |
| 188 { |
| 189 FractionalLayoutUnit m; |
| 190 m.m_value = std::numeric_limits<int>::max() - kFixedPointDenominator / 2
; |
| 191 return m; |
| 192 } |
| 193 static const FractionalLayoutUnit nearlyMin() |
| 194 { |
| 195 FractionalLayoutUnit m; |
| 196 m.m_value = std::numeric_limits<int>::min() + kFixedPointDenominator / 2
; |
| 197 return m; |
| 198 } |
| 199 |
185 static FractionalLayoutUnit clamp(double value) | 200 static FractionalLayoutUnit clamp(double value) |
186 { | 201 { |
187 return clampTo<FractionalLayoutUnit>(value, FractionalLayoutUnit::min(),
FractionalLayoutUnit::max()); | 202 return clampTo<FractionalLayoutUnit>(value, FractionalLayoutUnit::min(),
FractionalLayoutUnit::max()); |
188 } | 203 } |
189 | 204 |
190 private: | 205 private: |
191 static bool isInBounds(int value) | 206 static bool isInBounds(int value) |
192 { | 207 { |
193 return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDeno
minator; | 208 return ::abs(value) <= std::numeric_limits<int>::max() / kFixedPointDeno
minator; |
194 } | 209 } |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 } | 693 } |
679 | 694 |
680 inline float& operator/=(float& a, const FractionalLayoutUnit& b) | 695 inline float& operator/=(float& a, const FractionalLayoutUnit& b) |
681 { | 696 { |
682 a = a / b; | 697 a = a / b; |
683 return a; | 698 return a; |
684 } | 699 } |
685 | 700 |
686 inline int snapSizeToPixel(FractionalLayoutUnit size, FractionalLayoutUnit locat
ion) | 701 inline int snapSizeToPixel(FractionalLayoutUnit size, FractionalLayoutUnit locat
ion) |
687 { | 702 { |
688 return (location + size).round() - location.round(); | 703 FractionalLayoutUnit fraction = location - location.floor(); |
| 704 return (fraction + size).round() - fraction.round(); |
689 } | 705 } |
690 | 706 |
691 #if PLATFORM(QT) | 707 #if PLATFORM(QT) |
692 inline QDataStream& operator<<(QDataStream& stream, const FractionalLayoutUnit&
value) | 708 inline QDataStream& operator<<(QDataStream& stream, const FractionalLayoutUnit&
value) |
693 { | 709 { |
694 if (kFixedPointDenominator == 1) | 710 if (kFixedPointDenominator == 1) |
695 stream << value.rawValue(); | 711 stream << value.rawValue(); |
696 else | 712 else |
697 stream << QString::fromLatin1("%1").arg(value.toFloat(), 0, 'f', 2); | 713 stream << QString::fromLatin1("%1").arg(value.toFloat(), 0, 'f', 2); |
698 | 714 |
699 return stream; | 715 return stream; |
700 } | 716 } |
701 | 717 |
702 inline QDataStream& operator>>(QDataStream& stream, FractionalLayoutUnit& value) | 718 inline QDataStream& operator>>(QDataStream& stream, FractionalLayoutUnit& value) |
703 { | 719 { |
704 float v; | 720 float v; |
705 stream >> v; | 721 stream >> v; |
706 value = v; | 722 value = v; |
707 return stream; | 723 return stream; |
708 } | 724 } |
709 #endif | 725 #endif |
710 | 726 |
711 } // namespace WebCore | 727 } // namespace WebCore |
712 | 728 |
713 #endif // FractionalLayoutUnit_h | 729 #endif // FractionalLayoutUnit_h |
OLD | NEW |