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 "SVGNames.h"
30
31 namespace WebCore {
32
33 // Animated property declarations
DEFINE_ANIMATED_BOOLEAN(SVGGElement,SVGNames::externalResourcesRequiredAttr,ExternalResourcesRequired,externalResourcesRequired)34 DEFINE_ANIMATED_BOOLEAN(SVGGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
35
36 SVGGElement::SVGGElement(const QualifiedName& tagName, Document* document)
37 : SVGStyledTransformableElement(tagName, document)
38 {
39 }
40
create(const QualifiedName & tagName,Document * document)41 PassRefPtr<SVGGElement> SVGGElement::create(const QualifiedName& tagName, Document* document)
42 {
43 return adoptRef(new SVGGElement(tagName, document));
44 }
45
parseMappedAttribute(Attribute * attr)46 void SVGGElement::parseMappedAttribute(Attribute* attr)
47 {
48 if (SVGTests::parseMappedAttribute(attr))
49 return;
50 if (SVGLangSpace::parseMappedAttribute(attr))
51 return;
52 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
53 return;
54
55 SVGStyledTransformableElement::parseMappedAttribute(attr);
56 }
57
svgAttributeChanged(const QualifiedName & attrName)58 void SVGGElement::svgAttributeChanged(const QualifiedName& attrName)
59 {
60 SVGStyledTransformableElement::svgAttributeChanged(attrName);
61
62 if (SVGTests::handleAttributeChange(this, attrName))
63 return;
64
65 RenderObject* renderer = this->renderer();
66 if (!renderer)
67 return;
68
69 if (SVGLangSpace::isKnownAttribute(attrName)
70 || SVGExternalResourcesRequired::isKnownAttribute(attrName))
71 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
72 }
73
synchronizeProperty(const QualifiedName & attrName)74 void SVGGElement::synchronizeProperty(const QualifiedName& attrName)
75 {
76 SVGStyledTransformableElement::synchronizeProperty(attrName);
77
78 if (attrName == anyQName()) {
79 synchronizeExternalResourcesRequired();
80 SVGTests::synchronizeProperties(this, attrName);
81 return;
82 }
83
84 if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
85 synchronizeExternalResourcesRequired();
86 else if (SVGTests::isKnownAttribute(attrName))
87 SVGTests::synchronizeProperties(this, attrName);
88 }
89
attributeToPropertyTypeMap()90 AttributeToPropertyTypeMap& SVGGElement::attributeToPropertyTypeMap()
91 {
92 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
93 return s_attributeToPropertyTypeMap;
94 }
95
fillAttributeToPropertyTypeMap()96 void SVGGElement::fillAttributeToPropertyTypeMap()
97 {
98 SVGStyledTransformableElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap());
99 }
100
createRenderer(RenderArena * arena,RenderStyle * style)101 RenderObject* SVGGElement::createRenderer(RenderArena* arena, RenderStyle* style)
102 {
103 // SVG 1.1 testsuite explicitely uses constructs like <g display="none"><linearGradient>
104 // We still have to create renderers for the <g> & <linearGradient> element, though the
105 // subtree may be hidden - we only want the resource renderers to exist so they can be
106 // referenced from somewhere else.
107 if (style->display() == NONE)
108 return new (arena) RenderSVGHiddenContainer(this);
109
110 return new (arena) RenderSVGTransformableContainer(this);
111 }
112
rendererIsNeeded(RenderStyle *)113 bool SVGGElement::rendererIsNeeded(RenderStyle*)
114 {
115 return parentNode() && parentNode()->isSVGElement();
116 }
117
118 }
119
120 #endif // ENABLE(SVG)
121