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