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

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

Issue 896773002: [svg2] Make 'x' and 'y' presentation attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 5 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
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | Source/core/svg/SVGMaskElement.h » ('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/layout/LayoutObject.h" 27 #include "core/layout/LayoutObject.h"
28 #include "core/layout/style/LayoutStyle.h" 28 #include "core/layout/style/LayoutStyle.h"
29 #include "core/svg/SVGSVGElement.h" 29 #include "core/svg/SVGSVGElement.h"
30 #include "platform/LengthFunctions.h"
30 #include "platform/fonts/FontMetrics.h" 31 #include "platform/fonts/FontMetrics.h"
31 32
32 namespace blink { 33 namespace blink {
33 34
34 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) 35 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize)
35 { 36 {
36 switch (mode) { 37 switch (mode) {
37 case LengthModeWidth: 38 case LengthModeWidth:
38 return viewportSize.width(); 39 return viewportSize.width();
39 case LengthModeHeight: 40 case LengthModeHeight:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); 89 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
89 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { 90 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
90 SVGLengthContext lengthContext(context); 91 SVGLengthContext lengthContext(context);
91 return x.value(lengthContext); 92 return x.value(lengthContext);
92 } 93 }
93 94
94 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t o be resolved in user space and then be considered in objectBoundingBox space. 95 // FIXME: valueAsPercentage() won't be correct for eg. cm units. They need t o be resolved in user space and then be considered in objectBoundingBox space.
95 return x.valueAsPercentage(); 96 return x.valueAsPercentage();
96 } 97 }
97 98
99 float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode)
100 {
101 if (length.isAuto())
102 return 0;
103
104 FloatSize viewportSize;
105 determineViewport(viewportSize);
106
107 if (length.isPercent())
108 return length.value() * dimensionForLengthMode(mode, viewportSize) / 100 ;
109
110 return floatValueForLength(length, dimensionForLengthMode(mode, viewportSize ));
111 }
112
98 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const 113 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const
99 { 114 {
100 switch (fromUnit) { 115 switch (fromUnit) {
101 case LengthTypeUnknown: 116 case LengthTypeUnknown:
102 return 0; 117 return 0;
103 case LengthTypeNumber: 118 case LengthTypeNumber:
104 return value; 119 return value;
105 case LengthTypePX: 120 case LengthTypePX:
106 return value; 121 return value;
107 case LengthTypePercentage: { 122 case LengthTypePercentage: {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 264
250 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 265 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
251 viewportSize = svg.currentViewBoxRect().size(); 266 viewportSize = svg.currentViewBoxRect().size();
252 if (viewportSize.isEmpty()) 267 if (viewportSize.isEmpty())
253 viewportSize = svg.currentViewportSize(); 268 viewportSize = svg.currentViewportSize();
254 269
255 return true; 270 return true;
256 } 271 }
257 272
258 } 273 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | Source/core/svg/SVGMaskElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698