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)
38 DEFINE_NODE_FACTORY(SVGMPathElement)
40 SVGMPathElement::~SVGMPathElement()
43 clearResourceReferences();
47 void SVGMPathElement::buildPendingResource()
49 clearResourceReferences();
54 Element* target = SVGURIReference::targetElementFromIRIString(hrefString(), treeScope(), &id);
56 // Do not register as pending if we are already pending this resource.
57 if (document().accessSVGExtensions().isElementPendingResource(this, id))
61 document().accessSVGExtensions().addPendingResource(id, this);
62 ASSERT(hasPendingResources());
64 } else if (isSVGPathElement(target)) {
65 // Register us with the target in the dependencies map. Any change of hrefElement
66 // that leads to relayout/repainting now informs us, so we can react to it.
67 addReferenceTo(toSVGElement(target));
73 void SVGMPathElement::clearResourceReferences()
75 removeAllOutgoingReferences();
78 Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode* rootParent)
80 SVGElement::insertedInto(rootParent);
81 if (rootParent->inDocument())
82 buildPendingResource();
86 void SVGMPathElement::removedFrom(ContainerNode* rootParent)
88 SVGElement::removedFrom(rootParent);
89 notifyParentOfPathChange(rootParent);
90 if (rootParent->inDocument())
91 clearResourceReferences();
94 void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
96 parseAttributeNew(name, value);
99 void SVGMPathElement::svgAttributeChanged(const QualifiedName& attrName)
101 if (SVGURIReference::isKnownAttribute(attrName)) {
102 SVGElement::InvalidationGuard invalidationGuard(this);
103 buildPendingResource();
107 SVGElement::svgAttributeChanged(attrName);
110 SVGPathElement* SVGMPathElement::pathElement()
112 Element* target = targetElementFromIRIString(hrefString(), treeScope());
113 return isSVGPathElement(target) ? toSVGPathElement(target) : 0;
116 void SVGMPathElement::targetPathChanged()
118 notifyParentOfPathChange(parentNode());
121 void SVGMPathElement::notifyParentOfPathChange(ContainerNode* parent)
123 if (isSVGAnimateMotionElement(parent))
124 toSVGAnimateMotionElement(parent)->updateAnimationPath();