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

Side by Side Diff: Source/core/rendering/svg/RenderSVGRect.cpp

Issue 810343003: Fix pointer-events:all when stroke="none" (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove braces from single-line if statement Created 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 University of Szeged 2 * Copyright (C) 2011 University of Szeged
3 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org> 3 * Copyright (C) 2011 Renata Hodovan <reni@webkit.org>
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 12 matching lines...) Expand all
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "config.h" 28 #include "config.h"
29 29
30 #include "core/rendering/svg/RenderSVGRect.h" 30 #include "core/rendering/svg/RenderSVGRect.h"
31 #include "core/svg/SVGRectElement.h" 31 #include "core/svg/SVGRectElement.h"
32 32
33 #include <cmath>
34
33 namespace blink { 35 namespace blink {
34 36
35 RenderSVGRect::RenderSVGRect(SVGRectElement* node) 37 RenderSVGRect::RenderSVGRect(SVGRectElement* node)
36 : RenderSVGShape(node) 38 : RenderSVGShape(node)
37 , m_usePathFallback(false) 39 , m_usePathFallback(false)
38 { 40 {
39 } 41 }
40 42
41 RenderSVGRect::~RenderSVGRect() 43 RenderSVGRect::~RenderSVGRect()
42 { 44 {
43 } 45 }
44 46
45 void RenderSVGRect::updateShapeFromElement() 47 void RenderSVGRect::updateShapeFromElement()
46 { 48 {
47 // Before creating a new object we need to clear the cached bounding box 49 // Before creating a new object we need to clear the cached bounding box
48 // to avoid using garbage. 50 // to avoid using garbage.
49 m_fillBoundingBox = FloatRect(); 51 m_fillBoundingBox = FloatRect();
50 m_innerStrokeRect = FloatRect(); 52 m_strokeBoundingBox = FloatRect();
51 m_outerStrokeRect = FloatRect();
52 m_usePathFallback = false; 53 m_usePathFallback = false;
53 SVGRectElement* rect = toSVGRectElement(element()); 54 SVGRectElement* rect = toSVGRectElement(element());
54 ASSERT(rect); 55 ASSERT(rect);
55 56
56 SVGLengthContext lengthContext(rect); 57 SVGLengthContext lengthContext(rect);
57 FloatSize boundingBoxSize(rect->width()->currentValue()->value(lengthContext ), rect->height()->currentValue()->value(lengthContext)); 58 FloatSize boundingBoxSize(rect->width()->currentValue()->value(lengthContext ), rect->height()->currentValue()->value(lengthContext));
58 59
59 // Spec: "A negative value is an error." 60 // Spec: "A negative value is an error."
60 if (boundingBoxSize.width() < 0 || boundingBoxSize.height() < 0) 61 if (boundingBoxSize.width() < 0 || boundingBoxSize.height() < 0)
61 return; 62 return;
62 63
63 // Spec: "A value of zero disables rendering of the element." 64 // Spec: "A value of zero disables rendering of the element."
64 if (!boundingBoxSize.isEmpty()) { 65 if (!boundingBoxSize.isEmpty()) {
65 // Fallback to RenderSVGShape and path-based hit detection if the rect 66 // Fallback to RenderSVGShape and path-based hit detection if the rect
66 // has rounded corners or a non-scaling or non-simple stroke. 67 // has rounded corners or a non-scaling or non-simple stroke.
67 if (rect->rx()->currentValue()->value(lengthContext) > 0 68 if (rect->rx()->currentValue()->value(lengthContext) > 0
68 || rect->ry()->currentValue()->value(lengthContext) > 0 69 || rect->ry()->currentValue()->value(lengthContext) > 0
69 || hasNonScalingStroke() 70 || hasNonScalingStroke()
70 || !definitelyHasSimpleStroke()) { 71 || !definitelyHasSimpleStroke()) {
71 RenderSVGShape::updateShapeFromElement(); 72 RenderSVGShape::updateShapeFromElement();
72 m_usePathFallback = true; 73 m_usePathFallback = true;
73 return; 74 return;
74 } 75 }
75 } 76 }
76 77
77 m_fillBoundingBox = FloatRect(FloatPoint(rect->x()->currentValue()->value(le ngthContext), rect->y()->currentValue()->value(lengthContext)), boundingBoxSize) ; 78 m_fillBoundingBox = FloatRect(FloatPoint(rect->x()->currentValue()->value(le ngthContext), rect->y()->currentValue()->value(lengthContext)), boundingBoxSize) ;
78 79 m_strokeBoundingBox = m_fillBoundingBox;
79 // To decide if the stroke contains a point we create two rects which repres ent the inner and 80 m_strokeBoundingBox.inflate(strokeWidth() / 2);
80 // the outer stroke borders. A stroke contains the point, if the point is be tween them.
81 m_innerStrokeRect = m_fillBoundingBox;
82 m_outerStrokeRect = m_fillBoundingBox;
83
84 if (style()->svgStyle().hasStroke()) {
85 float strokeWidth = this->strokeWidth();
86 m_innerStrokeRect.inflate(-strokeWidth / 2);
87 m_outerStrokeRect.inflate(strokeWidth / 2);
88 }
89
90 m_strokeBoundingBox = m_outerStrokeRect;
91 } 81 }
92 82
93 bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point) 83 bool RenderSVGRect::shapeDependentStrokeContains(const FloatPoint& point)
94 { 84 {
95 // The optimized code below does not support non-simple strokes so we need 85 // The optimized code below does not support non-simple strokes so we need
96 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas es. 86 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas es.
97 if (m_usePathFallback || !definitelyHasSimpleStroke()) { 87 if (m_usePathFallback || !definitelyHasSimpleStroke()) {
98 if (!hasPath()) 88 if (!hasPath())
99 RenderSVGShape::updateShapeFromElement(); 89 RenderSVGShape::updateShapeFromElement();
100 return RenderSVGShape::shapeDependentStrokeContains(point); 90 return RenderSVGShape::shapeDependentStrokeContains(point);
101 } 91 }
102 92
103 return m_outerStrokeRect.contains(point, FloatRect::InsideOrOnStroke) && !m_ innerStrokeRect.contains(point, FloatRect::InsideButNotOnStroke); 93 const float halfStrokeWidth = strokeWidth() / 2;
94 const float halfWidth = m_fillBoundingBox.width() / 2;
95 const float halfHeight = m_fillBoundingBox.height() / 2;
96
97 const FloatPoint fillBoundingBoxCenter = FloatPoint(m_fillBoundingBox.x() + halfWidth, m_fillBoundingBox.y() + halfHeight);
98 const float absDeltaX = std::abs(point.x() - fillBoundingBoxCenter.x());
99 const float absDeltaY = std::abs(point.y() - fillBoundingBoxCenter.y());
100
101 if (!(absDeltaX <= halfWidth + halfStrokeWidth && absDeltaY <= halfHeight + halfStrokeWidth))
102 return false;
103
104 return (halfWidth - halfStrokeWidth <= absDeltaX)
105 || (halfHeight - halfStrokeWidth <= absDeltaY);
104 } 106 }
105 107
106 bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi ndRule fillRule) const 108 bool RenderSVGRect::shapeDependentFillContains(const FloatPoint& point, const Wi ndRule fillRule) const
107 { 109 {
108 if (m_usePathFallback) 110 if (m_usePathFallback)
109 return RenderSVGShape::shapeDependentFillContains(point, fillRule); 111 return RenderSVGShape::shapeDependentFillContains(point, fillRule);
110 return m_fillBoundingBox.contains(point.x(), point.y()); 112 return m_fillBoundingBox.contains(point.x(), point.y());
111 } 113 }
112 114
113 // Returns true if the stroke is continuous and definitely uses miter joins. 115 // Returns true if the stroke is continuous and definitely uses miter joins.
(...skipping 16 matching lines...) Expand all
130 // An approximation of sqrt(2) is used here because at certain precise 132 // An approximation of sqrt(2) is used here because at certain precise
131 // miterlimits, the join style used might not be correct (e.g. a miterlimit 133 // miterlimits, the join style used might not be correct (e.g. a miterlimit
132 // of 1.4142135 should result in bevel joins, but may be drawn using miter 134 // of 1.4142135 should result in bevel joins, but may be drawn using miter
133 // joins). 135 // joins).
134 return svgStyle.strokeDashArray()->isEmpty() 136 return svgStyle.strokeDashArray()->isEmpty()
135 && svgStyle.joinStyle() == MiterJoin 137 && svgStyle.joinStyle() == MiterJoin
136 && svgStyle.strokeMiterLimit() >= 1.5; 138 && svgStyle.strokeMiterLimit() >= 1.5;
137 } 139 }
138 140
139 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698