OLD | NEW |
| (Empty) |
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 | |
26 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-elemen
t.html#canvasrenderingcontext2d | |
27 | |
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 | |
32 HTMLCanvasElement // or | |
33 // CanvasRenderingContext2D or | |
34 // ImageBitmap | |
35 ) CanvasImageSource; | |
36 | |
37 enum CanvasFillRule { "nonzero", "evenodd" }; | |
38 | |
39 [ | |
40 TypeChecking=(Interface,Unrestricted), | |
41 ] interface CanvasRenderingContext2D { | |
42 // back-reference to the canvas | |
43 readonly attribute HTMLCanvasElement canvas; | |
44 | |
45 // state | |
46 void save(); // push state on state stack | |
47 void restore(); // pop state stack and restore state | |
48 | |
49 // transformations (default transform is the identity matrix) | |
50 void scale(unrestricted float x, unrestricted float y); | |
51 void rotate(unrestricted float angle); | |
52 void translate(unrestricted float x, unrestricted float y); | |
53 void transform(unrestricted float a, unrestricted float b, unrestricted floa
t c, unrestricted float d, unrestricted float e, unrestricted float f); | |
54 void setTransform(unrestricted float a, unrestricted float b, unrestricted f
loat c, unrestricted float d, unrestricted float e, unrestricted float f); | |
55 void resetTransform(); | |
56 | |
57 // image smoothing | |
58 attribute boolean imageSmoothingEnabled; | |
59 | |
60 // colors and styles (see also the CanvasDrawingStyles interface) | |
61 // FIXME: Use union types when supported: http://crbug.com/372891 | |
62 // [Custom] attribute object strokeStyle; // (default black) | |
63 // [Custom] attribute object fillStyle; // (default black) | |
64 | |
65 attribute DOMString strokeColor; // (default black) | |
66 attribute DOMString fillColor; // (default black) | |
67 | |
68 CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1); | |
69 [RaisesException] CanvasGradient createRadialGradient(float x0, float y0, fl
oat r0, float x1, float y1, float r1); | |
70 [RaisesException] CanvasPattern createPattern(HTMLCanvasElement canvas, DOMS
tring? repetitionType); | |
71 // Dart does not support overloads! | |
72 // [RaisesException] CanvasPattern createPattern(HTMLImageElement image, DOM
String? repetitionType); | |
73 | |
74 // shadows | |
75 attribute unrestricted float shadowOffsetX; | |
76 attribute unrestricted float shadowOffsetY; | |
77 attribute unrestricted float shadowBlur; | |
78 [TreatNullAs=NullString] attribute DOMString shadowColor; | |
79 | |
80 // rects | |
81 void clearRect(unrestricted float x, unrestricted float y, unrestricted floa
t width, unrestricted float height); | |
82 void fillRect(unrestricted float x, unrestricted float y, unrestricted float
width, unrestricted float height); | |
83 void strokeRect(unrestricted float x, unrestricted float y, unrestricted flo
at width, unrestricted float height); | |
84 | |
85 // path API (see also CanvasPathMethods) | |
86 void beginPath(); | |
87 void fill(optional CanvasFillRule winding); | |
88 // void fill(Path2D path, optional CanvasFillRule winding); | |
89 void stroke(); | |
90 // void stroke(Path2D path); | |
91 // Focus rings | |
92 void drawFocusIfNeeded(Element element); | |
93 // void drawFocusIfNeeded(Path2D path, Element element); | |
94 | |
95 void clip(optional CanvasFillRule winding); | |
96 // void clip(Path2D path, optional CanvasFillRule winding); | |
97 boolean isPointInPath(unrestricted float x, unrestricted float y, optional C
anvasFillRule winding); | |
98 // boolean isPointInPath(Path2D path, unrestricted float x, unrestricted flo
at y, optional CanvasFillRule winding); | |
99 boolean isPointInStroke(unrestricted float x, unrestricted float y); | |
100 // boolean isPointInStroke(Path2D path, unrestricted float x, unrestricted f
loat y); | |
101 | |
102 // text (see also the CanvasDrawingStyles interface) | |
103 void fillText(DOMString text, unrestricted float x, unrestricted float y, op
tional unrestricted float maxWidth); | |
104 void strokeText(DOMString text, unrestricted float x, unrestricted float y,
optional unrestricted float maxWidth); | |
105 TextMetrics measureText(DOMString text); | |
106 | |
107 // drawing images | |
108 [RaisesException] void drawImage(HTMLImageElement image, unrestricted float
x, unrestricted float y); | |
109 //[RaisesException] void drawImage(HTMLImageElement image, unrestricted floa
t x, unrestricted float y, unrestricted float width, unrestricted float height); | |
110 //[RaisesException] void drawImage(HTMLImageElement image, unrestricted floa
t sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unres
tricted float dx, unrestricted float dy, unrestricted float dw, unrestricted flo
at dh); | |
111 //[RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted fl
oat x, unrestricted float y); | |
112 //[RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted fl
oat x, unrestricted float y, unrestricted float width, unrestricted float height
); | |
113 //[RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted fl
oat sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unr
estricted float dx, unrestricted float dy, unrestricted float dw, unrestricted f
loat dh); | |
114 // [RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted fl
oat x, unrestricted float y); | |
115 //[RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted flo
at x, unrestricted float y, unrestricted float width, unrestricted float height)
; | |
116 //[RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted flo
at sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unre
stricted float dx, unrestricted float dy, unrestricted float dw, unrestricted fl
oat dh); | |
117 | |
118 // pixel manipulation | |
119 ImageData createImageData(ImageData imagedata); | |
120 //[RaisesException] ImageData createImageData(float sw, float sh); | |
121 [RaisesException] ImageData getImageData(float sx, float sy, float sw, float
sh); | |
122 void putImageData(ImageData imagedata, float dx, float dy); | |
123 //void putImageData(ImageData imagedata, float dx, float dy, float dirtyX, f
loat dirtyY, float dirtyWidth, float dirtyHeight); | |
124 | |
125 // Context state | |
126 // Should be merged with WebGL counterpart in CanvasRenderingContext, once n
o-longer experimental | |
127 boolean isContextLost(); | |
128 | |
129 Canvas2DContextAttributes getContextAttributes(); | |
130 | |
131 // FIXME: factor out to CanvasDrawingStyles | |
132 // line caps/joins | |
133 attribute unrestricted float lineWidth; // (default 1) | |
134 [TreatNullAs=NullString] attribute DOMString lineCap; // "butt", "round", "s
quare" (default "butt") | |
135 [TreatNullAs=NullString] attribute DOMString lineJoin; // "round", "bevel",
"miter" (default "miter") | |
136 attribute unrestricted float miterLimit; // (default 10) | |
137 | |
138 // dashed lines | |
139 // TODO(eseidel): Generator doesn't handle List<unrestricted float> yet. | |
140 // void setLineDash(sequence<unrestricted float> dash); | |
141 // sequence<unrestricted float> getLineDash(); | |
142 attribute unrestricted float lineDashOffset; | |
143 | |
144 // text | |
145 attribute DOMString font; // (default 10px sans-serif) | |
146 attribute DOMString textAlign; // "start", "end", "left", "right", "center"
(default: "start") | |
147 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic
", "ideographic", "bottom" (default: "alphabetic") | |
148 attribute DOMString direction; // "inherit", "rtl", "ltr" (default: "inherit
") | |
149 | |
150 // Non-standard APIs. Candidates for deprecation | |
151 // https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D | |
152 void setLineWidth(unrestricted float width); | |
153 void setLineCap(DOMString cap); | |
154 void setLineJoin(DOMString join); | |
155 void setMiterLimit(unrestricted float limit); | |
156 void clearShadow(); | |
157 void setStrokeColor(DOMString color, optional unrestricted float alpha); | |
158 //void setStrokeColor(unrestricted float grayLevel, optional unrestricted fl
oat alpha); | |
159 //void setStrokeColor(unrestricted float r, unrestricted float g, unrestrict
ed float b, unrestricted float a); | |
160 //void setStrokeColor(unrestricted float c, unrestricted float m, unrestrict
ed float y, unrestricted float k, unrestricted float a); | |
161 void setFillColor(DOMString color, optional unrestricted float alpha); | |
162 //void setFillColor(unrestricted float grayLevel, optional unrestricted floa
t alpha); | |
163 //void setFillColor(unrestricted float r, unrestricted float g, unrestricted
float b, unrestricted float a); | |
164 //void setFillColor(unrestricted float c, unrestricted float m, unrestricted
float y, unrestricted float k, unrestricted float a); | |
165 void drawImageFromRect( | |
166 HTMLImageElement? image, optional unrestricted float sx, optional unrest
ricted float sy, optional unrestricted float sw, optional unrestricted float sh, | |
167 optional unrestricted float dx, optional unrestricted float dy, optional
unrestricted float dw, optional unrestricted float dh, optional DOMString compo
siteOperation); | |
168 void setShadow(unrestricted float width, unrestricted float height, unrestri
cted float blur, optional DOMString color, optional unrestricted float alpha); | |
169 //void setShadow(unrestricted float width, unrestricted float height, unrest
ricted float blur, unrestricted float grayLevel, optional unrestricted float alp
ha); | |
170 //void setShadow(unrestricted float width, unrestricted float height, unrest
ricted float blur, unrestricted float r, unrestricted float g, unrestricted floa
t b, unrestricted float a); | |
171 //void setShadow(unrestricted float width, unrestricted float height, unrest
ricted float blur, unrestricted float c, unrestricted float m, unrestricted floa
t y, unrestricted float k, unrestricted float a); | |
172 }; | |
173 | |
174 CanvasRenderingContext2D implements CanvasPathMethods; | |
OLD | NEW |