Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGSymbolElement.cpp
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 #include "core/svg/SVGSymbolElement.h"
24
25 #include "SVGNames.h"
26 #include "core/rendering/svg/RenderSVGHiddenContainer.h"
27 #include "core/svg/SVGElementInstance.h"
28
29 namespace WebCore {
30
31 inline SVGSymbolElement::SVGSymbolElement(Document& document)
32     : SVGElement(SVGNames::symbolTag, document)
33     , SVGFitToViewBox(this)
34 {
35     ScriptWrappable::init(this);
36 }
37
38 PassRefPtr<SVGSymbolElement> SVGSymbolElement::create(Document& document)
39 {
40     return adoptRef(new SVGSymbolElement(document));
41 }
42
43 bool SVGSymbolElement::isSupportedAttribute(const QualifiedName& attrName)
44 {
45     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
46     if (supportedAttributes.isEmpty())
47         SVGFitToViewBox::addSupportedAttributes(supportedAttributes);
48
49     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
50 }
51
52 void SVGSymbolElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
53 {
54     if (!isSupportedAttribute(name)) {
55         SVGElement::parseAttribute(name, value);
56         return;
57     }
58
59     SVGParsingError parseError = NoError;
60     if (SVGFitToViewBox::parseAttribute(name, value, document(), parseError)) {
61     } else {
62         ASSERT_NOT_REACHED();
63     }
64
65     reportAttributeParsingError(parseError, name, value);
66 }
67
68 void SVGSymbolElement::svgAttributeChanged(const QualifiedName& attrName)
69 {
70     if (!isSupportedAttribute(attrName)) {
71         SVGElement::svgAttributeChanged(attrName);
72         return;
73     }
74
75     SVGElement::InvalidationGuard invalidationGuard(this);
76
77     // Every other property change is ignored.
78     if (attrName == SVGNames::viewBoxAttr)
79         updateRelativeLengthsInformation();
80 }
81
82 bool SVGSymbolElement::selfHasRelativeLengths() const
83 {
84     return hasAttribute(SVGNames::viewBoxAttr);
85 }
86
87 RenderObject* SVGSymbolElement::createRenderer(RenderStyle*)
88 {
89     return new RenderSVGHiddenContainer(this);
90 }
91
92 }