Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGMPathElement.cpp
1 /*
2  * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21
22 #include "core/svg/SVGMPathElement.h"
23
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"
29
30 namespace WebCore {
31
32 // Animated property definitions
33
34 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGMPathElement)
35 END_REGISTER_ANIMATED_PROPERTIES
36
37 inline SVGMPathElement::SVGMPathElement(Document& document)
38     : SVGElement(SVGNames::mpathTag, document)
39     , SVGURIReference(this)
40 {
41     ScriptWrappable::init(this);
42     registerAnimatedPropertiesForSVGMPathElement();
43 }
44
45 PassRefPtr<SVGMPathElement> SVGMPathElement::create(Document& document)
46 {
47     return adoptRef(new SVGMPathElement(document));
48 }
49
50 SVGMPathElement::~SVGMPathElement()
51 {
52     clearResourceReferences();
53 }
54
55 void SVGMPathElement::buildPendingResource()
56 {
57     clearResourceReferences();
58     if (!inDocument())
59         return;
60
61     AtomicString id;
62     Element* target = SVGURIReference::targetElementFromIRIString(hrefString(), document(), &id);
63     if (!target) {
64         // Do not register as pending if we are already pending this resource.
65         if (document().accessSVGExtensions()->isElementPendingResource(this, id))
66             return;
67
68         if (!id.isEmpty()) {
69             document().accessSVGExtensions()->addPendingResource(id, this);
70             ASSERT(hasPendingResources());
71         }
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));
76     }
77
78     targetPathChanged();
79 }
80
81 void SVGMPathElement::clearResourceReferences()
82 {
83     document().accessSVGExtensions()->removeAllTargetReferencesForElement(this);
84 }
85
86 Node::InsertionNotificationRequest SVGMPathElement::insertedInto(ContainerNode* rootParent)
87 {
88     SVGElement::insertedInto(rootParent);
89     if (rootParent->inDocument())
90         buildPendingResource();
91     return InsertionDone;
92 }
93
94 void SVGMPathElement::removedFrom(ContainerNode* rootParent)
95 {
96     SVGElement::removedFrom(rootParent);
97     notifyParentOfPathChange(rootParent);
98     if (rootParent->inDocument())
99         clearResourceReferences();
100 }
101
102 bool SVGMPathElement::isSupportedAttribute(const QualifiedName& attrName)
103 {
104     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
105     if (supportedAttributes.isEmpty()) {
106         SVGURIReference::addSupportedAttributes(supportedAttributes);
107     }
108     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
109 }
110
111 void SVGMPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
112 {
113     SVGParsingError parseError = NoError;
114
115     if (!isSupportedAttribute(name)) {
116         SVGElement::parseAttribute(name, value);
117     } else if (SVGURIReference::parseAttribute(name, value, parseError)) {
118     } else {
119         ASSERT_NOT_REACHED();
120     }
121
122     reportAttributeParsingError(parseError, name, value);
123 }
124
125 void SVGMPathElement::svgAttributeChanged(const QualifiedName& attrName)
126 {
127     if (!isSupportedAttribute(attrName)) {
128         SVGElement::svgAttributeChanged(attrName);
129         return;
130     }
131
132     SVGElementInstance::InvalidationGuard invalidationGuard(this);
133
134     if (SVGURIReference::isKnownAttribute(attrName)) {
135         buildPendingResource();
136         return;
137     }
138
139     ASSERT_NOT_REACHED();
140 }
141
142 SVGPathElement* SVGMPathElement::pathElement()
143 {
144     Element* target = targetElementFromIRIString(hrefString(), document());
145     if (target && target->hasTagName(SVGNames::pathTag))
146         return toSVGPathElement(target);
147     return 0;
148 }
149
150 void SVGMPathElement::targetPathChanged()
151 {
152     notifyParentOfPathChange(parentNode());
153 }
154
155 void SVGMPathElement::notifyParentOfPathChange(ContainerNode* parent)
156 {
157     if (parent && parent->hasTagName(SVGNames::animateMotionTag))
158         toSVGAnimateMotionElement(parent)->updateAnimationPath();
159 }
160
161 } // namespace WebCore