2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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 CanvasRenderingContext2D_h
27 #define CanvasRenderingContext2D_h
29 #include "AffineTransform.h"
30 #include "FloatSize.h"
31 #include "GraphicsTypes.h"
33 #include "PlatformString.h"
34 #include <wtf/Vector.h>
37 #include <ApplicationServices/ApplicationServices.h>
46 class GraphicsContext;
47 class HTMLCanvasElement;
48 class HTMLImageElement;
52 typedef int ExceptionCode;
54 class CanvasRenderingContext2D : Noncopyable {
56 CanvasRenderingContext2D(HTMLCanvasElement*);
61 HTMLCanvasElement* canvas() const { return m_canvas; }
63 CanvasStyle* strokeStyle() const;
64 void setStrokeStyle(PassRefPtr<CanvasStyle>);
66 CanvasStyle* fillStyle() const;
67 void setFillStyle(PassRefPtr<CanvasStyle>);
69 float lineWidth() const;
70 void setLineWidth(float);
72 String lineCap() const;
73 void setLineCap(const String&);
75 String lineJoin() const;
76 void setLineJoin(const String&);
78 float miterLimit() const;
79 void setMiterLimit(float);
81 float shadowOffsetX() const;
82 void setShadowOffsetX(float);
84 float shadowOffsetY() const;
85 void setShadowOffsetY(float);
87 float shadowBlur() const;
88 void setShadowBlur(float);
90 String shadowColor() const;
91 void setShadowColor(const String&);
93 float globalAlpha() const;
94 void setGlobalAlpha(float);
96 String globalCompositeOperation() const;
97 void setGlobalCompositeOperation(const String&);
102 void scale(float sx, float sy);
103 void rotate(float angleInRadians);
104 void translate(float tx, float ty);
105 void transform(float m11, float m12, float m21, float m22, float dx, float dy);
107 void setStrokeColor(const String& color);
108 void setStrokeColor(float grayLevel);
109 void setStrokeColor(const String& color, float alpha);
110 void setStrokeColor(float grayLevel, float alpha);
111 void setStrokeColor(float r, float g, float b, float a);
112 void setStrokeColor(float c, float m, float y, float k, float a);
114 void setFillColor(const String& color);
115 void setFillColor(float grayLevel);
116 void setFillColor(const String& color, float alpha);
117 void setFillColor(float grayLevel, float alpha);
118 void setFillColor(float r, float g, float b, float a);
119 void setFillColor(float c, float m, float y, float k, float a);
124 void moveTo(float x, float y);
125 void lineTo(float x, float y);
126 void quadraticCurveTo(float cpx, float cpy, float x, float y);
127 void bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y);
128 void arcTo(float x0, float y0, float x1, float y1, float radius, ExceptionCode&);
129 void arc(float x, float y, float r, float sa, float ea, bool clockwise, ExceptionCode&);
130 void rect(float x, float y, float width, float height);
136 bool isPointInPath(const float x, const float y);
138 void clearRect(float x, float y, float width, float height);
139 void fillRect(float x, float y, float width, float height);
140 void strokeRect(float x, float y, float width, float height);
141 void strokeRect(float x, float y, float width, float height, float lineWidth);
143 void setShadow(float width, float height, float blur);
144 void setShadow(float width, float height, float blur, const String& color);
145 void setShadow(float width, float height, float blur, float grayLevel);
146 void setShadow(float width, float height, float blur, const String& color, float alpha);
147 void setShadow(float width, float height, float blur, float grayLevel, float alpha);
148 void setShadow(float width, float height, float blur, float r, float g, float b, float a);
149 void setShadow(float width, float height, float blur, float c, float m, float y, float k, float a);
153 void drawImage(HTMLImageElement*, float x, float y);
154 void drawImage(HTMLImageElement*, float x, float y, float width, float height, ExceptionCode&);
155 void drawImage(HTMLImageElement*, const FloatRect& srcRect, const FloatRect& dstRect, ExceptionCode&);
156 void drawImage(HTMLCanvasElement*, float x, float y);
157 void drawImage(HTMLCanvasElement*, float x, float y, float width, float height, ExceptionCode&);
158 void drawImage(HTMLCanvasElement*, const FloatRect& srcRect, const FloatRect& dstRect, ExceptionCode&);
160 void drawImageFromRect(HTMLImageElement*, float sx, float sy, float sw, float sh,
161 float dx, float dy, float dw, float dh, const String& compositeOperation);
163 void setAlpha(float);
165 void setCompositeOperation(const String&);
167 PassRefPtr<CanvasGradient> createLinearGradient(float x0, float y0, float x1, float y1);
168 PassRefPtr<CanvasGradient> createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
169 PassRefPtr<CanvasPattern> createPattern(HTMLImageElement*, const String& repetitionType, ExceptionCode&);
170 PassRefPtr<CanvasPattern> createPattern(HTMLCanvasElement*, const String& repetitionType, ExceptionCode&);
172 PassRefPtr<ImageData> createImageData(float width, float height) const;
173 PassRefPtr<ImageData> getImageData(float sx, float sy, float sw, float sh, ExceptionCode&) const;
174 void putImageData(ImageData*, float dx, float dy, ExceptionCode&);
175 void putImageData(ImageData*, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight, ExceptionCode&);
183 RefPtr<CanvasStyle> m_strokeStyle;
184 RefPtr<CanvasStyle> m_fillStyle;
189 FloatSize m_shadowOffset;
191 String m_shadowColor;
193 CompositeOperator m_globalComposite;
194 bool m_appliedStrokePattern;
195 bool m_appliedFillPattern;
196 AffineTransform m_transform;
198 CGAffineTransform m_strokeStylePatternTransform;
199 CGAffineTransform m_fillStylePatternTransform;
204 State& state() { return m_stateStack.last(); }
205 const State& state() const { return m_stateStack.last(); }
209 void willDraw(const FloatRect&);
211 GraphicsContext* drawingContext() const;
213 void applyStrokePattern();
214 void applyFillPattern();
216 #if ENABLE(DASHBOARD_SUPPORT)
217 void clearPathForDashboardBackwardCompatibilityMode();
220 void checkOrigin(const KURL&);
222 HTMLCanvasElement* m_canvas;
223 Vector<State, 1> m_stateStack;
226 } // namespace WebCore