initial import
[vuplus_webkit] / Source / WebCore / svg / SVGGElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2007, 2008 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 #if ENABLE(SVG)
24 #include "SVGGElement.h"
25
26 #include "RenderSVGHiddenContainer.h"
27 #include "RenderSVGResource.h"
28 #include "RenderSVGTransformableContainer.h"
29 #include "SVGElementInstance.h"
30 #include "SVGNames.h"
31
32 namespace WebCore {
33
34 // Animated property definitions
35 DEFINE_ANIMATED_BOOLEAN(SVGGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
36
37 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGElement)
38     REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
39     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledTransformableElement)
40     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests)
41 END_REGISTER_ANIMATED_PROPERTIES
42
43 SVGGElement::SVGGElement(const QualifiedName& tagName, Document* document)
44     : SVGStyledTransformableElement(tagName, document)
45 {
46     ASSERT(hasTagName(SVGNames::gTag));
47     registerAnimatedPropertiesForSVGGElement();
48 }
49
50 PassRefPtr<SVGGElement> SVGGElement::create(const QualifiedName& tagName, Document* document)
51 {
52     return adoptRef(new SVGGElement(tagName, document));
53 }
54
55 bool SVGGElement::isSupportedAttribute(const QualifiedName& attrName)
56 {
57     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
58     if (supportedAttributes.isEmpty()) {
59         SVGTests::addSupportedAttributes(supportedAttributes);
60         SVGLangSpace::addSupportedAttributes(supportedAttributes);
61         SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
62     }
63     return supportedAttributes.contains(attrName);
64 }
65
66 void SVGGElement::parseMappedAttribute(Attribute* attr)
67 {
68     if (!isSupportedAttribute(attr->name())) {
69         SVGStyledTransformableElement::parseMappedAttribute(attr);
70         return;
71     }
72
73     if (SVGTests::parseMappedAttribute(attr))
74         return;
75     if (SVGLangSpace::parseMappedAttribute(attr))
76         return;
77     if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
78         return;
79
80     ASSERT_NOT_REACHED();
81 }
82
83 void SVGGElement::svgAttributeChanged(const QualifiedName& attrName)
84 {
85     if (!isSupportedAttribute(attrName)) {
86         SVGStyledTransformableElement::svgAttributeChanged(attrName);
87         return;
88     }
89
90     SVGElementInstance::InvalidationGuard invalidationGuard(this);
91     
92     if (SVGTests::handleAttributeChange(this, attrName))
93         return;
94
95     if (RenderObject* renderer = this->renderer())
96         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
97 }
98
99 RenderObject* SVGGElement::createRenderer(RenderArena* arena, RenderStyle* style)
100 {
101     // SVG 1.1 testsuite explicitely uses constructs like <g display="none"><linearGradient>
102     // We still have to create renderers for the <g> & <linearGradient> element, though the
103     // subtree may be hidden - we only want the resource renderers to exist so they can be
104     // referenced from somewhere else.
105     if (style->display() == NONE)
106         return new (arena) RenderSVGHiddenContainer(this);
107
108     return new (arena) RenderSVGTransformableContainer(this);
109 }
110
111 bool SVGGElement::rendererIsNeeded(const NodeRenderingContext&)
112 {
113     return parentNode() && parentNode()->isSVGElement(); 
114 }
115
116 }
117
118 #endif // ENABLE(SVG)