1 /*
2  * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2004, 2005, 2007, 2008 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 "third_party/blink/renderer/core/svg/svg_fe_flood_element.h"
22 
23 #include "third_party/blink/renderer/core/dom/node_computed_style.h"
24 #include "third_party/blink/renderer/core/style/computed_style.h"
25 #include "third_party/blink/renderer/core/style/svg_computed_style.h"
26 #include "third_party/blink/renderer/core/svg_names.h"
27 #include "third_party/blink/renderer/platform/graphics/filters/fe_flood.h"
28 #include "third_party/blink/renderer/platform/heap/heap.h"
29 
30 namespace blink {
31 
SVGFEFloodElement(Document & document)32 SVGFEFloodElement::SVGFEFloodElement(Document& document)
33     : SVGFilterPrimitiveStandardAttributes(svg_names::kFEFloodTag, document) {}
34 
SetFilterEffectAttribute(FilterEffect * effect,const QualifiedName & attr_name)35 bool SVGFEFloodElement::SetFilterEffectAttribute(
36     FilterEffect* effect,
37     const QualifiedName& attr_name) {
38   const ComputedStyle& style = ComputedStyleRef();
39 
40   FEFlood* flood = static_cast<FEFlood*>(effect);
41   if (attr_name == svg_names::kFloodColorAttr) {
42     return flood->SetFloodColor(
43         style.VisitedDependentColor(GetCSSPropertyFloodColor()));
44   }
45   if (attr_name == svg_names::kFloodOpacityAttr)
46     return flood->SetFloodOpacity(style.SvgStyle().FloodOpacity());
47 
48   return SVGFilterPrimitiveStandardAttributes::SetFilterEffectAttribute(
49       effect, attr_name);
50 }
51 
Build(SVGFilterBuilder *,Filter * filter)52 FilterEffect* SVGFEFloodElement::Build(SVGFilterBuilder*, Filter* filter) {
53   const ComputedStyle* style = GetComputedStyle();
54   if (!style)
55     return nullptr;
56 
57   Color color = style->VisitedDependentColor(GetCSSPropertyFloodColor());
58   float opacity = style->SvgStyle().FloodOpacity();
59 
60   return MakeGarbageCollected<FEFlood>(filter, color, opacity);
61 }
62 
TaintsOrigin() const63 bool SVGFEFloodElement::TaintsOrigin() const {
64   const ComputedStyle* style = GetComputedStyle();
65   // TaintsOrigin() is only called after a successful call to Build()
66   // (see above), so we should have a ComputedStyle here.
67   DCHECK(style);
68   return style->SvgStyle().FloodColor().IsCurrentColor();
69 }
70 
71 }  // namespace blink
72