1 /*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #if ENABLE(SVG)
26 #include "SVGLineElement.h"
27
28 #include "FloatPoint.h"
29 #include "MappedAttribute.h"
30 #include "RenderPath.h"
31 #include "SVGLength.h"
32 #include "SVGNames.h"
33
34 namespace WebCore {
35
SVGLineElement(const QualifiedName & tagName,Document * doc)36 SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document* doc)
37 : SVGStyledTransformableElement(tagName, doc)
38 , SVGTests()
39 , SVGLangSpace()
40 , SVGExternalResourcesRequired()
41 , m_x1(this, SVGNames::x1Attr, LengthModeWidth)
42 , m_y1(this, SVGNames::y1Attr, LengthModeHeight)
43 , m_x2(this, SVGNames::x2Attr, LengthModeWidth)
44 , m_y2(this, SVGNames::y2Attr, LengthModeHeight)
45 {
46 }
47
~SVGLineElement()48 SVGLineElement::~SVGLineElement()
49 {
50 }
51
parseMappedAttribute(MappedAttribute * attr)52 void SVGLineElement::parseMappedAttribute(MappedAttribute* attr)
53 {
54 if (attr->name() == SVGNames::x1Attr)
55 setX1BaseValue(SVGLength(LengthModeWidth, attr->value()));
56 else if (attr->name() == SVGNames::y1Attr)
57 setY1BaseValue(SVGLength(LengthModeHeight, attr->value()));
58 else if (attr->name() == SVGNames::x2Attr)
59 setX2BaseValue(SVGLength(LengthModeWidth, attr->value()));
60 else if (attr->name() == SVGNames::y2Attr)
61 setY2BaseValue(SVGLength(LengthModeHeight, attr->value()));
62 else {
63 if (SVGTests::parseMappedAttribute(attr))
64 return;
65 if (SVGLangSpace::parseMappedAttribute(attr))
66 return;
67 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
68 return;
69 SVGStyledTransformableElement::parseMappedAttribute(attr);
70 }
71 }
72
svgAttributeChanged(const QualifiedName & attrName)73 void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName)
74 {
75 SVGStyledTransformableElement::svgAttributeChanged(attrName);
76
77 if (!renderer())
78 return;
79
80 if (attrName == SVGNames::x1Attr || attrName == SVGNames::y1Attr ||
81 attrName == SVGNames::x2Attr || attrName == SVGNames::y2Attr ||
82 SVGTests::isKnownAttribute(attrName) ||
83 SVGLangSpace::isKnownAttribute(attrName) ||
84 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
85 SVGStyledTransformableElement::isKnownAttribute(attrName))
86 renderer()->setNeedsLayout(true);
87 }
88
toPathData() const89 Path SVGLineElement::toPathData() const
90 {
91 return Path::createLine(FloatPoint(x1().value(this), y1().value(this)),
92 FloatPoint(x2().value(this), y2().value(this)));
93 }
94
hasRelativeValues() const95 bool SVGLineElement::hasRelativeValues() const
96 {
97 return (x1().isRelative() || y1().isRelative() ||
98 x2().isRelative() || y2().isRelative());
99 }
100
101 }
102
103 #endif // ENABLE(SVG)
104