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

Side by Side Diff: Source/core/svg/SVGLengthContext.cpp

Issue 87453003: Less magic numbers in converting CSS lengths of cm/mm/pc/pt types. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Created 7 years 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/CSSPrimitiveValue.cpp ('k') | Source/core/svg/SVGSVGElement.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) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 5 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 return value; 104 return value;
105 case LengthTypePX: 105 case LengthTypePX:
106 return value; 106 return value;
107 case LengthTypePercentage: 107 case LengthTypePercentage:
108 return convertValueFromPercentageToUserUnits(value / 100, mode, exceptio nState); 108 return convertValueFromPercentageToUserUnits(value / 100, mode, exceptio nState);
109 case LengthTypeEMS: 109 case LengthTypeEMS:
110 return convertValueFromEMSToUserUnits(value, exceptionState); 110 return convertValueFromEMSToUserUnits(value, exceptionState);
111 case LengthTypeEXS: 111 case LengthTypeEXS:
112 return convertValueFromEXSToUserUnits(value, exceptionState); 112 return convertValueFromEXSToUserUnits(value, exceptionState);
113 case LengthTypeCM: 113 case LengthTypeCM:
114 return value * cssPixelsPerInch / 2.54f; 114 return value * cssPixelsPerCentimeter;
115 case LengthTypeMM: 115 case LengthTypeMM:
116 return value * cssPixelsPerInch / 25.4f; 116 return value * cssPixelsPerMillimeter;
117 case LengthTypeIN: 117 case LengthTypeIN:
118 return value * cssPixelsPerInch; 118 return value * cssPixelsPerInch;
119 case LengthTypePT: 119 case LengthTypePT:
120 return value * cssPixelsPerInch / 72; 120 return value * cssPixelsPerPoint;
121 case LengthTypePC: 121 case LengthTypePC:
122 return value * cssPixelsPerInch / 6; 122 return value * cssPixelsPerPica;
123 } 123 }
124 124
125 ASSERT_NOT_REACHED(); 125 ASSERT_NOT_REACHED();
126 return 0; 126 return 0;
127 } 127 }
128 128
129 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod e, SVGLengthType toUnit, ExceptionState& exceptionState) const 129 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod e, SVGLengthType toUnit, ExceptionState& exceptionState) const
130 { 130 {
131 switch (toUnit) { 131 switch (toUnit) {
132 case LengthTypeUnknown: 132 case LengthTypeUnknown:
133 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r); 133 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedErro r);
134 return 0; 134 return 0;
135 case LengthTypeNumber: 135 case LengthTypeNumber:
136 return value; 136 return value;
137 case LengthTypePercentage: 137 case LengthTypePercentage:
138 return convertValueFromUserUnitsToPercentage(value * 100, mode, exceptio nState); 138 return convertValueFromUserUnitsToPercentage(value * 100, mode, exceptio nState);
139 case LengthTypeEMS: 139 case LengthTypeEMS:
140 return convertValueFromUserUnitsToEMS(value, exceptionState); 140 return convertValueFromUserUnitsToEMS(value, exceptionState);
141 case LengthTypeEXS: 141 case LengthTypeEXS:
142 return convertValueFromUserUnitsToEXS(value, exceptionState); 142 return convertValueFromUserUnitsToEXS(value, exceptionState);
143 case LengthTypePX: 143 case LengthTypePX:
144 return value; 144 return value;
145 case LengthTypeCM: 145 case LengthTypeCM:
146 return value * 2.54f / cssPixelsPerInch; 146 return value / cssPixelsPerCentimeter;
147 case LengthTypeMM: 147 case LengthTypeMM:
148 return value * 25.4f / cssPixelsPerInch; 148 return value / cssPixelsPerMillimeter;
149 case LengthTypeIN: 149 case LengthTypeIN:
150 return value / cssPixelsPerInch; 150 return value / cssPixelsPerInch;
151 case LengthTypePT: 151 case LengthTypePT:
152 return value * 72 / cssPixelsPerInch; 152 return value / cssPixelsPerPoint;
153 case LengthTypePC: 153 case LengthTypePC:
154 return value * 6 / cssPixelsPerInch; 154 return value / cssPixelsPerPica;
155 } 155 }
156 156
157 ASSERT_NOT_REACHED(); 157 ASSERT_NOT_REACHED();
158 return 0; 158 return 0;
159 } 159 }
160 160
161 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe ngthMode mode, ExceptionState& exceptionState) const 161 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe ngthMode mode, ExceptionState& exceptionState) const
162 { 162 {
163 FloatSize viewportSize; 163 FloatSize viewportSize;
164 if (!determineViewport(viewportSize)) { 164 if (!determineViewport(viewportSize)) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement ); 302 const SVGSVGElement* svg = static_cast<const SVGSVGElement*>(viewportElement );
303 viewportSize = svg->currentViewBoxRect().size(); 303 viewportSize = svg->currentViewBoxRect().size();
304 if (viewportSize.isEmpty()) 304 if (viewportSize.isEmpty())
305 viewportSize = svg->currentViewportSize(); 305 viewportSize = svg->currentViewportSize();
306 306
307 return true; 307 return true;
308 } 308 }
309 309
310 } 310 }
OLDNEW
« no previous file with comments | « Source/core/css/CSSPrimitiveValue.cpp ('k') | Source/core/svg/SVGSVGElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698