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 enum CanvasLineCap { "butt", "round", "square" };
17 enum CanvasLineJoin { "round", "bevel", "miter" };
18 enum CanvasTextAlign { "start", "end", "left", "right", "center" };
19 enum CanvasTextBaseline { "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" };
20 enum CanvasDirection { "ltr", "rtl", "inherit" };
21 enum CanvasFontKerning { "auto", "normal", "none" };
22 enum CanvasFontStretch { "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" };
23 enum CanvasFontVariantCaps { "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase", "titling-caps" };
24 enum CanvasTextRendering { "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" };
27 dictionary CanvasRenderingContext2DSettings {
28 // signal if the canvas contains an alpha channel
31 boolean desynchronized = false;
33 PredefinedColorSpace colorSpace = "srgb";
35 // whether or not we're planning to do a lot of readback operations
36 boolean willReadFrequently = false;
39 dictionary HitRegionOptions {
42 Element? control = null;
45 typedef (HTMLImageElement or
46 SVGImageElement) HTMLOrSVGImageElement;
48 typedef (HTMLOrSVGImageElement or
53 VideoFrame) CanvasImageSource;
56 interface CanvasRenderingContext2D {
58 // back-reference to the canvas. Might be null if we're not
59 // associated with a canvas.
60 readonly attribute HTMLCanvasElement? canvas;
62 CanvasRenderingContext2DSettings getContextAttributes();
64 // Show the caret if appropriate when drawing
65 [Func="CanvasUtils::HasDrawWindowPrivilege"]
66 const unsigned long DRAWWINDOW_DRAW_CARET = 0x01;
67 // Don't flush pending layout notifications that could otherwise
69 [Func="CanvasUtils::HasDrawWindowPrivilege"]
70 const unsigned long DRAWWINDOW_DO_NOT_FLUSH = 0x02;
71 // Draw scrollbars and scroll the viewport if they are present
72 [Func="CanvasUtils::HasDrawWindowPrivilege"]
73 const unsigned long DRAWWINDOW_DRAW_VIEW = 0x04;
74 // Use the widget layer manager if available. This means hardware
75 // acceleration may be used, but it might actually be slower or
76 // lower quality than normal. It will however more accurately reflect
77 // the pixels rendered to the screen.
78 [Func="CanvasUtils::HasDrawWindowPrivilege"]
79 const unsigned long DRAWWINDOW_USE_WIDGET_LAYERS = 0x08;
80 // Don't synchronously decode images - draw what we have
81 [Func="CanvasUtils::HasDrawWindowPrivilege"]
82 const unsigned long DRAWWINDOW_ASYNC_DECODE_IMAGES = 0x10;
85 * Renders a region of a window into the canvas. The contents of
86 * the window's viewport are rendered, ignoring viewport clipping
92 * @param h specify the area of the window to render, in CSS
95 * @param backgroundColor the canvas is filled with this color
96 * before we render the window into it. This color may be
97 * transparent/translucent. It is given as a CSS color string
98 * (e.g., rgb() or rgba()).
100 * @param flags Used to better control the drawWindow call.
101 * Flags can be ORed together.
103 * Of course, the rendering obeys the current scale, transform and
104 * globalAlpha values.
107 * -- If 'rgba(0,0,0,0)' is used for the background color, the
108 * drawing will be transparent wherever the window is transparent.
109 * -- Top-level browsed documents are usually not transparent
110 * because the user's background-color preference is applied,
111 * but IFRAMEs are transparent if the page doesn't set a background.
112 * -- If an opaque color is used for the background color, rendering
113 * will be faster because we won't have to compute the window's
116 * This API cannot currently be used by Web content. It is chrome
117 * and Web Extensions (with a permission) only.
119 [Throws, NeedsSubjectPrincipal, Func="CanvasUtils::HasDrawWindowPrivilege"]
120 undefined drawWindow(Window window, double x, double y, double w, double h,
121 UTF8String bgColor, optional unsigned long flags = 0);
124 * This causes a context that is currently using a hardware-accelerated
125 * backend to fallback to a software one. All state should be preserved.
131 CanvasRenderingContext2D includes CanvasState;
132 CanvasRenderingContext2D includes CanvasTransform;
133 CanvasRenderingContext2D includes CanvasCompositing;
134 CanvasRenderingContext2D includes CanvasImageSmoothing;
135 CanvasRenderingContext2D includes CanvasFillStrokeStyles;
136 CanvasRenderingContext2D includes CanvasShadowStyles;
137 CanvasRenderingContext2D includes CanvasFilters;
138 CanvasRenderingContext2D includes CanvasRect;
139 CanvasRenderingContext2D includes CanvasDrawPath;
140 CanvasRenderingContext2D includes CanvasUserInterface;
141 CanvasRenderingContext2D includes CanvasText;
142 CanvasRenderingContext2D includes CanvasDrawImage;
143 CanvasRenderingContext2D includes CanvasImageData;
144 CanvasRenderingContext2D includes CanvasPathDrawingStyles;
145 CanvasRenderingContext2D includes CanvasTextDrawingStyles;
146 CanvasRenderingContext2D includes CanvasPathMethods;
149 interface mixin CanvasState {
151 undefined save(); // push state on state stack
152 undefined restore(); // pop state stack and restore state
153 undefined reset(); // reset the rendering context to its default state
154 boolean isContextLost(); // return whether context is lost
157 interface mixin CanvasTransform {
158 // transformations (default transform is the identity matrix)
159 [Throws, LenientFloat]
160 undefined scale(double x, double y);
161 [Throws, LenientFloat]
162 undefined rotate(double angle);
163 [Throws, LenientFloat]
164 undefined translate(double x, double y);
165 [Throws, LenientFloat]
166 undefined transform(double a, double b, double c, double d, double e, double f);
168 [NewObject, Throws] DOMMatrix getTransform();
169 [Throws, LenientFloat]
170 undefined setTransform(double a, double b, double c, double d, double e, double f);
172 undefined setTransform(optional DOMMatrix2DInit transform = {});
174 undefined resetTransform();
177 interface mixin CanvasCompositing {
178 attribute unrestricted double globalAlpha; // (default 1.0)
180 attribute DOMString globalCompositeOperation; // (default source-over)
183 interface mixin CanvasImageSmoothing {
185 attribute boolean imageSmoothingEnabled;
188 interface mixin CanvasFillStrokeStyles {
189 // colors and styles (see also the CanvasPathDrawingStyles interface)
190 attribute (UTF8String or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
191 attribute (UTF8String or CanvasGradient or CanvasPattern) fillStyle; // (default black)
193 CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
195 CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
197 CanvasGradient createConicGradient(double angle, double cx, double cy);
199 CanvasPattern? createPattern(CanvasImageSource image, [LegacyNullToEmptyString] DOMString repetition);
202 interface mixin CanvasShadowStyles {
204 attribute double shadowOffsetX; // (default 0)
206 attribute double shadowOffsetY; // (default 0)
208 attribute double shadowBlur; // (default 0)
209 attribute UTF8String shadowColor; // (default transparent black)
212 interface mixin CanvasFilters {
214 attribute UTF8String filter; // (default empty string = no filter)
217 interface mixin CanvasRect {
219 undefined clearRect(double x, double y, double w, double h);
221 undefined fillRect(double x, double y, double w, double h);
223 undefined strokeRect(double x, double y, double w, double h);
226 interface mixin CanvasDrawPath {
227 // path API (see also CanvasPathMethods)
228 undefined beginPath();
229 undefined fill(optional CanvasWindingRule winding = "nonzero");
230 undefined fill(Path2D path, optional CanvasWindingRule winding = "nonzero");
232 undefined stroke(Path2D path);
233 undefined clip(optional CanvasWindingRule winding = "nonzero");
234 undefined clip(Path2D path, optional CanvasWindingRule winding = "nonzero");
235 // NOT IMPLEMENTED undefined resetClip();
236 [NeedsSubjectPrincipal]
237 boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
238 [NeedsSubjectPrincipal] // Only required because overloads can't have different extended attributes.
239 boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
240 [NeedsSubjectPrincipal]
241 boolean isPointInStroke(double x, double y);
242 [NeedsSubjectPrincipal] // Only required because overloads can't have different extended attributes.
243 boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
246 interface mixin CanvasUserInterface {
247 [Throws] undefined drawFocusIfNeeded(Element element);
248 // NOT IMPLEMENTED undefined scrollPathIntoView();
249 // NOT IMPLEMENTED undefined scrollPathIntoView(Path path);
252 interface mixin CanvasText {
253 // text (see also the CanvasPathDrawingStyles interface)
254 [Throws, LenientFloat]
255 undefined fillText(DOMString text, double x, double y, optional double maxWidth);
256 [Throws, LenientFloat]
257 undefined strokeText(DOMString text, double x, double y, optional double maxWidth);
259 TextMetrics measureText(DOMString text);
262 interface mixin CanvasDrawImage {
263 [Throws, LenientFloat]
264 undefined drawImage(CanvasImageSource image, double dx, double dy);
265 [Throws, LenientFloat]
266 undefined drawImage(CanvasImageSource image, double dx, double dy, double dw, double dh);
267 [Throws, LenientFloat]
268 undefined drawImage(CanvasImageSource image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);
271 // See https://github.com/whatwg/html/issues/6262 for [EnforceRange] usage.
272 interface mixin CanvasImageData {
273 // pixel manipulation
275 ImageData createImageData([EnforceRange] long sw, [EnforceRange] long sh);
277 ImageData createImageData(ImageData imagedata);
278 [NewObject, Throws, NeedsSubjectPrincipal]
279 ImageData getImageData([EnforceRange] long sx, [EnforceRange] long sy, [EnforceRange] long sw, [EnforceRange] long sh);
281 undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy);
283 undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy, [EnforceRange] long dirtyX, [EnforceRange] long dirtyY, [EnforceRange] long dirtyWidth, [EnforceRange] long dirtyHeight);
286 interface mixin CanvasPathDrawingStyles {
289 attribute double lineWidth; // (default 1)
290 attribute CanvasLineCap lineCap; // (default "butt")
291 attribute CanvasLineJoin lineJoin; // (default "miter")
293 attribute double miterLimit; // (default 10)
296 [LenientFloat, Throws] undefined setLineDash(sequence<double> segments); // default empty
297 sequence<double> getLineDash();
298 [LenientFloat] attribute double lineDashOffset;
301 interface mixin CanvasTextDrawingStyles {
304 attribute UTF8String font; // (default 10px sans-serif)
305 attribute CanvasTextAlign textAlign; // (default: "start")
306 attribute CanvasTextBaseline textBaseline; // (default: "alphabetic")
307 attribute CanvasDirection direction; // (default: "inherit")
308 attribute UTF8String letterSpacing; // default: "0px"
309 attribute CanvasFontKerning fontKerning; // (default: "auto")
310 attribute CanvasFontStretch fontStretch; // (default: "normal")
311 attribute CanvasFontVariantCaps fontVariantCaps; // (default: "normal")
312 attribute CanvasTextRendering textRendering; // (default: "auto")
313 attribute UTF8String wordSpacing; // default: "0px"
316 interface mixin CanvasPathMethods {
317 // shared path API methods
318 undefined closePath();
320 undefined moveTo(double x, double y);
322 undefined lineTo(double x, double y);
324 undefined quadraticCurveTo(double cpx, double cpy, double x, double y);
327 undefined bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
329 [Throws, LenientFloat]
330 undefined arcTo(double x1, double y1, double x2, double y2, double radius);
331 // NOT IMPLEMENTED [LenientFloat] undefined arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);
334 undefined rect(double x, double y, double w, double h);
337 undefined roundRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h, optional (unrestricted double or DOMPointInit or sequence<(unrestricted double or DOMPointInit)>) radii = 0);
339 [Throws, LenientFloat]
340 undefined arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false);
342 [Throws, LenientFloat]
343 undefined ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, optional boolean anticlockwise = false);
346 [Exposed=(Window,Worker),
347 Func="mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread"]
348 interface CanvasGradient {
351 // addColorStop should take a double
352 undefined addColorStop(float offset, UTF8String color);
355 [Exposed=(Window,Worker),
356 Func="mozilla::dom::OffscreenCanvas::PrefEnabledOnWorkerThread"]
357 interface CanvasPattern {
359 // [Throws, LenientFloat] - could not do this overload because of bug 1020975
360 // undefined setTransform(double a, double b, double c, double d, double e, double f);
363 undefined setTransform(optional DOMMatrix2DInit matrix = {});
366 [Exposed=(Window,Worker)]
367 interface TextMetrics {
370 readonly attribute double width; // advance width
372 // [experimental] actualBoundingBox* attributes
373 [Pref="dom.textMetrics.actualBoundingBox.enabled"]
374 readonly attribute double actualBoundingBoxLeft;
375 [Pref="dom.textMetrics.actualBoundingBox.enabled"]
376 readonly attribute double actualBoundingBoxRight;
379 // [experimental] fontBoundingBox* attributes
380 [Pref="dom.textMetrics.fontBoundingBox.enabled"]
381 readonly attribute double fontBoundingBoxAscent;
382 [Pref="dom.textMetrics.fontBoundingBox.enabled"]
383 readonly attribute double fontBoundingBoxDescent;
385 // [experimental] actualBoundingBox* attributes
386 [Pref="dom.textMetrics.actualBoundingBox.enabled"]
387 readonly attribute double actualBoundingBoxAscent;
388 [Pref="dom.textMetrics.actualBoundingBox.enabled"]
389 readonly attribute double actualBoundingBoxDescent;
391 // [experimental] emHeight* attributes
392 [Pref="dom.textMetrics.emHeight.enabled"]
393 readonly attribute double emHeightAscent;
394 [Pref="dom.textMetrics.emHeight.enabled"]
395 readonly attribute double emHeightDescent;
397 // [experimental] *Baseline attributes
398 [Pref="dom.textMetrics.baselines.enabled"]
399 readonly attribute double hangingBaseline;
400 [Pref="dom.textMetrics.baselines.enabled"]
401 readonly attribute double alphabeticBaseline;
402 [Pref="dom.textMetrics.baselines.enabled"]
403 readonly attribute double ideographicBaseline;
406 [Exposed=(Window,Worker)]
410 constructor(Path2D other);
411 constructor(DOMString pathString);
413 [Throws] undefined addPath(Path2D path, optional DOMMatrix2DInit transform = {});
415 Path2D includes CanvasPathMethods;