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 DCHECK(GetElement());
38 attributes_wrapper_->Set(LinearGradientAttributes());
39 To<SVGLinearGradientElement>(GetElement())
40 ->CollectGradientAttributes(MutableAttributes());
41 }
42
StartPoint(const LinearGradientAttributes & attributes) const43 FloatPoint LayoutSVGResourceLinearGradient::StartPoint(
44 const LinearGradientAttributes& attributes) const {
45 return SVGLengthContext::ResolvePoint(GetElement(),
46 attributes.GradientUnits(),
47 *attributes.X1(), *attributes.Y1());
48 }
49
EndPoint(const LinearGradientAttributes & attributes) const50 FloatPoint LayoutSVGResourceLinearGradient::EndPoint(
51 const LinearGradientAttributes& attributes) const {
52 return SVGLengthContext::ResolvePoint(GetElement(),
53 attributes.GradientUnits(),
54 *attributes.X2(), *attributes.Y2());
55 }
56
BuildGradient() const57 scoped_refptr<Gradient> LayoutSVGResourceLinearGradient::BuildGradient() const {
58 const LinearGradientAttributes& attributes = Attributes();
59 scoped_refptr<Gradient> gradient = Gradient::CreateLinear(
60 StartPoint(attributes), EndPoint(attributes),
61 PlatformSpreadMethodFromSVGType(attributes.SpreadMethod()),
62 Gradient::ColorInterpolation::kUnpremultiplied,
63 Gradient::DegenerateHandling::kAllow);
64 gradient->AddColorStops(attributes.Stops());
65 return gradient;
66 }
67
68 } // namespace blink
69