]> git.saurik.com Git - iphone-api.git/blob - WebCore/Image.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / Image.h
1 /*
2 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
3 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
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 Image_h
28 #define Image_h
29
30 #include "Color.h"
31 #include "GraphicsTypes.h"
32 #include "ImageSource.h"
33 #include "IntRect.h"
34 #include <wtf/RefPtr.h>
35 #include <wtf/PassRefPtr.h>
36 #include "SharedBuffer.h"
37
38 #if PLATFORM(MAC)
39 #ifdef __OBJC__
40 @class NSImage;
41 #else
42 class NSImage;
43 #endif
44 #endif
45
46 #if PLATFORM(CG)
47 struct CGContext;
48 #endif
49
50 #if PLATFORM(WIN)
51 typedef struct tagSIZE SIZE;
52 typedef SIZE* LPSIZE;
53 typedef struct HBITMAP__ *HBITMAP;
54 #endif
55
56 #if PLATFORM(SKIA)
57 class NativeImageSkia;
58 #endif
59
60 #if PLATFORM(QT)
61 #include <QPixmap>
62 #endif
63
64 namespace WebCore {
65
66 class TransformationMatrix;
67 class FloatPoint;
68 class FloatRect;
69 class FloatSize;
70 class GraphicsContext;
71 class SharedBuffer;
72 class String;
73
74 // This class gets notified when an image creates or destroys decoded frames and when it advances animation frames.
75 class ImageObserver;
76
77 class Image : public RefCounted<Image> {
78 friend class GeneratedImage;
79 friend class GraphicsContext;
80 public:
81 virtual ~Image();
82
83 static PassRefPtr<Image> create(ImageObserver* = 0);
84 static PassRefPtr<Image> loadPlatformResource(const char* name);
85 static bool supportsType(const String&);
86
87 virtual bool isBitmapImage() const { return false; }
88
89 // Derived classes should override this if they can assure that
90 // the image contains only resources from its own security origin.
91 virtual bool hasSingleSecurityOrigin() const { return false; }
92
93 static Image* nullImage();
94 bool isNull() const { return size().isEmpty(); }
95
96 // These are only used for SVGImage right now
97 virtual void setContainerSize(const IntSize&) { }
98 virtual bool usesContainerSize() const { return false; }
99 virtual bool hasRelativeWidth() const { return false; }
100 virtual bool hasRelativeHeight() const { return false; }
101
102 virtual IntSize size() const = 0;
103 IntRect rect() const { return IntRect(IntPoint(), size()); }
104 int width() const { return size().width(); }
105 int height() const { return size().height(); }
106
107 bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived);
108 virtual bool dataChanged(bool /*allDataReceived*/) { return false; }
109
110 virtual String filenameExtension() const { return String(); } // null string if unknown
111
112 virtual void destroyDecodedData(bool destroyAll = true) = 0;
113 virtual unsigned decodedSize() const = 0;
114
115 SharedBuffer* data() { return m_data.get(); }
116
117 // Animation begins whenever someone draws the image, so startAnimation() is not normally called.
118 // It will automatically pause once all observers no longer want to render the image anywhere.
119 virtual void startAnimation(bool /*catchUpIfNecessary*/ = true) { }
120 virtual void stopAnimation() {}
121 virtual void resetAnimation() {}
122
123 // Typically the CachedImage that owns us.
124 ImageObserver* imageObserver() const { return m_imageObserver; }
125
126 enum TileRule { StretchTile, RoundTile, RepeatTile };
127
128 virtual NativeImagePtr nativeImageForCurrentFrame() { return 0; }
129
130 #if PLATFORM(MAC)
131 // Accessors for native image formats.
132 virtual NSImage* getNSImage() { return 0; }
133 virtual CFDataRef getTIFFRepresentation() { return 0; }
134 #endif
135
136 #if PLATFORM(CG)
137 virtual CGImageRef getCGImageRef() { return 0; }
138 #endif
139
140 #if PLATFORM(WIN)
141 virtual bool getHBITMAP(HBITMAP) { return false; }
142 virtual bool getHBITMAPOfSize(HBITMAP, LPSIZE) { return false; }
143 #endif
144
145 virtual unsigned animatedImageSize() { return 0; }
146 virtual void disableImageAnimation() { }
147
148 protected:
149 Image(ImageObserver* = 0);
150
151 static void fillWithSolidColor(GraphicsContext* ctxt, const FloatRect& dstRect, const Color& color, CompositeOperator op);
152
153 #if PLATFORM(WIN)
154 virtual void drawFrameMatchingSourceSize(GraphicsContext*, const FloatRect& dstRect, const IntSize& srcSize, CompositeOperator) { }
155 #endif
156 virtual void draw(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator) = 0;
157 void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatPoint& srcPoint, const FloatSize& tileSize, CompositeOperator);
158 void drawTiled(GraphicsContext*, const FloatRect& dstRect, const FloatRect& srcRect, TileRule hRule, TileRule vRule, CompositeOperator);
159
160 // Supporting tiled drawing
161 virtual bool mayFillWithSolidColor() const { return false; }
162 virtual Color solidColor() const { return Color(); }
163
164 virtual void drawPattern(GraphicsContext*, const FloatRect& srcRect, const TransformationMatrix& patternTransform,
165 const FloatPoint& phase, CompositeOperator, const FloatRect& destRect);
166 #if PLATFORM(CG)
167 // These are private to CG. Ideally they would be only in the .cpp file, but the callback requires access
168 // to the private function nativeImageForCurrentFrame()
169 static void drawPatternCallback(void* info, CGContext*);
170 #endif
171
172 protected:
173 RefPtr<SharedBuffer> m_data; // The encoded raw data for the image.
174 ImageObserver* m_imageObserver;
175 };
176
177 }
178
179 #endif