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.
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.
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.
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.
25 #include "SVGClipPathElement.h"
27 #include "Attribute.h"
28 #include "CSSStyleSelector.h"
30 #include "RenderSVGResourceClipper.h"
31 #include "SVGElementInstance.h"
33 #include "SVGTransformList.h"
37 // Animated property definitions
38 DEFINE_ANIMATED_ENUMERATION(SVGClipPathElement, SVGNames::clipPathUnitsAttr, ClipPathUnits, clipPathUnits, SVGUnitTypes::SVGUnitType)
39 DEFINE_ANIMATED_BOOLEAN(SVGClipPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
41 BEGIN_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)
46 END_REGISTER_ANIMATED_PROPERTIES
48 inline SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* document)
49 : SVGStyledTransformableElement(tagName, document)
50 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
52 ASSERT(hasTagName(SVGNames::clipPathTag));
53 registerAnimatedPropertiesForSVGClipPathElement();
56 PassRefPtr<SVGClipPathElement> SVGClipPathElement::create(const QualifiedName& tagName, Document* document)
58 return adoptRef(new SVGClipPathElement(tagName, document));
61 bool SVGClipPathElement::isSupportedAttribute(const QualifiedName& attrName)
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);
70 return supportedAttributes.contains(attrName);
73 void SVGClipPathElement::parseMappedAttribute(Attribute* attr)
75 if (!isSupportedAttribute(attr->name())) {
76 SVGStyledTransformableElement::parseMappedAttribute(attr);
80 if (attr->name() == SVGNames::clipPathUnitsAttr) {
81 SVGUnitTypes::SVGUnitType propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(attr->value());
82 if (propertyValue > 0)
83 setClipPathUnitsBaseValue(propertyValue);
87 if (SVGTests::parseMappedAttribute(attr))
89 if (SVGLangSpace::parseMappedAttribute(attr))
91 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
97 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName)
99 if (!isSupportedAttribute(attrName)) {
100 SVGStyledTransformableElement::svgAttributeChanged(attrName);
104 SVGElementInstance::InvalidationGuard invalidationGuard(this);
106 if (RenderObject* object = renderer())
107 object->setNeedsLayout(true);
110 void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
112 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
117 if (RenderObject* object = renderer())
118 object->setNeedsLayout(true);
121 RenderObject* SVGClipPathElement::createRenderer(RenderArena* arena, RenderStyle*)
123 return new (arena) RenderSVGResourceClipper(this);
128 #endif // ENABLE(SVG)