don't discard iframe children.
[kdelibs.git] / khtml / svg / graphics / SVGPaintServerGradient.h
blob345ea5e82e55cde6314794dba66ef0a20226ee49
1 /*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef SVGPaintServerGradient_h
27 #define SVGPaintServerGradient_h
29 #if ENABLE(SVG)
31 #include "AffineTransform.h"
32 #include "Color.h"
33 #include "SVGPaintServer.h"
35 #include <wtf/RefCounted.h>
36 #include <wtf/RefPtr.h>
38 #if PLATFORM(QT)
39 #include <qglobal.h>
40 QT_BEGIN_NAMESPACE
41 class QGradient;
42 QT_END_NAMESPACE
43 #endif
45 namespace WebCore {
47 class ImageBuffer;
48 class SVGGradientElement;
50 // FIXME: Remove the spread method enum in SVGGradientElement
51 enum SVGGradientSpreadMethod {
52 SPREADMETHOD_PAD = 1,
53 SPREADMETHOD_REFLECT = 2,
54 SPREADMETHOD_REPEAT = 3
57 #if PLATFORM(CG)
58 typedef std::pair<CGFloat, Color> SVGGradientStop;
59 #else
60 typedef std::pair<float, Color> SVGGradientStop;
61 #endif
64 class SVGPaintServerGradient : public SVGPaintServer {
65 public:
66 virtual ~SVGPaintServerGradient();
68 const Vector<SVGGradientStop>& gradientStops() const;
69 void setGradientStops(const Vector<SVGGradientStop>&);
71 SVGGradientSpreadMethod spreadMethod() const;
72 void setGradientSpreadMethod(const SVGGradientSpreadMethod&);
74 // Gradient start and end points are percentages when used in boundingBox mode.
75 // For instance start point with value (0,0) is top-left and end point with
76 // value (100, 100) is bottom-right. BoundingBox mode is enabled by default.
77 bool boundingBoxMode() const;
78 void setBoundingBoxMode(bool mode = true);
80 AffineTransform gradientTransform() const;
81 void setGradientTransform(const AffineTransform&);
83 /*virtual TextStream& externalRepresentation(TextStream&) const;*/
85 virtual bool setup(QPainter* painter, QPainterPath* path, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
86 #if PLATFORM(CG)
87 virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
88 virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const;
90 virtual void invalidate();
92 // Helpers
93 void updateQuartzGradientStopsCache(const Vector<SVGGradientStop>&);
94 void updateQuartzGradientCache(const SVGPaintServerGradient*);
95 void handleBoundingBoxModeAndGradientTransformation(GraphicsContext*, const FloatRect& targetRect) const;
96 #endif
98 #if PLATFORM(QT)
99 protected:
100 void fillColorArray(QGradient&, const Vector<SVGGradientStop>&, float opacity) const;
101 virtual QGradient setupGradient(QPainter* painter, QPainterPath* painterPath, const RenderObject*) const = 0;
102 #endif
104 protected:
105 SVGPaintServerGradient(const SVGGradientElement* owner);
107 private:
108 Vector<SVGGradientStop> m_stops;
109 SVGGradientSpreadMethod m_spreadMethod;
110 bool m_boundingBoxMode;
111 AffineTransform m_gradientTransform;
112 const SVGGradientElement* m_ownerElement;
114 #if PLATFORM(CG)
115 public:
116 typedef struct {
117 CGFloat colorArray[4];
118 CGFloat offset;
119 CGFloat previousDeltaInverse;
120 } QuartzGradientStop;
122 struct SharedStopCache : public RefCounted<SharedStopCache> {
123 public:
124 static PassRefPtr<SharedStopCache> create() { return adoptRef(new SharedStopCache); }
126 Vector<QuartzGradientStop> m_stops;
128 private:
129 SharedStopCache() { }
132 RefPtr<SharedStopCache> m_stopsCache;
134 CGShadingRef m_shadingCache;
135 mutable GraphicsContext* m_savedContext;
136 mutable ImageBuffer* m_imageBuffer;
137 #endif
140 inline SVGGradientStop makeGradientStop(float offset, const Color& color)
142 return std::make_pair(offset, color);
145 } // namespace WebCore
147 #endif
149 #endif // SVGPaintServerGradient_h