• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 SVGPaintServerGradient_h
28 #define SVGPaintServerGradient_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 
41 namespace WebCore {
42 
43     class ImageBuffer;
44     class SVGGradientElement;
45 
46     typedef std::pair<float, Color> SVGGradientStop;
47 
48     class SVGPaintServerGradient : public SVGPaintServer {
49     public:
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 
setGradientStops(const Vector<SVGGradientStop> & stops)64         void setGradientStops(const Vector<SVGGradientStop>& stops) { m_stops = stops; }
gradientStops()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 
72     protected:
73         SVGPaintServerGradient(const SVGGradientElement* owner);
74 
75     private:
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)
83     public:
84         mutable GraphicsContext* m_savedContext;
85         mutable OwnPtr<ImageBuffer> m_imageBuffer;
86 #endif
87     };
88 
makeGradientStop(float offset,const Color & color)89     inline 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 // SVGPaintServerGradient_h
99