1/* 2 * Copyright (C) 2004, 2005 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#include "SVGSymbolElement.h" 23 24#include "RenderSVGHiddenContainer.h" 25#include "SVGElementInstance.h" 26#include "SVGFitToViewBox.h" 27#include "SVGNames.h" 28#include <wtf/NeverDestroyed.h> 29 30namespace WebCore { 31 32// Animated property definitions 33DEFINE_ANIMATED_BOOLEAN(SVGSymbolElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 34DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGSymbolElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) 35DEFINE_ANIMATED_RECT(SVGSymbolElement, SVGNames::viewBoxAttr, ViewBox, viewBox) 36 37BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGSymbolElement) 38 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) 39 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox) 40 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio) 41 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement) 42END_REGISTER_ANIMATED_PROPERTIES 43 44inline SVGSymbolElement::SVGSymbolElement(const QualifiedName& tagName, Document& document) 45 : SVGElement(tagName, document) 46{ 47 ASSERT(hasTagName(SVGNames::symbolTag)); 48 registerAnimatedPropertiesForSVGSymbolElement(); 49} 50 51PassRefPtr<SVGSymbolElement> SVGSymbolElement::create(const QualifiedName& tagName, Document& document) 52{ 53 return adoptRef(new SVGSymbolElement(tagName, document)); 54} 55 56bool SVGSymbolElement::isSupportedAttribute(const QualifiedName& attrName) 57{ 58 static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes; 59 if (supportedAttributes.get().isEmpty()) { 60 SVGLangSpace::addSupportedAttributes(supportedAttributes); 61 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); 62 SVGFitToViewBox::addSupportedAttributes(supportedAttributes); 63 } 64 return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName); 65} 66 67void SVGSymbolElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 68{ 69 if (!isSupportedAttribute(name)) { 70 SVGElement::parseAttribute(name, value); 71 return; 72 } 73 74 if (SVGLangSpace::parseAttribute(name, value)) 75 return; 76 if (SVGExternalResourcesRequired::parseAttribute(name, value)) 77 return; 78 if (SVGFitToViewBox::parseAttribute(this, name, value)) 79 return; 80 81 ASSERT_NOT_REACHED(); 82} 83 84void SVGSymbolElement::svgAttributeChanged(const QualifiedName& attrName) 85{ 86 if (!isSupportedAttribute(attrName)) { 87 SVGElement::svgAttributeChanged(attrName); 88 return; 89 } 90 91 SVGElementInstance::InvalidationGuard invalidationGuard(this); 92 93 // Every other property change is ignored. 94 if (attrName == SVGNames::viewBoxAttr) 95 updateRelativeLengthsInformation(); 96} 97 98bool SVGSymbolElement::selfHasRelativeLengths() const 99{ 100 return hasAttribute(SVGNames::viewBoxAttr); 101} 102 103RenderPtr<RenderElement> SVGSymbolElement::createElementRenderer(PassRef<RenderStyle> style) 104{ 105 return createRenderer<RenderSVGHiddenContainer>(*this, WTF::move(style)); 106} 107 108} 109