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

Side by Side Diff: Source/WebCore/platform/FractionalLayoutUnit.h

Issue 10996032: Merge 129370 - snapToSize rounds the incorrectly for negative locations (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1271/
Patch Set: Created 8 years, 2 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
« no previous file with comments | « LayoutTests/platform/wk2/Skipped ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 { 220 {
221 #if ENABLE(SUBPIXEL_LAYOUT) 221 #if ENABLE(SUBPIXEL_LAYOUT)
222 if (m_value >= 0) 222 if (m_value >= 0)
223 return toInt(); 223 return toInt();
224 return (m_value - kFixedPointDenominator + 1) / kFixedPointDenominator; 224 return (m_value - kFixedPointDenominator + 1) / kFixedPointDenominator;
225 #else 225 #else
226 return m_value; 226 return m_value;
227 #endif 227 #endif
228 } 228 }
229 229
230 FractionalLayoutUnit fraction() const
231 {
232 // Add the fraction to the size (as opposed to the full location) to avo id overflows.
233 // Compute fraction using the mod operator to preserve the sign of the v alue as it may affect rounding.
234 FractionalLayoutUnit fraction;
235 fraction.setRawValue(rawValue() % kFixedPointDenominator);
236 return fraction;
237 }
238
230 #if ENABLE(SUBPIXEL_LAYOUT) 239 #if ENABLE(SUBPIXEL_LAYOUT)
231 static float epsilon() { return 1.0f / kFixedPointDenominator; } 240 static float epsilon() { return 1.0f / kFixedPointDenominator; }
232 #else 241 #else
233 static int epsilon() { return 0; } 242 static int epsilon() { return 0; }
234 #endif 243 #endif
235 static const FractionalLayoutUnit max() 244 static const FractionalLayoutUnit max()
236 { 245 {
237 FractionalLayoutUnit m; 246 FractionalLayoutUnit m;
238 m.m_value = std::numeric_limits<int>::max(); 247 m.m_value = std::numeric_limits<int>::max();
239 return m; 248 return m;
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 } 809 }
801 810
802 inline float& operator/=(float& a, const FractionalLayoutUnit& b) 811 inline float& operator/=(float& a, const FractionalLayoutUnit& b)
803 { 812 {
804 a = a / b; 813 a = a / b;
805 return a; 814 return a;
806 } 815 }
807 816
808 inline int snapSizeToPixel(FractionalLayoutUnit size, FractionalLayoutUnit locat ion) 817 inline int snapSizeToPixel(FractionalLayoutUnit size, FractionalLayoutUnit locat ion)
809 { 818 {
810 FractionalLayoutUnit fraction = location - location.floor(); 819 FractionalLayoutUnit fraction = location.fraction();
811 return (fraction + size).round() - fraction.round(); 820 return (fraction + size).round() - fraction.round();
812 } 821 }
813 822
814 #if PLATFORM(QT) 823 #if PLATFORM(QT)
815 inline QDataStream& operator<<(QDataStream& stream, const FractionalLayoutUnit& value) 824 inline QDataStream& operator<<(QDataStream& stream, const FractionalLayoutUnit& value)
816 { 825 {
817 if (kFixedPointDenominator == 1) 826 if (kFixedPointDenominator == 1)
818 stream << value.rawValue(); 827 stream << value.rawValue();
819 else 828 else
820 stream << QString::fromLatin1("%1").arg(value.toFloat(), 0, 'f', 2); 829 stream << QString::fromLatin1("%1").arg(value.toFloat(), 0, 'f', 2);
821 830
822 return stream; 831 return stream;
823 } 832 }
824 833
825 inline QDataStream& operator>>(QDataStream& stream, FractionalLayoutUnit& value) 834 inline QDataStream& operator>>(QDataStream& stream, FractionalLayoutUnit& value)
826 { 835 {
827 float v; 836 float v;
828 stream >> v; 837 stream >> v;
829 value = v; 838 value = v;
830 return stream; 839 return stream;
831 } 840 }
832 #endif 841 #endif
833 842
834 } // namespace WebCore 843 } // namespace WebCore
835 844
836 #endif // FractionalLayoutUnit_h 845 #endif // FractionalLayoutUnit_h
OLDNEW
« no previous file with comments | « LayoutTests/platform/wk2/Skipped ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698