1 /*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
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/layout/svg/layout_svg_resource_linear_gradient.h"
22
23 #include "third_party/blink/renderer/core/svg/svg_linear_gradient_element.h"
24 #include "third_party/blink/renderer/platform/heap/heap.h"
25
26 namespace blink {
27
LayoutSVGResourceLinearGradient(SVGLinearGradientElement * node)28 LayoutSVGResourceLinearGradient::LayoutSVGResourceLinearGradient(
29 SVGLinearGradientElement* node)
30 : LayoutSVGResourceGradient(node),
31 attributes_wrapper_(
32 MakeGarbageCollected<LinearGradientAttributesWrapper>()) {}
33
34 LayoutSVGResourceLinearGradient::~LayoutSVGResourceLinearGradient() = default;
35
CollectGradientAttributes()36 void LayoutSVGResourceLinearGradient::CollectGradientAttributes() {
37 NOT_DESTROYED();
38 DCHECK(GetElement());
39 attributes_wrapper_->Set(LinearGradientAttributes());
40 To<SVGLinearGradientElement>(GetElement())
41 ->CollectGradientAttributes(MutableAttributes());
42 }
43
StartPoint(const LinearGradientAttributes & attributes) const44 FloatPoint LayoutSVGResourceLinearGradient::StartPoint(
45 const LinearGradientAttributes& attributes) const {
46 NOT_DESTROYED();
47 return SVGLengthContext::ResolvePoint(GetElement(),
48 attributes.GradientUnits(),
49 *attributes.X1(), *attributes.Y1());
50 }
51
EndPoint(const LinearGradientAttributes & attributes) const52 FloatPoint LayoutSVGResourceLinearGradient::EndPoint(
53 const LinearGradientAttributes& attributes) const {
54 NOT_DESTROYED();
55 return SVGLengthContext::ResolvePoint(GetElement(),
56 attributes.GradientUnits(),
57 *attributes.X2(), *attributes.Y2());
58 }
59
BuildGradient() const60 scoped_refptr<Gradient> LayoutSVGResourceLinearGradient::BuildGradient() const {
61 NOT_DESTROYED();
62 const LinearGradientAttributes& attributes = Attributes();
63 scoped_refptr<Gradient> gradient = Gradient::CreateLinear(
64 StartPoint(attributes), EndPoint(attributes),
65 PlatformSpreadMethodFromSVGType(attributes.SpreadMethod()),
66 Gradient::ColorInterpolation::kUnpremultiplied,
67 Gradient::DegenerateHandling::kAllow);
68 gradient->AddColorStops(attributes.Stops());
69 return gradient;
70 }
71
72 } // namespace blink
73