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
34 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGMPathElement)
35 END_REGISTER_ANIMATED_PROPERTIES
37 inline SVGMPathElement::SVGMPathElement(Document& document)
38 : SVGElement(SVGNames::mpathTag, document)
39 , SVGURIReference(this)
41 ScriptWrappable::init(this);
42 registerAnimatedPropertiesForSVGMPathElement();
45 PassRefPtr<SVGMPathElement> SVGMPathElement::create(Document& document)
47 return adoptRef(new SVGMPathElement(document));
50 SVGMPathElement::~SVGMPathElement()
52 clearResourceReferences();
55 void SVGMPathElement::buildPendingResource()
57 clearResourceReferences();
62 Element* target = SVGURIReference::targetElementFromIRIString(hrefString(), document(), &id);
64 // Do not register as pending if we are already pending this resource.
65 if (document().accessSVGExtensions()->isElementPendingResource(this, id))
69 document().accessSVGExtensions()->addPendingResource(id, this);
70 ASSERT(hasPendingResources());
72 } else if (target->isSVGElement()) {
73 // Register us with the target in the dependencies map. Any change of hrefElement
74 // that leads to relayout/repainting now informs us, so we can react to it.
75 document().accessSVGExtensions()->addElementReferencingTarget(this, toSVGElement(target));
81 void SVGMPathElement::clearResourceReferences()
83 document().accessSVGExtensions()->removeAllTargetReferencesForElement(this);
86 Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode* rootParent)
88 SVGElement::insertedInto(rootParent);
89 if (rootParent->inDocument())
90 buildPendingResource();
94 void SVGMPathElement::removedFrom(ContainerNode* rootParent)
96 SVGElement::removedFrom(rootParent);
97 notifyParentOfPathChange(rootParent);
98 if (rootParent->inDocument())
99 clearResourceReferences();
102 bool SVGMPathElement::isSupportedAttribute(const QualifiedName& attrName)
104 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
105 if (supportedAttributes.isEmpty()) {
106 SVGURIReference::addSupportedAttributes(supportedAttributes);
108 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
111 void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
113 SVGParsingError parseError = NoError;
115 if (!isSupportedAttribute(name)) {
116 SVGElement::parseAttribute(name, value);
117 } else if (SVGURIReference::parseAttribute(name, value, parseError)) {
119 ASSERT_NOT_REACHED();
122 reportAttributeParsingError(parseError, name, value);
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(hrefString(), 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