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

Unified 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: cleanup 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/svg/SVGLengthContext.cpp
diff --git a/Source/core/svg/SVGLengthContext.cpp b/Source/core/svg/SVGLengthContext.cpp
index 9c1a4d15c19902e297c787185e7235ac2ac2bef3..e559e889822dcc24a026de6f2cababcf0070044d 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -32,6 +32,7 @@
#include "core/rendering/svg/RenderSVGRoot.h"
#include "core/rendering/svg/RenderSVGViewportContainer.h"
#include "core/svg/SVGSVGElement.h"
+#include "platform/LengthFunctions.h"
#include "platform/fonts/FontMetrics.h"
namespace blink {
@@ -91,6 +92,27 @@ float SVGLengthContext::resolveLength(const SVGElement* context, SVGUnitTypes::S
return x->valueAsPercentage();
}
+float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode)
+{
+ if (length.isPercent())
+ return convertValueFromPercentageToUserUnits(length.value() / 100, mode, IGNORE_EXCEPTION);
fs 2015/02/04 13:24:53 Move this after the 'auto' check, and then use the
fs 2015/02/04 13:24:53 I'm sure bratell would want you to do the division
Erik Dahlström (inactive) 2015/02/05 16:09:02 Done.
Erik Dahlström (inactive) 2015/02/05 16:09:02 Done.
+ if (length.isAuto())
+ return 0;
+
+ FloatSize viewportSize;
+ determineViewport(viewportSize);
+
+ switch (mode) {
+ case LengthModeWidth:
fs 2015/02/04 13:24:53 (Given the amount of these switches this file/clas
Erik Dahlström (inactive) 2015/02/05 16:09:02 Acknowledged.
+ return floatValueForLength(length, viewportSize.width());
+ case LengthModeHeight:
+ return floatValueForLength(length, viewportSize.height());
+ case LengthModeOther:
+ return floatValueForLength(length, sqrtf(viewportSize.diagonalLengthSquared() / 2));
+ };
+ return 0;
+}
+
float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit, ExceptionState& exceptionState) const
{
switch (fromUnit) {

Powered by Google App Engine
This is Rietveld 408576698