2 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "core/svg/SVGFEDropShadowElement.h"
23 #include "core/SVGNames.h"
24 #include "core/rendering/RenderObject.h"
25 #include "core/rendering/style/RenderStyle.h"
26 #include "core/rendering/style/SVGRenderStyle.h"
27 #include "core/svg/SVGParserUtilities.h"
28 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
32 inline SVGFEDropShadowElement::SVGFEDropShadowElement(Document& document)
33 : SVGFilterPrimitiveStandardAttributes(SVGNames::feDropShadowTag, document)
34 , m_dx(SVGAnimatedNumber::create(this, SVGNames::dxAttr, SVGNumber::create(2)))
35 , m_dy(SVGAnimatedNumber::create(this, SVGNames::dyAttr, SVGNumber::create(2)))
36 , m_stdDeviation(SVGAnimatedNumberOptionalNumber::create(this, SVGNames::stdDeviationAttr, 2, 2))
37 , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
39 addToPropertyMap(m_dx);
40 addToPropertyMap(m_dy);
41 addToPropertyMap(m_stdDeviation);
42 addToPropertyMap(m_in1);
45 DEFINE_NODE_FACTORY(SVGFEDropShadowElement)
47 void SVGFEDropShadowElement::setStdDeviation(float x, float y)
49 stdDeviationX()->baseValue()->setValue(x);
50 stdDeviationY()->baseValue()->setValue(y);
54 bool SVGFEDropShadowElement::isSupportedAttribute(const QualifiedName& attrName)
56 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
57 if (supportedAttributes.isEmpty()) {
58 supportedAttributes.add(SVGNames::inAttr);
59 supportedAttributes.add(SVGNames::dxAttr);
60 supportedAttributes.add(SVGNames::dyAttr);
61 supportedAttributes.add(SVGNames::stdDeviationAttr);
63 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
66 void SVGFEDropShadowElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
68 parseAttributeNew(name, value);
71 void SVGFEDropShadowElement::svgAttributeChanged(const QualifiedName& attrName)
73 if (!isSupportedAttribute(attrName)) {
74 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
78 SVGElement::InvalidationGuard invalidationGuard(this);
80 if (attrName == SVGNames::inAttr
81 || attrName == SVGNames::stdDeviationAttr
82 || attrName == SVGNames::dxAttr
83 || attrName == SVGNames::dyAttr) {
91 PassRefPtr<FilterEffect> SVGFEDropShadowElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
93 RenderObject* renderer = this->renderer();
97 if (stdDeviationX()->currentValue()->value() < 0 || stdDeviationY()->currentValue()->value() < 0)
100 ASSERT(renderer->style());
101 const SVGRenderStyle& svgStyle = renderer->style()->svgStyle();
103 Color color = svgStyle.floodColor();
104 float opacity = svgStyle.floodOpacity();
106 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
110 RefPtr<FilterEffect> effect = FEDropShadow::create(filter, stdDeviationX()->currentValue()->value(), stdDeviationY()->currentValue()->value(), m_dx->currentValue()->value(), m_dy->currentValue()->value(), color, opacity);
111 effect->inputEffects().append(input1);
112 return effect.release();