Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / svg / SVGEllipseElement.cpp
blob7016497693190ffd77a927c947af6c87fc12a309
1 /*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "config.h"
22 #include "core/svg/SVGEllipseElement.h"
24 #include "core/layout/svg/LayoutSVGEllipse.h"
25 #include "core/svg/SVGLength.h"
27 namespace blink {
29 inline SVGEllipseElement::SVGEllipseElement(Document& document)
30 : SVGGeometryElement(SVGNames::ellipseTag, document)
31 , m_cx(SVGAnimatedLength::create(this, SVGNames::cxAttr, SVGLength::create(SVGLengthMode::Width), AllowNegativeLengths))
32 , m_cy(SVGAnimatedLength::create(this, SVGNames::cyAttr, SVGLength::create(SVGLengthMode::Height), AllowNegativeLengths))
33 , m_rx(SVGAnimatedLength::create(this, SVGNames::rxAttr, SVGLength::create(SVGLengthMode::Width), ForbidNegativeLengths))
34 , m_ry(SVGAnimatedLength::create(this, SVGNames::ryAttr, SVGLength::create(SVGLengthMode::Height), ForbidNegativeLengths))
36 addToPropertyMap(m_cx);
37 addToPropertyMap(m_cy);
38 addToPropertyMap(m_rx);
39 addToPropertyMap(m_ry);
42 DEFINE_TRACE(SVGEllipseElement)
44 visitor->trace(m_cx);
45 visitor->trace(m_cy);
46 visitor->trace(m_rx);
47 visitor->trace(m_ry);
48 SVGGeometryElement::trace(visitor);
51 DEFINE_NODE_FACTORY(SVGEllipseElement)
53 Path SVGEllipseElement::asPath() const
55 Path path;
57 SVGLengthContext lengthContext(this);
58 ASSERT(layoutObject());
59 const ComputedStyle& style = layoutObject()->styleRef();
60 const SVGComputedStyle& svgStyle = style.svgStyle();
62 float rx = lengthContext.valueForLength(svgStyle.rx(), style, SVGLengthMode::Width);
63 if (rx < 0)
64 return path;
65 float ry = lengthContext.valueForLength(svgStyle.ry(), style, SVGLengthMode::Height);
66 if (ry < 0)
67 return path;
68 if (!rx && !ry)
69 return path;
71 path.addEllipse(FloatRect(
72 lengthContext.valueForLength(svgStyle.cx(), style, SVGLengthMode::Width) - rx,
73 lengthContext.valueForLength(svgStyle.cy(), style, SVGLengthMode::Height) - ry,
74 rx * 2, ry * 2));
76 return path;
79 bool SVGEllipseElement::isPresentationAttribute(const QualifiedName& attrName) const
81 if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr
82 || attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr)
83 return true;
84 return SVGGeometryElement::isPresentationAttribute(attrName);
87 bool SVGEllipseElement::isPresentationAttributeWithSVGDOM(const QualifiedName& attrName) const
89 if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr
90 || attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr)
91 return true;
92 return SVGGeometryElement::isPresentationAttributeWithSVGDOM(attrName);
95 void SVGEllipseElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStylePropertySet* style)
97 RefPtrWillBeRawPtr<SVGAnimatedPropertyBase> property = propertyFromAttribute(name);
98 if (property == m_cx)
99 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyCx, *m_cx->currentValue());
100 else if (property == m_cy)
101 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyCy, *m_cy->currentValue());
102 else if (property == m_rx)
103 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyRx, *m_rx->currentValue());
104 else if (property == m_ry)
105 addSVGLengthPropertyToPresentationAttributeStyle(style, CSSPropertyRy, *m_ry->currentValue());
106 else
107 SVGGeometryElement::collectStyleForPresentationAttribute(name, value, style);
111 void SVGEllipseElement::svgAttributeChanged(const QualifiedName& attrName)
113 if (attrName == SVGNames::cxAttr || attrName == SVGNames::cyAttr
114 || attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr) {
115 SVGElement::InvalidationGuard invalidationGuard(this);
117 invalidateSVGPresentationAttributeStyle();
118 setNeedsStyleRecalc(LocalStyleChange,
119 StyleChangeReasonForTracing::fromAttribute(attrName));
120 updateRelativeLengthsInformation();
122 LayoutSVGShape* layoutObject = toLayoutSVGShape(this->layoutObject());
123 if (!layoutObject)
124 return;
126 layoutObject->setNeedsShapeUpdate();
127 markForLayoutAndParentResourceInvalidation(layoutObject);
128 return;
131 SVGGeometryElement::svgAttributeChanged(attrName);
134 bool SVGEllipseElement::selfHasRelativeLengths() const
136 return m_cx->currentValue()->isRelative()
137 || m_cy->currentValue()->isRelative()
138 || m_rx->currentValue()->isRelative()
139 || m_ry->currentValue()->isRelative();
142 LayoutObject* SVGEllipseElement::createLayoutObject(const ComputedStyle&)
144 return new LayoutSVGEllipse(this);
147 } // namespace blink