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

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

Issue 1031223003: SVG doesn't recognize rem units (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixes builderror Created 5 years, 8 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') | Source/core/svg/SVGLengthTearOff.h » ('j') | 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 7ad5ef687aa6c9a6217cc4b85433be8694561519..3bf1f9a27ad61ef7e4abb842f82c4149cb6ceb4b 100644
--- a/Source/core/svg/SVGLengthContext.cpp
+++ b/Source/core/svg/SVGLengthContext.cpp
@@ -25,6 +25,7 @@
#include "core/css/CSSHelper.h"
#include "core/css/CSSPrimitiveValue.h"
+#include "core/dom/NodeComputedStyle.h"
#include "core/layout/LayoutObject.h"
#include "core/style/ComputedStyle.h"
#include "core/svg/SVGSVGElement.h"
@@ -168,6 +169,9 @@ float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode,
case LengthTypePC:
userUnits = value * cssPixelsPerPica;
break;
+ case LengthTypeREMS:
+ userUnits = convertValueFromREMSToUserUnits(value);
+ break;
default:
ASSERT_NOT_REACHED();
break;
@@ -198,6 +202,8 @@ float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod
return convertValueFromUserUnitsToEMS(value);
case LengthTypeEXS:
return convertValueFromUserUnitsToEXS(value);
+ case LengthTypeREMS:
+ return convertValueFromUserUnitsToREMS(value);
case LengthTypePX:
return value;
case LengthTypeCM:
@@ -254,6 +260,48 @@ float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const
return value * style->specifiedFontSize();
}
+float SVGLengthContext::convertValueFromUserUnitsToREMS(float value) const
+{
+ if (!m_context)
+ return 0;
+
+ const ComputedStyle* style = 0;
+ const Document& document = m_context->document();
+ Node* documentElement = document.documentElement();
+ const ComputedStyle* documentStyle = document.computedStyle();
+ style = documentElement && (static_cast<const Node*>(m_context.get()) != documentElement) ? documentElement->computedStyle() : documentStyle;
+ if (!style)
+ style = documentStyle;
+
+ if (!style)
+ return 0;
+
+ float fontSize = style->specifiedFontSize();
+ if (!fontSize)
+ return 0;
+
+ return value / fontSize;
+}
+
+float SVGLengthContext::convertValueFromREMSToUserUnits(float value) const
+{
+ if (!m_context)
+ return 0;
+
+ const ComputedStyle* style = 0;
+ const Document& document = m_context->document();
+ Node* documentElement = document.documentElement();
+ const ComputedStyle* documentStyle = document.computedStyle();
+ style = documentElement && (static_cast<const Node*>(m_context.get()) != documentElement) ? documentElement->computedStyle() : documentStyle;
+ if (!style)
+ style = documentStyle;
+
+ if (!style)
+ return 0;
+
+ return value * style->specifiedFontSize();
+}
+
float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const
{
const ComputedStyle* style = computedStyleForLengthResolving(m_context);
« no previous file with comments | « Source/core/svg/SVGLengthContext.h ('k') | Source/core/svg/SVGLengthTearOff.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698