1 /* 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) 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 #include "core/svg/SVGCursorElement.h" 24 25 #include "core/SVGNames.h" 26 #include "core/XLinkNames.h" 27 28 namespace blink { 29 30 inline SVGCursorElement::SVGCursorElement(Document& document) 31 : SVGElement(SVGNames::cursorTag, document) 32 , SVGTests(this) 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)) 36 { 37 addToPropertyMap(m_x); 38 addToPropertyMap(m_y); 39 } 40 41 DEFINE_NODE_FACTORY(SVGCursorElement) 42 43 SVGCursorElement::~SVGCursorElement() 44 { 45 // The below teardown is all handled by weak pointer processing in oilpan. 46 #if !ENABLE(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(); 50 #endif 51 } 52 53 bool SVGCursorElement::isSupportedAttribute(const QualifiedName& attrName) 54 { 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); 61 } 62 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 63 } 64 65 void SVGCursorElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 66 { 67 SVGParsingError parseError = NoError; 68 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)) { 77 } else { 78 ASSERT_NOT_REACHED(); 79 } 80 81 reportAttributeParsingError(parseError, name, value); 82 } 83 84 void SVGCursorElement::addClient(SVGElement* element) 85 { 86 m_clients.add(element); 87 element->setCursorElement(this); 88 } 89 90 #if !ENABLE(OILPAN) 91 void SVGCursorElement::removeClient(SVGElement* element) 92 { 93 HashSet<RawPtr<SVGElement> >::iterator it = m_clients.find(element); 94 if (it != m_clients.end()) { 95 m_clients.remove(it); 96 element->cursorElementRemoved(); 97 } 98 } 99 #endif 100 101 void SVGCursorElement::removeReferencedElement(SVGElement* element) 102 { 103 m_clients.remove(element); 104 } 105 106 void SVGCursorElement::svgAttributeChanged(const QualifiedName& attrName) 107 { 108 if (!isSupportedAttribute(attrName)) { 109 SVGElement::svgAttributeChanged(attrName); 110 return; 111 } 112 113 SVGElement::InvalidationGuard invalidationGuard(this); 114 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(); 118 119 for (; it != end; ++it) 120 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 121 } 122 123 void SVGCursorElement::trace(Visitor* visitor) 124 { 125 #if ENABLE(OILPAN) 126 visitor->trace(m_clients); 127 #endif 128 SVGElement::trace(visitor); 129 } 130 131 } // namespace blink 132