| 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 |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF SZEGED OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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/layout/svg/LayoutSVGEllipse.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 | 33 |
| 34 #include <cmath> | 34 #include <cmath> |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 RenderSVGEllipse::RenderSVGEllipse(SVGGraphicsElement* node) | 38 LayoutSVGEllipse::LayoutSVGEllipse(SVGGraphicsElement* node) |
| 39 : RenderSVGShape(node) | 39 : LayoutSVGShape(node) |
| 40 , m_usePathFallback(false) | 40 , m_usePathFallback(false) |
| 41 { | 41 { |
| 42 } | 42 } |
| 43 | 43 |
| 44 RenderSVGEllipse::~RenderSVGEllipse() | 44 LayoutSVGEllipse::~LayoutSVGEllipse() |
| 45 { | 45 { |
| 46 } | 46 } |
| 47 | 47 |
| 48 void RenderSVGEllipse::updateShapeFromElement() | 48 void LayoutSVGEllipse::updateShapeFromElement() |
| 49 { | 49 { |
| 50 // Before creating a new object we need to clear the cached bounding box | 50 // Before creating a new object we need to clear the cached bounding box |
| 51 // to avoid using garbage. | 51 // to avoid using garbage. |
| 52 m_fillBoundingBox = FloatRect(); | 52 m_fillBoundingBox = FloatRect(); |
| 53 m_strokeBoundingBox = FloatRect(); | 53 m_strokeBoundingBox = FloatRect(); |
| 54 m_center = FloatPoint(); | 54 m_center = FloatPoint(); |
| 55 m_radii = FloatSize(); | 55 m_radii = FloatSize(); |
| 56 m_usePathFallback = false; | 56 m_usePathFallback = false; |
| 57 | 57 |
| 58 calculateRadiiAndCenter(); | 58 calculateRadiiAndCenter(); |
| 59 | 59 |
| 60 // Spec: "A negative value is an error. A value of zero disables rendering o
f the element." | 60 // Spec: "A negative value is an error. A value of zero disables rendering o
f the element." |
| 61 if (m_radii.width() < 0 || m_radii.height() < 0) | 61 if (m_radii.width() < 0 || m_radii.height() < 0) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 if (!m_radii.isEmpty()) { | 64 if (!m_radii.isEmpty()) { |
| 65 // Fall back to RenderSVGShape and path-based hit detection if the ellip
se | 65 // Fall back to LayoutSVGShape and path-based hit detection if the ellip
se |
| 66 // has a non-scaling or discontinuous stroke. | 66 // has a non-scaling or discontinuous stroke. |
| 67 if (hasNonScalingStroke() || !hasContinuousStroke()) { | 67 if (hasNonScalingStroke() || !hasContinuousStroke()) { |
| 68 RenderSVGShape::updateShapeFromElement(); | 68 LayoutSVGShape::updateShapeFromElement(); |
| 69 m_usePathFallback = true; | 69 m_usePathFallback = true; |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 clearPath(); | 74 clearPath(); |
| 75 | 75 |
| 76 m_fillBoundingBox = FloatRect(m_center.x() - m_radii.width(), m_center.y() -
m_radii.height(), 2 * m_radii.width(), 2 * m_radii.height()); | 76 m_fillBoundingBox = FloatRect(m_center.x() - m_radii.width(), m_center.y() -
m_radii.height(), 2 * m_radii.width(), 2 * m_radii.height()); |
| 77 m_strokeBoundingBox = m_fillBoundingBox; | 77 m_strokeBoundingBox = m_fillBoundingBox; |
| 78 if (style()->svgStyle().hasStroke()) | 78 if (style()->svgStyle().hasStroke()) |
| 79 m_strokeBoundingBox.inflate(strokeWidth() / 2); | 79 m_strokeBoundingBox.inflate(strokeWidth() / 2); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void RenderSVGEllipse::calculateRadiiAndCenter() | 82 void LayoutSVGEllipse::calculateRadiiAndCenter() |
| 83 { | 83 { |
| 84 ASSERT(element()); | 84 ASSERT(element()); |
| 85 if (isSVGCircleElement(*element())) { | 85 if (isSVGCircleElement(*element())) { |
| 86 SVGCircleElement& circle = toSVGCircleElement(*element()); | 86 SVGCircleElement& circle = toSVGCircleElement(*element()); |
| 87 | 87 |
| 88 SVGLengthContext lengthContext(&circle); | 88 SVGLengthContext lengthContext(&circle); |
| 89 float radius = circle.r()->currentValue()->value(lengthContext); | 89 float radius = circle.r()->currentValue()->value(lengthContext); |
| 90 m_radii = FloatSize(radius, radius); | 90 m_radii = FloatSize(radius, radius); |
| 91 m_center = FloatPoint(circle.cx()->currentValue()->value(lengthContext),
circle.cy()->currentValue()->value(lengthContext)); | 91 m_center = FloatPoint(circle.cx()->currentValue()->value(lengthContext),
circle.cy()->currentValue()->value(lengthContext)); |
| 92 return; | 92 return; |
| 93 } | 93 } |
| 94 | 94 |
| 95 SVGEllipseElement& ellipse = toSVGEllipseElement(*element()); | 95 SVGEllipseElement& ellipse = toSVGEllipseElement(*element()); |
| 96 | 96 |
| 97 SVGLengthContext lengthContext(&ellipse); | 97 SVGLengthContext lengthContext(&ellipse); |
| 98 m_radii = FloatSize(ellipse.rx()->currentValue()->value(lengthContext), elli
pse.ry()->currentValue()->value(lengthContext)); | 98 m_radii = FloatSize(ellipse.rx()->currentValue()->value(lengthContext), elli
pse.ry()->currentValue()->value(lengthContext)); |
| 99 m_center = FloatPoint(ellipse.cx()->currentValue()->value(lengthContext), el
lipse.cy()->currentValue()->value(lengthContext)); | 99 m_center = FloatPoint(ellipse.cx()->currentValue()->value(lengthContext), el
lipse.cy()->currentValue()->value(lengthContext)); |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool RenderSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point) | 102 bool LayoutSVGEllipse::shapeDependentStrokeContains(const FloatPoint& point) |
| 103 { | 103 { |
| 104 // The optimized check below for circles does not support non-scaling or | 104 // The optimized check below for circles does not support non-scaling or |
| 105 // discontinuous strokes. | 105 // discontinuous strokes. |
| 106 if (m_usePathFallback | 106 if (m_usePathFallback |
| 107 || !hasContinuousStroke() | 107 || !hasContinuousStroke() |
| 108 || m_radii.width() != m_radii.height()) { | 108 || m_radii.width() != m_radii.height()) { |
| 109 if (!hasPath()) | 109 if (!hasPath()) |
| 110 createPath(); | 110 createPath(); |
| 111 return RenderSVGShape::shapeDependentStrokeContains(point); | 111 return LayoutSVGShape::shapeDependentStrokeContains(point); |
| 112 } | 112 } |
| 113 | 113 |
| 114 const FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y()
- point.y()); | 114 const FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y()
- point.y()); |
| 115 const float halfStrokeWidth = strokeWidth() / 2; | 115 const float halfStrokeWidth = strokeWidth() / 2; |
| 116 const float r = m_radii.width(); | 116 const float r = m_radii.width(); |
| 117 return std::abs(center.length() - r) <= halfStrokeWidth; | 117 return std::abs(center.length() - r) <= halfStrokeWidth; |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool RenderSVGEllipse::shapeDependentFillContains(const FloatPoint& point, const
WindRule fillRule) const | 120 bool LayoutSVGEllipse::shapeDependentFillContains(const FloatPoint& point, const
WindRule fillRule) const |
| 121 { | 121 { |
| 122 const FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y()
- point.y()); | 122 const FloatPoint center = FloatPoint(m_center.x() - point.x(), m_center.y()
- point.y()); |
| 123 | 123 |
| 124 // This works by checking if the point satisfies the ellipse equation. | 124 // This works by checking if the point satisfies the ellipse equation. |
| 125 // (x/rX)^2 + (y/rY)^2 <= 1 | 125 // (x/rX)^2 + (y/rY)^2 <= 1 |
| 126 const float xrX = center.x() / m_radii.width(); | 126 const float xrX = center.x() / m_radii.width(); |
| 127 const float yrY = center.y() / m_radii.height(); | 127 const float yrY = center.y() / m_radii.height(); |
| 128 return xrX * xrX + yrY * yrY <= 1.0; | 128 return xrX * xrX + yrY * yrY <= 1.0; |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool RenderSVGEllipse::hasContinuousStroke() const | 131 bool LayoutSVGEllipse::hasContinuousStroke() const |
| 132 { | 132 { |
| 133 const SVGLayoutStyle& svgStyle = style()->svgStyle(); | 133 const SVGLayoutStyle& svgStyle = style()->svgStyle(); |
| 134 return svgStyle.strokeDashArray()->isEmpty(); | 134 return svgStyle.strokeDashArray()->isEmpty(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 } | 137 } |
| OLD | NEW |