Chromium Code Reviews| Index: third_party/WebKit/Source/core/layout/svg/LayoutSVGShape.cpp |
| diff --git a/third_party/WebKit/Source/core/layout/svg/LayoutSVGShape.cpp b/third_party/WebKit/Source/core/layout/svg/LayoutSVGShape.cpp |
| index 485dad1fedb51470f1f1e638460decb932f1c2cd..48407740dc8dbb93663ae3ecd3cc4061e9e95e1e 100644 |
| --- a/third_party/WebKit/Source/core/layout/svg/LayoutSVGShape.cpp |
| +++ b/third_party/WebKit/Source/core/layout/svg/LayoutSVGShape.cpp |
| @@ -37,6 +37,7 @@ |
| #include "core/paint/SVGShapePainter.h" |
| #include "core/svg/SVGGeometryElement.h" |
| #include "core/svg/SVGLengthContext.h" |
| +#include "core/svg/SVGPathElement.h" |
| #include "platform/geometry/FloatPoint.h" |
| #include "platform/graphics/StrokeData.h" |
| #include "wtf/MathExtras.h" |
| @@ -64,6 +65,28 @@ void LayoutSVGShape::createPath() |
| m_rareData->m_cachedNonScalingStrokePath.clear(); |
| } |
| +float LayoutSVGShape::dashScaleFactor() const |
| +{ |
| + if (!isSVGPathElement(element())) |
| + return 1; |
| + SVGPathElement& pathElement = toSVGPathElement(*element()); |
| + if (!pathElement.pathLength()->isSpecified()) |
| + return 1; |
| + const SVGComputedStyle& svgStyle = styleRef().svgStyle(); |
| + float authorPathLength = pathElement.pathLength()->currentValue()->value(); |
| + if (authorPathLength < 0 || !svgStyle.strokeDashArray()->size()) |
|
f(malita)
2016/02/02 13:44:00
Is pathLength applicable beyond dashing? I'm assum
fs
2016/02/02 13:47:23
It applies to <textPath> too I think, so I guess t
|
| + return 1; |
| + if (!authorPathLength) |
| + return 0; |
| + // Since we know this is a <path> element, we also know the source of the |
| + // path - the 'd' presentation attribute. Since the StylePath already |
| + // caches the computed path length for use, use that here directly. |
| + float computedPathLength = svgStyle.d()->length(); |
| + if (!computedPathLength) |
| + return 1; |
| + return computedPathLength / authorPathLength; |
| +} |
| + |
| void LayoutSVGShape::updateShapeFromElement() |
| { |
| createPath(); |
| @@ -91,7 +114,7 @@ bool LayoutSVGShape::shapeDependentStrokeContains(const FloatPoint& point) |
| { |
| ASSERT(m_path); |
| StrokeData strokeData; |
| - SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this); |
| + SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this, dashScaleFactor()); |
| if (hasNonScalingStroke()) { |
| AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
| @@ -257,7 +280,7 @@ FloatRect LayoutSVGShape::calculateStrokeBoundingBox() const |
| if (style()->svgStyle().hasStroke()) { |
| StrokeData strokeData; |
| - SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this); |
| + SVGLayoutSupport::applyStrokeStyleToStrokeData(strokeData, styleRef(), *this, dashScaleFactor()); |
| if (hasNonScalingStroke()) { |
| AffineTransform nonScalingTransform = nonScalingStrokeTransform(); |
| if (nonScalingTransform.isInvertible()) { |