Upstream version 5.34.92.0
[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
26 namespace WebCore {
27
28 // Animated property definitions
29
30 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGViewElement)
31     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement)
32 END_REGISTER_ANIMATED_PROPERTIES
33
34 inline SVGViewElement::SVGViewElement(Document& document)
35     : SVGElement(SVGNames::viewTag, document)
36     , m_viewBox(SVGAnimatedRect::create(this, SVGNames::viewBoxAttr))
37     , m_preserveAspectRatio(SVGAnimatedPreserveAspectRatio::create(this, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create()))
38     , m_zoomAndPan(SVGZoomAndPanMagnify)
39     , m_viewTarget(SVGNames::viewTargetAttr)
40 {
41     ScriptWrappable::init(this);
42
43     addToPropertyMap(m_viewBox);
44     addToPropertyMap(m_preserveAspectRatio);
45     registerAnimatedPropertiesForSVGViewElement();
46 }
47
48 PassRefPtr<SVGViewElement> SVGViewElement::create(Document& document)
49 {
50     return adoptRef(new SVGViewElement(document));
51 }
52
53 bool SVGViewElement::isSupportedAttribute(const QualifiedName& attrName)
54 {
55     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
56     if (supportedAttributes.isEmpty()) {
57         SVGFitToViewBox::addSupportedAttributes(supportedAttributes);
58         SVGZoomAndPan::addSupportedAttributes(supportedAttributes);
59         supportedAttributes.add(SVGNames::viewTargetAttr);
60     }
61     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
62 }
63
64 void SVGViewElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
65 {
66     if (!isSupportedAttribute(name)) {
67         SVGElement::parseAttribute(name, value);
68         return;
69     }
70
71     if (name == SVGNames::viewTargetAttr) {
72         viewTarget().reset(value);
73         return;
74     }
75
76     if (SVGFitToViewBox::parseAttribute(this, name, value))
77         return;
78     if (SVGZoomAndPan::parseAttribute(this, name, value))
79         return;
80
81     ASSERT_NOT_REACHED();
82 }
83
84 }