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