Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / layout / svg / LayoutSVGResourcePaintServer.h
blob28ec9a5dba668ffadf46b91d1a2d58e20afba64d
1 /*
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef LayoutSVGResourcePaintServer_h
21 #define LayoutSVGResourcePaintServer_h
23 #include "core/layout/svg/LayoutSVGResourceContainer.h"
24 #include "platform/graphics/Color.h"
25 #include "platform/graphics/Gradient.h"
26 #include "platform/graphics/Pattern.h"
27 #include "wtf/Allocator.h"
29 class SkPaint;
31 namespace blink {
33 enum LayoutSVGResourceMode {
34 ApplyToFillMode,
35 ApplyToStrokeMode,
38 class LayoutObject;
39 class LayoutSVGResourcePaintServer;
40 class ComputedStyle;
42 class SVGPaintServer {
43 STACK_ALLOCATED();
44 public:
45 explicit SVGPaintServer(Color);
46 explicit SVGPaintServer(PassRefPtr<Gradient>);
47 explicit SVGPaintServer(PassRefPtr<Pattern>);
49 static SVGPaintServer requestForLayoutObject(const LayoutObject&, const ComputedStyle&, LayoutSVGResourceMode);
50 static bool existsForLayoutObject(const LayoutObject&, const ComputedStyle&, LayoutSVGResourceMode);
52 void applyToSkPaint(SkPaint&, float paintAlpha);
54 static SVGPaintServer invalid() { return SVGPaintServer(Color(Color::transparent)); }
55 bool isValid() const { return m_color != Color::transparent; }
57 bool isTransformDependent() const { return m_gradient || m_pattern; }
58 void prependTransform(const AffineTransform&);
60 private:
61 RefPtr<Gradient> m_gradient;
62 RefPtr<Pattern> m_pattern;
63 Color m_color;
66 // If |SVGPaintDescription::hasFallback| is true, |SVGPaintDescription::color| is set to a fallback color.
67 struct SVGPaintDescription {
68 STACK_ALLOCATED();
69 SVGPaintDescription() : resource(nullptr), isValid(false), hasFallback(false) { }
70 SVGPaintDescription(Color color) : resource(nullptr), color(color), isValid(true), hasFallback(false) { }
71 SVGPaintDescription(LayoutSVGResourcePaintServer* resource) : resource(resource), isValid(true), hasFallback(false) { ASSERT(resource); }
72 SVGPaintDescription(LayoutSVGResourcePaintServer* resource, Color fallbackColor) : resource(resource), color(fallbackColor), isValid(true), hasFallback(true) { ASSERT(resource); }
74 LayoutSVGResourcePaintServer* resource;
75 Color color;
76 bool isValid;
77 bool hasFallback;
80 class LayoutSVGResourcePaintServer : public LayoutSVGResourceContainer {
81 public:
82 LayoutSVGResourcePaintServer(SVGElement*);
83 ~LayoutSVGResourcePaintServer() override;
85 virtual SVGPaintServer preparePaintServer(const LayoutObject&) = 0;
87 // Helper utilities used in to access the underlying resources for DRT.
88 static SVGPaintDescription requestPaintDescription(const LayoutObject&, const ComputedStyle&, LayoutSVGResourceMode);
91 DEFINE_TYPE_CASTS(LayoutSVGResourcePaintServer, LayoutSVGResourceContainer, resource, resource->isSVGPaintServer(), resource.isSVGPaintServer());
95 #endif