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 "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 // Animated property definitions
33 DEFINE_ANIMATED_STRING(SVGMPathElement, XLinkNames::hrefAttr, Href, href)
35 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGMPathElement)
36 REGISTER_LOCAL_ANIMATED_PROPERTY(href)
37 END_REGISTER_ANIMATED_PROPERTIES
39 inline SVGMPathElement::SVGMPathElement(Document& document)
40 : SVGElement(SVGNames::mpathTag, document)
42 ScriptWrappable::init(this);
43 registerAnimatedPropertiesForSVGMPathElement();
46 PassRefPtr<SVGMPathElement> SVGMPathElement::create(Document& document)
48 return adoptRef(new SVGMPathElement(document));
51 SVGMPathElement::~SVGMPathElement()
53 clearResourceReferences();
56 void SVGMPathElement::buildPendingResource()
58 clearResourceReferences();
63 Element* target = SVGURIReference::targetElementFromIRIString(hrefCurrentValue(), document(), &id);
65 // Do not register as pending if we are already pending this resource.
66 if (document().accessSVGExtensions()->isElementPendingResource(this, id))
70 document().accessSVGExtensions()->addPendingResource(id, this);
71 ASSERT(hasPendingResources());
73 } else if (target->isSVGElement()) {
74 // Register us with the target in the dependencies map. Any change of hrefElement
75 // that leads to relayout/repainting now informs us, so we can react to it.
76 document().accessSVGExtensions()->addElementReferencingTarget(this, toSVGElement(target));
82 void SVGMPathElement::clearResourceReferences()
84 document().accessSVGExtensions()->removeAllTargetReferencesForElement(this);
87 Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode* rootParent)
89 SVGElement::insertedInto(rootParent);
90 if (rootParent->inDocument())
91 buildPendingResource();
95 void SVGMPathElement::removedFrom(ContainerNode* rootParent)
97 SVGElement::removedFrom(rootParent);
98 notifyParentOfPathChange(rootParent);
99 if (rootParent->inDocument())
100 clearResourceReferences();
103 bool SVGMPathElement::isSupportedAttribute(const QualifiedName& attrName)
105 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
106 if (supportedAttributes.isEmpty()) {
107 SVGURIReference::addSupportedAttributes(supportedAttributes);
109 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
112 void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
114 if (!isSupportedAttribute(name)) {
115 SVGElement::parseAttribute(name, value);
119 if (SVGURIReference::parseAttribute(name, value))
122 ASSERT_NOT_REACHED();
125 void SVGMPathElement::svgAttributeChanged(const QualifiedName& attrName)
127 if (!isSupportedAttribute(attrName)) {
128 SVGElement::svgAttributeChanged(attrName);
132 SVGElementInstance::InvalidationGuard invalidationGuard(this);
134 if (SVGURIReference::isKnownAttribute(attrName)) {
135 buildPendingResource();
139 ASSERT_NOT_REACHED();
142 SVGPathElement* SVGMPathElement::pathElement()
144 Element* target = targetElementFromIRIString(hrefCurrentValue(), document());
145 if (target && target->hasTagName(SVGNames::pathTag))
146 return toSVGPathElement(target);
150 void SVGMPathElement::targetPathChanged()
152 notifyParentOfPathChange(parentNode());
155 void SVGMPathElement::notifyParentOfPathChange(ContainerNode* parent)
157 if (parent && parent->hasTagName(SVGNames::animateMotionTag))
158 toSVGAnimateMotionElement(parent)->updateAnimationPath();
161 } // namespace WebCore