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 "CSSStyleSelector.h"
29 #include "Document.h"
30 #include "RenderSVGResourceClipper.h"
31 #include "SVGNames.h"
32 #include "SVGTransformList.h"
33 #include "SVGUnitTypes.h"
34
35 namespace WebCore {
36
37 // Animated property definitions
DEFINE_ANIMATED_ENUMERATION(SVGClipPathElement,SVGNames::clipPathUnitsAttr,ClipPathUnits,clipPathUnits)38 DEFINE_ANIMATED_ENUMERATION(SVGClipPathElement, SVGNames::clipPathUnitsAttr, ClipPathUnits, clipPathUnits)
39 DEFINE_ANIMATED_BOOLEAN(SVGClipPathElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
40
41 inline SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document* document)
42 : SVGStyledTransformableElement(tagName, document)
43 , m_clipPathUnits(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE)
44 {
45 }
46
create(const QualifiedName & tagName,Document * document)47 PassRefPtr<SVGClipPathElement> SVGClipPathElement::create(const QualifiedName& tagName, Document* document)
48 {
49 return adoptRef(new SVGClipPathElement(tagName, document));
50 }
51
parseMappedAttribute(Attribute * attr)52 void SVGClipPathElement::parseMappedAttribute(Attribute* attr)
53 {
54 if (attr->name() == SVGNames::clipPathUnitsAttr) {
55 if (attr->value() == "userSpaceOnUse")
56 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE);
57 else if (attr->value() == "objectBoundingBox")
58 setClipPathUnitsBaseValue(SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX);
59 } else {
60 if (SVGTests::parseMappedAttribute(attr))
61 return;
62 if (SVGLangSpace::parseMappedAttribute(attr))
63 return;
64 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
65 return;
66 SVGStyledTransformableElement::parseMappedAttribute(attr);
67 }
68 }
69
svgAttributeChanged(const QualifiedName & attrName)70 void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName)
71 {
72 SVGStyledTransformableElement::svgAttributeChanged(attrName);
73
74 RenderObject* object = renderer();
75 if (!object)
76 return;
77
78 if (attrName == SVGNames::clipPathUnitsAttr
79 || SVGTests::isKnownAttribute(attrName)
80 || SVGLangSpace::isKnownAttribute(attrName)
81 || SVGExternalResourcesRequired::isKnownAttribute(attrName)
82 || SVGStyledTransformableElement::isKnownAttribute(attrName))
83 object->setNeedsLayout(true);
84 }
85
synchronizeProperty(const QualifiedName & attrName)86 void SVGClipPathElement::synchronizeProperty(const QualifiedName& attrName)
87 {
88 SVGStyledTransformableElement::synchronizeProperty(attrName);
89
90 if (attrName == anyQName()) {
91 synchronizeClipPathUnits();
92 synchronizeExternalResourcesRequired();
93 SVGTests::synchronizeProperties(this, attrName);
94 return;
95 }
96
97 if (attrName == SVGNames::clipPathUnitsAttr)
98 synchronizeClipPathUnits();
99 else if (SVGExternalResourcesRequired::isKnownAttribute(attrName))
100 synchronizeExternalResourcesRequired();
101 else if (SVGTests::isKnownAttribute(attrName))
102 SVGTests::synchronizeProperties(this, attrName);
103 }
104
attributeToPropertyTypeMap()105 AttributeToPropertyTypeMap& SVGClipPathElement::attributeToPropertyTypeMap()
106 {
107 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
108 return s_attributeToPropertyTypeMap;
109 }
110
fillAttributeToPropertyTypeMap()111 void SVGClipPathElement::fillAttributeToPropertyTypeMap()
112 {
113 AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
114
115 SVGStyledTransformableElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
116 attributeToPropertyTypeMap.set(SVGNames::clipPathUnitsAttr, AnimatedEnumeration);
117 }
118
childrenChanged(bool changedByParser,Node * beforeChange,Node * afterChange,int childCountDelta)119 void SVGClipPathElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
120 {
121 SVGStyledTransformableElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
122
123 if (changedByParser)
124 return;
125
126 if (RenderObject* object = renderer())
127 object->setNeedsLayout(true);
128 }
129
createRenderer(RenderArena * arena,RenderStyle *)130 RenderObject* SVGClipPathElement::createRenderer(RenderArena* arena, RenderStyle*)
131 {
132 return new (arena) RenderSVGResourceClipper(this);
133 }
134
135 }
136
137 #endif // ENABLE(SVG)
138