• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 "FloatPoint.h"
27 #include "MappedAttribute.h"
28 #include "RenderPath.h"
29 #include "SVGLength.h"
30 #include "SVGNames.h"
31 
32 namespace WebCore {
33 
SVGLineElement(const QualifiedName & tagName,Document * doc)34 SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document* doc)
35     : SVGStyledTransformableElement(tagName, doc)
36     , SVGTests()
37     , SVGLangSpace()
38     , SVGExternalResourcesRequired()
39     , m_x1(LengthModeWidth)
40     , m_y1(LengthModeHeight)
41     , m_x2(LengthModeWidth)
42     , m_y2(LengthModeHeight)
43 {
44 }
45 
~SVGLineElement()46 SVGLineElement::~SVGLineElement()
47 {
48 }
49 
parseMappedAttribute(MappedAttribute * attr)50 void SVGLineElement::parseMappedAttribute(MappedAttribute* attr)
51 {
52     if (attr->name() == SVGNames::x1Attr)
53         setX1BaseValue(SVGLength(LengthModeWidth, attr->value()));
54     else if (attr->name() == SVGNames::y1Attr)
55         setY1BaseValue(SVGLength(LengthModeHeight, attr->value()));
56     else if (attr->name() == SVGNames::x2Attr)
57         setX2BaseValue(SVGLength(LengthModeWidth, attr->value()));
58     else if (attr->name() == SVGNames::y2Attr)
59         setY2BaseValue(SVGLength(LengthModeHeight, attr->value()));
60     else {
61         if (SVGTests::parseMappedAttribute(attr))
62             return;
63         if (SVGLangSpace::parseMappedAttribute(attr))
64             return;
65         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
66             return;
67         SVGStyledTransformableElement::parseMappedAttribute(attr);
68     }
69 }
70 
svgAttributeChanged(const QualifiedName & attrName)71 void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName)
72 {
73     SVGStyledTransformableElement::svgAttributeChanged(attrName);
74 
75     if (!renderer())
76         return;
77 
78     if (attrName == SVGNames::x1Attr || attrName == SVGNames::y1Attr ||
79         attrName == SVGNames::x2Attr || attrName == SVGNames::y2Attr ||
80         SVGTests::isKnownAttribute(attrName) ||
81         SVGLangSpace::isKnownAttribute(attrName) ||
82         SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
83         SVGStyledTransformableElement::isKnownAttribute(attrName))
84         renderer()->setNeedsLayout(true);
85 }
86 
synchronizeProperty(const QualifiedName & attrName)87 void SVGLineElement::synchronizeProperty(const QualifiedName& attrName)
88 {
89     SVGStyledTransformableElement::synchronizeProperty(attrName);
90 
91     if (attrName == anyQName()) {
92         synchronizeX1();
93         synchronizeY1();
94         synchronizeX2();
95         synchronizeY2();
96         synchronizeExternalResourcesRequired();
97         return;
98     }
99 
100     if (attrName == SVGNames::x1Attr)
101         synchronizeX1();
102     else if (attrName == SVGNames::y1Attr)
103         synchronizeY1();
104     else if (attrName == SVGNames::x2Attr)
105         synchronizeX2();
106     else if (attrName == SVGNames::y2Attr)
107         synchronizeY2();
108     else if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
109         synchronizeExternalResourcesRequired();
110 }
111 
toPathData() const112 Path SVGLineElement::toPathData() const
113 {
114     return Path::createLine(FloatPoint(x1().value(this), y1().value(this)),
115                             FloatPoint(x2().value(this), y2().value(this)));
116 }
117 
hasRelativeValues() const118 bool SVGLineElement::hasRelativeValues() const
119 {
120     return (x1().isRelative() || y1().isRelative() ||
121             x2().isRelative() || y2().isRelative());
122 }
123 
124 }
125 
126 #endif // ENABLE(SVG)
127