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..22b768839f3dbc38612b45138d2df0a4bdb956c8 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" |
| @@ -101,6 +102,26 @@ static float convertValueFromEMSToUserUnits(const ComputedStyle* style, float va |
| return value * style->specifiedFontSize(); |
| } |
| +static float viewportWidthPercent(const FloatSize& viewportSize) |
|
rwlbuis
2015/12/22 16:41:49
These 4 helper functions should be inline and shou
Shanmuga Pandi
2015/12/23 09:00:59
Done.
|
| +{ |
| + return viewportSize.width() / 100; |
| +} |
| + |
| +static float viewportHeightPercent(const FloatSize& viewportSize) |
| +{ |
| + return viewportSize.height() / 100; |
| +} |
|
rwlbuis
2015/12/22 16:41:49
You can probably unify above two by passing a dime
Shanmuga Pandi
2015/12/23 09:00:59
Done.
|
| + |
| +static float viewportMinPercent(const FloatSize& viewportSize) |
| +{ |
| + return std::min(viewportSize.width(), viewportSize.height()) / 100; |
| +} |
| + |
| +static float viewportMaxPercent(const FloatSize& viewportSize) |
| +{ |
| + return std::max(viewportSize.width(), viewportSize.height()) / 100; |
| +} |
| + |
| SVGLengthContext::SVGLengthContext(const SVGElement* context) |
| : m_context(context) |
| { |
| @@ -226,6 +247,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 +300,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 +361,70 @@ float SVGLengthContext::convertValueFromEXSToUserUnits(float value) const |
| return value * ceilf(style->fontMetrics().xHeight() / style->effectiveZoom()); |
| } |
| +float SVGLengthContext::convertValueFromUserUnitsToViewportUnits(CSSPrimitiveValue::UnitType toUnit, float value) const |
|
rwlbuis
2015/12/22 16:41:49
Do we need to take zoom into account in these 2 me
Shanmuga Pandi
2015/12/23 09:00:59
Acknowledged.
|
| +{ |
| + if (!m_context) |
| + return 0; |
| + |
| + const Document& document = m_context->document(); |
| + FrameView* view = document.view(); |
| + if (!view) |
| + return 0; |
| + |
| + FloatSize viewportSize(view->width(), view->height()); |
| + |
| + switch (toUnit) { |
| + case CSSPrimitiveValue::UnitType::ViewportWidth: |
| + return value / viewportWidthPercent(viewportSize); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + return value / viewportHeightPercent(viewportSize); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + return value / viewportMinPercent(viewportSize); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + return value / viewportMaxPercent(viewportSize); |
| + default: |
| + break; |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| +float SVGLengthContext::convertValueFromViewportUnitsToUserUnits(CSSPrimitiveValue::UnitType fromUnit, float value) const |
| +{ |
| + if (!m_context) |
| + 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 * viewportWidthPercent(viewportSize); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportHeight: |
| + return value * viewportHeightPercent(viewportSize); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMin: |
| + return value * viewportMinPercent(viewportSize); |
| + |
| + case CSSPrimitiveValue::UnitType::ViewportMax: |
| + return value * viewportMaxPercent(viewportSize); |
| + default: |
| + break; |
| + } |
| + |
| + ASSERT_NOT_REACHED(); |
| + return 0; |
| +} |
| + |
| bool SVGLengthContext::determineViewport(FloatSize& viewportSize) const |
| { |
| if (!m_context) |