OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-elemen
t.html#canvasrenderingcontext2d | 26 // http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-elemen
t.html#canvasrenderingcontext2d |
27 | 27 |
28 // FIXME: float => double throughout | |
29 typedef (HTMLImageElement or | 28 typedef (HTMLImageElement or |
30 HTMLVideoElement or | 29 HTMLVideoElement or |
31 HTMLCanvasElement or | 30 HTMLCanvasElement or |
32 // CanvasRenderingContext2D or | 31 // CanvasRenderingContext2D or |
33 ImageBitmap) CanvasImageSource; | 32 ImageBitmap) CanvasImageSource; |
34 | 33 |
35 enum CanvasFillRule { "nonzero", "evenodd" }; | 34 enum CanvasFillRule { "nonzero", "evenodd" }; |
36 enum ImageSmoothingQuality {"low", "medium", "high"}; | 35 enum ImageSmoothingQuality {"low", "medium", "high"}; |
37 | 36 |
38 [ | 37 [ |
39 SetWrapperReferenceFrom=canvas, | 38 SetWrapperReferenceFrom=canvas, |
40 TypeChecking=Interface, | 39 TypeChecking=Interface, |
41 WillBeGarbageCollected, | 40 WillBeGarbageCollected, |
42 ] interface CanvasRenderingContext2D { | 41 ] interface CanvasRenderingContext2D { |
43 // back-reference to the canvas | 42 // back-reference to the canvas |
44 readonly attribute HTMLCanvasElement canvas; | 43 readonly attribute HTMLCanvasElement canvas; |
45 | 44 |
46 // state | 45 // state |
47 void save(); // push state on state stack | 46 void save(); // push state on state stack |
48 void restore(); // pop state stack and restore state | 47 void restore(); // pop state stack and restore state |
49 | 48 |
50 // transformations (default transform is the identity matrix) | 49 // transformations (default transform is the identity matrix) |
51 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute SVGMatrix currentTrans
form; | 50 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute SVGMatrix currentTrans
form; |
52 void scale(unrestricted float x, unrestricted float y); | 51 void scale(unrestricted double x, unrestricted double y); |
53 void rotate(unrestricted float angle); | 52 void rotate(unrestricted double angle); |
54 void translate(unrestricted float x, unrestricted float y); | 53 void translate(unrestricted double x, unrestricted double y); |
55 void transform(unrestricted float a, unrestricted float b, unrestricted floa
t c, unrestricted float d, unrestricted float e, unrestricted float f); | 54 void transform(unrestricted double a, unrestricted double b, unrestricted do
uble c, unrestricted double d, unrestricted double e, unrestricted double f); |
56 void setTransform(unrestricted float a, unrestricted float b, unrestricted f
loat c, unrestricted float d, unrestricted float e, unrestricted float f); | 55 void setTransform(unrestricted double a, unrestricted double b, unrestricted
double c, unrestricted double d, unrestricted double e, unrestricted double f); |
57 void resetTransform(); | 56 void resetTransform(); |
58 | 57 |
59 // compositing | 58 // compositing |
60 attribute unrestricted float globalAlpha; // (default 1.0) | 59 attribute unrestricted double globalAlpha; // (default 1.0) |
61 attribute DOMString globalCompositeOperation; // (default source-over) | 60 attribute DOMString globalCompositeOperation; // (default source-over) |
62 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString filter; // (
default 'none') | 61 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString filter; // (
default 'none') |
63 | 62 |
64 // image smoothing | 63 // image smoothing |
65 [ImplementedAs=imageSmoothingEnabled, DeprecateAs=PrefixedImageSmoothingEnab
led] attribute boolean webkitImageSmoothingEnabled; | 64 [ImplementedAs=imageSmoothingEnabled, DeprecateAs=PrefixedImageSmoothingEnab
led] attribute boolean webkitImageSmoothingEnabled; |
66 [MeasureAs=UnprefixedImageSmoothingEnabled] attribute boolean imageSmoothing
Enabled; // (default True) | 65 [MeasureAs=UnprefixedImageSmoothingEnabled] attribute boolean imageSmoothing
Enabled; // (default True) |
67 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute ImageSmoothingQuality
imageSmoothingQuality; // (default "low") | 66 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute ImageSmoothingQuality
imageSmoothingQuality; // (default "low") |
68 | 67 |
69 // colors and styles (see also the CanvasDrawingStyles interface) | 68 // colors and styles (see also the CanvasDrawingStyles interface) |
70 attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (de
fault black) | 69 attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (de
fault black) |
71 attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (defa
ult black) | 70 attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (defa
ult black) |
72 CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1); | 71 CanvasGradient createLinearGradient(double x0, double y0, double x1, double
y1); |
73 [RaisesException] CanvasGradient createRadialGradient(float x0, float y0, fl
oat r0, float x1, float y1, float r1); | 72 [RaisesException] CanvasGradient createRadialGradient(double x0, double y0,
double r0, double x1, double y1, double r1); |
74 [RaisesException] CanvasPattern createPattern(CanvasImageSource image, DOMSt
ring? repetitionType); | 73 [RaisesException] CanvasPattern createPattern(CanvasImageSource image, DOMSt
ring? repetitionType); |
75 | 74 |
76 // shadows | 75 // shadows |
77 attribute unrestricted float shadowOffsetX; | 76 attribute unrestricted double shadowOffsetX; |
78 attribute unrestricted float shadowOffsetY; | 77 attribute unrestricted double shadowOffsetY; |
79 attribute unrestricted float shadowBlur; | 78 attribute unrestricted double shadowBlur; |
80 attribute DOMString shadowColor; | 79 attribute DOMString shadowColor; |
81 | 80 |
82 // rects | 81 // rects |
83 void clearRect(unrestricted float x, unrestricted float y, unrestricted floa
t width, unrestricted float height); | 82 void clearRect(unrestricted double x, unrestricted double y, unrestricted do
uble width, unrestricted double height); |
84 void fillRect(unrestricted float x, unrestricted float y, unrestricted float
width, unrestricted float height); | 83 void fillRect(unrestricted double x, unrestricted double y, unrestricted dou
ble width, unrestricted double height); |
85 void strokeRect(unrestricted float x, unrestricted float y, unrestricted flo
at width, unrestricted float height); | 84 void strokeRect(unrestricted double x, unrestricted double y, unrestricted d
ouble width, unrestricted double height); |
86 | 85 |
87 // path API (see also CanvasPathMethods) | 86 // path API (see also CanvasPathMethods) |
88 void beginPath(); | 87 void beginPath(); |
89 void fill(optional CanvasFillRule winding); | 88 void fill(optional CanvasFillRule winding); |
90 void fill(Path2D path, optional CanvasFillRule winding); | 89 void fill(Path2D path, optional CanvasFillRule winding); |
91 void stroke(); | 90 void stroke(); |
92 void stroke(Path2D path); | 91 void stroke(Path2D path); |
93 // Focus rings | 92 // Focus rings |
94 void drawFocusIfNeeded(Element element); | 93 void drawFocusIfNeeded(Element element); |
95 void drawFocusIfNeeded(Path2D path, Element element); | 94 void drawFocusIfNeeded(Path2D path, Element element); |
96 | 95 |
97 [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(optional
Path2D path); | 96 [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(optional
Path2D path); |
98 void clip(optional CanvasFillRule winding); | 97 void clip(optional CanvasFillRule winding); |
99 void clip(Path2D path, optional CanvasFillRule winding); | 98 void clip(Path2D path, optional CanvasFillRule winding); |
100 boolean isPointInPath(unrestricted float x, unrestricted float y, optional C
anvasFillRule winding); | 99 boolean isPointInPath(unrestricted double x, unrestricted double y, optional
CanvasFillRule winding); |
101 boolean isPointInPath(Path2D path, unrestricted float x, unrestricted float
y, optional CanvasFillRule winding); | 100 boolean isPointInPath(Path2D path, unrestricted double x, unrestricted doubl
e y, optional CanvasFillRule winding); |
102 boolean isPointInStroke(unrestricted float x, unrestricted float y); | 101 boolean isPointInStroke(unrestricted double x, unrestricted double y); |
103 boolean isPointInStroke(Path2D path, unrestricted float x, unrestricted floa
t y); | 102 boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted dou
ble y); |
104 | 103 |
105 // text (see also the CanvasDrawingStyles interface) | 104 // text (see also the CanvasDrawingStyles interface) |
106 void fillText(DOMString text, unrestricted float x, unrestricted float y, op
tional unrestricted float maxWidth); | 105 void fillText(DOMString text, unrestricted double x, unrestricted double y,
optional unrestricted double maxWidth); |
107 void strokeText(DOMString text, unrestricted float x, unrestricted float y,
optional unrestricted float maxWidth); | 106 void strokeText(DOMString text, unrestricted double x, unrestricted double y
, optional unrestricted double maxWidth); |
108 TextMetrics measureText(DOMString text); | 107 TextMetrics measureText(DOMString text); |
109 | 108 |
110 // drawing images | 109 // drawing images |
111 [RaisesException] void drawImage(CanvasImageSource image, unrestricted float
x, unrestricted float y); | 110 [RaisesException] void drawImage(CanvasImageSource image, unrestricted doubl
e x, unrestricted double y); |
112 [RaisesException] void drawImage(CanvasImageSource image, unrestricted float
x, unrestricted float y, unrestricted float width, unrestricted float height); | 111 [RaisesException] void drawImage(CanvasImageSource image, unrestricted doubl
e x, unrestricted double y, unrestricted double width, unrestricted double heigh
t); |
113 [RaisesException] void drawImage(CanvasImageSource image, unrestricted float
sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrest
ricted float dx, unrestricted float dy, unrestricted float dw, unrestricted floa
t dh); | 112 [RaisesException] void drawImage(CanvasImageSource image, unrestricted doubl
e sx, unrestricted double sy, unrestricted double sw, unrestricted double sh, un
restricted double dx, unrestricted double dy, unrestricted double dw, unrestrict
ed double dh); |
114 | 113 |
115 // hit regions | 114 // hit regions |
116 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegi
on(optional HitRegionOptions options); | 115 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegi
on(optional HitRegionOptions options); |
117 [RuntimeEnabled=ExperimentalCanvasFeatures] void removeHitRegion(DOMString i
d); | 116 [RuntimeEnabled=ExperimentalCanvasFeatures] void removeHitRegion(DOMString i
d); |
118 [RuntimeEnabled=ExperimentalCanvasFeatures] void clearHitRegions(); | 117 [RuntimeEnabled=ExperimentalCanvasFeatures] void clearHitRegions(); |
119 | 118 |
120 // pixel manipulation | 119 // pixel manipulation |
121 ImageData createImageData(ImageData imagedata); | 120 ImageData createImageData(ImageData imagedata); |
122 [RaisesException] ImageData createImageData(float sw, float sh); | 121 [RaisesException] ImageData createImageData(double sw, double sh); |
123 [RaisesException] ImageData getImageData(float sx, float sy, float sw, float
sh); | 122 [RaisesException] ImageData getImageData(double sx, double sy, double sw, do
uble sh); |
124 [RaisesException] void putImageData(ImageData imagedata, float dx, float dy)
; | 123 [RaisesException] void putImageData(ImageData imagedata, double dx, double d
y); |
125 [RaisesException] void putImageData(ImageData imagedata, float dx, float dy,
float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight); | 124 [RaisesException] void putImageData(ImageData imagedata, double dx, double d
y, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight); |
126 | 125 |
127 // Context state | 126 // Context state |
128 // Should be merged with WebGL counterpart in CanvasRenderingContext, once n
o-longer experimental | 127 // Should be merged with WebGL counterpart in CanvasRenderingContext, once n
o-longer experimental |
129 [RuntimeEnabled=ExperimentalCanvasFeatures] boolean isContextLost(); | 128 [RuntimeEnabled=ExperimentalCanvasFeatures] boolean isContextLost(); |
130 | 129 |
131 Canvas2DContextAttributes getContextAttributes(); | 130 Canvas2DContextAttributes getContextAttributes(); |
132 | 131 |
133 // FIXME: factor out to CanvasDrawingStyles | 132 // FIXME: factor out to CanvasDrawingStyles |
134 // line caps/joins | 133 // line caps/joins |
135 attribute unrestricted float lineWidth; // (default 1) | 134 attribute unrestricted double lineWidth; // (default 1) |
136 attribute DOMString lineCap; // "butt", "round", "square" (default "butt") | 135 attribute DOMString lineCap; // "butt", "round", "square" (default "butt") |
137 attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") | 136 attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") |
138 attribute unrestricted float miterLimit; // (default 10) | 137 attribute unrestricted double miterLimit; // (default 10) |
139 | 138 |
140 // dashed lines | 139 // dashed lines |
141 void setLineDash(sequence<unrestricted float> dash); | 140 void setLineDash(sequence<unrestricted double> dash); |
142 sequence<unrestricted float> getLineDash(); | 141 sequence<unrestricted double> getLineDash(); |
143 attribute unrestricted float lineDashOffset; | 142 attribute unrestricted double lineDashOffset; |
144 | 143 |
145 // text | 144 // text |
146 attribute DOMString font; // (default 10px sans-serif) | 145 attribute DOMString font; // (default 10px sans-serif) |
147 attribute DOMString textAlign; // "start", "end", "left", "right", "center"
(default: "start") | 146 attribute DOMString textAlign; // "start", "end", "left", "right", "center"
(default: "start") |
148 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic
", "ideographic", "bottom" (default: "alphabetic") | 147 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic
", "ideographic", "bottom" (default: "alphabetic") |
149 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString direction; /
/ "inherit", "rtl", "ltr" (default: "inherit") | 148 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString direction; /
/ "inherit", "rtl", "ltr" (default: "inherit") |
150 | 149 |
151 }; | 150 }; |
152 | 151 |
153 CanvasRenderingContext2D implements CanvasPathMethods; | 152 CanvasRenderingContext2D implements CanvasPathMethods; |
OLD | NEW |