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

Side by Side Diff: Source/core/css/CSSLengthFunctions.cpp

Issue 122973002: Refactor the length functions to remove passing around the extra bool parameter for rounding behavi… (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Try again Created 6 years, 11 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 | « Source/core/css/CSSLengthFunctions.h ('k') | Source/core/rendering/RenderBoxModelObject.cpp » ('j') | 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) 1999 Lars Knoll (knoll@kde.org) 2 Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 3 Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4 Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com) 4 Copyright (C) 2011 Rik Cabanier (cabanier@adobe.com)
5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 5 Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
6 Copyright (C) 2012 Motorola Mobility, Inc. All rights reserved. 6 Copyright (C) 2012 Motorola Mobility, Inc. All rights reserved.
7 Copyright (C) 2013 Google, Inc. All rights reserved. 7 Copyright (C) 2013 Google, Inc. All rights reserved.
8 8
9 This library is free software; you can redistribute it and/or 9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public 10 modify it under the terms of the GNU Library General Public
(...skipping 13 matching lines...) Expand all
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/css/CSSLengthFunctions.h" 26 #include "core/css/CSSLengthFunctions.h"
27 27
28 #include "platform/LayoutUnit.h" 28 #include "platform/LayoutUnit.h"
29 #include "platform/Length.h" 29 #include "platform/Length.h"
30 #include "platform/LengthFunctions.h" 30 #include "platform/LengthFunctions.h"
31 31
32 namespace WebCore { 32 namespace WebCore {
33 33
34 int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) 34 int minimumIntValueForLength(const Length& length, LayoutUnit maximumValue)
35 { 35 {
36 return static_cast<int>(minimumValueForLength(length, maximumValue, roundPer centages)); 36 return static_cast<int>(minimumValueForLength(length, maximumValue));
37 } 37 }
38 38
39 int intValueForLength(const Length& length, LayoutUnit maximumValue, bool roundP ercentages) 39 int intValueForLength(const Length& length, LayoutUnit maximumValue)
40 { 40 {
41 return static_cast<int>(valueForLength(length, maximumValue, roundPercentage s)); 41 return static_cast<int>(valueForLength(length, maximumValue));
42 } 42 }
43 43
44 LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue, bool roundPercentages) 44 LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue)
45 { 45 {
46 switch (length.type()) { 46 switch (length.type()) {
47 case Fixed: 47 case Fixed:
48 return length.value(); 48 return length.value();
49 case Percent: 49 case Percent:
50 if (roundPercentages)
51 return static_cast<LayoutUnit>(round(maximumValue * length.percent() / 100.0f));
52 // Don't remove the extra cast to float. It is needed for rounding on 32 -bit Intel machines that use the FPU stack. 50 // Don't remove the extra cast to float. It is needed for rounding on 32 -bit Intel machines that use the FPU stack.
53 return static_cast<float>(maximumValue * length.percent() / 100.0f); 51 return static_cast<float>(maximumValue * length.percent() / 100.0f);
54 case Calculated: 52 case Calculated:
55 return length.nonNanCalculatedValue(maximumValue); 53 return length.nonNanCalculatedValue(maximumValue);
56 case FillAvailable: 54 case FillAvailable:
57 case Auto: 55 case Auto:
58 return 0; 56 return 0;
59 case Intrinsic: 57 case Intrinsic:
60 case MinIntrinsic: 58 case MinIntrinsic:
61 case MinContent: 59 case MinContent:
62 case MaxContent: 60 case MaxContent:
63 case FitContent: 61 case FitContent:
64 case ExtendToZoom: 62 case ExtendToZoom:
65 case DeviceWidth: 63 case DeviceWidth:
66 case DeviceHeight: 64 case DeviceHeight:
67 case Undefined: 65 case Undefined:
68 ASSERT_NOT_REACHED(); 66 ASSERT_NOT_REACHED();
69 return 0; 67 return 0;
70 } 68 }
71 ASSERT_NOT_REACHED(); 69 ASSERT_NOT_REACHED();
72 return 0; 70 return 0;
73 } 71 }
74 72
75 LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue, bool ro undPercentages) 73 LayoutUnit roundedMinimumValueForLength(const Length& length, LayoutUnit maximum Value)
74 {
75 if (length.type() == Percent)
76 return static_cast<LayoutUnit>(round(maximumValue * length.percent() / 1 00.0f));
77 return minimumValueForLength(length, maximumValue);
78 }
79
80 LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue)
76 { 81 {
77 switch (length.type()) { 82 switch (length.type()) {
78 case Fixed: 83 case Fixed:
79 case Percent: 84 case Percent:
80 case Calculated: 85 case Calculated:
81 return minimumValueForLength(length, maximumValue, roundPercentages); 86 return minimumValueForLength(length, maximumValue);
82 case FillAvailable: 87 case FillAvailable:
83 case Auto: 88 case Auto:
84 return maximumValue; 89 return maximumValue;
85 case Intrinsic: 90 case Intrinsic:
86 case MinIntrinsic: 91 case MinIntrinsic:
87 case MinContent: 92 case MinContent:
88 case MaxContent: 93 case MaxContent:
89 case FitContent: 94 case FitContent:
90 case ExtendToZoom: 95 case ExtendToZoom:
91 case DeviceWidth: 96 case DeviceWidth:
92 case DeviceHeight: 97 case DeviceHeight:
93 case Undefined: 98 case Undefined:
94 ASSERT_NOT_REACHED(); 99 ASSERT_NOT_REACHED();
95 return 0; 100 return 0;
96 } 101 }
97 ASSERT_NOT_REACHED(); 102 ASSERT_NOT_REACHED();
98 return 0; 103 return 0;
99 } 104 }
100 105
101 } // namespace WebCore 106 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSLengthFunctions.h ('k') | Source/core/rendering/RenderBoxModelObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698