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

Side by Side Diff: Source/WebCore/css/CSSPrimitiveValue.h

Issue 10349004: Revert 115573 - Move Length and CSS length computation to float (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1123/
Patch Set: Created 8 years, 7 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 24 matching lines...) Expand all
35 class DashboardRegion; 35 class DashboardRegion;
36 class Pair; 36 class Pair;
37 class Quad; 37 class Quad;
38 class RGBColor; 38 class RGBColor;
39 class Rect; 39 class Rect;
40 class RenderStyle; 40 class RenderStyle;
41 class CSSWrapShape; 41 class CSSWrapShape;
42 42
43 struct Length; 43 struct Length;
44 44
45 // Dimension calculations are imprecise, often resulting in values of e.g.
46 // 44.99998. We need to go ahead and round if we're really close to the next
47 // integer value.
48 template<typename T> inline T roundForImpreciseConversion(double value) 45 template<typename T> inline T roundForImpreciseConversion(double value)
49 { 46 {
47 // Dimension calculations are imprecise, often resulting in values of e.g.
48 // 44.99998. We need to go ahead and round if we're really close to the
49 // next integer value.
50 value += (value < 0) ? -0.01 : +0.01; 50 value += (value < 0) ? -0.01 : +0.01;
51 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim its<T>::min())) ? 0 : static_cast<T>(value); 51 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_lim its<T>::min())) ? 0 : static_cast<T>(value);
52 } 52 }
53 53
54 template<> inline float roundForImpreciseConversion(double value)
55 {
56 double ceiledValue = ceil(value);
57 double proximityToNextInt = ceiledValue - value;
58 if (proximityToNextInt <= 0.01 && value > 0)
59 return static_cast<float>(ceiledValue);
60 if (proximityToNextInt >= 0.99 && value < 0)
61 return static_cast<float>(floor(value));
62 return static_cast<float>(value);
63 }
64
65 class CSSPrimitiveValue : public CSSValue { 54 class CSSPrimitiveValue : public CSSValue {
66 public: 55 public:
67 enum UnitTypes { 56 enum UnitTypes {
68 CSS_UNKNOWN = 0, 57 CSS_UNKNOWN = 0,
69 CSS_NUMBER = 1, 58 CSS_NUMBER = 1,
70 CSS_PERCENTAGE = 2, 59 CSS_PERCENTAGE = 2,
71 CSS_EMS = 3, 60 CSS_EMS = 3,
72 CSS_EXS = 4, 61 CSS_EXS = 4,
73 CSS_PX = 5, 62 CSS_PX = 5,
74 CSS_CM = 6, 63 CSS_CM = 6,
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 Pair* pair; 328 Pair* pair;
340 DashboardRegion* region; 329 DashboardRegion* region;
341 CSSWrapShape* shape; 330 CSSWrapShape* shape;
342 CSSCalcValue* calc; 331 CSSCalcValue* calc;
343 } m_value; 332 } m_value;
344 }; 333 };
345 334
346 } // namespace WebCore 335 } // namespace WebCore
347 336
348 #endif // CSSPrimitiveValue_h 337 #endif // CSSPrimitiveValue_h
OLDNEW
« no previous file with comments | « Source/WebCore/css/CSSComputedStyleDeclaration.cpp ('k') | Source/WebCore/css/CSSPrimitiveValue.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698