• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4  * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5  * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #include "config.h"
24 
25 #if ENABLE(FILTERS)
26 #include "FEFlood.h"
27 
28 #include "Filter.h"
29 #include "GraphicsContext.h"
30 #include "RenderTreeAsText.h"
31 #include "TextStream.h"
32 
33 namespace WebCore {
34 
FEFlood(Filter * filter,const Color & floodColor,float floodOpacity)35 FEFlood::FEFlood(Filter* filter, const Color& floodColor, float floodOpacity)
36     : FilterEffect(filter)
37     , m_floodColor(floodColor)
38     , m_floodOpacity(floodOpacity)
39 {
40 }
41 
create(Filter * filter,const Color & floodColor,float floodOpacity)42 PassRefPtr<FEFlood> FEFlood::create(Filter* filter, const Color& floodColor, float floodOpacity)
43 {
44     return adoptRef(new FEFlood(filter, floodColor, floodOpacity));
45 }
46 
floodColor() const47 Color FEFlood::floodColor() const
48 {
49     return m_floodColor;
50 }
51 
setFloodColor(const Color & color)52 bool FEFlood::setFloodColor(const Color& color)
53 {
54     if (m_floodColor == color)
55         return false;
56     m_floodColor = color;
57     return true;
58 }
59 
floodOpacity() const60 float FEFlood::floodOpacity() const
61 {
62     return m_floodOpacity;
63 }
64 
setFloodOpacity(float floodOpacity)65 bool FEFlood::setFloodOpacity(float floodOpacity)
66 {
67     if (m_floodOpacity == floodOpacity)
68         return false;
69     m_floodOpacity = floodOpacity;
70     return true;
71 }
72 
apply()73 void FEFlood::apply()
74 {
75     if (hasResult())
76         return;
77     ImageBuffer* resultImage = createImageBufferResult();
78     if (!resultImage)
79         return;
80 
81     Color color = colorWithOverrideAlpha(floodColor().rgb(), floodOpacity());
82     resultImage->context()->fillRect(FloatRect(FloatPoint(), absolutePaintRect().size()), color, ColorSpaceDeviceRGB);
83 }
84 
dump()85 void FEFlood::dump()
86 {
87 }
88 
externalRepresentation(TextStream & ts,int indent) const89 TextStream& FEFlood::externalRepresentation(TextStream& ts, int indent) const
90 {
91     writeIndent(ts, indent);
92     ts << "[feFlood";
93     FilterEffect::externalRepresentation(ts);
94     ts << " flood-color=\"" << floodColor().nameForRenderTreeAsText() << "\" "
95        << "flood-opacity=\"" << floodOpacity() << "\"]\n";
96     return ts;
97 }
98 
99 } // namespace WebCore
100 
101 #endif // ENABLE(FILTERS)
102