| 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" }; |
| 35 enum ImageSmoothingQuality {"low", "medium", "high"}; |
| 36 | 36 |
| 37 [ | 37 [ |
| 38 SetWrapperReferenceFrom=canvas, | 38 SetWrapperReferenceFrom=canvas, |
| 39 TypeChecking=Interface, | |
| 40 WillBeGarbageCollected, | 39 WillBeGarbageCollected, |
| 41 ] interface CanvasRenderingContext2D { | 40 ] interface CanvasRenderingContext2D { |
| 42 // back-reference to the canvas | 41 // back-reference to the canvas |
| 43 readonly attribute HTMLCanvasElement canvas; | 42 readonly attribute HTMLCanvasElement canvas; |
| 44 | 43 |
| 45 // state | 44 // state |
| 46 void save(); // push state on state stack | 45 void save(); // push state on state stack |
| 47 void restore(); // pop state stack and restore state | 46 void restore(); // pop state stack and restore state |
| 48 | 47 |
| 49 // transformations (default transform is the identity matrix) | 48 // transformations (default transform is the identity matrix) |
| 50 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute SVGMatrix currentTrans
form; | 49 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute SVGMatrix currentTrans
form; |
| 51 void scale(unrestricted float x, unrestricted float y); | 50 void scale(unrestricted double x, unrestricted double y); |
| 52 void rotate(unrestricted float angle); | 51 void rotate(unrestricted double angle); |
| 53 void translate(unrestricted float x, unrestricted float y); | 52 void translate(unrestricted double x, unrestricted double y); |
| 54 void transform(unrestricted float a, unrestricted float b, unrestricted floa
t c, unrestricted float d, unrestricted float e, unrestricted float f); | 53 void transform(unrestricted double a, unrestricted double b, unrestricted do
uble c, unrestricted double d, unrestricted double e, unrestricted double f); |
| 55 void setTransform(unrestricted float a, unrestricted float b, unrestricted f
loat c, unrestricted float d, unrestricted float e, unrestricted float f); | 54 void setTransform(unrestricted double a, unrestricted double b, unrestricted
double c, unrestricted double d, unrestricted double e, unrestricted double f); |
| 56 void resetTransform(); | 55 void resetTransform(); |
| 57 | 56 |
| 58 // compositing | 57 // compositing |
| 59 attribute unrestricted float globalAlpha; // (default 1.0) | 58 attribute unrestricted double globalAlpha; // (default 1.0) |
| 60 [TreatNullAs=NullString] attribute DOMString globalCompositeOperation; // (d
efault source-over) | 59 attribute DOMString globalCompositeOperation; // (default source-over) |
| 61 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString filter; // (
default 'none') | 60 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString filter; // (
default 'none') |
| 62 | 61 |
| 63 // image smoothing | 62 // image smoothing |
| 64 [ImplementedAs=imageSmoothingEnabled, DeprecateAs=PrefixedImageSmoothingEnab
led] attribute boolean webkitImageSmoothingEnabled; | 63 [ImplementedAs=imageSmoothingEnabled, DeprecateAs=PrefixedImageSmoothingEnab
led] attribute boolean webkitImageSmoothingEnabled; |
| 65 [MeasureAs=UnprefixedImageSmoothingEnabled] attribute boolean imageSmoothing
Enabled; | 64 [MeasureAs=UnprefixedImageSmoothingEnabled] attribute boolean imageSmoothing
Enabled; // (default True) |
| 65 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute ImageSmoothingQuality
imageSmoothingQuality; // (default "low") |
| 66 | 66 |
| 67 // colors and styles (see also the CanvasDrawingStyles interface) | 67 // colors and styles (see also the CanvasDrawingStyles interface) |
| 68 attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (de
fault black) | 68 attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (de
fault black) |
| 69 attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (defa
ult black) | 69 attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (defa
ult black) |
| 70 CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1); | 70 CanvasGradient createLinearGradient(double x0, double y0, double x1, double
y1); |
| 71 [RaisesException] CanvasGradient createRadialGradient(float x0, float y0, fl
oat r0, float x1, float y1, float r1); | 71 [RaisesException] CanvasGradient createRadialGradient(double x0, double y0,
double r0, double x1, double y1, double r1); |
| 72 [RaisesException] CanvasPattern createPattern(CanvasImageSource image, DOMSt
ring? repetitionType); | 72 [RaisesException] CanvasPattern? createPattern(CanvasImageSource image, [Tre
atNullAs=NullString] DOMString repetitionType); |
| 73 | 73 |
| 74 // shadows | 74 // shadows |
| 75 attribute unrestricted float shadowOffsetX; | 75 attribute unrestricted double shadowOffsetX; |
| 76 attribute unrestricted float shadowOffsetY; | 76 attribute unrestricted double shadowOffsetY; |
| 77 attribute unrestricted float shadowBlur; | 77 attribute unrestricted double shadowBlur; |
| 78 [TreatNullAs=NullString] attribute DOMString shadowColor; | 78 attribute DOMString shadowColor; |
| 79 | 79 |
| 80 // rects | 80 // rects |
| 81 void clearRect(unrestricted float x, unrestricted float y, unrestricted floa
t width, unrestricted float height); | 81 void clearRect(unrestricted double x, unrestricted double y, unrestricted do
uble width, unrestricted double height); |
| 82 void fillRect(unrestricted float x, unrestricted float y, unrestricted float
width, unrestricted float height); | 82 void fillRect(unrestricted double x, unrestricted double y, unrestricted dou
ble width, unrestricted double height); |
| 83 void strokeRect(unrestricted float x, unrestricted float y, unrestricted flo
at width, unrestricted float height); | 83 void strokeRect(unrestricted double x, unrestricted double y, unrestricted d
ouble width, unrestricted double height); |
| 84 | 84 |
| 85 // path API (see also CanvasPathMethods) | 85 // path API (see also CanvasPathMethods) |
| 86 void beginPath(); | 86 void beginPath(); |
| 87 void fill(optional CanvasFillRule winding); | 87 void fill(optional CanvasFillRule winding); |
| 88 void fill(Path2D path, optional CanvasFillRule winding); | 88 void fill(Path2D path, optional CanvasFillRule winding); |
| 89 void stroke(); | 89 void stroke(); |
| 90 void stroke(Path2D path); | 90 void stroke(Path2D path); |
| 91 // Focus rings | 91 // Focus rings |
| 92 void drawFocusIfNeeded(Element element); | 92 void drawFocusIfNeeded(Element element); |
| 93 void drawFocusIfNeeded(Path2D path, Element element); | 93 void drawFocusIfNeeded(Path2D path, Element element); |
| 94 | 94 |
| 95 [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(optional
Path2D path); | 95 [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(optional
Path2D path); |
| 96 void clip(optional CanvasFillRule winding); | 96 void clip(optional CanvasFillRule winding); |
| 97 void clip(Path2D path, optional CanvasFillRule winding); | 97 void clip(Path2D path, optional CanvasFillRule winding); |
| 98 boolean isPointInPath(unrestricted float x, unrestricted float y, optional C
anvasFillRule winding); | 98 boolean isPointInPath(unrestricted double x, unrestricted double y, optional
CanvasFillRule winding); |
| 99 boolean isPointInPath(Path2D path, unrestricted float x, unrestricted float
y, optional CanvasFillRule winding); | 99 boolean isPointInPath(Path2D path, unrestricted double x, unrestricted doubl
e y, optional CanvasFillRule winding); |
| 100 boolean isPointInStroke(unrestricted float x, unrestricted float y); | 100 boolean isPointInStroke(unrestricted double x, unrestricted double y); |
| 101 boolean isPointInStroke(Path2D path, unrestricted float x, unrestricted floa
t y); | 101 boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted dou
ble y); |
| 102 | 102 |
| 103 // text (see also the CanvasDrawingStyles interface) | 103 // text (see also the CanvasDrawingStyles interface) |
| 104 void fillText(DOMString text, unrestricted float x, unrestricted float y, op
tional unrestricted float maxWidth); | 104 void fillText(DOMString text, unrestricted double x, unrestricted double y,
optional unrestricted double maxWidth); |
| 105 void strokeText(DOMString text, unrestricted float x, unrestricted float y,
optional unrestricted float maxWidth); | 105 void strokeText(DOMString text, unrestricted double x, unrestricted double y
, optional unrestricted double maxWidth); |
| 106 TextMetrics measureText(DOMString text); | 106 TextMetrics measureText(DOMString text); |
| 107 | 107 |
| 108 // drawing images | 108 // drawing images |
| 109 [RaisesException] void drawImage(CanvasImageSource image, unrestricted float
x, unrestricted float y); | 109 [RaisesException] void drawImage(CanvasImageSource image, unrestricted doubl
e x, unrestricted double y); |
| 110 [RaisesException] void drawImage(CanvasImageSource image, unrestricted float
x, unrestricted float y, unrestricted float width, unrestricted float height); | 110 [RaisesException] void drawImage(CanvasImageSource image, unrestricted doubl
e x, unrestricted double y, unrestricted double width, unrestricted double heigh
t); |
| 111 [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); | 111 [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); |
| 112 | 112 |
| 113 // hit regions | 113 // hit regions |
| 114 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegi
on(optional HitRegionOptions options); | 114 [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void addHitRegi
on(optional HitRegionOptions options); |
| 115 [RuntimeEnabled=ExperimentalCanvasFeatures] void removeHitRegion(DOMString i
d); | 115 [RuntimeEnabled=ExperimentalCanvasFeatures] void removeHitRegion(DOMString i
d); |
| 116 [RuntimeEnabled=ExperimentalCanvasFeatures] void clearHitRegions(); | 116 [RuntimeEnabled=ExperimentalCanvasFeatures] void clearHitRegions(); |
| 117 | 117 |
| 118 // pixel manipulation | 118 // pixel manipulation |
| 119 ImageData createImageData(ImageData imagedata); | 119 ImageData createImageData(ImageData imagedata); |
| 120 [RaisesException] ImageData createImageData(float sw, float sh); | 120 [RaisesException] ImageData createImageData(double sw, double sh); |
| 121 [RaisesException] ImageData getImageData(float sx, float sy, float sw, float
sh); | 121 [RaisesException] ImageData getImageData(double sx, double sy, double sw, do
uble sh); |
| 122 void putImageData(ImageData imagedata, float dx, float dy); | 122 [RaisesException] void putImageData(ImageData imagedata, double dx, double d
y); |
| 123 void putImageData(ImageData imagedata, float dx, float dy, float dirtyX, flo
at dirtyY, float dirtyWidth, float dirtyHeight); | 123 [RaisesException] void putImageData(ImageData imagedata, double dx, double d
y, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight); |
| 124 | 124 |
| 125 // Context state | 125 // Context state |
| 126 // Should be merged with WebGL counterpart in CanvasRenderingContext, once n
o-longer experimental | 126 // Should be merged with WebGL counterpart in CanvasRenderingContext, once n
o-longer experimental |
| 127 [RuntimeEnabled=ExperimentalCanvasFeatures] boolean isContextLost(); | 127 [RuntimeEnabled=ExperimentalCanvasFeatures] boolean isContextLost(); |
| 128 | 128 |
| 129 Canvas2DContextAttributes getContextAttributes(); | 129 Canvas2DContextAttributes getContextAttributes(); |
| 130 | 130 |
| 131 // FIXME: factor out to CanvasDrawingStyles | 131 // FIXME: factor out to CanvasDrawingStyles |
| 132 // line caps/joins | 132 // line caps/joins |
| 133 attribute unrestricted float lineWidth; // (default 1) | 133 attribute unrestricted double lineWidth; // (default 1) |
| 134 [TreatNullAs=NullString] attribute DOMString lineCap; // "butt", "round", "s
quare" (default "butt") | 134 attribute DOMString lineCap; // "butt", "round", "square" (default "butt") |
| 135 [TreatNullAs=NullString] attribute DOMString lineJoin; // "round", "bevel",
"miter" (default "miter") | 135 attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") |
| 136 attribute unrestricted float miterLimit; // (default 10) | 136 attribute unrestricted double miterLimit; // (default 10) |
| 137 | 137 |
| 138 // dashed lines | 138 // dashed lines |
| 139 void setLineDash(sequence<unrestricted float> dash); | 139 void setLineDash(sequence<unrestricted double> dash); |
| 140 sequence<unrestricted float> getLineDash(); | 140 sequence<unrestricted double> getLineDash(); |
| 141 attribute unrestricted float lineDashOffset; | 141 attribute unrestricted double lineDashOffset; |
| 142 | 142 |
| 143 // text | 143 // text |
| 144 attribute DOMString font; // (default 10px sans-serif) | 144 attribute DOMString font; // (default 10px sans-serif) |
| 145 attribute DOMString textAlign; // "start", "end", "left", "right", "center"
(default: "start") | 145 attribute DOMString textAlign; // "start", "end", "left", "right", "center"
(default: "start") |
| 146 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic
", "ideographic", "bottom" (default: "alphabetic") | 146 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic
", "ideographic", "bottom" (default: "alphabetic") |
| 147 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString direction; /
/ "inherit", "rtl", "ltr" (default: "inherit") | 147 [RuntimeEnabled=ExperimentalCanvasFeatures] attribute DOMString direction; /
/ "inherit", "rtl", "ltr" (default: "inherit") |
| 148 | 148 |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 CanvasRenderingContext2D implements CanvasPathMethods; | 151 CanvasRenderingContext2D implements CanvasPathMethods; |
| OLD | NEW |