1 /*
2 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include "config.h"
22
23 #include "core/svg/SVGSymbolElement.h"
24
25 #include "SVGNames.h"
26 #include "core/rendering/svg/RenderSVGHiddenContainer.h"
27 #include "core/svg/SVGElementInstance.h"
28
29 namespace WebCore {
30
31 // Animated property definitions
DEFINE_ANIMATED_BOOLEAN(SVGSymbolElement,SVGNames::externalResourcesRequiredAttr,ExternalResourcesRequired,externalResourcesRequired)32 DEFINE_ANIMATED_BOOLEAN(SVGSymbolElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
33 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSymbolElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
34 DEFINE_ANIMATED_RECT(SVGSymbolElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
35
36 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSymbolElement)
37 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
38 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
39 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
40 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement)
41 END_REGISTER_ANIMATED_PROPERTIES
42
43 inline SVGSymbolElement::SVGSymbolElement(Document& document)
44 : SVGElement(SVGNames::symbolTag, document)
45 {
46 ScriptWrappable::init(this);
47 registerAnimatedPropertiesForSVGSymbolElement();
48 }
49
create(Document & document)50 PassRefPtr<SVGSymbolElement> SVGSymbolElement::create(Document& document)
51 {
52 return adoptRef(new SVGSymbolElement(document));
53 }
54
isSupportedAttribute(const QualifiedName & attrName)55 bool SVGSymbolElement::isSupportedAttribute(const QualifiedName& attrName)
56 {
57 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
58 if (supportedAttributes.isEmpty()) {
59 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
60 SVGFitToViewBox::addSupportedAttributes(supportedAttributes);
61 }
62 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
63 }
64
parseAttribute(const QualifiedName & name,const AtomicString & value)65 void SVGSymbolElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
66 {
67 if (!isSupportedAttribute(name)) {
68 SVGElement::parseAttribute(name, value);
69 return;
70 }
71
72 if (SVGExternalResourcesRequired::parseAttribute(name, value))
73 return;
74 if (SVGFitToViewBox::parseAttribute(this, name, value))
75 return;
76
77 ASSERT_NOT_REACHED();
78 }
79
svgAttributeChanged(const QualifiedName & attrName)80 void SVGSymbolElement::svgAttributeChanged(const QualifiedName& attrName)
81 {
82 if (!isSupportedAttribute(attrName)) {
83 SVGElement::svgAttributeChanged(attrName);
84 return;
85 }
86
87 SVGElementInstance::InvalidationGuard invalidationGuard(this);
88
89 // Every other property change is ignored.
90 if (attrName == SVGNames::viewBoxAttr)
91 updateRelativeLengthsInformation();
92 }
93
selfHasRelativeLengths() const94 bool SVGSymbolElement::selfHasRelativeLengths() const
95 {
96 return hasAttribute(SVGNames::viewBoxAttr);
97 }
98
createRenderer(RenderStyle *)99 RenderObject* SVGSymbolElement::createRenderer(RenderStyle*)
100 {
101 return new RenderSVGHiddenContainer(this);
102 }
103
104 }
105