initial import
[vuplus_webkit] / Source / WebCore / svg / SVGViewElement.cpp
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
32 namespace WebCore {
33
34 // Animated property definitions
35 DEFINE_ANIMATED_BOOLEAN(SVGViewElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
36 DEFINE_ANIMATED_RECT(SVGViewElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
37 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
38
39 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGViewElement)
40     REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
41     REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
42     REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
43     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledElement)
44 END_REGISTER_ANIMATED_PROPERTIES
45
46 inline SVGViewElement::SVGViewElement(const QualifiedName& tagName, Document* document)
47     : SVGStyledElement(tagName, document)
48     , m_viewTarget(SVGNames::viewTargetAttr)
49 {
50     ASSERT(hasTagName(SVGNames::viewTag));
51     registerAnimatedPropertiesForSVGViewElement();
52 }
53
54 PassRefPtr<SVGViewElement> SVGViewElement::create(const QualifiedName& tagName, Document* document)
55 {
56     return adoptRef(new SVGViewElement(tagName, document));
57 }
58
59 bool SVGViewElement::isSupportedAttribute(const QualifiedName& attrName)
60 {
61     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
62     if (supportedAttributes.isEmpty()) {
63         SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
64         SVGFitToViewBox::addSupportedAttributes(supportedAttributes);
65         SVGZoomAndPan::addSupportedAttributes(supportedAttributes);
66         supportedAttributes.add(SVGNames::viewTargetAttr);
67     }
68     return supportedAttributes.contains(attrName);
69 }
70
71 void SVGViewElement::parseMappedAttribute(Attribute* attr)
72 {
73     if (!isSupportedAttribute(attr->name())) {
74         SVGStyledElement::parseMappedAttribute(attr);
75         return;
76     }
77
78     if (attr->name() == SVGNames::viewTargetAttr) {
79         viewTarget().reset(attr->value());
80         return;
81     }
82
83     if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
84         return;
85     if (SVGFitToViewBox::parseMappedAttribute(document(), attr))
86         return;
87     if (SVGZoomAndPan::parseMappedAttribute(attr))
88         return;
89
90     ASSERT_NOT_REACHED();
91 }
92
93 }
94
95 #endif // ENABLE(SVG)