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

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: 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 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 40c86bb6f21d2f797a8a86e063768fa856c38f13..39c41c2712dc87b656e83ce815a1e45c58db7ded 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -32,10 +32,25 @@
#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 {
+static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize)
+{
+ switch (mode) {
+ case LengthModeWidth:
+ return viewportSize.width();
+ case LengthModeHeight:
+ return viewportSize.height();
+ case LengthModeOther:
+ return sqrtf(viewportSize.diagonalLengthSquared() / 2);
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
SVGLengthContext::SVGLengthContext(const SVGElement* context)
: m_context(context)
{
@@ -91,6 +106,20 @@ float SVGLengthContext::resolveLength(const SVGElement* context, SVGUnitTypes::S
return x->valueAsPercentage();
}
+float SVGLengthContext::valueForLength(const Length& length, SVGLengthMode mode)
+{
+ if (length.isAuto())
+ return 0;
+
+ FloatSize viewportSize;
+ determineViewport(viewportSize);
+
+ if (length.isPercent())
+ return convertValueFromPercentageToUserUnits(length.value(), mode, viewportSize) / 100;
+
+ return floatValueForLength(length, dimensionForLengthMode(mode, viewportSize));
+}
+
float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, SVGLengthType fromUnit, ExceptionState& exceptionState) const
{
switch (fromUnit) {
@@ -155,20 +184,6 @@ float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod
return 0;
}
-static inline float dimensionForLengthMode(SVGLengthMode mode, const FloatSize& viewportSize)
-{
- switch (mode) {
- case LengthModeWidth:
- return viewportSize.width();
- case LengthModeHeight:
- return viewportSize.height();
- case LengthModeOther:
- return sqrtf(viewportSize.diagonalLengthSquared() / 2);
- }
- ASSERT_NOT_REACHED();
- return 0;
-}
-
float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLengthMode mode, ExceptionState& exceptionState) const
{
FloatSize viewportSize;

Powered by Google App Engine
This is Rietveld 408576698