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.
23 #include "core/svg/SVGCursorElement.h"
25 #include "core/SVGNames.h"
26 #include "core/XLinkNames.h"
30 inline SVGCursorElement::SVGCursorElement(Document& document)
31 : SVGElement(SVGNames::cursorTag, document)
33 , SVGURIReference(this)
34 , m_x(SVGAnimatedLength::create(this, SVGNames::xAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths))
35 , m_y(SVGAnimatedLength::create(this, SVGNames::yAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths))
37 addToPropertyMap(m_x);
38 addToPropertyMap(m_y);
41 DEFINE_NODE_FACTORY(SVGCursorElement)
43 SVGCursorElement::~SVGCursorElement()
45 // The below teardown is all handled by weak pointer processing in oilpan.
47 HashSet<RawPtr<SVGElement> >::iterator end = m_clients.end();
48 for (HashSet<RawPtr<SVGElement> >::iterator it = m_clients.begin(); it != end; ++it)
49 (*it)->cursorElementRemoved();
53 bool SVGCursorElement::isSupportedAttribute(const QualifiedName& attrName)
55 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
56 if (supportedAttributes.isEmpty()) {
57 SVGTests::addSupportedAttributes(supportedAttributes);
58 SVGURIReference::addSupportedAttributes(supportedAttributes);
59 supportedAttributes.add(SVGNames::xAttr);
60 supportedAttributes.add(SVGNames::yAttr);
62 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
65 void SVGCursorElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
67 SVGParsingError parseError = NoError;
69 if (!isSupportedAttribute(name)) {
70 SVGElement::parseAttribute(name, value);
71 } else if (name == SVGNames::xAttr) {
72 m_x->setBaseValueAsString(value, parseError);
73 } else if (name == SVGNames::yAttr) {
74 m_y->setBaseValueAsString(value, parseError);
75 } else if (SVGURIReference::parseAttribute(name, value, parseError)) {
76 } else if (SVGTests::parseAttribute(name, value)) {
81 reportAttributeParsingError(parseError, name, value);
84 void SVGCursorElement::addClient(SVGElement* element)
86 m_clients.add(element);
87 element->setCursorElement(this);
91 void SVGCursorElement::removeClient(SVGElement* element)
93 HashSet<RawPtr<SVGElement> >::iterator it = m_clients.find(element);
94 if (it != m_clients.end()) {
96 element->cursorElementRemoved();
101 void SVGCursorElement::removeReferencedElement(SVGElement* element)
103 m_clients.remove(element);
106 void SVGCursorElement::svgAttributeChanged(const QualifiedName& attrName)
108 if (!isSupportedAttribute(attrName)) {
109 SVGElement::svgAttributeChanged(attrName);
113 SVGElement::InvalidationGuard invalidationGuard(this);
115 // Any change of a cursor specific attribute triggers this recalc.
116 WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >::const_iterator it = m_clients.begin();
117 WillBeHeapHashSet<RawPtrWillBeWeakMember<SVGElement> >::const_iterator end = m_clients.end();
119 for (; it != end; ++it)
120 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
123 void SVGCursorElement::trace(Visitor* visitor)
126 visitor->trace(m_clients);
128 SVGElement::trace(visitor);