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 * Copyright (C) 2018 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#include "config.h"
23#include "SVGGElement.h"
24
25#include "RenderSVGHiddenContainer.h"
26#include "RenderSVGResource.h"
27#include "RenderSVGTransformableContainer.h"
28#include "SVGNames.h"
29#include <wtf/IsoMallocInlines.h>
30#include <wtf/NeverDestroyed.h>
31
32namespace WebCore {
33
34WTF_MAKE_ISO_ALLOCATED_IMPL(SVGGElement);
35
36SVGGElement::SVGGElement(const QualifiedName& tagName, Document& document)
37 : SVGGraphicsElement(tagName, document)
38 , SVGExternalResourcesRequired(this)
39{
40 ASSERT(hasTagName(SVGNames::gTag));
41}
42
43Ref<SVGGElement> SVGGElement::create(const QualifiedName& tagName, Document& document)
44{
45 return adoptRef(*new SVGGElement(tagName, document));
46}
47
48Ref<SVGGElement> SVGGElement::create(Document& document)
49{
50 return create(SVGNames::gTag, document);
51}
52
53void SVGGElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
54{
55 SVGGraphicsElement::parseAttribute(name, value);
56 SVGExternalResourcesRequired::parseAttribute(name, value);
57}
58
59void SVGGElement::svgAttributeChanged(const QualifiedName& attrName)
60{
61 SVGGraphicsElement::svgAttributeChanged(attrName);
62 SVGExternalResourcesRequired::svgAttributeChanged(attrName);
63}
64
65RenderPtr<RenderElement> SVGGElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
66{
67 // SVG 1.1 testsuite explicitly uses constructs like <g display="none"><linearGradient>
68 // We still have to create renderers for the <g> & <linearGradient> element, though the
69 // subtree may be hidden - we only want the resource renderers to exist so they can be
70 // referenced from somewhere else.
71 if (style.display() == DisplayType::None)
72 return createRenderer<RenderSVGHiddenContainer>(*this, WTFMove(style));
73
74 return createRenderer<RenderSVGTransformableContainer>(*this, WTFMove(style));
75}
76
77bool SVGGElement::rendererIsNeeded(const RenderStyle&)
78{
79 // Unlike SVGElement::rendererIsNeeded(), we still create renderers, even if
80 // display is set to 'none' - which is special to SVG <g> container elements.
81 return parentOrShadowHostElement() && parentOrShadowHostElement()->isSVGElement();
82}
83
84}
85