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#include "core/svg/SVGGElement.h" 24 25#include "SVGNames.h" 26#include "core/rendering/svg/RenderSVGHiddenContainer.h" 27#include "core/rendering/svg/RenderSVGResource.h" 28#include "core/rendering/svg/RenderSVGTransformableContainer.h" 29#include "core/svg/SVGElementInstance.h" 30 31namespace WebCore { 32 33// Animated property definitions 34DEFINE_ANIMATED_BOOLEAN(SVGGElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 35 36BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGGElement) 37 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) 38 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) 39END_REGISTER_ANIMATED_PROPERTIES 40 41SVGGElement::SVGGElement(Document& document, ConstructionType constructionType) 42 : SVGGraphicsElement(SVGNames::gTag, document, constructionType) 43{ 44 ScriptWrappable::init(this); 45 registerAnimatedPropertiesForSVGGElement(); 46} 47 48PassRefPtr<SVGGElement> SVGGElement::create(Document& document) 49{ 50 return adoptRef(new SVGGElement(document)); 51} 52 53bool SVGGElement::isSupportedAttribute(const QualifiedName& attrName) 54{ 55 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 56 if (supportedAttributes.isEmpty()) 57 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); 58 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 59} 60 61void SVGGElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 62{ 63 if (!isSupportedAttribute(name)) { 64 SVGGraphicsElement::parseAttribute(name, value); 65 return; 66 } 67 68 ASSERT_NOT_REACHED(); 69} 70 71void SVGGElement::svgAttributeChanged(const QualifiedName& attrName) 72{ 73 if (!isSupportedAttribute(attrName)) { 74 SVGGraphicsElement::svgAttributeChanged(attrName); 75 return; 76 } 77 78 SVGElementInstance::InvalidationGuard invalidationGuard(this); 79 80 if (RenderObject* renderer = this->renderer()) 81 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 82} 83 84RenderObject* SVGGElement::createRenderer(RenderStyle* style) 85{ 86 // SVG 1.1 testsuite explicitely uses constructs like <g display="none"><linearGradient> 87 // We still have to create renderers for the <g> & <linearGradient> element, though the 88 // subtree may be hidden - we only want the resource renderers to exist so they can be 89 // referenced from somewhere else. 90 if (style->display() == NONE) 91 return new RenderSVGHiddenContainer(this); 92 93 return new RenderSVGTransformableContainer(this); 94} 95 96bool SVGGElement::rendererIsNeeded(const RenderStyle&) 97{ 98 // Unlike SVGElement::rendererIsNeeded(), we still create renderers, even if 99 // display is set to 'none' - which is special to SVG <g> container elements. 100 return parentOrShadowHostElement() && parentOrShadowHostElement()->isSVGElement(); 101} 102 103} 104