2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Oliver Hunt <oliver@nerget.com>
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.
23 #include "core/svg/SVGFELightElement.h"
25 #include "core/SVGNames.h"
26 #include "core/dom/ElementTraversal.h"
27 #include "core/rendering/RenderObject.h"
28 #include "core/svg/SVGFEDiffuseLightingElement.h"
29 #include "core/svg/SVGFESpecularLightingElement.h"
33 SVGFELightElement::SVGFELightElement(const QualifiedName& tagName, Document& document)
34 : SVGElement(tagName, document)
35 , m_azimuth(SVGAnimatedNumber::create(this, SVGNames::azimuthAttr, SVGNumber::create()))
36 , m_elevation(SVGAnimatedNumber::create(this, SVGNames::elevationAttr, SVGNumber::create()))
37 , m_x(SVGAnimatedNumber::create(this, SVGNames::xAttr, SVGNumber::create()))
38 , m_y(SVGAnimatedNumber::create(this, SVGNames::yAttr, SVGNumber::create()))
39 , m_z(SVGAnimatedNumber::create(this, SVGNames::zAttr, SVGNumber::create()))
40 , m_pointsAtX(SVGAnimatedNumber::create(this, SVGNames::pointsAtXAttr, SVGNumber::create()))
41 , m_pointsAtY(SVGAnimatedNumber::create(this, SVGNames::pointsAtYAttr, SVGNumber::create()))
42 , m_pointsAtZ(SVGAnimatedNumber::create(this, SVGNames::pointsAtZAttr, SVGNumber::create()))
43 , m_specularExponent(SVGAnimatedNumber::create(this, SVGNames::specularExponentAttr, SVGNumber::create(1)))
44 , m_limitingConeAngle(SVGAnimatedNumber::create(this, SVGNames::limitingConeAngleAttr, SVGNumber::create()))
46 addToPropertyMap(m_azimuth);
47 addToPropertyMap(m_elevation);
48 addToPropertyMap(m_x);
49 addToPropertyMap(m_y);
50 addToPropertyMap(m_z);
51 addToPropertyMap(m_pointsAtX);
52 addToPropertyMap(m_pointsAtY);
53 addToPropertyMap(m_pointsAtZ);
54 addToPropertyMap(m_specularExponent);
55 addToPropertyMap(m_limitingConeAngle);
58 SVGFELightElement* SVGFELightElement::findLightElement(const SVGElement& svgElement)
60 return Traversal<SVGFELightElement>::firstChild(svgElement);
63 FloatPoint3D SVGFELightElement::position() const
65 return FloatPoint3D(x()->currentValue()->value(), y()->currentValue()->value(), z()->currentValue()->value());
68 FloatPoint3D SVGFELightElement::pointsAt() const
70 return FloatPoint3D(pointsAtX()->currentValue()->value(), pointsAtY()->currentValue()->value(), pointsAtZ()->currentValue()->value());
73 bool SVGFELightElement::isSupportedAttribute(const QualifiedName& attrName)
75 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
76 if (supportedAttributes.isEmpty()) {
77 supportedAttributes.add(SVGNames::azimuthAttr);
78 supportedAttributes.add(SVGNames::elevationAttr);
79 supportedAttributes.add(SVGNames::xAttr);
80 supportedAttributes.add(SVGNames::yAttr);
81 supportedAttributes.add(SVGNames::zAttr);
82 supportedAttributes.add(SVGNames::pointsAtXAttr);
83 supportedAttributes.add(SVGNames::pointsAtYAttr);
84 supportedAttributes.add(SVGNames::pointsAtZAttr);
85 supportedAttributes.add(SVGNames::specularExponentAttr);
86 supportedAttributes.add(SVGNames::limitingConeAngleAttr);
88 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
91 void SVGFELightElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
93 parseAttributeNew(name, value);
96 void SVGFELightElement::svgAttributeChanged(const QualifiedName& attrName)
98 if (!isSupportedAttribute(attrName)) {
99 SVGElement::svgAttributeChanged(attrName);
103 SVGElement::InvalidationGuard invalidationGuard(this);
105 if (attrName == SVGNames::azimuthAttr
106 || attrName == SVGNames::elevationAttr
107 || attrName == SVGNames::xAttr
108 || attrName == SVGNames::yAttr
109 || attrName == SVGNames::zAttr
110 || attrName == SVGNames::pointsAtXAttr
111 || attrName == SVGNames::pointsAtYAttr
112 || attrName == SVGNames::pointsAtZAttr
113 || attrName == SVGNames::specularExponentAttr
114 || attrName == SVGNames::limitingConeAngleAttr) {
115 ContainerNode* parent = parentNode();
119 RenderObject* renderer = parent->renderer();
120 if (!renderer || !renderer->isSVGResourceFilterPrimitive())
123 if (isSVGFEDiffuseLightingElement(*parent)) {
124 toSVGFEDiffuseLightingElement(*parent).lightElementAttributeChanged(this, attrName);
127 if (isSVGFESpecularLightingElement(*parent)) {
128 toSVGFESpecularLightingElement(*parent).lightElementAttributeChanged(this, attrName);
133 ASSERT_NOT_REACHED();
136 void SVGFELightElement::childrenChanged(const ChildrenChange& change)
138 SVGElement::childrenChanged(change);
140 if (!change.byParser) {
141 if (ContainerNode* parent = parentNode()) {
142 RenderObject* renderer = parent->renderer();
143 if (renderer && renderer->isSVGResourceFilterPrimitive())
144 markForLayoutAndParentResourceInvalidation(renderer);