1 /* 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis (at) 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/SVGGElement.h" 24 25 #include "core/SVGNames.h" 26 #include "core/rendering/svg/RenderSVGHiddenContainer.h" 27 #include "core/rendering/svg/RenderSVGResource.h" 28 #include "core/rendering/svg/RenderSVGTransformableContainer.h" 29 30 namespace WebCore { 31 32 inline SVGGElement::SVGGElement(Document& document, ConstructionType constructionType) 33 : SVGGraphicsElement(SVGNames::gTag, document, constructionType) 34 { 35 ScriptWrappable::init(this); 36 } 37 38 DEFINE_NODE_FACTORY(SVGGElement) 39 40 bool SVGGElement::isSupportedAttribute(const QualifiedName& attrName) 41 { 42 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 43 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 44 } 45 46 void SVGGElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 47 { 48 if (!isSupportedAttribute(name)) { 49 SVGGraphicsElement::parseAttribute(name, value); 50 return; 51 } 52 53 ASSERT_NOT_REACHED(); 54 } 55 56 void SVGGElement::svgAttributeChanged(const QualifiedName& attrName) 57 { 58 if (!isSupportedAttribute(attrName)) { 59 SVGGraphicsElement::svgAttributeChanged(attrName); 60 return; 61 } 62 63 SVGElement::InvalidationGuard invalidationGuard(this); 64 65 if (RenderObject* renderer = this->renderer()) 66 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 67 } 68 69 RenderObject* SVGGElement::createRenderer(RenderStyle* style) 70 { 71 // SVG 1.1 testsuite explicitely uses constructs like <g display="none"><linearGradient> 72 // We still have to create renderers for the <g> & <linearGradient> element, though the 73 // subtree may be hidden - we only want the resource renderers to exist so they can be 74 // referenced from somewhere else. 75 if (style->display() == NONE) 76 return new RenderSVGHiddenContainer(this); 77 78 return new RenderSVGTransformableContainer(this); 79 } 80 81 bool SVGGElement::rendererIsNeeded(const RenderStyle&) 82 { 83 // Unlike SVGElement::rendererIsNeeded(), we still create renderers, even if 84 // display is set to 'none' - which is special to SVG <g> container elements. 85 return parentOrShadowHostElement() && parentOrShadowHostElement()->isSVGElement(); 86 } 87 88 } 89