OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google, Inc. | 2 * Copyright (C) 2012 Google, Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 m_radii = FloatSize(); | 53 m_radii = FloatSize(); |
54 m_usePathFallback = false; | 54 m_usePathFallback = false; |
55 | 55 |
56 calculateRadiiAndCenter(); | 56 calculateRadiiAndCenter(); |
57 | 57 |
58 // Spec: "A negative value is an error. A value of zero disables rendering o
f the element." | 58 // Spec: "A negative value is an error. A value of zero disables rendering o
f the element." |
59 if (m_radii.width() < 0 || m_radii.height() < 0) | 59 if (m_radii.width() < 0 || m_radii.height() < 0) |
60 return; | 60 return; |
61 | 61 |
62 if (!m_radii.isEmpty()) { | 62 if (!m_radii.isEmpty()) { |
63 // Fallback to RenderSVGShape if shape has a non-scaling stroke. | 63 // Fallback to RenderSVGShape and path-based hit detection if the ellips
e |
64 if (hasNonScalingStroke()) { | 64 // has a non-scaling or discontinuous stroke. |
| 65 if (hasNonScalingStroke() || !hasContinuousStroke()) { |
65 RenderSVGShape::updateShapeFromElement(); | 66 RenderSVGShape::updateShapeFromElement(); |
66 m_usePathFallback = true; | 67 m_usePathFallback = true; |
67 return; | 68 return; |
68 } | 69 } |
69 } | 70 } |
70 | 71 |
71 m_fillBoundingBox = FloatRect(m_center.x() - m_radii.width(), m_center.y() -
m_radii.height(), 2 * m_radii.width(), 2 * m_radii.height()); | 72 m_fillBoundingBox = FloatRect(m_center.x() - m_radii.width(), m_center.y() -
m_radii.height(), 2 * m_radii.width(), 2 * m_radii.height()); |
72 m_strokeBoundingBox = m_fillBoundingBox; | 73 m_strokeBoundingBox = m_fillBoundingBox; |
73 if (style()->svgStyle().hasStroke()) | 74 if (style()->svgStyle().hasStroke()) |
74 m_strokeBoundingBox.inflate(strokeWidth() / 2); | 75 m_strokeBoundingBox.inflate(strokeWidth() / 2); |
(...skipping 14 matching lines...) Expand all Loading... |
89 | 90 |
90 SVGEllipseElement& ellipse = toSVGEllipseElement(*element()); | 91 SVGEllipseElement& ellipse = toSVGEllipseElement(*element()); |
91 | 92 |
92 SVGLengthContext lengthContext(&ellipse); | 93 SVGLengthContext lengthContext(&ellipse); |
93 m_radii = FloatSize(ellipse.rx()->currentValue()->value(lengthContext), elli
pse.ry()->currentValue()->value(lengthContext)); | 94 m_radii = FloatSize(ellipse.rx()->currentValue()->value(lengthContext), elli
pse.ry()->currentValue()->value(lengthContext)); |
94 m_center = FloatPoint(ellipse.cx()->currentValue()->value(lengthContext), el
lipse.cy()->currentValue()->value(lengthContext)); | 95 m_center = FloatPoint(ellipse.cx()->currentValue()->value(lengthContext), el
lipse.cy()->currentValue()->value(lengthContext)); |
95 } | 96 } |
96 | 97 |
97 bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point) | 98 bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point) |
98 { | 99 { |
99 // The optimized contains code below does not support non-smooth strokes so
we need | 100 // The optimized code below does not support discontinuous strokes so we nee
d |
100 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas
es. | 101 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas
es. |
101 if (m_usePathFallback || !hasSmoothStroke()) { | 102 if (m_usePathFallback || !hasContinuousStroke()) { |
102 if (!hasPath()) | 103 if (!hasPath()) |
103 RenderSVGShape::updateShapeFromElement(); | 104 RenderSVGShape::updateShapeFromElement(); |
104 return RenderSVGShape::shapeDependentStrokeContains(point); | 105 return RenderSVGShape::shapeDependentStrokeContains(point); |
105 } | 106 } |
106 | 107 |
107 float halfStrokeWidth = strokeWidth() / 2; | 108 float halfStrokeWidth = strokeWidth() / 2; |
108 FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - poin
t.y()); | 109 FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - poin
t.y()); |
109 | 110 |
110 // This works by checking if the point satisfies the ellipse equation, | 111 // This works by checking if the point satisfies the ellipse equation, |
111 // (x/rX)^2 + (y/rY)^2 <= 1, for the outer but not the inner stroke. | 112 // (x/rX)^2 + (y/rY)^2 <= 1, for the outer but not the inner stroke. |
(...skipping 14 matching lines...) Expand all Loading... |
126 | 127 |
127 FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - poin
t.y()); | 128 FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - poin
t.y()); |
128 | 129 |
129 // This works by checking if the point satisfies the ellipse equation. | 130 // This works by checking if the point satisfies the ellipse equation. |
130 // (x/rX)^2 + (y/rY)^2 <= 1 | 131 // (x/rX)^2 + (y/rY)^2 <= 1 |
131 float xrX = center.x() / m_radii.width(); | 132 float xrX = center.x() / m_radii.width(); |
132 float yrY = center.y() / m_radii.height(); | 133 float yrY = center.y() / m_radii.height(); |
133 return xrX * xrX + yrY * yrY <= 1.0; | 134 return xrX * xrX + yrY * yrY <= 1.0; |
134 } | 135 } |
135 | 136 |
| 137 bool RenderSVGEllipse::hasContinuousStroke() const |
| 138 { |
| 139 const SVGRenderStyle& svgStyle = style()->svgStyle(); |
| 140 return svgStyle.strokeDashArray()->isEmpty(); |
136 } | 141 } |
| 142 |
| 143 } |
OLD | NEW |