Index: Source/core/svg/SVGLengthContext.cpp |
diff --git a/Source/core/svg/SVGLengthContext.cpp b/Source/core/svg/SVGLengthContext.cpp |
index f9cc9e6e5f310e01e1801dfa7ec833d84b7a4e76..dda2635eee1712e20a160372ed55d446d46f633c 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/NodeLayoutStyle.h" |
#include "core/layout/LayoutObject.h" |
#include "core/layout/style/LayoutStyle.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,63 @@ float SVGLengthContext::convertValueFromEMSToUserUnits(float value) const |
return value * style->specifiedFontSize(); |
} |
+float SVGLengthContext::convertValueFromUserUnitsToREMS(float value) const |
+{ |
+ if (!m_context) |
+ return 0; |
+ |
+ const LayoutStyle* style = 0; |
+ const ContainerNode* currentContext = m_context; |
+ |
+ do { |
+ if (currentContext->layoutObject()) { |
Erik Dahlström (inactive)
2015/04/02 07:58:41
Do we really need this loop? Why not just fetch th
Shanmuga Pandi
2015/04/02 13:06:51
Done.
|
+ const Document& document = currentContext->layoutObject()->document(); |
+ Node* documentElement = document.documentElement(); |
+ const LayoutStyle* documentStyle = document.layoutStyle(); |
+ style = documentElement && !currentContext->layoutObject()->isDocumentElement() ? documentElement->layoutStyle() : documentStyle; |
+ if (!style) |
+ style = documentStyle; |
+ break; |
+ } |
+ currentContext = currentContext->parentNode(); |
+ } while (currentContext); |
+ |
+ 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 LayoutStyle* style = 0; |
+ const ContainerNode* currentContext = m_context; |
+ |
+ do { |
+ if (currentContext->layoutObject()) { |
+ const Document& document = currentContext->layoutObject()->document(); |
+ Node* documentElement = document.documentElement(); |
+ const LayoutStyle* documentStyle = document.layoutStyle(); |
+ style = documentElement && !currentContext->layoutObject()->isDocumentElement() ? documentElement->layoutStyle() : documentStyle; |
+ if (!style) |
+ style = documentStyle; |
+ break; |
+ } |
+ currentContext = currentContext->parentNode(); |
+ } while (currentContext); |
+ |
+ if (!style) |
+ return 0; |
+ return value * style->specifiedFontSize(); |
+} |
+ |
float SVGLengthContext::convertValueFromUserUnitsToEXS(float value) const |
{ |
const LayoutStyle* style = layoutStyleForLengthResolving(m_context); |