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 "core/rendering/svg/RenderSVGResourceClipper.h" 27 28 namespace WebCore { 29 30 inline SVGClipPathElement::SVGClipPathElement(Document& document) 31 : SVGGraphicsElement(SVGNames::clipPathTag, document) 32 , m_clipPathUnits(SVGAnimatedEnumeration<SVGUnitTypes::SVGUnitType>::create(this, SVGNames::clipPathUnitsAttr, SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)) 33 { 34 ScriptWrappable::init(this); 35 addToPropertyMap(m_clipPathUnits); 36 } 37 38 DEFINE_NODE_FACTORY(SVGClipPathElement) 39 40 bool SVGClipPathElement::isSupportedAttribute(const QualifiedName& attrName) 41 { 42 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 43 if (supportedAttributes.isEmpty()) 44 supportedAttributes.add(SVGNames::clipPathUnitsAttr); 45 46 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 47 } 48 49 void SVGClipPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 50 { 51 if (!isSupportedAttribute(name)) { 52 SVGGraphicsElement::parseAttribute(name, value); 53 return; 54 } 55 56 SVGParsingError parseError = NoError; 57 58 if (name == SVGNames::clipPathUnitsAttr) 59 m_clipPathUnits->setBaseValueAsString(value, parseError); 60 else 61 ASSERT_NOT_REACHED(); 62 63 reportAttributeParsingError(parseError, name, value); 64 } 65 66 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName) 67 { 68 if (!isSupportedAttribute(attrName)) { 69 SVGGraphicsElement::svgAttributeChanged(attrName); 70 return; 71 } 72 73 SVGElement::InvalidationGuard invalidationGuard(this); 74 75 RenderSVGResourceContainer* renderer = toRenderSVGResourceContainer(this->renderer()); 76 if (renderer) 77 renderer->invalidateCacheAndMarkForLayout(); 78 } 79 80 void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) 81 { 82 SVGGraphicsElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); 83 84 if (changedByParser) 85 return; 86 87 if (RenderObject* object = renderer()) 88 object->setNeedsLayoutAndFullPaintInvalidation(); 89 } 90 91 RenderObject* SVGClipPathElement::createRenderer(RenderStyle*) 92 { 93 return new RenderSVGResourceClipper(this); 94 } 95 96 } 97