- add third_party src.
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / 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 #include "core/svg/SVGViewElement.h"
24
25 #include "SVGNames.h"
26 #include "core/svg/SVGFitToViewBox.h"
27 #include "core/svg/SVGStringList.h"
28 #include "core/svg/SVGZoomAndPan.h"
29
30 namespace WebCore {
31
32 // Animated property definitions
33 DEFINE_ANIMATED_BOOLEAN(SVGViewElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
34 DEFINE_ANIMATED_RECT(SVGViewElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
35 DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
36
37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGViewElement)
38     REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
39     REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
40     REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
41     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement)
42 END_REGISTER_ANIMATED_PROPERTIES
43
44 inline SVGViewElement::SVGViewElement(const QualifiedName& tagName, Document& document)
45     : SVGElement(tagName, document)
46     , m_zoomAndPan(SVGZoomAndPanMagnify)
47     , m_viewTarget(SVGNames::viewTargetAttr)
48 {
49     ASSERT(hasTagName(SVGNames::viewTag));
50     ScriptWrappable::init(this);
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<SVGAttributeHashTranslator>(attrName);
69 }
70
71 void SVGViewElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
72 {
73     if (!isSupportedAttribute(name)) {
74         SVGElement::parseAttribute(name, value);
75         return;
76     }
77
78     if (name == SVGNames::viewTargetAttr) {
79         viewTarget().reset(value);
80         return;
81     }
82
83     if (SVGExternalResourcesRequired::parseAttribute(name, value))
84         return;
85     if (SVGFitToViewBox::parseAttribute(this, name, value))
86         return;
87     if (SVGZoomAndPan::parseAttribute(this, name, value))
88         return;
89
90     ASSERT_NOT_REACHED();
91 }
92
93 }