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

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

Issue 1031223003: SVG doesn't recognize rem units (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixes builderror Created 5 years, 8 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/SVGLengthTearOff.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/css/CSSPrimitiveValue.h" 27 #include "core/css/CSSPrimitiveValue.h"
28 #include "core/dom/NodeComputedStyle.h"
28 #include "core/layout/LayoutObject.h" 29 #include "core/layout/LayoutObject.h"
29 #include "core/style/ComputedStyle.h" 30 #include "core/style/ComputedStyle.h"
30 #include "core/svg/SVGSVGElement.h" 31 #include "core/svg/SVGSVGElement.h"
31 #include "platform/LengthFunctions.h" 32 #include "platform/LengthFunctions.h"
32 #include "platform/fonts/FontMetrics.h" 33 #include "platform/fonts/FontMetrics.h"
33 34
34 namespace blink { 35 namespace blink {
35 36
36 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize) 37 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize)
37 { 38 {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 break; 162 break;
162 case LengthTypeIN: 163 case LengthTypeIN:
163 userUnits = value * cssPixelsPerInch; 164 userUnits = value * cssPixelsPerInch;
164 break; 165 break;
165 case LengthTypePT: 166 case LengthTypePT:
166 userUnits = value * cssPixelsPerPoint; 167 userUnits = value * cssPixelsPerPoint;
167 break; 168 break;
168 case LengthTypePC: 169 case LengthTypePC:
169 userUnits = value * cssPixelsPerPica; 170 userUnits = value * cssPixelsPerPica;
170 break; 171 break;
172 case LengthTypeREMS:
173 userUnits = convertValueFromREMSToUserUnits(value);
174 break;
171 default: 175 default:
172 ASSERT_NOT_REACHED(); 176 ASSERT_NOT_REACHED();
173 break; 177 break;
174 } 178 }
175 179
176 // Since we mix css <length> values with svg's length values we need to 180 // Since we mix css <length> values with svg's length values we need to
177 // clamp values to the narrowest range, otherwise it can result in 181 // clamp values to the narrowest range, otherwise it can result in
178 // rendering issues. 182 // rendering issues.
179 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits); 183 return CSSPrimitiveValue::clampToCSSLengthRange(userUnits);
180 } 184 }
(...skipping 10 matching lines...) Expand all
191 if (!determineViewport(viewportSize)) 195 if (!determineViewport(viewportSize))
192 return 0; 196 return 0;
193 // LengthTypePercentage is represented with 100% = 100.0. 197 // LengthTypePercentage is represented with 100% = 100.0.
194 // Good for accuracy but could eventually be changed. 198 // Good for accuracy but could eventually be changed.
195 return value * 100 / dimensionForLengthMode(mode, viewportSize); 199 return value * 100 / dimensionForLengthMode(mode, viewportSize);
196 } 200 }
197 case LengthTypeEMS: 201 case LengthTypeEMS:
198 return convertValueFromUserUnitsToEMS(value); 202 return convertValueFromUserUnitsToEMS(value);
199 case LengthTypeEXS: 203 case LengthTypeEXS:
200 return convertValueFromUserUnitsToEXS(value); 204 return convertValueFromUserUnitsToEXS(value);
205 case LengthTypeREMS:
206 return convertValueFromUserUnitsToREMS(value);
201 case LengthTypePX: 207 case LengthTypePX:
202 return value; 208 return value;
203 case LengthTypeCM: 209 case LengthTypeCM:
204 return value / cssPixelsPerCentimeter; 210 return value / cssPixelsPerCentimeter;
205 case LengthTypeMM: 211 case LengthTypeMM:
206 return value / cssPixelsPerMillimeter; 212 return value / cssPixelsPerMillimeter;
207 case LengthTypeIN: 213 case LengthTypeIN:
208 return value / cssPixelsPerInch; 214 return value / cssPixelsPerInch;
209 case LengthTypePT: 215 case LengthTypePT:
210 return value / cssPixelsPerPoint; 216 return value / cssPixelsPerPoint;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 253 }
248 254
249 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const 255 float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const
250 { 256 {
251 const ComputedStyle* style = computedStyleForLengthResolving(m_context); 257 const ComputedStyle* style = computedStyleForLengthResolving(m_context);
252 if (!style) 258 if (!style)
253 return 0; 259 return 0;
254 return value * style->specifiedFontSize(); 260 return value * style->specifiedFontSize();
255 } 261 }
256 262
263 float SVGLengthContext::convertValueFromUserUnitsToREMS(float value) const
264 {
265 if (!m_context)
266 return 0;
267
268 const ComputedStyle* style = 0;
269 const Document& document = m_context->document();
270 Node* documentElement = document.documentElement();
271 const ComputedStyle* documentStyle = document.computedStyle();
272 style = documentElement && (static_cast<const Node*>(m_context.get()) != doc umentElement) ? documentElement->computedStyle() : documentStyle;
273 if (!style)
274 style = documentStyle;
275
276 if (!style)
277 return 0;
278
279 float fontSize = style->specifiedFontSize();
280 if (!fontSize)
281 return 0;
282
283 return value / fontSize;
284 }
285
286 float SVGLengthContext::convertValueFromREMSToUserUnits(float value) const
287 {
288 if (!m_context)
289 return 0;
290
291 const ComputedStyle* style = 0;
292 const Document& document = m_context->document();
293 Node* documentElement = document.documentElement();
294 const ComputedStyle* documentStyle = document.computedStyle();
295 style = documentElement && (static_cast<const Node*>(m_context.get()) != doc umentElement) ? documentElement->computedStyle() : documentStyle;
296 if (!style)
297 style = documentStyle;
298
299 if (!style)
300 return 0;
301
302 return value * style->specifiedFontSize();
303 }
304
257 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const 305 float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const
258 { 306 {
259 const ComputedStyle* style = computedStyleForLengthResolving(m_context); 307 const ComputedStyle* style = computedStyleForLengthResolving(m_context);
260 if (!style) 308 if (!style)
261 return 0; 309 return 0;
262 310
263 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg 311 // Use of ceil allows a pixel match to the W3Cs expected output of coords-un its-03-b.svg
264 // if this causes problems in real world cases maybe it would be best to rem ove this 312 // if this causes problems in real world cases maybe it would be best to rem ove this
265 float xHeight = ceilf(style->fontMetrics().xHeight()); 313 float xHeight = ceilf(style->fontMetrics().xHeight());
266 if (!xHeight) 314 if (!xHeight)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 346
299 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 347 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
300 viewportSize = svg.currentViewBoxRect().size(); 348 viewportSize = svg.currentViewBoxRect().size();
301 if (viewportSize.isEmpty()) 349 if (viewportSize.isEmpty())
302 viewportSize = svg.currentViewportSize(); 350 viewportSize = svg.currentViewportSize();
303 351
304 return true; 352 return true;
305 } 353 }
306 354
307 } 355 }
OLDNEW
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | Source/core/svg/SVGLengthTearOff.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698