OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | |
3 * | |
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. | |
12 * | |
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. | |
24 */ | |
25 | |
26 #ifndef CanvasRenderingContext2D_h | |
27 #define CanvasRenderingContext2D_h | |
28 | |
29 #include "AffineTransform.h" | |
30 #include "FloatSize.h" | |
31 #include "Font.h" | |
32 #include "GraphicsTypes.h" | |
33 #include "Path.h" | |
34 #include "PlatformString.h" | |
35 #include <wtf/Vector.h> | |
36 | |
37 #if PLATFORM(CG) | |
38 #include <ApplicationServices/ApplicationServices.h> | |
39 #endif | |
40 | |
41 namespace WebCore { | |
42 | |
43 class CanvasGradient; | |
44 class CanvasPattern; | |
45 class CanvasStyle; | |
46 class FloatRect; | |
47 class GraphicsContext; | |
48 class HTMLCanvasElement; | |
49 class HTMLImageElement; | |
50 class ImageData; | |
51 class KURL; | |
52 class TextMetrics; | |
53 | |
54 typedef int ExceptionCode; | |
55 | |
56 class CanvasRenderingContext2D : | |
57 #if USE(V8) | |
58 Peerable // Already has Noncopyable as a superclass. | |
59 #else | |
60 Noncopyable | |
61 #endif | |
62 { | |
63 public: | |
64 CanvasRenderingContext2D(HTMLCanvasElement*); | |
65 | |
66 void ref(); | |
67 void deref(); | |
68 | |
69 #if USE(V8) | |
70 virtual void setPeer(void* peer) | |
71 { | |
72 ASSERT(m_peer != peer); | |
73 if (peer) | |
74 ref(); | |
75 else | |
76 deref(); | |
77 m_peer = peer; | |
78 | |
79 } | |
80 virtual void* peer() const | |
81 { | |
82 return m_peer; | |
83 } | |
84 #endif | |
85 | |
86 HTMLCanvasElement* canvas() const { return m_canvas; } | |
87 | |
88 CanvasStyle* strokeStyle() const; | |
89 void setStrokeStyle(PassRefPtr<CanvasStyle>); | |
90 | |
91 CanvasStyle* fillStyle() const; | |
92 void setFillStyle(PassRefPtr<CanvasStyle>); | |
93 | |
94 float lineWidth() const; | |
95 void setLineWidth(float); | |
96 | |
97 String lineCap() const; | |
98 void setLineCap(const String&); | |
99 | |
100 String lineJoin() const; | |
101 void setLineJoin(const String&); | |
102 | |
103 float miterLimit() const; | |
104 void setMiterLimit(float); | |
105 | |
106 float shadowOffsetX() const; | |
107 void setShadowOffsetX(float); | |
108 | |
109 float shadowOffsetY() const; | |
110 void setShadowOffsetY(float); | |
111 | |
112 float shadowBlur() const; | |
113 void setShadowBlur(float); | |
114 | |
115 String shadowColor() const; | |
116 void setShadowColor(const String&); | |
117 | |
118 float globalAlpha() const; | |
119 void setGlobalAlpha(float); | |
120 | |
121 String globalCompositeOperation() const; | |
122 void setGlobalCompositeOperation(const String&); | |
123 | |
124 void save(); | |
125 void restore(); | |
126 | |
127 void scale(float sx, float sy); | |
128 void rotate(float angleInRadians); | |
129 void translate(float tx, float ty); | |
130 void transform(float m11, float m12, float m21, float m22, float dx, flo
at dy); | |
131 | |
132 void setStrokeColor(const String& color); | |
133 void setStrokeColor(float grayLevel); | |
134 void setStrokeColor(const String& color, float alpha); | |
135 void setStrokeColor(float grayLevel, float alpha); | |
136 void setStrokeColor(float r, float g, float b, float a); | |
137 void setStrokeColor(float c, float m, float y, float k, float a); | |
138 | |
139 void setFillColor(const String& color); | |
140 void setFillColor(float grayLevel); | |
141 void setFillColor(const String& color, float alpha); | |
142 void setFillColor(float grayLevel, float alpha); | |
143 void setFillColor(float r, float g, float b, float a); | |
144 void setFillColor(float c, float m, float y, float k, float a); | |
145 | |
146 void beginPath(); | |
147 void closePath(); | |
148 | |
149 void moveTo(float x, float y); | |
150 void lineTo(float x, float y); | |
151 void quadraticCurveTo(float cpx, float cpy, float x, float y); | |
152 void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float
x, float y); | |
153 void arcTo(float x0, float y0, float x1, float y1, float radius, Excepti
onCode&); | |
154 void arc(float x, float y, float r, float sa, float ea, bool clockwise,
ExceptionCode&); | |
155 void rect(float x, float y, float width, float height); | |
156 | |
157 void fill(); | |
158 void stroke(); | |
159 void clip(); | |
160 | |
161 bool isPointInPath(const float x, const float y); | |
162 | |
163 void clearRect(float x, float y, float width, float height); | |
164 void fillRect(float x, float y, float width, float height); | |
165 void strokeRect(float x, float y, float width, float height); | |
166 void strokeRect(float x, float y, float width, float height, float lineW
idth); | |
167 | |
168 void setShadow(float width, float height, float blur); | |
169 void setShadow(float width, float height, float blur, const String& colo
r); | |
170 void setShadow(float width, float height, float blur, float grayLevel); | |
171 void setShadow(float width, float height, float blur, const String& colo
r, float alpha); | |
172 void setShadow(float width, float height, float blur, float grayLevel, f
loat alpha); | |
173 void setShadow(float width, float height, float blur, float r, float g,
float b, float a); | |
174 void setShadow(float width, float height, float blur, float c, float m,
float y, float k, float a); | |
175 | |
176 void clearShadow(); | |
177 | |
178 void drawImage(HTMLImageElement*, float x, float y); | |
179 void drawImage(HTMLImageElement*, float x, float y, float width, float h
eight, ExceptionCode&); | |
180 void drawImage(HTMLImageElement*, const FloatRect& srcRect, const FloatR
ect& dstRect, ExceptionCode&); | |
181 void drawImage(HTMLCanvasElement*, float x, float y); | |
182 void drawImage(HTMLCanvasElement*, float x, float y, float width, float
height, ExceptionCode&); | |
183 void drawImage(HTMLCanvasElement*, const FloatRect& srcRect, const Float
Rect& dstRect, ExceptionCode&); | |
184 | |
185 void drawImageFromRect(HTMLImageElement*, float sx, float sy, float sw,
float sh, | |
186 float dx, float dy, float dw, float dh, const String& compositeOpera
tion); | |
187 | |
188 void setAlpha(float); | |
189 | |
190 void setCompositeOperation(const String&); | |
191 | |
192 PassRefPtr<CanvasGradient> createLinearGradient(float x0, float y0, floa
t x1, float y1); | |
193 PassRefPtr<CanvasGradient> createRadialGradient(float x0, float y0, floa
t r0, float x1, float y1, float r1); | |
194 PassRefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String&
repetitionType, ExceptionCode&); | |
195 PassRefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String
& repetitionType, ExceptionCode&); | |
196 | |
197 PassRefPtr<ImageData> createImageData(float width, float height) const; | |
198 PassRefPtr<ImageData> getImageData(float sx, float sy, float sw, float s
h, ExceptionCode&) const; | |
199 void putImageData(ImageData*, float dx, float dy, ExceptionCode&); | |
200 void putImageData(ImageData*, float dx, float dy, float dirtyX, float di
rtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&); | |
201 | |
202 void reset(); | |
203 | |
204 String font() const; | |
205 void setFont(const String&); | |
206 | |
207 String textAlign() const; | |
208 void setTextAlign(const String&); | |
209 | |
210 String textBaseline() const; | |
211 void setTextBaseline(const String&); | |
212 | |
213 void fillText(const String& text, float x, float y); | |
214 void fillText(const String& text, float x, float y, float maxWidth); | |
215 void strokeText(const String& text, float x, float y); | |
216 void strokeText(const String& text, float x, float y, float maxWidth); | |
217 PassRefPtr<TextMetrics> measureText(const String& text); | |
218 | |
219 private: | |
220 struct State { | |
221 State(); | |
222 | |
223 RefPtr<CanvasStyle> m_strokeStyle; | |
224 RefPtr<CanvasStyle> m_fillStyle; | |
225 float m_lineWidth; | |
226 LineCap m_lineCap; | |
227 LineJoin m_lineJoin; | |
228 float m_miterLimit; | |
229 FloatSize m_shadowOffset; | |
230 float m_shadowBlur; | |
231 String m_shadowColor; | |
232 float m_globalAlpha; | |
233 CompositeOperator m_globalComposite; | |
234 AffineTransform m_transform; | |
235 | |
236 // Text state. | |
237 TextAlign m_textAlign; | |
238 TextBaseline m_textBaseline; | |
239 | |
240 String m_unparsedFont; | |
241 Font m_font; | |
242 bool m_realizedFont; | |
243 }; | |
244 Path m_path; | |
245 | |
246 State& state() { return m_stateStack.last(); } | |
247 const State& state() const { return m_stateStack.last(); } | |
248 | |
249 void applyShadow(); | |
250 | |
251 void willDraw(const FloatRect&); | |
252 | |
253 GraphicsContext* drawingContext() const; | |
254 | |
255 void applyStrokePattern(); | |
256 void applyFillPattern(); | |
257 | |
258 void drawTextInternal(const String& text, float x, float y, bool fill, f
loat maxWidth = 0, bool useMaxWidth = false); | |
259 | |
260 const Font& accessFont(); | |
261 | |
262 #if ENABLE(DASHBOARD_SUPPORT) | |
263 void clearPathForDashboardBackwardCompatibilityMode(); | |
264 #endif | |
265 | |
266 void checkOrigin(const KURL&); | |
267 | |
268 HTMLCanvasElement* m_canvas; | |
269 Vector<State, 1> m_stateStack; | |
270 #if USE(V8) | |
271 void* m_peer; | |
272 #endif | |
273 }; | |
274 | |
275 } // namespace WebCore | |
276 | |
277 #endif | |
OLD | NEW |