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.
22 #include "core/svg/SVGFEDropShadowElement.h"
24 #include "core/SVGNames.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 ScriptWrappable::init(this);
41 addToPropertyMap(m_dx);
42 addToPropertyMap(m_dy);
43 addToPropertyMap(m_stdDeviation);
44 addToPropertyMap(m_in1);
47 DEFINE_NODE_FACTORY(SVGFEDropShadowElement)
49 void SVGFEDropShadowElement::setStdDeviation(float x, float y)
51 stdDeviationX()->baseValue()->setValue(x);
52 stdDeviationY()->baseValue()->setValue(y);
56 bool SVGFEDropShadowElement::isSupportedAttribute(const QualifiedName& attrName)
58 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
59 if (supportedAttributes.isEmpty()) {
60 supportedAttributes.add(SVGNames::inAttr);
61 supportedAttributes.add(SVGNames::dxAttr);
62 supportedAttributes.add(SVGNames::dyAttr);
63 supportedAttributes.add(SVGNames::stdDeviationAttr);
65 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
68 void SVGFEDropShadowElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
70 if (!isSupportedAttribute(name)) {
71 SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value);
75 SVGParsingError parseError = NoError;
77 if (name == SVGNames::inAttr)
78 m_in1->setBaseValueAsString(value, parseError);
79 else if (name == SVGNames::dxAttr)
80 m_dx->setBaseValueAsString(value, parseError);
81 else if (name == SVGNames::dyAttr)
82 m_dy->setBaseValueAsString(value, parseError);
83 else if (name == SVGNames::stdDeviationAttr)
84 m_stdDeviation->setBaseValueAsString(value, parseError);
88 reportAttributeParsingError(parseError, name, value);
91 void SVGFEDropShadowElement::svgAttributeChanged(const QualifiedName& attrName)
93 if (!isSupportedAttribute(attrName)) {
94 SVGFilterPrimitiveStandardAttributes::svgAttributeChanged(attrName);
98 SVGElement::InvalidationGuard invalidationGuard(this);
100 if (attrName == SVGNames::inAttr
101 || attrName == SVGNames::stdDeviationAttr
102 || attrName == SVGNames::dxAttr
103 || attrName == SVGNames::dyAttr) {
108 ASSERT_NOT_REACHED();
111 PassRefPtr<FilterEffect> SVGFEDropShadowElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
113 RenderObject* renderer = this->renderer();
117 if (stdDeviationX()->currentValue()->value() < 0 || stdDeviationY()->currentValue()->value() < 0)
120 ASSERT(renderer->style());
121 const SVGRenderStyle& svgStyle = renderer->style()->svgStyle();
123 Color color = svgStyle.floodColor();
124 float opacity = svgStyle.floodOpacity();
126 FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
130 RefPtr<FilterEffect> effect = FEDropShadow::create(filter, stdDeviationX()->currentValue()->value(), stdDeviationY()->currentValue()->value(), m_dx->currentValue()->value(), m_dy->currentValue()->value(), color, opacity);
131 effect->inputEffects().append(input1);
132 return effect.release();