| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> |
| 4 | * Copyright (C) 2018-2019 Apple Inc. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "SVGCursorElement.h" |
| 24 | |
| 25 | #include "CSSCursorImageValue.h" |
| 26 | #include "Document.h" |
| 27 | #include "SVGNames.h" |
| 28 | #include "SVGStringList.h" |
| 29 | #include <wtf/IsoMallocInlines.h> |
| 30 | #include <wtf/NeverDestroyed.h> |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGCursorElement); |
| 35 | |
| 36 | inline SVGCursorElement::SVGCursorElement(const QualifiedName& tagName, Document& document) |
| 37 | : SVGElement(tagName, document) |
| 38 | , SVGExternalResourcesRequired(this) |
| 39 | , SVGTests(this) |
| 40 | , SVGURIReference(this) |
| 41 | { |
| 42 | ASSERT(hasTagName(SVGNames::cursorTag)); |
| 43 | |
| 44 | static std::once_flag onceFlag; |
| 45 | std::call_once(onceFlag, [] { |
| 46 | PropertyRegistry::registerProperty<SVGNames::xAttr, &SVGCursorElement::m_x>(); |
| 47 | PropertyRegistry::registerProperty<SVGNames::yAttr, &SVGCursorElement::m_y>(); |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | Ref<SVGCursorElement> SVGCursorElement::create(const QualifiedName& tagName, Document& document) |
| 52 | { |
| 53 | return adoptRef(*new SVGCursorElement(tagName, document)); |
| 54 | } |
| 55 | |
| 56 | SVGCursorElement::~SVGCursorElement() |
| 57 | { |
| 58 | for (auto& client : m_clients) |
| 59 | client->cursorElementRemoved(*this); |
| 60 | } |
| 61 | |
| 62 | void SVGCursorElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 63 | { |
| 64 | SVGParsingError parseError = NoError; |
| 65 | |
| 66 | if (name == SVGNames::xAttr) |
| 67 | m_x->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError)); |
| 68 | else if (name == SVGNames::yAttr) |
| 69 | m_y->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError)); |
| 70 | |
| 71 | reportAttributeParsingError(parseError, name, value); |
| 72 | |
| 73 | SVGElement::parseAttribute(name, value); |
| 74 | SVGTests::parseAttribute(name, value); |
| 75 | SVGExternalResourcesRequired::parseAttribute(name, value); |
| 76 | SVGURIReference::parseAttribute(name, value); |
| 77 | } |
| 78 | |
| 79 | void SVGCursorElement::addClient(CSSCursorImageValue& value) |
| 80 | { |
| 81 | m_clients.add(&value); |
| 82 | } |
| 83 | |
| 84 | void SVGCursorElement::removeClient(CSSCursorImageValue& value) |
| 85 | { |
| 86 | m_clients.remove(&value); |
| 87 | } |
| 88 | |
| 89 | void SVGCursorElement::svgAttributeChanged(const QualifiedName& attrName) |
| 90 | { |
| 91 | if (PropertyRegistry::isKnownAttribute(attrName)) { |
| 92 | InstanceInvalidationGuard guard(*this); |
| 93 | for (auto& client : m_clients) |
| 94 | client->cursorElementChanged(*this); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | SVGElement::svgAttributeChanged(attrName); |
| 99 | } |
| 100 | |
| 101 | void SVGCursorElement::addSubresourceAttributeURLs(ListHashSet<URL>& urls) const |
| 102 | { |
| 103 | SVGElement::addSubresourceAttributeURLs(urls); |
| 104 | |
| 105 | addSubresourceURL(urls, document().completeURL(href())); |
| 106 | } |
| 107 | |
| 108 | } |
| 109 | |