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