2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "core/svg/SVGMPathElement.h"
24 #include "core/XLinkNames.h"
25 #include "core/dom/Document.h"
26 #include "core/svg/SVGAnimateMotionElement.h"
27 #include "core/svg/SVGDocumentExtensions.h"
28 #include "core/svg/SVGPathElement.h"
32 inline SVGMPathElement::SVGMPathElement(Document& document)
33 : SVGElement(SVGNames::mpathTag, document)
34 , SVGURIReference(this)
36 ScriptWrappable::init(this);
39 DEFINE_NODE_FACTORY(SVGMPathElement)
41 SVGMPathElement::~SVGMPathElement()
44 clearResourceReferences();
48 void SVGMPathElement::buildPendingResource()
50 clearResourceReferences();
55 Element* target = SVGURIReference::targetElementFromIRIString(hrefString(), treeScope(), &id);
57 // Do not register as pending if we are already pending this resource.
58 if (document().accessSVGExtensions().isElementPendingResource(this, id))
62 document().accessSVGExtensions().addPendingResource(id, this);
63 ASSERT(hasPendingResources());
65 } else if (isSVGPathElement(target)) {
66 // Register us with the target in the dependencies map. Any change of hrefElement
67 // that leads to relayout/repainting now informs us, so we can react to it.
68 addReferenceTo(toSVGElement(target));
74 void SVGMPathElement::clearResourceReferences()
76 removeAllOutgoingReferences();
79 Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode* rootParent)
81 SVGElement::insertedInto(rootParent);
82 if (rootParent->inDocument())
83 buildPendingResource();
87 void SVGMPathElement::removedFrom(ContainerNode* rootParent)
89 SVGElement::removedFrom(rootParent);
90 notifyParentOfPathChange(rootParent);
91 if (rootParent->inDocument())
92 clearResourceReferences();
95 bool SVGMPathElement::isSupportedAttribute(const QualifiedName& attrName)
97 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
98 if (supportedAttributes.isEmpty()) {
99 SVGURIReference::addSupportedAttributes(supportedAttributes);
101 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
104 void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
106 SVGParsingError parseError = NoError;
108 if (!isSupportedAttribute(name)) {
109 SVGElement::parseAttribute(name, value);
110 } else if (SVGURIReference::parseAttribute(name, value, parseError)) {
112 ASSERT_NOT_REACHED();
115 reportAttributeParsingError(parseError, name, value);
118 void SVGMPathElement::svgAttributeChanged(const QualifiedName& attrName)
120 if (!isSupportedAttribute(attrName)) {
121 SVGElement::svgAttributeChanged(attrName);
125 SVGElement::InvalidationGuard invalidationGuard(this);
127 if (SVGURIReference::isKnownAttribute(attrName)) {
128 buildPendingResource();
132 ASSERT_NOT_REACHED();
135 SVGPathElement* SVGMPathElement::pathElement()
137 Element* target = targetElementFromIRIString(hrefString(), treeScope());
138 return isSVGPathElement(target) ? toSVGPathElement(target) : 0;
141 void SVGMPathElement::targetPathChanged()
143 notifyParentOfPathChange(parentNode());
146 void SVGMPathElement::notifyParentOfPathChange(ContainerNode* parent)
148 if (isSVGAnimateMotionElement(parent))
149 toSVGAnimateMotionElement(parent)->updateAnimationPath();