Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGFELightElement.cpp
1 /*
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>
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 #include "core/svg/SVGFELightElement.h"
24
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"
30
31 namespace blink {
32
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()))
45 {
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);
56 }
57
58 SVGFELightElement* SVGFELightElement::findLightElement(const SVGElement& svgElement)
59 {
60     return Traversal<SVGFELightElement>::firstChild(svgElement);
61 }
62
63 FloatPoint3D SVGFELightElement::position() const
64 {
65     return FloatPoint3D(x()->currentValue()->value(), y()->currentValue()->value(), z()->currentValue()->value());
66 }
67
68 FloatPoint3D SVGFELightElement::pointsAt() const
69 {
70     return FloatPoint3D(pointsAtX()->currentValue()->value(), pointsAtY()->currentValue()->value(), pointsAtZ()->currentValue()->value());
71 }
72
73 bool SVGFELightElement::isSupportedAttribute(const QualifiedName& attrName)
74 {
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);
87     }
88     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
89 }
90
91 void SVGFELightElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
92 {
93     parseAttributeNew(name, value);
94 }
95
96 void SVGFELightElement::svgAttributeChanged(const QualifiedName& attrName)
97 {
98     if (!isSupportedAttribute(attrName)) {
99         SVGElement::svgAttributeChanged(attrName);
100         return;
101     }
102
103     SVGElement::InvalidationGuard invalidationGuard(this);
104
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();
116         if (!parent)
117             return;
118
119         RenderObject* renderer = parent->renderer();
120         if (!renderer || !renderer->isSVGResourceFilterPrimitive())
121             return;
122
123         if (isSVGFEDiffuseLightingElement(*parent)) {
124             toSVGFEDiffuseLightingElement(*parent).lightElementAttributeChanged(this, attrName);
125             return;
126         }
127         if (isSVGFESpecularLightingElement(*parent)) {
128             toSVGFESpecularLightingElement(*parent).lightElementAttributeChanged(this, attrName);
129             return;
130         }
131     }
132
133     ASSERT_NOT_REACHED();
134 }
135
136 void SVGFELightElement::childrenChanged(const ChildrenChange& change)
137 {
138     SVGElement::childrenChanged(change);
139
140     if (!change.byParser) {
141         if (ContainerNode* parent = parentNode()) {
142             RenderObject* renderer = parent->renderer();
143             if (renderer && renderer->isSVGResourceFilterPrimitive())
144                 markForLayoutAndParentResourceInvalidation(renderer);
145         }
146     }
147 }
148
149 }