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

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

Issue 897313004: Fold up the SVGLengthContext::convertValueFrom* helpers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | « Source/core/svg/SVGLengthContext.h ('k') | 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 447df21ca06ace55048dc7ed306856eaf0a59ac9..28a43cda93c9b5e9f6c54ed2db4beb0ffae4f161 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -31,6 +31,25 @@
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;
+}
+
+static float convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize)
+{
+ return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), viewportSize));
+}
+
SVGLengthContext::SVGLengthContext(const SVGElement* context)
: m_context(context)
{
@@ -99,7 +118,7 @@ float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode,
FloatSize viewportSize;
if (!determineViewport(viewportSize))
return 0;
- return convertValueFromPercentageToUserUnits(value, mode, viewportSize) / 100;
+ return value * dimensionForLengthMode(mode, viewportSize) / 100;
}
case LengthTypeEMS:
return convertValueFromEMSToUserUnits(value);
@@ -132,7 +151,9 @@ float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod
FloatSize viewportSize;
if (!determineViewport(viewportSize))
return 0;
- return convertValueFromUserUnitsToPercentage(value * 100, mode, viewportSize);
+ // LengthTypePercentage is represented with 100% = 100.0.
+ // Good for accuracy but could eventually be changed.
+ return value * 100 / dimensionForLengthMode(mode, viewportSize);
}
case LengthTypeEMS:
return convertValueFromUserUnitsToEMS(value);
@@ -156,35 +177,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, const FloatSize& viewportSize)
-{
- return value / dimensionForLengthMode(mode, viewportSize) * 100;
-}
-
-float SVGLengthContext::convertValueFromPercentageToUserUnits(float value, SVGLengthMode mode, const FloatSize& viewportSize)
-{
- return value * dimensionForLengthMode(mode, viewportSize);
-}
-
-float SVGLengthContext::convertValueFromPercentageToUserUnits(const SVGLength& value, const FloatSize& viewportSize)
-{
- return value.scaleByPercentage(dimensionForLengthMode(value.unitMode(), viewportSize));
-}
-
static inline LayoutStyle* layoutStyleForLengthResolving(const SVGElement* context)
{
if (!context)
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698