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.
22 #include "core/svg/SVGEllipseElement.h"
24 #include "core/layout/svg/LayoutSVGEllipse.h"
25 #include "core/svg/SVGLength.h"
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
)
48 SVGGeometryElement::trace(visitor
);
51 DEFINE_NODE_FACTORY(SVGEllipseElement
)
53 Path
SVGEllipseElement::asPath() const
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
);
65 float ry
= lengthContext
.valueForLength(svgStyle
.ry(), style
, SVGLengthMode::Height
);
71 path
.addEllipse(FloatRect(
72 lengthContext
.valueForLength(svgStyle
.cx(), style
, SVGLengthMode::Width
) - rx
,
73 lengthContext
.valueForLength(svgStyle
.cy(), style
, SVGLengthMode::Height
) - ry
,
79 bool SVGEllipseElement::isPresentationAttribute(const QualifiedName
& attrName
) const
81 if (attrName
== SVGNames::cxAttr
|| attrName
== SVGNames::cyAttr
82 || attrName
== SVGNames::rxAttr
|| attrName
== SVGNames::ryAttr
)
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
)
92 return SVGGeometryElement::isPresentationAttributeWithSVGDOM(attrName
);
95 void SVGEllipseElement::collectStyleForPresentationAttribute(const QualifiedName
& name
, const AtomicString
& value
, MutableStylePropertySet
* style
)
97 RefPtrWillBeRawPtr
<SVGAnimatedPropertyBase
> property
= propertyFromAttribute(name
);
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());
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());
126 layoutObject
->setNeedsShapeUpdate();
127 markForLayoutAndParentResourceInvalidation(layoutObject
);
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);