tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / svg / SVGLineElement.cpp
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>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include "config.h"
22
23 #if ENABLE(SVG)
24 #include "SVGLineElement.h"
25
26 #include "Attribute.h"
27 #include "FloatPoint.h"
28 #include "RenderSVGPath.h"
29 #include "RenderSVGResource.h"
30 #include "SVGElementInstance.h"
31 #include "SVGLength.h"
32 #include "SVGNames.h"
33
34 namespace WebCore {
35
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)
42
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
52
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)
59 {
60     ASSERT(hasTagName(SVGNames::lineTag));
61     registerAnimatedPropertiesForSVGLineElement();
62 }
63
64 PassRefPtr<SVGLineElement> SVGLineElement::create(const QualifiedName& tagName, Document* document)
65 {
66     return adoptRef(new SVGLineElement(tagName, document));
67 }
68
69 bool SVGLineElement::isSupportedAttribute(const QualifiedName& attrName)
70 {
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);
80     }
81     return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
82 }
83
84 void SVGLineElement::parseMappedAttribute(Attribute* attr)
85 {
86     SVGParsingError parseError = NoError;
87
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)) {
101     } else
102         ASSERT_NOT_REACHED();
103
104     reportAttributeParsingError(parseError, attr);
105 }
106
107 void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName)
108 {
109     if (!isSupportedAttribute(attrName)) {
110         SVGStyledTransformableElement::svgAttributeChanged(attrName);
111         return;
112     }
113
114     SVGElementInstance::InvalidationGuard invalidationGuard(this);
115     
116     bool isLengthAttribute = attrName == SVGNames::x1Attr
117                           || attrName == SVGNames::y1Attr
118                           || attrName == SVGNames::x2Attr
119                           || attrName == SVGNames::y2Attr;
120
121     if (isLengthAttribute)
122         updateRelativeLengthsInformation();
123
124     if (SVGTests::handleAttributeChange(this, attrName))
125         return;
126
127     RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer());
128     if (!renderer)
129         return;
130
131     if (isLengthAttribute) {
132         renderer->setNeedsShapeUpdate();
133         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
134         return;
135     }
136
137     if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
138         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
139         return;
140     }
141
142     ASSERT_NOT_REACHED();
143 }
144
145 bool SVGLineElement::selfHasRelativeLengths() const
146 {
147     return x1().isRelative()
148         || y1().isRelative()
149         || x2().isRelative()
150         || y2().isRelative();
151 }
152
153 }
154
155 #endif // ENABLE(SVG)