1/* 2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2007 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 "SVGViewElement.h" 23 24#include "Attribute.h" 25#include "SVGFitToViewBox.h" 26#include "SVGNames.h" 27#include "SVGStringList.h" 28#include "SVGZoomAndPan.h" 29#include <wtf/NeverDestroyed.h> 30 31namespace WebCore { 32 33// Animated property definitions 34DEFINE_ANIMATED_BOOLEAN(SVGViewElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 35DEFINE_ANIMATED_RECT(SVGViewElement, SVGNames::viewBoxAttr, ViewBox, viewBox) 36DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGViewElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio) 37 38BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGViewElement) 39 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) 40 REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox) 41 REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio) 42 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGElement) 43END_REGISTER_ANIMATED_PROPERTIES 44 45inline SVGViewElement::SVGViewElement(const QualifiedName& tagName, Document& document) 46 : SVGElement(tagName, document) 47 , m_zoomAndPan(SVGZoomAndPanMagnify) 48 , m_viewTarget(SVGNames::viewTargetAttr) 49{ 50 ASSERT(hasTagName(SVGNames::viewTag)); 51 registerAnimatedPropertiesForSVGViewElement(); 52} 53 54PassRefPtr<SVGViewElement> SVGViewElement::create(const QualifiedName& tagName, Document& document) 55{ 56 return adoptRef(new SVGViewElement(tagName, document)); 57} 58 59bool SVGViewElement::isSupportedAttribute(const QualifiedName& attrName) 60{ 61 static NeverDestroyed<HashSet<QualifiedName>> supportedAttributes; 62 if (supportedAttributes.get().isEmpty()) { 63 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); 64 SVGFitToViewBox::addSupportedAttributes(supportedAttributes); 65 SVGZoomAndPan::addSupportedAttributes(supportedAttributes); 66 supportedAttributes.get().add(SVGNames::viewTargetAttr); 67 } 68 return supportedAttributes.get().contains<SVGAttributeHashTranslator>(attrName); 69} 70 71void SVGViewElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 72{ 73 if (!isSupportedAttribute(name)) { 74 SVGElement::parseAttribute(name, value); 75 return; 76 } 77 78 if (name == SVGNames::viewTargetAttr) { 79 viewTarget().reset(value); 80 return; 81 } 82 83 if (SVGExternalResourcesRequired::parseAttribute(name, value)) 84 return; 85 if (SVGFitToViewBox::parseAttribute(this, name, value)) 86 return; 87 if (SVGZoomAndPan::parseAttribute(this, name, value)) 88 return; 89 90 ASSERT_NOT_REACHED(); 91} 92 93} 94