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#if ENABLE(SVG)
24#include "SVGSymbolElement.h"
25
26#include "SVGFitToViewBox.h"
27#include "SVGNames.h"
28
29namespace WebCore {
30
31// Animated property definitions
32DEFINE_ANIMATED_BOOLEAN(SVGSymbolElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
33DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSymbolElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
34DEFINE_ANIMATED_RECT(SVGSymbolElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
35
36inline SVGSymbolElement::SVGSymbolElement(const QualifiedName& tagName, Document* document)
37    : SVGStyledElement(tagName, document)
38{
39}
40
41PassRefPtr<SVGSymbolElement> SVGSymbolElement::create(const QualifiedName& tagName, Document* document)
42{
43    return adoptRef(new SVGSymbolElement(tagName, document));
44}
45
46void SVGSymbolElement::parseMappedAttribute(Attribute* attr)
47{
48    if (SVGLangSpace::parseMappedAttribute(attr))
49        return;
50    if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
51        return;
52    if (SVGFitToViewBox::parseMappedAttribute(document(), attr))
53        return;
54
55    SVGStyledElement::parseMappedAttribute(attr);
56}
57
58void SVGSymbolElement::svgAttributeChanged(const QualifiedName& attrName)
59{
60    SVGStyledElement::svgAttributeChanged(attrName);
61
62    if (attrName == SVGNames::viewBoxAttr)
63        updateRelativeLengthsInformation();
64}
65
66void SVGSymbolElement::synchronizeProperty(const QualifiedName& attrName)
67{
68    SVGStyledElement::synchronizeProperty(attrName);
69
70    if (attrName == anyQName()) {
71        synchronizePreserveAspectRatio();
72        synchronizeViewBox();
73        synchronizeExternalResourcesRequired();
74        synchronizeViewBox();
75        synchronizePreserveAspectRatio();
76        return;
77    }
78
79    if (attrName == SVGNames::preserveAspectRatioAttr)
80        synchronizePreserveAspectRatio();
81    else if (attrName == SVGNames::viewBoxAttr)
82        synchronizeViewBox();
83    else if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
84        synchronizeExternalResourcesRequired();
85    else if (SVGFitToViewBox::isKnownAttribute(attrName)) {
86        synchronizeViewBox();
87        synchronizePreserveAspectRatio();
88    }
89}
90
91AttributeToPropertyTypeMap& SVGSymbolElement::attributeToPropertyTypeMap()
92{
93    DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
94    return s_attributeToPropertyTypeMap;
95}
96
97void SVGSymbolElement::fillAttributeToPropertyTypeMap()
98{
99    AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
100
101    SVGStyledElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
102    attributeToPropertyTypeMap.set(SVGNames::viewBoxAttr, AnimatedRect);
103    attributeToPropertyTypeMap.set(SVGNames::preserveAspectRatioAttr, AnimatedPreserveAspectRatio);
104}
105
106bool SVGSymbolElement::selfHasRelativeLengths() const
107{
108    return hasAttribute(SVGNames::viewBoxAttr);
109}
110
111}
112
113#endif // ENABLE(SVG)
114