1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/.
6 * The origin of this IDL file is
7 * http://www.whatwg.org/specs/web-apps/current-work/
9 * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
10 * Opera Software ASA. You are granted a license to use, reproduce
11 * and create derivative works of this document.
14 enum CanvasWindingRule { "nonzero", "evenodd" };
16 dictionary ContextAttributes2D {
17 // whether or not we're planning to do a lot of readback operations
18 boolean willReadFrequently = false;
19 // signal if the canvas contains an alpha channel
23 dictionary HitRegionOptions {
25 Element? control = null;
28 interface CanvasRenderingContext2D {
30 // back-reference to the canvas. Might be null if we're not
31 // associated with a canvas.
32 readonly attribute HTMLCanvasElement? canvas;
35 void save(); // push state on state stack
36 void restore(); // pop state stack and restore state
38 // transformations (default transform is the identity matrix)
39 // NOT IMPLEMENTED attribute SVGMatrix currentTransform;
40 [Throws, LenientFloat]
41 void scale(double x, double y);
42 [Throws, LenientFloat]
43 void rotate(double angle);
44 [Throws, LenientFloat]
45 void translate(double x, double y);
46 [Throws, LenientFloat]
47 void transform(double a, double b, double c, double d, double e, double f);
48 [Throws, LenientFloat]
49 void setTransform(double a, double b, double c, double d, double e, double f);
51 void resetTransform();
54 attribute unrestricted double globalAlpha; // (default 1.0)
56 attribute DOMString globalCompositeOperation; // (default source-over)
58 // colors and styles (see also the CanvasDrawingStyles interface)
59 attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
60 attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black)
62 CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
64 CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
66 CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, [TreatNullAs=EmptyString] DOMString repetition);
70 attribute double shadowOffsetX; // (default 0)
72 attribute double shadowOffsetY; // (default 0)
74 attribute double shadowBlur; // (default 0)
75 attribute DOMString shadowColor; // (default transparent black)
77 [Pref="canvas.filters.enabled", SetterThrows]
78 attribute DOMString filter; // (default empty string = no filter)
82 void clearRect(double x, double y, double w, double h);
84 void fillRect(double x, double y, double w, double h);
86 void strokeRect(double x, double y, double w, double h);
88 // path API (see also CanvasPathMethods)
90 void fill(optional CanvasWindingRule winding = "nonzero");
91 void fill(Path2D path, optional CanvasWindingRule winding = "nonzero");
93 void stroke(Path2D path);
94 [Pref="canvas.focusring.enabled"] void drawFocusIfNeeded(Element element);
95 // NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element);
96 [Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element);
97 // NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element);
98 // NOT IMPLEMENTED void scrollPathIntoView();
99 // NOT IMPLEMENTED void scrollPathIntoView(Path path);
100 void clip(optional CanvasWindingRule winding = "nonzero");
101 void clip(Path2D path, optional CanvasWindingRule winding = "nonzero");
102 // NOT IMPLEMENTED void resetClip();
103 boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
104 boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
105 boolean isPointInStroke(double x, double y);
106 boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
108 // text (see also the CanvasDrawingStyles interface)
109 [Throws, LenientFloat]
110 void fillText(DOMString text, double x, double y, optional double maxWidth);
111 [Throws, LenientFloat]
112 void strokeText(DOMString text, double x, double y, optional double maxWidth);
114 TextMetrics measureText(DOMString text);
117 // NOT IMPLEMENTED attribute boolean imageSmoothingEnabled; // (default true)
118 [Throws, LenientFloat]
119 void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy);
120 [Throws, LenientFloat]
121 void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy, double dw, double dh);
122 [Throws, LenientFloat]
123 void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);
126 [Pref="canvas.hitregions.enabled", Throws] void addHitRegion(optional HitRegionOptions options);
127 [Pref="canvas.hitregions.enabled"] void removeHitRegion(DOMString id);
129 // pixel manipulation
131 ImageData createImageData(double sw, double sh);
133 ImageData createImageData(ImageData imagedata);
135 ImageData getImageData(double sx, double sy, double sw, double sh);
137 void putImageData(ImageData imagedata, double dx, double dy);
139 void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
141 // Mozilla-specific stuff
142 // FIXME Bug 768048 mozCurrentTransform/mozCurrentTransformInverse should return a WebIDL array.
144 attribute object mozCurrentTransform; // [ m11, m12, m21, m22, dx, dy ], i.e. row major
146 attribute object mozCurrentTransformInverse;
148 attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */
151 attribute any mozDash; /* default |null| */
154 attribute double mozDashOffset; /* default 0.0 */
157 attribute DOMString mozTextStyle;
159 // image smoothing mode -- if disabled, images won't be smoothed
161 attribute boolean mozImageSmoothingEnabled;
163 // Show the caret if appropriate when drawing
165 const unsigned long DRAWWINDOW_DRAW_CARET = 0x01;
166 // Don't flush pending layout notifications that could otherwise
169 const unsigned long DRAWWINDOW_DO_NOT_FLUSH = 0x02;
170 // Draw scrollbars and scroll the viewport if they are present
172 const unsigned long DRAWWINDOW_DRAW_VIEW = 0x04;
173 // Use the widget layer manager if available. This means hardware
174 // acceleration may be used, but it might actually be slower or
175 // lower quality than normal. It will however more accurately reflect
176 // the pixels rendered to the screen.
178 const unsigned long DRAWWINDOW_USE_WIDGET_LAYERS = 0x08;
179 // Don't synchronously decode images - draw what we have
181 const unsigned long DRAWWINDOW_ASYNC_DECODE_IMAGES = 0x10;
184 * Renders a region of a window into the canvas. The contents of
185 * the window's viewport are rendered, ignoring viewport clipping
191 * @param h specify the area of the window to render, in CSS
194 * @param backgroundColor the canvas is filled with this color
195 * before we render the window into it. This color may be
196 * transparent/translucent. It is given as a CSS color string
197 * (e.g., rgb() or rgba()).
199 * @param flags Used to better control the drawWindow call.
200 * Flags can be ORed together.
202 * Of course, the rendering obeys the current scale, transform and
203 * globalAlpha values.
206 * -- If 'rgba(0,0,0,0)' is used for the background color, the
207 * drawing will be transparent wherever the window is transparent.
208 * -- Top-level browsed documents are usually not transparent
209 * because the user's background-color preference is applied,
210 * but IFRAMEs are transparent if the page doesn't set a background.
211 * -- If an opaque color is used for the background color, rendering
212 * will be faster because we won't have to compute the window's
215 * This API cannot currently be used by Web content. It is chrome
219 void drawWindow(Window window, double x, double y, double w, double h,
220 DOMString bgColor, optional unsigned long flags = 0);
222 void asyncDrawXULElement(XULElement elem, double x, double y, double w,
223 double h, DOMString bgColor,
224 optional unsigned long flags = 0);
226 * This causes a context that is currently using a hardware-accelerated
227 * backend to fallback to a software one. All state should be preserved.
232 CanvasRenderingContext2D implements CanvasDrawingStyles;
233 CanvasRenderingContext2D implements CanvasPathMethods;
236 interface CanvasDrawingStyles {
239 attribute double lineWidth; // (default 1)
240 attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
242 attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
244 attribute double miterLimit; // (default 10)
247 [LenientFloat] void setLineDash(sequence<double> segments); // default empty
248 sequence<double> getLineDash();
249 [LenientFloat] attribute double lineDashOffset;
253 attribute DOMString font; // (default 10px sans-serif)
254 attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
255 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")
259 interface CanvasPathMethods {
260 // shared path API methods
263 void moveTo(double x, double y);
265 void lineTo(double x, double y);
267 void quadraticCurveTo(double cpx, double cpy, double x, double y);
270 void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
272 [Throws, LenientFloat]
273 void arcTo(double x1, double y1, double x2, double y2, double radius);
274 // NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);
277 void rect(double x, double y, double w, double h);
279 [Throws, LenientFloat]
280 void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false);
281 // NOT IMPLEMENTED [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise);
284 interface CanvasGradient {
287 // addColorStop should take a double
288 void addColorStop(float offset, DOMString color);
291 interface CanvasPattern {
293 // [Throws, LenientFloat] - could not do this overload because of bug 1020975
294 // void setTransform(double a, double b, double c, double d, double e, double f);
296 // No throw necessary here - SVGMatrix is always good.
297 void setTransform(SVGMatrix matrix);
300 interface TextMetrics {
303 readonly attribute double width; // advance width
306 * NOT IMPLEMENTED YET
308 readonly attribute double actualBoundingBoxLeft;
309 readonly attribute double actualBoundingBoxRight;
312 readonly attribute double fontBoundingBoxAscent;
313 readonly attribute double fontBoundingBoxDescent;
314 readonly attribute double actualBoundingBoxAscent;
315 readonly attribute double actualBoundingBoxDescent;
316 readonly attribute double emHeightAscent;
317 readonly attribute double emHeightDescent;
318 readonly attribute double hangingBaseline;
319 readonly attribute double alphabeticBaseline;
320 readonly attribute double ideographicBaseline;
325 [Pref="canvas.path.enabled",
327 Constructor(Path2D other),
328 Constructor(DOMString pathString)]
331 void addPath(Path2D path, optional SVGMatrix transformation);
333 Path2D implements CanvasPathMethods;