2 * Copyright (C) 2006 Apple Computer, 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 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#canvasrenderingcontext2d
28 // FIXME: float => double throughout
29 // FIXME: Use union type in drawImage and createPattern once supported:
30 // http://crbug.com/372891
31 typedef (HTMLImageElement or
33 HTMLCanvasElement // or
34 // CanvasRenderingContext2D or
38 enum CanvasFillRule { "nonzero", "evenodd" };
41 TypeChecking=Interface|Unrestricted,
42 WillBeGarbageCollected,
43 ] interface CanvasRenderingContext2D {
44 // back-reference to the canvas
45 readonly attribute HTMLCanvasElement canvas;
48 void save(); // push state on state stack
49 void restore(); // pop state stack and restore state
51 // transformations (default transform is the identity matrix)
52 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute SVGMatrix currentTransform;
53 void scale(unrestricted float x, unrestricted float y);
54 void rotate(unrestricted float angle);
55 void translate(unrestricted float x, unrestricted float y);
56 void transform(unrestricted float a, unrestricted float b, unrestricted float c, unrestricted float d, unrestricted float e, unrestricted float f);
57 void setTransform(unrestricted float a, unrestricted float b, unrestricted float c, unrestricted float d, unrestricted float e, unrestricted float f);
58 void resetTransform();
61 attribute unrestricted float globalAlpha; // (default 1.0)
62 [TreatNullAs=NullString] attribute DOMString globalCompositeOperation; // (default source-over)
65 [ImplementedAs=imageSmoothingEnabled, MeasureAs=PrefixedImageSmoothingEnabled] attribute boolean webkitImageSmoothingEnabled;
66 [MeasureAs=UnprefixedImageSmoothingEnabled] attribute boolean imageSmoothingEnabled;
68 // colors and styles (see also the CanvasDrawingStyles interface)
69 // FIXME: Use union types when supported: http://crbug.com/372891
70 [Custom] attribute object strokeStyle; // (default black)
71 [Custom] attribute object fillStyle; // (default black)
72 CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1);
73 [RaisesException] CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
74 [RaisesException] CanvasPattern createPattern(HTMLCanvasElement canvas, DOMString? repetitionType);
75 [RaisesException] CanvasPattern createPattern(HTMLImageElement image, DOMString? repetitionType);
76 [RaisesException] CanvasPattern createPattern(HTMLVideoElement image, DOMString? repetitionType);
79 attribute unrestricted float shadowOffsetX;
80 attribute unrestricted float shadowOffsetY;
81 attribute unrestricted float shadowBlur;
82 [TreatNullAs=NullString] attribute DOMString shadowColor;
85 void clearRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
86 void fillRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
87 void strokeRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
89 // path API (see also CanvasPathMethods)
91 void fill(optional CanvasFillRule winding);
92 [RuntimeEnabled=Path2D] void fill(Path2D path, optional CanvasFillRule winding);
94 [RuntimeEnabled=Path2D] void stroke(Path2D path);
96 void drawFocusIfNeeded(Element element);
97 [RuntimeEnabled=Path2D] void drawFocusIfNeeded(Path2D path, Element element);
99 [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(optional Path2D path);
100 void clip(optional CanvasFillRule winding);
101 [RuntimeEnabled=Path2D] void clip(Path2D path, optional CanvasFillRule winding);
102 boolean isPointInPath(unrestricted float x, unrestricted float y, optional CanvasFillRule winding);
103 [RuntimeEnabled=Path2D] boolean isPointInPath(Path2D path, unrestricted float x, unrestricted float y, optional CanvasFillRule winding);
104 boolean isPointInStroke(unrestricted float x, unrestricted float y);
105 [RuntimeEnabled=Path2D] boolean isPointInStroke(Path2D path, unrestricted float x, unrestricted float y);
107 // text (see also the CanvasDrawingStyles interface)
108 void fillText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);
109 void strokeText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);
110 TextMetrics measureText(DOMString text);
113 [RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y);
114 [RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
115 [RaisesException] void drawImage(HTMLImageElement image, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
116 [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float x, unrestricted float y);
117 [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
118 [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
119 [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float x, unrestricted float y);
120 [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
121 [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
122 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float x, unrestricted float y);
123 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
124 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
127 // FIXME: Blink does not currently support WebIDL dictionary definitions.
128 // See http://crbug.com/321462
129 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegion(optional Dictionary options);
130 [RuntimeEnabled=ExperimentalCanvasFeatures] void removeHitRegion(DOMString id);
131 [RuntimeEnabled=ExperimentalCanvasFeatures] void clearHitRegions();
133 // pixel manipulation
134 ImageData createImageData(ImageData imagedata);
135 [RaisesException] ImageData createImageData(float sw, float sh);
136 [RaisesException] ImageData getImageData(float sx, float sy, float sw, float sh);
137 void putImageData(ImageData imagedata, float dx, float dy);
138 void putImageData(ImageData imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
141 // Should be merged with WebGL counterpart in CanvasRenderingContext, once no-longer experimental
142 [RuntimeEnabled=ExperimentalCanvasFeatures] boolean isContextLost();
144 Canvas2DContextAttributes getContextAttributes();
146 // FIXME: factor out to CanvasDrawingStyles
148 attribute unrestricted float lineWidth; // (default 1)
149 [TreatNullAs=NullString] attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
150 [TreatNullAs=NullString] attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
151 attribute unrestricted float miterLimit; // (default 10)
154 void setLineDash(sequence<unrestricted float> dash);
155 sequence<unrestricted float> getLineDash();
156 attribute unrestricted float lineDashOffset;
159 attribute DOMString font; // (default 10px sans-serif)
160 attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
161 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")
163 // Non-standard APIs. Candidates for deprecation
164 // https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D
165 [MeasureAs=CanvasRenderingContext2DSetAlpha] void setAlpha(unrestricted float alpha);
166 [MeasureAs=CanvasRenderingContext2DSetCompositeOperation] void setCompositeOperation(DOMString compositeOperation);
167 [MeasureAs=CanvasRenderingContext2DSetLineWidth] void setLineWidth(unrestricted float width);
168 [MeasureAs=CanvasRenderingContext2DSetLineCap] void setLineCap(DOMString cap);
169 [MeasureAs=CanvasRenderingContext2DSetLineJoin] void setLineJoin(DOMString join);
170 [MeasureAs=CanvasRenderingContext2DSetMiterLimit] void setMiterLimit(unrestricted float limit);
171 [MeasureAs=CanvasRenderingContext2DClearShadow] void clearShadow();
172 [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(DOMString color, optional unrestricted float alpha);
173 [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(unrestricted float grayLevel, optional unrestricted float alpha);
174 [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
175 [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
176 [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(DOMString color, optional unrestricted float alpha);
177 [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha);
178 [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
179 [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
180 [MeasureAs=CanvasRenderingContext2DDrawImageFromRect] void drawImageFromRect(
181 HTMLImageElement? image, optional unrestricted float sx, optional unrestricted float sy, optional unrestricted float sw, optional unrestricted float sh,
182 optional unrestricted float dx, optional unrestricted float dy, optional unrestricted float dw, optional unrestricted float dh, optional DOMString compositeOperation);
183 [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, optional DOMString color, optional unrestricted float alpha);
184 [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float grayLevel, optional unrestricted float alpha);
185 [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
186 [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
189 CanvasRenderingContext2D implements CanvasPathMethods;