1 /* 2 * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis (at) 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 #include "core/svg/SVGClipPathElement.h" 25 26 #include "SVGNames.h" 27 #include "core/rendering/svg/RenderSVGResourceClipper.h" 28 #include "core/svg/SVGElementInstance.h" 29 30 namespace WebCore { 31 32 // Animated property definitions 33 DEFINE_ANIMATED_ENUMERATION(SVGClipPathElement, SVGNames::clipPathUnitsAttr, ClipPathUnits, clipPathUnits, SVGUnitTypes::SVGUnitType) 34 DEFINE_ANIMATED_BOOLEAN(SVGClipPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 35 36 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGClipPathElement) 37 REGISTER_LOCAL_ANIMATED_PROPERTY(clipPathUnits) 38 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired) 39 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement) 40 END_REGISTER_ANIMATED_PROPERTIES 41 42 inline SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* document) 43 : SVGGraphicsElement(tagName, document) 44 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) 45 { 46 ASSERT(hasTagName(SVGNames::clipPathTag)); 47 ScriptWrappable::init(this); 48 registerAnimatedPropertiesForSVGClipPathElement(); 49 } 50 51 PassRefPtr<SVGClipPathElement> SVGClipPathElement::create(const QualifiedName& tagName, Document* document) 52 { 53 return adoptRef(new SVGClipPathElement(tagName, document)); 54 } 55 56 bool SVGClipPathElement::isSupportedAttribute(const QualifiedName& attrName) 57 { 58 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 59 if (supportedAttributes.isEmpty()) { 60 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes); 61 supportedAttributes.add(SVGNames::clipPathUnitsAttr); 62 } 63 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 64 } 65 66 void SVGClipPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 67 { 68 if (!isSupportedAttribute(name)) { 69 SVGGraphicsElement::parseAttribute(name, value); 70 return; 71 } 72 73 if (name == SVGNames::clipPathUnitsAttr) { 74 SVGUnitTypes::SVGUnitType propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value); 75 if (propertyValue > 0) 76 setClipPathUnitsBaseValue(propertyValue); 77 return; 78 } 79 80 if (SVGExternalResourcesRequired::parseAttribute(name, value)) 81 return; 82 83 ASSERT_NOT_REACHED(); 84 } 85 86 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName) 87 { 88 if (!isSupportedAttribute(attrName)) { 89 SVGGraphicsElement::svgAttributeChanged(attrName); 90 return; 91 } 92 93 SVGElementInstance::InvalidationGuard invalidationGuard(this); 94 95 if (RenderObject* object = renderer()) 96 object->setNeedsLayout(); 97 } 98 99 void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 100 { 101 SVGGraphicsElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 102 103 if (changedByParser) 104 return; 105 106 if (RenderObject* object = renderer()) 107 object->setNeedsLayout(); 108 } 109 110 RenderObject* SVGClipPathElement::createRenderer(RenderStyle*) 111 { 112 return new RenderSVGResourceClipper(this); 113 } 114 115 } 116