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

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

Issue 1544543003: Adding support of viewport units to SVG (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Align with review comments Created 4 years, 11 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 | « third_party/WebKit/Source/core/svg/SVGLength.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..d68166f469c9ac18014fdfbd6139b495fa55a7f4 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,57 @@ static float convertValueFromEMSToUserUnits(const ComputedStyle* style, float va
return value * style->specifiedFontSize();
}
+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;
+}
+
+static inline float dimensionForViewportUnit(const SVGElement* context, CSSPrimitiveValue::UnitType unit)
+{
+ if (!context)
+ return 0;
+
+ const Document& document = context->document();
+ FrameView* view = document.view();
+ if (!view)
+ return 0;
+
+ const ComputedStyle* style = computedStyleForLengthResolving(context);
+ if (!style)
+ return 0;
+
+ FloatSize viewportSize(view->width(), view->height());
+
+ switch (unit) {
+ case CSSPrimitiveValue::UnitType::ViewportWidth:
+ return viewportLengthPercent(viewportSize.width()) / style->effectiveZoom();
+
+ case CSSPrimitiveValue::UnitType::ViewportHeight:
+ return viewportLengthPercent(viewportSize.height()) / style->effectiveZoom();
+
+ case CSSPrimitiveValue::UnitType::ViewportMin:
+ return viewportMinPercent(viewportSize) / style->effectiveZoom();
+
+ case CSSPrimitiveValue::UnitType::ViewportMax:
+ return viewportMaxPercent(viewportSize) / style->effectiveZoom();
+ default:
+ break;
+ }
+
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
SVGLengthContext::SVGLengthContext(const SVGElement* context)
: m_context(context)
{
@@ -226,6 +278,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 = value * dimensionForViewportUnit(m_context, fromUnit);
+ break;
default:
ASSERT_NOT_REACHED();
break;
@@ -273,6 +331,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 value / dimensionForViewportUnit(m_context, toUnit);
default:
break;
}
« no previous file with comments | « third_party/WebKit/Source/core/svg/SVGLength.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698