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 12 matching lines...) Expand all Loading... |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 */ | 25 */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 | 28 |
29 #include "core/rendering/svg/RenderSVGEllipse.h" | 29 #include "core/rendering/svg/RenderSVGEllipse.h" |
30 | 30 |
31 #include "core/svg/SVGCircleElement.h" | 31 #include "core/svg/SVGCircleElement.h" |
32 #include "core/svg/SVGEllipseElement.h" | 32 #include "core/svg/SVGEllipseElement.h" |
33 #include "platform/graphics/GraphicsContext.h" | |
34 | 33 |
35 namespace blink { | 34 namespace blink { |
36 | 35 |
37 RenderSVGEllipse::RenderSVGEllipse(SVGGraphicsElement* node) | 36 RenderSVGEllipse::RenderSVGEllipse(SVGGraphicsElement* node) |
38 : RenderSVGShape(node) | 37 : RenderSVGShape(node) |
39 , m_usePathFallback(false) | 38 , m_usePathFallback(false) |
40 { | 39 { |
41 } | 40 } |
42 | 41 |
43 RenderSVGEllipse::~RenderSVGEllipse() | 42 RenderSVGEllipse::~RenderSVGEllipse() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return; | 87 return; |
89 } | 88 } |
90 | 89 |
91 SVGEllipseElement& ellipse = toSVGEllipseElement(*element()); | 90 SVGEllipseElement& ellipse = toSVGEllipseElement(*element()); |
92 | 91 |
93 SVGLengthContext lengthContext(&ellipse); | 92 SVGLengthContext lengthContext(&ellipse); |
94 m_radii = FloatSize(ellipse.rx()->currentValue()->value(lengthContext), elli
pse.ry()->currentValue()->value(lengthContext)); | 93 m_radii = FloatSize(ellipse.rx()->currentValue()->value(lengthContext), elli
pse.ry()->currentValue()->value(lengthContext)); |
95 m_center = FloatPoint(ellipse.cx()->currentValue()->value(lengthContext), el
lipse.cy()->currentValue()->value(lengthContext)); | 94 m_center = FloatPoint(ellipse.cx()->currentValue()->value(lengthContext), el
lipse.cy()->currentValue()->value(lengthContext)); |
96 } | 95 } |
97 | 96 |
98 void RenderSVGEllipse::fillShape(GraphicsContext* context) const | |
99 { | |
100 if (m_usePathFallback) { | |
101 RenderSVGShape::fillShape(context); | |
102 return; | |
103 } | |
104 context->fillEllipse(m_fillBoundingBox); | |
105 } | |
106 | |
107 void RenderSVGEllipse::strokeShape(GraphicsContext* context) const | |
108 { | |
109 if (!style()->svgStyle().hasVisibleStroke()) | |
110 return; | |
111 if (m_usePathFallback) { | |
112 RenderSVGShape::strokeShape(context); | |
113 return; | |
114 } | |
115 context->strokeEllipse(m_fillBoundingBox); | |
116 } | |
117 | |
118 bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point) | 97 bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point) |
119 { | 98 { |
120 // The optimized contains code below does not support non-smooth strokes so
we need | 99 // The optimized contains code below does not support non-smooth strokes so
we need |
121 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas
es. | 100 // to fall back to RenderSVGShape::shapeDependentStrokeContains in these cas
es. |
122 if (m_usePathFallback || !hasSmoothStroke()) { | 101 if (m_usePathFallback || !hasSmoothStroke()) { |
123 if (!hasPath()) | 102 if (!hasPath()) |
124 RenderSVGShape::updateShapeFromElement(); | 103 RenderSVGShape::updateShapeFromElement(); |
125 return RenderSVGShape::shapeDependentStrokeContains(point); | 104 return RenderSVGShape::shapeDependentStrokeContains(point); |
126 } | 105 } |
127 | 106 |
(...skipping 20 matching lines...) Expand all Loading... |
148 FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - poin
t.y()); | 127 FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y() - poin
t.y()); |
149 | 128 |
150 // This works by checking if the point satisfies the ellipse equation. | 129 // This works by checking if the point satisfies the ellipse equation. |
151 // (x/rX)^2 + (y/rY)^2 <= 1 | 130 // (x/rX)^2 + (y/rY)^2 <= 1 |
152 float xrX = center.x() / m_radii.width(); | 131 float xrX = center.x() / m_radii.width(); |
153 float yrY = center.y() / m_radii.height(); | 132 float yrY = center.y() / m_radii.height(); |
154 return xrX * xrX + yrY * yrY <= 1.0; | 133 return xrX * xrX + yrY * yrY <= 1.0; |
155 } | 134 } |
156 | 135 |
157 } | 136 } |
OLD | NEW |