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

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
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 14 matching lines...) Expand all
25 25
26 #include "bindings/core/v8/ExceptionMessages.h" 26 #include "bindings/core/v8/ExceptionMessages.h"
27 #include "bindings/core/v8/ExceptionState.h" 27 #include "bindings/core/v8/ExceptionState.h"
28 #include "core/SVGNames.h" 28 #include "core/SVGNames.h"
29 #include "core/css/CSSHelper.h" 29 #include "core/css/CSSHelper.h"
30 #include "core/dom/ExceptionCode.h" 30 #include "core/dom/ExceptionCode.h"
31 #include "core/rendering/RenderView.h" 31 #include "core/rendering/RenderView.h"
32 #include "core/rendering/svg/RenderSVGRoot.h" 32 #include "core/rendering/svg/RenderSVGRoot.h"
33 #include "core/rendering/svg/RenderSVGViewportContainer.h" 33 #include "core/rendering/svg/RenderSVGViewportContainer.h"
34 #include "core/svg/SVGSVGElement.h" 34 #include "core/svg/SVGSVGElement.h"
35 #include "platform/LengthFunctions.h"
35 #include "platform/fonts/FontMetrics.h" 36 #include "platform/fonts/FontMetrics.h"
36 37
37 namespace blink { 38 namespace blink {
38 39
40 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize)
41 {
42 switch (mode) {
43 case LengthModeWidth:
44 return viewportSize.width();
45 case LengthModeHeight:
46 return viewportSize.height();
47 case LengthModeOther:
48 return sqrtf(viewportSize.diagonalLengthSquared() / 2);
49 }
50 ASSERT_NOT_REACHED();
51 return 0;
52 }
53
39 SVGLengthContext::SVGLengthContext(const SVGElement* context) 54 SVGLengthContext::SVGLengthContext(const SVGElement* context)
40 : m_context(context) 55 : m_context(context)
41 { 56 {
42 } 57 }
43 58
44 FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitT ypes::SVGUnitType type, const FloatRect& viewport, PassRefPtrWillBeRawPtr<SVGLen gth> passX, PassRefPtrWillBeRawPtr<SVGLength> passY, PassRefPtrWillBeRawPtr<SVGL ength> passWidth, PassRefPtrWillBeRawPtr<SVGLength> passHeight) 59 FloatRect SVGLengthContext::resolveRectangle(const SVGElement* context, SVGUnitT ypes::SVGUnitType type, const FloatRect& viewport, PassRefPtrWillBeRawPtr<SVGLen gth> passX, PassRefPtrWillBeRawPtr<SVGLength> passY, PassRefPtrWillBeRawPtr<SVGL ength> passWidth, PassRefPtrWillBeRawPtr<SVGLength> passHeight)
45 { 60 {
46 RefPtrWillBeRawPtr<SVGLength> x = passX; 61 RefPtrWillBeRawPtr<SVGLength> x = passX;
47 RefPtrWillBeRawPtr<SVGLength> y = passY; 62 RefPtrWillBeRawPtr<SVGLength> y = passY;
48 RefPtrWillBeRawPtr<SVGLength> width = passWidth; 63 RefPtrWillBeRawPtr<SVGLength> width = passWidth;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN); 99 ASSERT(type != SVGUnitTypes::SVG_UNIT_TYPE_UNKNOWN);
85 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) { 100 if (type == SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) {
86 SVGLengthContext lengthContext(context); 101 SVGLengthContext lengthContext(context);
87 return x->value(lengthContext); 102 return x->value(lengthContext);
88 } 103 }
89 104
90 // 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. 105 // 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.
91 return x->valueAsPercentage(); 106 return x->valueAsPercentage();
92 } 107 }
93 108
109 float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode)
110 {
111 if (length.isAuto())
112 return 0;
113
114 FloatSize viewportSize;
115 determineViewport(viewportSize);
116
117 if (length.isPercent())
118 return convertValueFromPercentageToUserUnits(length.value(), mode, viewp ortSize) / 100;
119
120 return floatValueForLength(length, dimensionForLengthMode(mode, viewportSize ));
121 }
122
94 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit, ExceptionState& exceptionState) const 123 float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit, ExceptionState& exceptionState) const
95 { 124 {
96 switch (fromUnit) { 125 switch (fromUnit) {
97 case LengthTypeUnknown: 126 case LengthTypeUnknown:
98 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::a rgumentNullOrIncorrectType(3, "SVGLengthType")); 127 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::a rgumentNullOrIncorrectType(3, "SVGLengthType"));
99 return 0; 128 return 0;
100 case LengthTypeNumber: 129 case LengthTypeNumber:
101 return value; 130 return value;
102 case LengthTypePX: 131 case LengthTypePX:
103 return value; 132 return value;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 case LengthTypePT: 177 case LengthTypePT:
149 return value / cssPixelsPerPoint; 178 return value / cssPixelsPerPoint;
150 case LengthTypePC: 179 case LengthTypePC:
151 return value / cssPixelsPerPica; 180 return value / cssPixelsPerPica;
152 } 181 }
153 182
154 ASSERT_NOT_REACHED(); 183 ASSERT_NOT_REACHED();
155 return 0; 184 return 0;
156 } 185 }
157 186
158 static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize)
159 {
160 switch (mode) {
161 case LengthModeWidth:
162 return viewportSize.width();
163 case LengthModeHeight:
164 return viewportSize.height();
165 case LengthModeOther:
166 return sqrtf(viewportSize.diagonalLengthSquared() / 2);
167 }
168 ASSERT_NOT_REACHED();
169 return 0;
170 }
171
172 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe ngthMode mode, ExceptionState& exceptionState) const 187 float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe ngthMode mode, ExceptionState& exceptionState) const
173 { 188 {
174 FloatSize viewportSize; 189 FloatSize viewportSize;
175 if (!determineViewport(viewportSize)) { 190 if (!determineViewport(viewportSize)) {
176 exceptionState.throwDOMException(NotSupportedError, "The viewport could not be determined."); 191 exceptionState.throwDOMException(NotSupportedError, "The viewport could not be determined.");
177 return 0; 192 return 0;
178 } 193 }
179 194
180 return value / dimensionForLengthMode(mode, viewportSize) * 100; 195 return value / dimensionForLengthMode(mode, viewportSize) * 100;
181 } 196 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 310
296 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement); 311 const SVGSVGElement& svg = toSVGSVGElement(*viewportElement);
297 viewportSize = svg.currentViewBoxRect().size(); 312 viewportSize = svg.currentViewBoxRect().size();
298 if (viewportSize.isEmpty()) 313 if (viewportSize.isEmpty())
299 viewportSize = svg.currentViewportSize(); 314 viewportSize = svg.currentViewportSize();
300 315
301 return true; 316 return true;
302 } 317 }
303 318
304 } 319 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698