OLD | NEW |
---|---|
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. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 */ | 21 */ |
22 | 22 |
23 #include "config.h" | 23 #include "config.h" |
24 #include "core/svg/SVGLengthContext.h" | 24 #include "core/svg/SVGLengthContext.h" |
25 | 25 |
26 #include "core/css/CSSHelper.h" | 26 #include "core/css/CSSHelper.h" |
27 #include "core/css/CSSPrimitiveValue.h" | |
27 #include "core/layout/LayoutObject.h" | 28 #include "core/layout/LayoutObject.h" |
28 #include "core/layout/style/LayoutStyle.h" | 29 #include "core/layout/style/LayoutStyle.h" |
29 #include "core/svg/SVGSVGElement.h" | 30 #include "core/svg/SVGSVGElement.h" |
30 #include "platform/LengthFunctions.h" | 31 #include "platform/LengthFunctions.h" |
31 #include "platform/fonts/FontMetrics.h" | 32 #include "platform/fonts/FontMetrics.h" |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) | 36 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) |
36 { | 37 { |
37 switch (mode) { | 38 switch (mode) { |
38 case SVGLengthMode::Width: | 39 case SVGLengthMode::Width: |
39 return viewportSize.width(); | 40 return viewportSize.width(); |
40 case SVGLengthMode::Height: | 41 case SVGLengthMode::Height: |
41 return viewportSize.height(); | 42 return viewportSize.height(); |
42 case SVGLengthMode::Other: | 43 case SVGLengthMode::Other: |
43 return sqrtf(viewportSize.diagonalLengthSquared() / 2); | 44 return sqrtf(viewportSize.diagonalLengthSquared() / 2); |
44 } | 45 } |
45 ASSERT_NOT_REACHED(); | 46 ASSERT_NOT_REACHED(); |
46 return 0; | 47 return 0; |
47 } | 48 } |
48 | 49 |
49 static float convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize) | 50 static float convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize) |
50 { | 51 { |
51 return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), view portSize)); | 52 return CSSPrimitiveValue::clampToCSSLengthRange(value.scaleByPercentage(dime nsionForLengthMode(value.unitMode(), viewportSize))); |
52 } | 53 } |
53 | 54 |
54 SVGLengthContext::SVGLengthContext(const SVGElement* context) | 55 SVGLengthContext::SVGLengthContext(const SVGElement* context) |
55 : m_context(context) | 56 : m_context(context) |
56 { | 57 { |
57 } | 58 } |
58 | 59 |
59 FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitT ypes::SVGUnitType type, const FloatRect& viewport, const SVGLength& x, const SVG Length& y, const SVGLength& width, const SVGLength& height) | 60 FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitT ypes::SVGUnitType type, const FloatRect& viewport, const SVGLength& x, const SVG Length& y, const SVGLength& width, const SVGLength& height) |
60 { | 61 { |
61 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); | 62 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 ASSERT(zoom != 0); | 129 ASSERT(zoom != 0); |
129 return floatValueForLength(length, dimension * zoom) / zoom; | 130 return floatValueForLength(length, dimension * zoom) / zoom; |
130 } | 131 } |
131 | 132 |
132 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const | 133 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const |
133 { | 134 { |
134 switch (fromUnit) { | 135 switch (fromUnit) { |
135 case LengthTypeUnknown: | 136 case LengthTypeUnknown: |
136 return 0; | 137 return 0; |
137 case LengthTypeNumber: | 138 case LengthTypeNumber: |
138 return value; | 139 return CSSPrimitiveValue::clampToCSSLengthRange(value); |
fs
2015/03/12 14:28:48
This is begging to be sunk out of the switch in on
Erik Dahlström (inactive)
2015/03/12 16:14:56
Done.
| |
139 case LengthTypePX: | 140 case LengthTypePX: |
140 return value; | 141 return CSSPrimitiveValue::clampToCSSLengthRange(value); |
141 case LengthTypePercentage: { | 142 case LengthTypePercentage: { |
142 FloatSize viewportSize; | 143 FloatSize viewportSize; |
143 if (!determineViewport(viewportSize)) | 144 if (!determineViewport(viewportSize)) |
144 return 0; | 145 return 0; |
145 return value * dimensionForLengthMode(mode, viewportSize) / 100; | 146 return CSSPrimitiveValue::clampToCSSLengthRange(value * dimensionForLeng thMode(mode, viewportSize) / 100); |
146 } | 147 } |
147 case LengthTypeEMS: | 148 case LengthTypeEMS: |
148 return convertValueFromEMSToUserUnits(value); | 149 return CSSPrimitiveValue::clampToCSSLengthRange(convertValueFromEMSToUse rUnits(value)); |
149 case LengthTypeEXS: | 150 case LengthTypeEXS: |
150 return convertValueFromEXSToUserUnits(value); | 151 return CSSPrimitiveValue::clampToCSSLengthRange(convertValueFromEXSToUse rUnits(value)); |
151 case LengthTypeCM: | 152 case LengthTypeCM: |
152 return value * cssPixelsPerCentimeter; | 153 return CSSPrimitiveValue::clampToCSSLengthRange(value * cssPixelsPerCent imeter); |
153 case LengthTypeMM: | 154 case LengthTypeMM: |
154 return value * cssPixelsPerMillimeter; | 155 return CSSPrimitiveValue::clampToCSSLengthRange(value * cssPixelsPerMill imeter); |
155 case LengthTypeIN: | 156 case LengthTypeIN: |
156 return value * cssPixelsPerInch; | 157 return CSSPrimitiveValue::clampToCSSLengthRange(value * cssPixelsPerInch ); |
157 case LengthTypePT: | 158 case LengthTypePT: |
158 return value * cssPixelsPerPoint; | 159 return CSSPrimitiveValue::clampToCSSLengthRange(value * cssPixelsPerPoin t); |
159 case LengthTypePC: | 160 case LengthTypePC: |
160 return value * cssPixelsPerPica; | 161 return CSSPrimitiveValue::clampToCSSLengthRange(value * cssPixelsPerPica ); |
161 } | 162 } |
162 | 163 |
163 ASSERT_NOT_REACHED(); | 164 ASSERT_NOT_REACHED(); |
164 return 0; | 165 return 0; |
165 } | 166 } |
166 | 167 |
167 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod e, SVGLengthType toUnit) const | 168 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod e, SVGLengthType toUnit) const |
168 { | 169 { |
169 switch (toUnit) { | 170 switch (toUnit) { |
170 case LengthTypeUnknown: | 171 case LengthTypeUnknown: |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
283 | 284 |
284 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); | 285 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); |
285 viewportSize = svg.currentViewBoxRect().size(); | 286 viewportSize = svg.currentViewBoxRect().size(); |
286 if (viewportSize.isEmpty()) | 287 if (viewportSize.isEmpty()) |
287 viewportSize = svg.currentViewportSize(); | 288 viewportSize = svg.currentViewportSize(); |
288 | 289 |
289 return true; | 290 return true; |
290 } | 291 } |
291 | 292 |
292 } | 293 } |
OLD | NEW |