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.
23 #include "SVGMPathElement.h"
26 #include "SVGAnimateMotionElement.h"
27 #include "SVGDocumentExtensions.h"
29 #include "SVGPathElement.h"
30 #include "XLinkNames.h"
34 // Animated property definitions
35 DEFINE_ANIMATED_STRING(SVGMPathElement, XLinkNames::hrefAttr, Href, href)
36 DEFINE_ANIMATED_BOOLEAN(SVGMPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
38 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGMPathElement)
39 REGISTER_LOCAL_ANIMATED_PROPERTY(href)
40 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
41 END_REGISTER_ANIMATED_PROPERTIES
43 inline SVGMPathElement::SVGMPathElement(const QualifiedName& tagName, Document& document)
44 : SVGElement(tagName, document)
46 ASSERT(hasTagName(SVGNames::mpathTag));
47 registerAnimatedPropertiesForSVGMPathElement();
50 PassRefPtr<SVGMPathElement> SVGMPathElement::create(const QualifiedName& tagName, Document& document)
52 return adoptRef(new SVGMPathElement(tagName, document));
55 SVGMPathElement::~SVGMPathElement()
57 clearResourceReferences();
60 void SVGMPathElement::buildPendingResource()
62 clearResourceReferences();
67 Element* target = SVGURIReference::targetElementFromIRIString(href(), document(), &id);
69 // Do not register as pending if we are already pending this resource.
70 if (document().accessSVGExtensions()->isElementPendingResource(this, id))
74 document().accessSVGExtensions()->addPendingResource(id, this);
75 ASSERT(hasPendingResources());
77 } else if (target->isSVGElement()) {
78 // Register us with the target in the dependencies map. Any change of hrefElement
79 // that leads to relayout/repainting now informs us, so we can react to it.
80 document().accessSVGExtensions()->addElementReferencingTarget(this, toSVGElement(target));
86 void SVGMPathElement::clearResourceReferences()
88 document().accessSVGExtensions()->removeAllTargetReferencesForElement(this);
91 Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode* rootParent)
93 SVGElement::insertedInto(rootParent);
94 if (rootParent->inDocument())
95 buildPendingResource();
99 void SVGMPathElement::removedFrom(ContainerNode* rootParent)
101 SVGElement::removedFrom(rootParent);
102 notifyParentOfPathChange(rootParent);
103 if (rootParent->inDocument())
104 clearResourceReferences();
107 bool SVGMPathElement::isSupportedAttribute(const QualifiedName& attrName)
109 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
110 if (supportedAttributes.isEmpty()) {
111 SVGURIReference::addSupportedAttributes(supportedAttributes);
112 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
114 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
117 void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
119 if (!isSupportedAttribute(name)) {
120 SVGElement::parseAttribute(name, value);
124 if (SVGURIReference::parseAttribute(name, value))
126 if (SVGExternalResourcesRequired::parseAttribute(name, value))
129 ASSERT_NOT_REACHED();
132 void SVGMPathElement::svgAttributeChanged(const QualifiedName& attrName)
134 if (!isSupportedAttribute(attrName)) {
135 SVGElement::svgAttributeChanged(attrName);
139 SVGElementInstance::InvalidationGuard invalidationGuard(this);
141 if (SVGURIReference::isKnownAttribute(attrName)) {
142 buildPendingResource();
146 if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
149 ASSERT_NOT_REACHED();
152 SVGPathElement* SVGMPathElement::pathElement()
154 Element* target = targetElementFromIRIString(href(), document());
155 if (target && target->hasTagName(SVGNames::pathTag))
156 return toSVGPathElement(target);
160 void SVGMPathElement::targetPathChanged()
162 notifyParentOfPathChange(parentNode());
165 void SVGMPathElement::notifyParentOfPathChange(ContainerNode* parent)
167 if (parent && isSVGAnimateMotionElement(parent))
168 toSVGAnimateMotionElement(parent)->updateAnimationPath();
171 } // namespace WebCore
173 #endif // ENABLE(SVG)