1/* 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> 4 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22#include "config.h" 23 24#if ENABLE(SVG) 25#include "SVGClipPathElement.h" 26 27#include "Attribute.h" 28#include "Document.h" 29#include "RenderSVGResourceClipper.h" 30#include "SVGElementInstance.h" 31#include "SVGNames.h" 32#include "SVGTransformList.h" 33#include "StyleResolver.h" 34 35namespace WebCore { 36 37// Animated property definitions 38DEFINE_ANIMATED_ENUMERATION(SVGClipPathElement, SVGNames::clipPathUnitsAttr, ClipPathUnits, clipPathUnits, SVGUnitTypes::SVGUnitType) 39DEFINE_ANIMATED_BOOLEAN(SVGClipPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 40 41BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGClipPathElement) 42 REGISTER_LOCAL_ANIMATED_PROPERTY(clipPathUnits) 43 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) 44 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledTransformableElement) 45 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTests) 46END_REGISTER_ANIMATED_PROPERTIES 47 48inline SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* document) 49 : SVGStyledTransformableElement(tagName, document) 50 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) 51{ 52 ASSERT(hasTagName(SVGNames::clipPathTag)); 53 registerAnimatedPropertiesForSVGClipPathElement(); 54} 55 56PassRefPtr<SVGClipPathElement> SVGClipPathElement::create(const QualifiedName& tagName, Document* document) 57{ 58 return adoptRef(new SVGClipPathElement(tagName, document)); 59} 60 61bool SVGClipPathElement::isSupportedAttribute(const QualifiedName& attrName) 62{ 63 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 64 if (supportedAttributes.isEmpty()) { 65 SVGTests::addSupportedAttributes(supportedAttributes); 66 SVGLangSpace::addSupportedAttributes(supportedAttributes); 67 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); 68 supportedAttributes.add(SVGNames::clipPathUnitsAttr); 69 } 70 return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName); 71} 72 73void SVGClipPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 74{ 75 if (!isSupportedAttribute(name)) { 76 SVGStyledTransformableElement::parseAttribute(name, value); 77 return; 78 } 79 80 if (name == SVGNames::clipPathUnitsAttr) { 81 SVGUnitTypes::SVGUnitType propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value); 82 if (propertyValue > 0) 83 setClipPathUnitsBaseValue(propertyValue); 84 return; 85 } 86 87 if (SVGTests::parseAttribute(name, value)) 88 return; 89 if (SVGLangSpace::parseAttribute(name, value)) 90 return; 91 if (SVGExternalResourcesRequired::parseAttribute(name, value)) 92 return; 93 94 ASSERT_NOT_REACHED(); 95} 96 97void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName) 98{ 99 if (!isSupportedAttribute(attrName)) { 100 SVGStyledTransformableElement::svgAttributeChanged(attrName); 101 return; 102 } 103 104 SVGElementInstance::InvalidationGuard invalidationGuard(this); 105 106 if (RenderObject* object = renderer()) 107 object->setNeedsLayout(true); 108} 109 110void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 111{ 112 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 113 114 if (changedByParser) 115 return; 116 117 if (RenderObject* object = renderer()) 118 object->setNeedsLayout(true); 119} 120 121RenderObject* SVGClipPathElement::createRenderer(RenderArena* arena, RenderStyle*) 122{ 123 return new (arena) RenderSVGResourceClipper(this); 124} 125 126} 127 128#endif // ENABLE(SVG) 129