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

Unified Diff: Source/core/svg/SVGLengthContext.cpp

Issue 902593002: Refactor LengthMode handling in SVGLengthContext (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: dimensionForLengthMode 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGLengthContext.cpp
diff --git a/Source/core/svg/SVGLengthContext.cpp b/Source/core/svg/SVGLengthContext.cpp
index 9c1a4d15c19902e297c787185e7235ac2ac2bef3..40c86bb6f21d2f797a8a86e063768fa856c38f13 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -155,6 +155,20 @@ 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;
@@ -163,17 +177,7 @@ float SVGLengthContext::convertValueFromUserUnitsToPercentage(float value, SVGLe
return 0;
}
- switch (mode) {
- case LengthModeWidth:
- return value / viewportSize.width() * 100;
- case LengthModeHeight:
- return value / viewportSize.height() * 100;
- case LengthModeOther:
- return value / sqrtf(viewportSize.diagonalLengthSquared() / 2) * 100;
- };
-
- ASSERT_NOT_REACHED();
- return 0;
+ return value / dimensionForLengthMode(mode, viewportSize) * 100;
}
float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLengthMode mode, ExceptionState& exceptionState) const
@@ -188,32 +192,12 @@ float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLe
float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLengthMode mode, const FloatSize& viewportSize)
{
- switch (mode) {
- case LengthModeWidth:
- return value * viewportSize.width();
- case LengthModeHeight:
- return value * viewportSize.height();
- case LengthModeOther:
- return value * sqrtf(viewportSize.diagonalLengthSquared() / 2);
- }
-
- ASSERT_NOT_REACHED();
- return 0;
+ return value * dimensionForLengthMode(mode, viewportSize);
}
float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize)
{
- switch (value.unitMode()) {
- case LengthModeWidth:
- return value.scaleByPercentage(viewportSize.width());
- case LengthModeHeight:
- return value.scaleByPercentage(viewportSize.height());
- case LengthModeOther:
- return value.scaleByPercentage(sqrtf(viewportSize.diagonalLengthSquared() / 2));
- }
-
- ASSERT_NOT_REACHED();
- return 0;
+ return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), viewportSize));
}
static inline RenderStyle* renderStyleForLengthResolving(const SVGElement* context)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698