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 "SVGCursorElement.h"
27
28 #include "Attr.h"
29 #include "Document.h"
30 #include "SVGNames.h"
31 #include "SVGLength.h"
32
33 namespace WebCore {
34
SVGCursorElement(const QualifiedName & tagName,Document * doc)35 SVGCursorElement::SVGCursorElement(const QualifiedName& tagName, Document* doc)
36 : SVGElement(tagName, doc)
37 , SVGTests()
38 , SVGExternalResourcesRequired()
39 , SVGURIReference()
40 , m_x(this, SVGNames::xAttr, LengthModeWidth)
41 , m_y(this, SVGNames::yAttr, LengthModeHeight)
42 {
43 }
44
~SVGCursorElement()45 SVGCursorElement::~SVGCursorElement()
46 {
47 HashSet<SVGElement*>::iterator end = m_clients.end();
48 for (HashSet<SVGElement*>::iterator it = m_clients.begin(); it != end; ++it)
49 (*it)->setCursorElement(0);
50 }
51
parseMappedAttribute(MappedAttribute * attr)52 void SVGCursorElement::parseMappedAttribute(MappedAttribute* attr)
53 {
54 if (attr->name() == SVGNames::xAttr)
55 setXBaseValue(SVGLength(LengthModeWidth, attr->value()));
56 else if (attr->name() == SVGNames::yAttr)
57 setYBaseValue(SVGLength(LengthModeHeight, attr->value()));
58 else {
59 if (SVGTests::parseMappedAttribute(attr))
60 return;
61 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
62 return;
63 if (SVGURIReference::parseMappedAttribute(attr))
64 return;
65
66 SVGElement::parseMappedAttribute(attr);
67 }
68 }
69
addClient(SVGElement * element)70 void SVGCursorElement::addClient(SVGElement* element)
71 {
72 m_clients.add(element);
73 element->setCursorElement(this);
74 }
75
removeClient(SVGElement * element)76 void SVGCursorElement::removeClient(SVGElement* element)
77 {
78 m_clients.remove(element);
79 element->setCursorElement(0);
80 }
81
svgAttributeChanged(const QualifiedName & attrName)82 void SVGCursorElement::svgAttributeChanged(const QualifiedName& attrName)
83 {
84 SVGElement::svgAttributeChanged(attrName);
85
86 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
87 SVGTests::isKnownAttribute(attrName) ||
88 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
89 SVGURIReference::isKnownAttribute(attrName)) {
90 HashSet<SVGElement*>::const_iterator it = m_clients.begin();
91 HashSet<SVGElement*>::const_iterator end = m_clients.end();
92
93 for (; it != end; ++it)
94 (*it)->setChanged();
95 }
96 }
97
addSubresourceAttributeURLs(ListHashSet<KURL> & urls) const98 void SVGCursorElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
99 {
100 SVGElement::addSubresourceAttributeURLs(urls);
101
102 addSubresourceURL(urls, document()->completeURL(href()));
103 }
104
105 }
106
107 #endif // ENABLE(SVG)
108