1/*
2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2007 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 "SVGViewElement.h"
25
26#include "Attribute.h"
27#include "SVGFitToViewBox.h"
28#include "SVGNames.h"
29#include "SVGStringList.h"
30#include "SVGZoomAndPan.h"
31
32namespace WebCore {
33
34// Animated property definitions
35DEFINE_ANIMATED_BOOLEAN(SVGViewElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
36DEFINE_ANIMATED_RECT(SVGViewElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
37DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
38
39inline SVGViewElement::SVGViewElement(const QualifiedName& tagName, Document* document)
40    : SVGStyledElement(tagName, document)
41    , m_viewTarget(SVGNames::viewTargetAttr)
42{
43}
44
45PassRefPtr<SVGViewElement> SVGViewElement::create(const QualifiedName& tagName, Document* document)
46{
47    return adoptRef(new SVGViewElement(tagName, document));
48}
49
50void SVGViewElement::parseMappedAttribute(Attribute* attr)
51{
52    if (attr->name() == SVGNames::viewTargetAttr)
53        viewTarget().reset(attr->value());
54    else {
55        if (SVGExternalResourcesRequired::parseMappedAttribute(attr)
56           || SVGFitToViewBox::parseMappedAttribute(document(), attr)
57           || SVGZoomAndPan::parseMappedAttribute(attr))
58            return;
59
60        SVGStyledElement::parseMappedAttribute(attr);
61    }
62}
63
64void SVGViewElement::synchronizeProperty(const QualifiedName& attrName)
65{
66    SVGStyledElement::synchronizeProperty(attrName);
67
68    if (attrName == anyQName()) {
69        synchronizeExternalResourcesRequired();
70        synchronizeViewBox();
71        synchronizePreserveAspectRatio();
72        return;
73    }
74
75    if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
76        synchronizeExternalResourcesRequired();
77    else if (SVGFitToViewBox::isKnownAttribute(attrName)) {
78        synchronizeViewBox();
79        synchronizePreserveAspectRatio();
80    }
81}
82
83AttributeToPropertyTypeMap& SVGViewElement::attributeToPropertyTypeMap()
84{
85    DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
86    return s_attributeToPropertyTypeMap;
87}
88
89void SVGViewElement::fillAttributeToPropertyTypeMap()
90{
91    AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
92
93    SVGStyledElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
94    attributeToPropertyTypeMap.set(SVGNames::viewBoxAttr, AnimatedRect);
95    attributeToPropertyTypeMap.set(SVGNames::preserveAspectRatioAttr, AnimatedPreserveAspectRatio);
96}
97
98}
99
100#endif // ENABLE(SVG)
101