Chromium Code Reviews| Index: third_party/WebKit/Source/core/svg/SVGLengthContext.cpp |
| diff --git a/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp b/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp |
| index f553158421f727b1c1c0d0772fdae44da33a1052..81404c2aab8f1c9e8d327086c74c3bf38444bd3c 100644 |
| --- a/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp |
| +++ b/third_party/WebKit/Source/core/svg/SVGLengthContext.cpp |
| @@ -26,6 +26,7 @@ |
| #include "core/css/CSSHelper.h" |
| #include "core/css/CSSPrimitiveValue.h" |
| #include "core/dom/NodeComputedStyle.h" |
| +#include "core/frame/FrameView.h" |
| #include "core/layout/LayoutObject.h" |
| #include "core/style/ComputedStyle.h" |
| #include "core/svg/SVGSVGElement.h" |
| @@ -226,6 +227,12 @@ float SVGLengthContext::convertValueToUserUnits(float value, SVGLengthMode mode, |
| case CSSPrimitiveValue::UnitType::Chs: |
| userUnits = convertValueFromCHSToUserUnits(value); |
| break; |
| + case CSSPrimitiveValue::UnitType::ViewportWidth: |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + userUnits = convertValueFromViewportUnitsToUserUnits(fromUnit, value); |
| + break; |
| default: |
| ASSERT_NOT_REACHED(); |
| break; |
| @@ -273,6 +280,11 @@ float SVGLengthContext::convertValueFromUserUnits(float value, SVGLengthMode mod |
| return value / cssPixelsPerPoint; |
| case CSSPrimitiveValue::UnitType::Picas: |
| return value / cssPixelsPerPica; |
| + case CSSPrimitiveValue::UnitType::ViewportWidth: |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + return convertValueFromUserUnitsToViewportUnits(toUnit, value); |
| default: |
| break; |
| } |
| @@ -329,6 +341,94 @@ float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const |
| return value * ceilf(style->fontMetrics().xHeight() / style->effectiveZoom()); |
| } |
| +static inline float viewportLengthPercent(const float widthOrHeight) |
| +{ |
| + return widthOrHeight / 100; |
| +} |
| + |
| +static inline float viewportMinPercent(const FloatSize& viewportSize) |
| +{ |
| + return std::min(viewportSize.width(), viewportSize.height()) / 100; |
| +} |
| + |
| +static inline float viewportMaxPercent(const FloatSize& viewportSize) |
| +{ |
| + return std::max(viewportSize.width(), viewportSize.height()) / 100; |
| +} |
| + |
| + |
| +float SVGLengthContext::convertValueFromUserUnitsToViewportUnits(CSSPrimitiveValue::UnitType toUnit, float value) const |
| +{ |
| + if (!m_context) |
| + return 0; |
| + |
| + const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
| + if (!style) |
| + return 0; |
| + |
| + const Document& document = m_context->document(); |
| + FrameView* view = document.view(); |
| + if (!view) |
| + return 0; |
| + |
| + FloatSize viewportSize(view->width(), view->height()); |
| + |
| + switch (toUnit) { |
|
fs
2016/01/04 19:40:05
I think this would be slightly if it was using sam
Shanmuga Pandi
2016/01/05 10:04:49
Done.
|
| + case CSSPrimitiveValue::UnitType::ViewportWidth: |
| + return value / viewportLengthPercent(viewportSize.width()) / style->effectiveZoom(); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + return value / viewportLengthPercent(viewportSize.height()) / style->effectiveZoom(); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + return value / viewportMinPercent(viewportSize) / style->effectiveZoom(); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + return value / viewportMaxPercent(viewportSize) / style->effectiveZoom(); |
| + default: |
| + break; |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| +float SVGLengthContext::convertValueFromViewportUnitsToUserUnits(CSSPrimitiveValue::UnitType fromUnit, float value) const |
| +{ |
| + if (!m_context) |
| + return 0; |
| + |
| + const ComputedStyle* style = computedStyleForLengthResolving(m_context); |
| + if (!style) |
| + return 0; |
| + |
| + const Document& document = m_context->document(); |
| + FrameView* view = document.view(); |
| + if (!view) |
| + return 0; |
| + |
| + FloatSize viewportSize(view->width(), view->height()); |
| + |
| + switch (fromUnit) { |
| + case CSSPrimitiveValue::UnitType::ViewportWidth: |
| + return value * viewportLengthPercent(viewportSize.width()) / style->effectiveZoom(); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + return value * viewportLengthPercent(viewportSize.height()) / style->effectiveZoom(); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + return value * viewportMinPercent(viewportSize) / style->effectiveZoom(); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + return value * viewportMaxPercent(viewportSize) / style->effectiveZoom(); |
| + default: |
| + break; |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const |
| { |
| if (!m_context) |