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

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

Issue 947983002: Move zoom handling for x and y properties to svg (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase + add NeedsRebaseline 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/css/resolver/StyleBuilderConverter.cpp ('k') | no next file » | 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); 89 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
90 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { 90 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
91 SVGLengthContext lengthContext(context); 91 SVGLengthContext lengthContext(context);
92 return x.value(lengthContext); 92 return x.value(lengthContext);
93 } 93 }
94 94
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 // 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.
96 return x.valueAsPercentage(); 96 return x.valueAsPercentage();
97 } 97 }
98 98
99 static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* conte xt)
100 {
101 if (!context)
102 return 0;
103
104 const ContainerNode* currentContext = context;
105 do {
106 if (currentContext->renderer())
107 return currentContext->renderer()->style();
108 currentContext = currentContext->parentNode();
109 } while (currentContext);
110
111 // There must be at least a LayoutSVGRoot renderer, carrying a style.
112 ASSERT_NOT_REACHED();
113 return 0;
114 }
115
99 float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode) const 116 float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode) const
100 { 117 {
118 LayoutStyle* style = layoutStyleForLengthResolving(m_context);
fs 2015/02/24 17:29:28 Should rather be passing a LayoutStyle& to here.
Erik Dahlström (inactive) 2015/02/25 09:17:36 Done.
119 if (!style)
120 return 0;
121
101 float dimension = 0; 122 float dimension = 0;
102 if (length.isPercent()) { 123 if (length.isPercent()) {
103 FloatSize viewportSize; 124 FloatSize viewportSize;
104 determineViewport(viewportSize); 125 determineViewport(viewportSize);
126 viewportSize.scale(style->effectiveZoom());
105 dimension = dimensionForLengthMode(mode, viewportSize); 127 dimension = dimensionForLengthMode(mode, viewportSize);
106 } 128 }
107 return floatValueForLength(length, dimension); 129 return floatValueForLength(length, dimension) / style->effectiveZoom();
108 } 130 }
109 131
110 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const 132 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit) const
111 { 133 {
112 switch (fromUnit) { 134 switch (fromUnit) {
113 case LengthTypeUnknown: 135 case LengthTypeUnknown:
114 return 0; 136 return 0;
115 case LengthTypeNumber: 137 case LengthTypeNumber:
116 return value; 138 return value;
117 case LengthTypePX: 139 case LengthTypePX:
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 case LengthTypePT: 194 case LengthTypePT:
173 return value / cssPixelsPerPoint; 195 return value / cssPixelsPerPoint;
174 case LengthTypePC: 196 case LengthTypePC:
175 return value / cssPixelsPerPica; 197 return value / cssPixelsPerPica;
176 } 198 }
177 199
178 ASSERT_NOT_REACHED(); 200 ASSERT_NOT_REACHED();
179 return 0; 201 return 0;
180 } 202 }
181 203
182 static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* conte xt)
183 {
184 if (!context)
185 return 0;
186
187 const ContainerNode* currentContext = context;
188 do {
189 if (currentContext->renderer())
190 return currentContext->renderer()->style();
191 currentContext = currentContext->parentNode();
192 } while (currentContext);
193
194 // There must be at least a LayoutSVGRoot renderer, carrying a style.
195 ASSERT_NOT_REACHED();
196 return 0;
197 }
198
199 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const 204 float SVGLengthContext::convertValueFromUserUnitsToEMS(float value) const
200 { 205 {
201 LayoutStyle* style = layoutStyleForLengthResolving(m_context); 206 LayoutStyle* style = layoutStyleForLengthResolving(m_context);
202 if (!style) 207 if (!style)
203 return 0; 208 return 0;
204 209
205 float fontSize = style->specifiedFontSize(); 210 float fontSize = style->specifiedFontSize();
206 if (!fontSize) 211 if (!fontSize)
207 return 0; 212 return 0;
208 213
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 266
262 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 267 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
263 viewportSize = svg.currentViewBoxRect().size(); 268 viewportSize = svg.currentViewBoxRect().size();
264 if (viewportSize.isEmpty()) 269 if (viewportSize.isEmpty())
265 viewportSize = svg.currentViewportSize(); 270 viewportSize = svg.currentViewportSize();
266 271
267 return true; 272 return true;
268 } 273 }
269 274
270 } 275 }
OLDNEW
« no previous file with comments | « Source/core/css/resolver/StyleBuilderConverter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698