Index: Source/core/layout/svg/LayoutSVGPath.cpp |
diff --git a/Source/core/layout/svg/LayoutSVGPath.cpp b/Source/core/layout/svg/LayoutSVGPath.cpp |
index 85ea5a85b2df52b05536d168bc94521cd4733453..82ad61dc58b2d52738cb9705f215bbb0389bb24a 100644 |
--- a/Source/core/layout/svg/LayoutSVGPath.cpp |
+++ b/Source/core/layout/svg/LayoutSVGPath.cpp |
@@ -35,6 +35,8 @@ |
#include "core/layout/svg/SVGSubpathData.h" |
#include "core/svg/SVGGraphicsElement.h" |
+#include <cmath> |
fs
2015/03/31 14:53:59
(I think it's pretty common to just pull in wtf/Ma
|
+ |
namespace blink { |
LayoutSVGPath::LayoutSVGPath(SVGGraphicsElement* node) |
@@ -55,6 +57,40 @@ void LayoutSVGPath::updateShapeFromElement() |
m_strokeBoundingBox = calculateUpdatedStrokeBoundingBox(); |
} |
+FloatRect LayoutSVGPath::hitTestStrokeBoundingBox() const |
+{ |
+ const SVGLayoutStyle& svgStyle = style()->svgStyle(); |
+ if (svgStyle.hasStroke()) |
+ return m_strokeBoundingBox; |
+ |
+ FloatRect result = m_fillBoundingBox; |
+ const float strokeWidth = this->strokeWidth(); |
+ |
+ if (svgStyle.joinStyle() == MiterJoin) { |
fs
2015/03/31 14:54:00
Could you pull this out into a helper?
http://dev
|
+ // We need to consider the miterlimit, because the would-be stroke |
+ // bounding box could extend outward quite far at a sharp angle along |
+ // the path. |
+ // |
+ // Per http://www.w3.org/TR/SVG/painting.html#StrokeMiterlimitProperty |
+ // the maximum miterLength is: |
+ // stroke-width * miterlimit |
+ // Inflate the result by the maximum of that amount and half the |
+ // stroke-width. |
+ // |
+ // Note that because the miterLength is the distance between the outer |
+ // tip and the inner corner of the miter, this technically overshoots |
+ // a bit. |
+ result.inflate(std::max(strokeWidth * svgStyle.strokeMiterLimit(), strokeWidth / 2)); |
+ } else { |
+ result.inflate(strokeWidth / 2); |
+ } |
+ |
+ for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) |
+ result.unite(zeroLengthSubpathRect(m_zeroLengthLinecapLocations[i], strokeWidth)); |
+ |
+ return result; |
+} |
+ |
FloatRect LayoutSVGPath::calculateUpdatedStrokeBoundingBox() const |
{ |
FloatRect strokeBoundingBox = m_strokeBoundingBox; |
@@ -78,9 +114,9 @@ bool LayoutSVGPath::shapeDependentStrokeContains(const FloatPoint& point) |
return true; |
const SVGLayoutStyle& svgStyle = style()->svgStyle(); |
+ const float strokeWidth = this->strokeWidth(); |
for (size_t i = 0; i < m_zeroLengthLinecapLocations.size(); ++i) { |
ASSERT(svgStyle.hasStroke()); |
- float strokeWidth = this->strokeWidth(); |
if (svgStyle.capStyle() == SquareCap) { |
if (zeroLengthSubpathRect(m_zeroLengthLinecapLocations[i], strokeWidth).contains(point)) |
return true; |