1/*
2 * Copyright (C) 2006 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 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 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
26enum CanvasWindingRule { "nonzero", "evenodd" };
27
28interface CanvasRenderingContext2D : CanvasRenderingContext {
29
30    void save();
31    void restore();
32
33    void scale(unrestricted float sx, unrestricted float sy);
34    void rotate(unrestricted float angle);
35    void translate(unrestricted float tx, unrestricted float ty);
36    void transform(unrestricted float m11, unrestricted float m12, unrestricted float m21, unrestricted float m22,
37        unrestricted float dx, unrestricted float dy);
38    void setTransform(unrestricted float m11, unrestricted float m12, unrestricted float m21, unrestricted float m22,
39        unrestricted float dx, unrestricted float dy);
40
41    attribute unrestricted float globalAlpha;
42    [TreatNullAs=NullString] attribute DOMString globalCompositeOperation;
43
44    [RaisesException] CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1);
45    [RaisesException] CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
46
47    attribute unrestricted float lineWidth;
48    [TreatNullAs=NullString] attribute DOMString lineCap;
49    [TreatNullAs=NullString] attribute DOMString lineJoin;
50    attribute unrestricted float miterLimit;
51
52    attribute unrestricted float shadowOffsetX;
53    attribute unrestricted float shadowOffsetY;
54    attribute unrestricted float shadowBlur;
55    [TreatNullAs=NullString] attribute DOMString shadowColor;
56
57    void setLineDash(sequence<unrestricted float> dash);
58    sequence<unrestricted float> getLineDash();
59    attribute unrestricted float lineDashOffset;
60
61    [Custom] attribute Array webkitLineDash;
62    attribute unrestricted float webkitLineDashOffset;
63
64    void clearRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
65    void fillRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
66
67    void beginPath();
68
69    // FIXME: These methods should be shared with CanvasRenderingContext2D in the CanvasPathMethods interface.
70    void closePath();
71    void moveTo(unrestricted float x, unrestricted float y);
72    void lineTo(unrestricted float x, unrestricted float y);
73    void quadraticCurveTo(unrestricted float cpx, unrestricted float cpy, unrestricted float x, unrestricted float y);
74    void bezierCurveTo(unrestricted float cp1x, unrestricted float cp1y, unrestricted float cp2x, unrestricted float cp2y,
75        unrestricted float x, unrestricted float y);
76    [RaisesException] void arcTo(unrestricted float x1, unrestricted float y1, unrestricted float x2, unrestricted float y2,
77        unrestricted float radius);
78    void rect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
79    [RaisesException] void arc(unrestricted float x, unrestricted float y, unrestricted float radius, unrestricted float startAngle,
80        unrestricted float endAngle, [Default=Undefined] optional boolean anticlockwise);
81
82    void fill(DOMPath path, optional CanvasWindingRule winding);
83    void stroke(DOMPath path);
84    void clip(DOMPath path, optional CanvasWindingRule winding);
85
86    void fill(optional CanvasWindingRule winding);
87    void stroke();
88    void clip(optional CanvasWindingRule winding);
89
90    boolean isPointInPath(DOMPath path, unrestricted float x, unrestricted float y, optional CanvasWindingRule winding);
91    boolean isPointInStroke(DOMPath path, unrestricted float x, unrestricted float y);
92
93    boolean isPointInPath(unrestricted float x, unrestricted float y, optional CanvasWindingRule winding);
94    boolean isPointInStroke(unrestricted float x, unrestricted float y);
95
96    // text
97    attribute DOMString font;
98    attribute DOMString textAlign;
99    attribute DOMString textBaseline;
100
101    TextMetrics measureText(DOMString text);
102
103    // other
104
105    void setAlpha([Default=Undefined] optional unrestricted float alpha);
106    void setCompositeOperation([Default=Undefined] optional DOMString compositeOperation);
107
108    void setLineWidth([Default=Undefined] optional unrestricted float width);
109    void setLineCap([Default=Undefined] optional DOMString cap);
110    void setLineJoin([Default=Undefined] optional DOMString join);
111    void setMiterLimit([Default=Undefined] optional unrestricted float limit);
112
113    void clearShadow();
114
115    void fillText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);
116    void strokeText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);
117
118    void setStrokeColor([StrictTypeChecking] DOMString color, optional unrestricted float alpha);
119    void setStrokeColor(unrestricted float grayLevel, optional float alpha);
120    void setStrokeColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
121    void setStrokeColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
122
123    void setFillColor([StrictTypeChecking] DOMString color, optional unrestricted float alpha);
124    void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha);
125    void setFillColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
126    void setFillColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
127
128    void strokeRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
129
130    [RaisesException] void drawImage(HTMLImageElement? image, unrestricted float x, unrestricted float y);
131    [RaisesException] void drawImage(HTMLImageElement? image, unrestricted float x, unrestricted float y,
132        unrestricted float width, unrestricted float height);
133    [RaisesException] void drawImage(HTMLImageElement? image, unrestricted float sx, unrestricted float sy, unrestricted float sw,
134        unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
135    [RaisesException] void drawImage(HTMLCanvasElement? canvas, unrestricted float x, unrestricted float y);
136    [RaisesException] void drawImage(HTMLCanvasElement? canvas, unrestricted float x, unrestricted float y,
137        unrestricted float width, unrestricted float height);
138    [RaisesException] void drawImage(HTMLCanvasElement? canvas, unrestricted float sx, unrestricted float sy, unrestricted float sw,
139        unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
140#if defined(ENABLE_VIDEO) && ENABLE_VIDEO
141    [RaisesException] void drawImage(HTMLVideoElement? video, unrestricted float x, unrestricted float y);
142    [RaisesException] void drawImage(HTMLVideoElement? video, unrestricted float x, unrestricted float y,
143        unrestricted float width, unrestricted float height);
144    [RaisesException] void drawImage(HTMLVideoElement? video, unrestricted float sx, unrestricted float sy, unrestricted float sw,
145        unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
146#endif
147
148    void drawImageFromRect(HTMLImageElement image,
149        optional unrestricted float sx, optional unrestricted float sy, optional unrestricted float sw, optional unrestricted float sh,
150        optional unrestricted float dx, optional unrestricted float dy, optional unrestricted float dw, optional unrestricted float dh,
151        optional DOMString compositeOperation);
152
153    void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur,
154        [StrictTypeChecking] optional DOMString color, optional unrestricted float alpha);
155    void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float grayLevel,
156        optional unrestricted float alpha);
157    void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float r,
158        unrestricted float g, unrestricted float b, unrestricted float a);
159    void setShadow(float width, unrestricted float height, unrestricted float blur, unrestricted float c, unrestricted float m,
160        unrestricted float y, unrestricted float k, unrestricted float a);
161
162    [RaisesException] void putImageData(ImageData? imagedata, float dx, float dy);
163    [RaisesException] void putImageData(ImageData? imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
164
165    [RaisesException] void webkitPutImageDataHD(ImageData? imagedata, float dx, float dy);
166    [RaisesException] void webkitPutImageDataHD(ImageData? imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
167
168    [RaisesException] CanvasPattern createPattern(HTMLCanvasElement? canvas, [TreatNullAs=NullString] DOMString repetitionType);
169    [RaisesException] CanvasPattern createPattern(HTMLImageElement? image, [TreatNullAs=NullString] DOMString repetitionType);
170    [RaisesException] ImageData createImageData(ImageData? imagedata);
171    [RaisesException] ImageData createImageData(float sw, float sh);
172
173    [Custom] attribute custom strokeStyle;
174    [Custom] attribute custom fillStyle;
175
176    // pixel manipulation
177    [RaisesException] ImageData getImageData(float sx, float sy, float sw, float sh);
178
179    [RaisesException] ImageData webkitGetImageDataHD(float sx, float sy, float sw, float sh);
180
181    // Focus rings
182    void drawFocusIfNeeded(Element element);
183
184    readonly attribute float webkitBackingStorePixelRatio;
185
186    attribute boolean webkitImageSmoothingEnabled;
187};
188
189