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.
24 #include "SVGLineElement.h"
26 #include "Attribute.h"
27 #include "FloatPoint.h"
28 #include "RenderSVGPath.h"
29 #include "RenderSVGResource.h"
30 #include "SVGElementInstance.h"
31 #include "SVGLength.h"
36 // Animated property definitions
37 DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::x1Attr, X1, x1)
38 DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::y1Attr, Y1, y1)
39 DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::x2Attr, X2, x2)
40 DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::y2Attr, Y2, y2)
41 DEFINE_ANIMATED_BOOLEAN(SVGLineElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
43 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGLineElement)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(x1)
45 REGISTER_LOCAL_ANIMATED_PROPERTY(y1)
46 REGISTER_LOCAL_ANIMATED_PROPERTY(x2)
47 REGISTER_LOCAL_ANIMATED_PROPERTY(y2)
48 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
49 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledTransformableElement)
50 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
51 END_REGISTER_ANIMATED_PROPERTIES
53 inline SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document* document)
54 : SVGStyledTransformableElement(tagName, document)
55 , m_x1(LengthModeWidth)
56 , m_y1(LengthModeHeight)
57 , m_x2(LengthModeWidth)
58 , m_y2(LengthModeHeight)
60 ASSERT(hasTagName(SVGNames::lineTag));
61 registerAnimatedPropertiesForSVGLineElement();
64 PassRefPtr<SVGLineElement> SVGLineElement::create(const QualifiedName& tagName, Document* document)
66 return adoptRef(new SVGLineElement(tagName, document));
69 bool SVGLineElement::isSupportedAttribute(const QualifiedName& attrName)
71 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
72 if (supportedAttributes.isEmpty()) {
73 SVGTests::addSupportedAttributes(supportedAttributes);
74 SVGLangSpace::addSupportedAttributes(supportedAttributes);
75 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
76 supportedAttributes.add(SVGNames::x1Attr);
77 supportedAttributes.add(SVGNames::x2Attr);
78 supportedAttributes.add(SVGNames::y1Attr);
79 supportedAttributes.add(SVGNames::y2Attr);
81 return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
84 void SVGLineElement::parseMappedAttribute(Attribute* attr)
86 SVGParsingError parseError = NoError;
88 if (!isSupportedAttribute(attr->name()))
89 SVGStyledTransformableElement::parseMappedAttribute(attr);
90 else if (attr->name() == SVGNames::x1Attr)
91 setX1BaseValue(SVGLength::construct(LengthModeWidth, attr->value(), parseError));
92 else if (attr->name() == SVGNames::y1Attr)
93 setY1BaseValue(SVGLength::construct(LengthModeHeight, attr->value(), parseError));
94 else if (attr->name() == SVGNames::x2Attr)
95 setX2BaseValue(SVGLength::construct(LengthModeWidth, attr->value(), parseError));
96 else if (attr->name() == SVGNames::y2Attr)
97 setY2BaseValue(SVGLength::construct(LengthModeHeight, attr->value(), parseError));
98 else if (SVGTests::parseMappedAttribute(attr)
99 || SVGLangSpace::parseMappedAttribute(attr)
100 || SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
102 ASSERT_NOT_REACHED();
104 reportAttributeParsingError(parseError, attr);
107 void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName)
109 if (!isSupportedAttribute(attrName)) {
110 SVGStyledTransformableElement::svgAttributeChanged(attrName);
114 SVGElementInstance::InvalidationGuard invalidationGuard(this);
116 bool isLengthAttribute = attrName == SVGNames::x1Attr
117 || attrName == SVGNames::y1Attr
118 || attrName == SVGNames::x2Attr
119 || attrName == SVGNames::y2Attr;
121 if (isLengthAttribute)
122 updateRelativeLengthsInformation();
124 if (SVGTests::handleAttributeChange(this, attrName))
127 RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer());
131 if (isLengthAttribute) {
132 renderer->setNeedsShapeUpdate();
133 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
137 if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
138 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
142 ASSERT_NOT_REACHED();
145 bool SVGLineElement::selfHasRelativeLengths() const
147 return x1().isRelative()
150 || y2().isRelative();
155 #endif // ENABLE(SVG)