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

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

Issue 963733002: [svg2] Make 'width' and 'height' presentation attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebaseline some EX tests [Mac Win] Created 5 years, 9 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/svg/SVGImageElement.cpp ('k') | Source/core/svg/SVGMaskElement.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.
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 125 }
125 126
126 float SVGLengthContext::valueForLength(const Length& length, float zoom, float d imension) 127 float SVGLengthContext::valueForLength(const Length& length, float zoom, float d imension)
127 { 128 {
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 {
135 float userUnits = value;
134 switch (fromUnit) { 136 switch (fromUnit) {
135 case LengthTypeUnknown: 137 case LengthTypeUnknown:
136 return 0; 138 return 0;
139 case LengthTypePX:
137 case LengthTypeNumber: 140 case LengthTypeNumber:
138 return value; 141 userUnits = value;
139 case LengthTypePX: 142 break;
140 return value;
141 case LengthTypePercentage: { 143 case LengthTypePercentage: {
142 FloatSize viewportSize; 144 FloatSize viewportSize;
143 if (!determineViewport(viewportSize)) 145 if (!determineViewport(viewportSize))
144 return 0; 146 return 0;
145 return value * dimensionForLengthMode(mode, viewportSize) / 100; 147 userUnits = value * dimensionForLengthMode(mode, viewportSize) / 100;
148 break;
146 } 149 }
147 case LengthTypeEMS: 150 case LengthTypeEMS:
148 return convertValueFromEMSToUserUnits(value); 151 userUnits = convertValueFromEMSToUserUnits(value);
152 break;
149 case LengthTypeEXS: 153 case LengthTypeEXS:
150 return convertValueFromEXSToUserUnits(value); 154 userUnits = convertValueFromEXSToUserUnits(value);
155 break;
151 case LengthTypeCM: 156 case LengthTypeCM:
152 return value * cssPixelsPerCentimeter; 157 userUnits = value * cssPixelsPerCentimeter;
158 break;
153 case LengthTypeMM: 159 case LengthTypeMM:
154 return value * cssPixelsPerMillimeter; 160 userUnits = value * cssPixelsPerMillimeter;
161 break;
155 case LengthTypeIN: 162 case LengthTypeIN:
156 return value * cssPixelsPerInch; 163 userUnits = value * cssPixelsPerInch;
164 break;
157 case LengthTypePT: 165 case LengthTypePT:
158 return value * cssPixelsPerPoint; 166 userUnits = value * cssPixelsPerPoint;
167 break;
159 case LengthTypePC: 168 case LengthTypePC:
160 return value * cssPixelsPerPica; 169 userUnits = value * cssPixelsPerPica;
170 break;
171 default:
172 ASSERT_NOT_REACHED();
173 break;
161 } 174 }
162 175
163 ASSERT_NOT_REACHED(); 176 // Since we mix css <length> values with svg's length values we need to
164 return 0; 177 // clamp values to the narrowest range, otherwise it can result in
178 // rendering issues.
179 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits);
165 } 180 }
166 181
167 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod e, SVGLengthType toUnit) const 182 float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod e, SVGLengthType toUnit) const
168 { 183 {
169 switch (toUnit) { 184 switch (toUnit) {
170 case LengthTypeUnknown: 185 case LengthTypeUnknown:
171 return 0; 186 return 0;
172 case LengthTypeNumber: 187 case LengthTypeNumber:
173 return value; 188 return value;
174 case LengthTypePercentage: { 189 case LengthTypePercentage: {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 298
284 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 299 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
285 viewportSize = svg.currentViewBoxRect().size(); 300 viewportSize = svg.currentViewBoxRect().size();
286 if (viewportSize.isEmpty()) 301 if (viewportSize.isEmpty())
287 viewportSize = svg.currentViewportSize(); 302 viewportSize = svg.currentViewportSize();
288 303
289 return true; 304 return true;
290 } 305 }
291 306
292 } 307 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGImageElement.cpp ('k') | Source/core/svg/SVGMaskElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698