Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGFEComponentTransferElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22
23 #include "core/svg/SVGFEComponentTransferElement.h"
24
25 #include "core/SVGNames.h"
26 #include "core/dom/ElementTraversal.h"
27 #include "core/svg/SVGFEFuncAElement.h"
28 #include "core/svg/SVGFEFuncBElement.h"
29 #include "core/svg/SVGFEFuncGElement.h"
30 #include "core/svg/SVGFEFuncRElement.h"
31 #include "core/svg/graphics/filters/SVGFilterBuilder.h"
32 #include "platform/graphics/filters/FilterEffect.h"
33
34 namespace blink {
35
36 inline SVGFEComponentTransferElement::SVGFEComponentTransferElement(Document& document)
37     : SVGFilterPrimitiveStandardAttributes(SVGNames::feComponentTransferTag, document)
38     , m_in1(SVGAnimatedString::create(this, SVGNames::inAttr, SVGString::create()))
39 {
40     addToPropertyMap(m_in1);
41 }
42
43 DEFINE_NODE_FACTORY(SVGFEComponentTransferElement)
44
45 bool SVGFEComponentTransferElement::isSupportedAttribute(const QualifiedName& attrName)
46 {
47     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
48     if (supportedAttributes.isEmpty())
49         supportedAttributes.add(SVGNames::inAttr);
50     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
51 }
52
53 void SVGFEComponentTransferElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
54 {
55     parseAttributeNew(name, value);
56 }
57
58 PassRefPtr<FilterEffect> SVGFEComponentTransferElement::build(SVGFilterBuilder* filterBuilder, Filter* filter)
59 {
60     FilterEffect* input1 = filterBuilder->getEffectById(AtomicString(m_in1->currentValue()->value()));
61
62     if (!input1)
63         return nullptr;
64
65     ComponentTransferFunction red;
66     ComponentTransferFunction green;
67     ComponentTransferFunction blue;
68     ComponentTransferFunction alpha;
69
70     for (SVGElement* element = Traversal<SVGElement>::firstChild(*this); element; element = Traversal<SVGElement>::nextSibling(*element)) {
71         if (isSVGFEFuncRElement(*element))
72             red = toSVGFEFuncRElement(*element).transferFunction();
73         else if (isSVGFEFuncGElement(*element))
74             green = toSVGFEFuncGElement(*element).transferFunction();
75         else if (isSVGFEFuncBElement(*element))
76             blue = toSVGFEFuncBElement(*element).transferFunction();
77         else if (isSVGFEFuncAElement(*element))
78             alpha = toSVGFEFuncAElement(*element).transferFunction();
79     }
80
81     RefPtr<FilterEffect> effect = FEComponentTransfer::create(filter, red, green, blue, alpha);
82     effect->inputEffects().append(input1);
83     return effect.release();
84 }
85
86 }