blob: eb8e184850cc77bd391fcc5695018306fc311ba7 [file] [log] [blame]
zimmermann@webkit.org9b559322010-04-22 13:50:44 +00001/*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * 2008 Eric Seidel <eric@webkit.org>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef RenderSVGResourceGradient_h
28#define RenderSVGResourceGradient_h
29
30#if ENABLE(SVG)
31
32#include "AffineTransform.h"
33#include "Color.h"
34#include "Gradient.h"
35#include "GraphicsContext.h"
36#include "SVGPaintServer.h"
37
38#include <wtf/RefCounted.h>
39#include <wtf/RefPtr.h>
40
41namespace WebCore {
42
43class ImageBuffer;
44class SVGGradientElement;
45
46typedef std::pair<float, Color> SVGGradientStop;
47
48class SVGPaintServerGradient : public SVGPaintServer {
49public:
50 virtual ~SVGPaintServerGradient();
51
52 void setGradient(PassRefPtr<Gradient>);
53 Gradient* gradient() const;
54
55 // Gradient start and end points are percentages when used in boundingBox mode.
56 // For instance start point with value (0,0) is top-left and end point with
57 // value (100, 100) is bottom-right. BoundingBox mode is enabled by default.
58 bool boundingBoxMode() const;
59 void setBoundingBoxMode(bool mode = true);
60
61 AffineTransform gradientTransform() const;
62 void setGradientTransform(const AffineTransform&);
63
64 void setGradientStops(const Vector<SVGGradientStop>& stops) { m_stops = stops; }
65 const Vector<SVGGradientStop>& gradientStops() const { return m_stops; }
66
67 virtual TextStream& externalRepresentation(TextStream&) const;
68
69 virtual bool setup(GraphicsContext*&, const RenderObject*, const RenderStyle*, SVGPaintTargetType, bool isPaintingText) const;
70 virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
71
72protected:
73 SVGPaintServerGradient(const SVGGradientElement* owner);
74
75private:
76 Vector<SVGGradientStop> m_stops;
77 RefPtr<Gradient> m_gradient;
78 bool m_boundingBoxMode;
79 AffineTransform m_gradientTransform;
80 const SVGGradientElement* m_ownerElement;
81
82#if PLATFORM(CG)
83public:
84 mutable GraphicsContext* m_savedContext;
85 mutable OwnPtr<ImageBuffer> m_imageBuffer;
86#endif
87};
88
89inline SVGGradientStop makeGradientStop(float offset, const Color& color)
90{
91 return std::make_pair(offset, color);
92}
93
94} // namespace WebCore
95
96#endif
97
98#endif // RenderSVGResourceGradient_h