1 /*
2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3  * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
4  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_SVG_LAYOUT_SVG_RESOURCE_GRADIENT_H_
23 #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_SVG_LAYOUT_SVG_RESOURCE_GRADIENT_H_
24 
25 #include <memory>
26 #include "third_party/blink/renderer/core/layout/svg/layout_svg_resource_paint_server.h"
27 #include "third_party/blink/renderer/core/svg/svg_gradient_element.h"
28 #include "third_party/blink/renderer/platform/transforms/affine_transform.h"
29 #include "third_party/blink/renderer/platform/wtf/hash_map.h"
30 
31 namespace blink {
32 
33 struct GradientData;
34 
35 class LayoutSVGResourceGradient : public LayoutSVGResourcePaintServer {
36  public:
37   explicit LayoutSVGResourceGradient(SVGGradientElement*);
38 
39   void RemoveAllClientsFromCache() final;
40   bool RemoveClientFromCache(SVGResourceClient&) final;
41 
42   bool ApplyShader(const SVGResourceClient&,
43                    const FloatRect& reference_box,
44                    const AffineTransform* additional_transform,
45                    PaintFlags&) final;
46 
47   bool IsChildAllowed(LayoutObject* child, const ComputedStyle&) const final;
48 
49  protected:
50   virtual SVGUnitTypes::SVGUnitType GradientUnits() const = 0;
51   virtual AffineTransform CalculateGradientTransform() const = 0;
52   virtual void CollectGradientAttributes() = 0;
53   virtual scoped_refptr<Gradient> BuildGradient() const = 0;
54 
55   static GradientSpreadMethod PlatformSpreadMethodFromSVGType(
56       SVGSpreadMethodType);
57 
58  private:
59   std::unique_ptr<GradientData> BuildGradientData(
60       const FloatRect& object_bounding_box);
61 
62   bool should_collect_gradient_attributes_ : 1;
63   using GradientMap = HeapHashMap<Member<const SVGResourceClient>,
64                                   std::unique_ptr<GradientData>>;
65   Persistent<GradientMap> gradient_map_;
66 };
67 
68 }  // namespace blink
69 
70 #endif
71