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

Side by Side Diff: third_party/WebKit/Source/platform/LengthFunctions.cpp

Issue 1648573002: Transition to explicit constructors in LayoutUnit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove int constructors for size/point... they result in incorrect conversions until LayoutUnit is … Created 4 years, 10 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 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 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
(...skipping 26 matching lines...) Expand all
37 { 37 {
38 switch (length.type()) { 38 switch (length.type()) {
39 case Fixed: 39 case Fixed:
40 return length.getFloatValue(); 40 return length.getFloatValue();
41 case Percent: 41 case Percent:
42 return static_cast<float>(maximumValue * length.percent() / 100.0f); 42 return static_cast<float>(maximumValue * length.percent() / 100.0f);
43 case FillAvailable: 43 case FillAvailable:
44 case Auto: 44 case Auto:
45 return static_cast<float>(maximumValue); 45 return static_cast<float>(maximumValue);
46 case Calculated: 46 case Calculated:
47 return length.nonNanCalculatedValue(maximumValue); 47 return length.nonNanCalculatedValue(LayoutUnit(maximumValue));
48 case MinContent: 48 case MinContent:
49 case MaxContent: 49 case MaxContent:
50 case FitContent: 50 case FitContent:
51 case ExtendToZoom: 51 case ExtendToZoom:
52 case DeviceWidth: 52 case DeviceWidth:
53 case DeviceHeight: 53 case DeviceHeight:
54 case MaxSizeNone: 54 case MaxSizeNone:
55 ASSERT_NOT_REACHED(); 55 ASSERT_NOT_REACHED();
56 return 0; 56 return 0;
57 } 57 }
58 ASSERT_NOT_REACHED(); 58 ASSERT_NOT_REACHED();
59 return 0; 59 return 0;
60 } 60 }
61 61
62 LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue) 62 LayoutUnit minimumValueForLength(const Length& length, LayoutUnit maximumValue)
63 { 63 {
64 switch (length.type()) { 64 switch (length.type()) {
65 case Fixed: 65 case Fixed:
66 return length.value(); 66 return LayoutUnit(length.value());
67 case Percent: 67 case Percent:
68 // Don't remove the extra cast to float. It is needed for rounding on 32 -bit Intel machines that use the FPU stack. 68 // Don't remove the extra cast to float. It is needed for rounding on 32 -bit Intel machines that use the FPU stack.
69 return static_cast<float>(maximumValue * length.percent() / 100.0f); 69 return LayoutUnit(static_cast<float>(maximumValue * length.percent() / 1 00.0f));
70 case Calculated: 70 case Calculated:
71 return length.nonNanCalculatedValue(maximumValue.toFloat()); 71 return LayoutUnit(length.nonNanCalculatedValue(maximumValue));
72 case FillAvailable: 72 case FillAvailable:
73 case Auto: 73 case Auto:
74 return 0; 74 return LayoutUnit();
75 case MinContent: 75 case MinContent:
76 case MaxContent: 76 case MaxContent:
77 case FitContent: 77 case FitContent:
78 case ExtendToZoom: 78 case ExtendToZoom:
79 case DeviceWidth: 79 case DeviceWidth:
80 case DeviceHeight: 80 case DeviceHeight:
81 case MaxSizeNone: 81 case MaxSizeNone:
82 ASSERT_NOT_REACHED(); 82 ASSERT_NOT_REACHED();
83 return 0; 83 return LayoutUnit();
84 } 84 }
85 ASSERT_NOT_REACHED(); 85 ASSERT_NOT_REACHED();
86 return 0; 86 return LayoutUnit();
87 } 87 }
88 88
89 LayoutUnit roundedMinimumValueForLength(const Length& length, LayoutUnit maximum Value) 89 LayoutUnit roundedMinimumValueForLength(const Length& length, LayoutUnit maximum Value)
90 { 90 {
91 if (length.type() == Percent) 91 if (length.type() == Percent)
92 return static_cast<LayoutUnit>(round(maximumValue * length.percent() / 1 00.0f)); 92 return static_cast<LayoutUnit>(round(maximumValue * length.percent() / 1 00.0f));
93 return minimumValueForLength(length, maximumValue); 93 return minimumValueForLength(length, maximumValue);
94 } 94 }
95 95
96 LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue) 96 LayoutUnit valueForLength(const Length& length, LayoutUnit maximumValue)
97 { 97 {
98 switch (length.type()) { 98 switch (length.type()) {
99 case Fixed: 99 case Fixed:
100 case Percent: 100 case Percent:
101 case Calculated: 101 case Calculated:
102 return minimumValueForLength(length, maximumValue); 102 return minimumValueForLength(length, maximumValue);
103 case FillAvailable: 103 case FillAvailable:
104 case Auto: 104 case Auto:
105 return maximumValue; 105 return maximumValue;
106 case MinContent: 106 case MinContent:
107 case MaxContent: 107 case MaxContent:
108 case FitContent: 108 case FitContent:
109 case ExtendToZoom: 109 case ExtendToZoom:
110 case DeviceWidth: 110 case DeviceWidth:
111 case DeviceHeight: 111 case DeviceHeight:
112 case MaxSizeNone: 112 case MaxSizeNone:
113 ASSERT_NOT_REACHED(); 113 ASSERT_NOT_REACHED();
114 return 0; 114 return LayoutUnit();
115 } 115 }
116 ASSERT_NOT_REACHED(); 116 ASSERT_NOT_REACHED();
117 return 0; 117 return LayoutUnit();
118 } 118 }
119 119
120 FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, const FloatSize& boxSize) 120 FloatSize floatSizeForLengthSize(const LengthSize& lengthSize, const FloatSize& boxSize)
121 { 121 {
122 return FloatSize(floatValueForLength(lengthSize.width(), boxSize.width()), f loatValueForLength(lengthSize.height(), boxSize.height())); 122 return FloatSize(floatValueForLength(lengthSize.width(), boxSize.width()), f loatValueForLength(lengthSize.height(), boxSize.height()));
123 } 123 }
124 124
125 } // namespace blink 125 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/LayoutUnit.h ('k') | third_party/WebKit/Source/platform/animation/AnimationUtilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698