dom/webidl/CanvasRenderingContext2D.webidl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 5 *
michael@0 6 * The origin of this IDL file is
michael@0 7 * http://www.whatwg.org/specs/web-apps/current-work/
michael@0 8 *
michael@0 9 * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and
michael@0 10 * Opera Software ASA. You are granted a license to use, reproduce
michael@0 11 * and create derivative works of this document.
michael@0 12 */
michael@0 13
michael@0 14 enum CanvasWindingRule { "nonzero", "evenodd" };
michael@0 15
michael@0 16 dictionary ContextAttributes2D {
michael@0 17 // whether or not we're planning to do a lot of readback operations
michael@0 18 boolean willReadFrequently = false;
michael@0 19 // signal if the canvas contains an alpha channel
michael@0 20 boolean alpha = true;
michael@0 21 };
michael@0 22
michael@0 23 dictionary HitRegionOptions {
michael@0 24 DOMString id = "";
michael@0 25 Element? control = null;
michael@0 26 };
michael@0 27
michael@0 28 interface CanvasRenderingContext2D {
michael@0 29
michael@0 30 // back-reference to the canvas. Might be null if we're not
michael@0 31 // associated with a canvas.
michael@0 32 readonly attribute HTMLCanvasElement? canvas;
michael@0 33
michael@0 34 // state
michael@0 35 void save(); // push state on state stack
michael@0 36 void restore(); // pop state stack and restore state
michael@0 37
michael@0 38 // transformations (default transform is the identity matrix)
michael@0 39 // NOT IMPLEMENTED attribute SVGMatrix currentTransform;
michael@0 40 [Throws, LenientFloat]
michael@0 41 void scale(double x, double y);
michael@0 42 [Throws, LenientFloat]
michael@0 43 void rotate(double angle);
michael@0 44 [Throws, LenientFloat]
michael@0 45 void translate(double x, double y);
michael@0 46 [Throws, LenientFloat]
michael@0 47 void transform(double a, double b, double c, double d, double e, double f);
michael@0 48 [Throws, LenientFloat]
michael@0 49 void setTransform(double a, double b, double c, double d, double e, double f);
michael@0 50 // NOT IMPLEMENTED void resetTransform();
michael@0 51
michael@0 52 // compositing
michael@0 53 attribute unrestricted double globalAlpha; // (default 1.0)
michael@0 54 [Throws]
michael@0 55 attribute DOMString globalCompositeOperation; // (default source-over)
michael@0 56
michael@0 57 // colors and styles (see also the CanvasDrawingStyles interface)
michael@0 58 attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black)
michael@0 59 attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black)
michael@0 60 [NewObject]
michael@0 61 CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
michael@0 62 [NewObject, Throws]
michael@0 63 CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
michael@0 64 [NewObject, Throws]
michael@0 65 CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, [TreatNullAs=EmptyString] DOMString repetition);
michael@0 66
michael@0 67 // shadows
michael@0 68 [LenientFloat]
michael@0 69 attribute double shadowOffsetX; // (default 0)
michael@0 70 [LenientFloat]
michael@0 71 attribute double shadowOffsetY; // (default 0)
michael@0 72 [LenientFloat]
michael@0 73 attribute double shadowBlur; // (default 0)
michael@0 74 attribute DOMString shadowColor; // (default transparent black)
michael@0 75
michael@0 76 // rects
michael@0 77 [LenientFloat]
michael@0 78 void clearRect(double x, double y, double w, double h);
michael@0 79 [LenientFloat]
michael@0 80 void fillRect(double x, double y, double w, double h);
michael@0 81 [LenientFloat]
michael@0 82 void strokeRect(double x, double y, double w, double h);
michael@0 83
michael@0 84 // path API (see also CanvasPathMethods)
michael@0 85 void beginPath();
michael@0 86 void fill(optional CanvasWindingRule winding = "nonzero");
michael@0 87 void fill(Path2D path, optional CanvasWindingRule winding = "nonzero");
michael@0 88 void stroke();
michael@0 89 void stroke(Path2D path);
michael@0 90 [Pref="canvas.focusring.enabled"] void drawFocusIfNeeded(Element element);
michael@0 91 // NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element);
michael@0 92 [Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element);
michael@0 93 // NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element);
michael@0 94 // NOT IMPLEMENTED void scrollPathIntoView();
michael@0 95 // NOT IMPLEMENTED void scrollPathIntoView(Path path);
michael@0 96 void clip(optional CanvasWindingRule winding = "nonzero");
michael@0 97 void clip(Path2D path, optional CanvasWindingRule winding = "nonzero");
michael@0 98 // NOT IMPLEMENTED void resetClip();
michael@0 99 boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
michael@0 100 boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero");
michael@0 101 boolean isPointInStroke(double x, double y);
michael@0 102 boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
michael@0 103
michael@0 104 // text (see also the CanvasDrawingStyles interface)
michael@0 105 [Throws, LenientFloat]
michael@0 106 void fillText(DOMString text, double x, double y, optional double maxWidth);
michael@0 107 [Throws, LenientFloat]
michael@0 108 void strokeText(DOMString text, double x, double y, optional double maxWidth);
michael@0 109 [NewObject, Throws]
michael@0 110 TextMetrics measureText(DOMString text);
michael@0 111
michael@0 112 // drawing images
michael@0 113 // NOT IMPLEMENTED attribute boolean imageSmoothingEnabled; // (default true)
michael@0 114 [Throws, LenientFloat]
michael@0 115 void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy);
michael@0 116 [Throws, LenientFloat]
michael@0 117 void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy, double dw, double dh);
michael@0 118 [Throws, LenientFloat]
michael@0 119 void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);
michael@0 120
michael@0 121 // hit regions
michael@0 122 [Pref="canvas.hitregions.enabled", Throws] void addHitRegion(optional HitRegionOptions options);
michael@0 123 [Pref="canvas.hitregions.enabled"] void removeHitRegion(DOMString id);
michael@0 124
michael@0 125 // pixel manipulation
michael@0 126 [NewObject, Throws]
michael@0 127 ImageData createImageData(double sw, double sh);
michael@0 128 [NewObject, Throws]
michael@0 129 ImageData createImageData(ImageData imagedata);
michael@0 130 [NewObject, Throws]
michael@0 131 ImageData getImageData(double sx, double sy, double sw, double sh);
michael@0 132 [Throws]
michael@0 133 void putImageData(ImageData imagedata, double dx, double dy);
michael@0 134 [Throws]
michael@0 135 void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight);
michael@0 136
michael@0 137 // Mozilla-specific stuff
michael@0 138 // FIXME Bug 768048 mozCurrentTransform/mozCurrentTransformInverse should return a WebIDL array.
michael@0 139 [Throws]
michael@0 140 attribute object mozCurrentTransform; // [ m11, m12, m21, m22, dx, dy ], i.e. row major
michael@0 141 [Throws]
michael@0 142 attribute object mozCurrentTransformInverse;
michael@0 143
michael@0 144 attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */
michael@0 145
michael@0 146 [Throws]
michael@0 147 attribute any mozDash; /* default |null| */
michael@0 148
michael@0 149 [LenientFloat]
michael@0 150 attribute double mozDashOffset; /* default 0.0 */
michael@0 151
michael@0 152 [SetterThrows]
michael@0 153 attribute DOMString mozTextStyle;
michael@0 154
michael@0 155 // image smoothing mode -- if disabled, images won't be smoothed
michael@0 156 // if scaled.
michael@0 157 attribute boolean mozImageSmoothingEnabled;
michael@0 158
michael@0 159 // Show the caret if appropriate when drawing
michael@0 160 [ChromeOnly]
michael@0 161 const unsigned long DRAWWINDOW_DRAW_CARET = 0x01;
michael@0 162 // Don't flush pending layout notifications that could otherwise
michael@0 163 // be batched up
michael@0 164 [ChromeOnly]
michael@0 165 const unsigned long DRAWWINDOW_DO_NOT_FLUSH = 0x02;
michael@0 166 // Draw scrollbars and scroll the viewport if they are present
michael@0 167 [ChromeOnly]
michael@0 168 const unsigned long DRAWWINDOW_DRAW_VIEW = 0x04;
michael@0 169 // Use the widget layer manager if available. This means hardware
michael@0 170 // acceleration may be used, but it might actually be slower or
michael@0 171 // lower quality than normal. It will however more accurately reflect
michael@0 172 // the pixels rendered to the screen.
michael@0 173 [ChromeOnly]
michael@0 174 const unsigned long DRAWWINDOW_USE_WIDGET_LAYERS = 0x08;
michael@0 175 // Don't synchronously decode images - draw what we have
michael@0 176 [ChromeOnly]
michael@0 177 const unsigned long DRAWWINDOW_ASYNC_DECODE_IMAGES = 0x10;
michael@0 178
michael@0 179 /**
michael@0 180 * Renders a region of a window into the canvas. The contents of
michael@0 181 * the window's viewport are rendered, ignoring viewport clipping
michael@0 182 * and scrolling.
michael@0 183 *
michael@0 184 * @param x
michael@0 185 * @param y
michael@0 186 * @param w
michael@0 187 * @param h specify the area of the window to render, in CSS
michael@0 188 * pixels.
michael@0 189 *
michael@0 190 * @param backgroundColor the canvas is filled with this color
michael@0 191 * before we render the window into it. This color may be
michael@0 192 * transparent/translucent. It is given as a CSS color string
michael@0 193 * (e.g., rgb() or rgba()).
michael@0 194 *
michael@0 195 * @param flags Used to better control the drawWindow call.
michael@0 196 * Flags can be ORed together.
michael@0 197 *
michael@0 198 * Of course, the rendering obeys the current scale, transform and
michael@0 199 * globalAlpha values.
michael@0 200 *
michael@0 201 * Hints:
michael@0 202 * -- If 'rgba(0,0,0,0)' is used for the background color, the
michael@0 203 * drawing will be transparent wherever the window is transparent.
michael@0 204 * -- Top-level browsed documents are usually not transparent
michael@0 205 * because the user's background-color preference is applied,
michael@0 206 * but IFRAMEs are transparent if the page doesn't set a background.
michael@0 207 * -- If an opaque color is used for the background color, rendering
michael@0 208 * will be faster because we won't have to compute the window's
michael@0 209 * transparency.
michael@0 210 *
michael@0 211 * This API cannot currently be used by Web content. It is chrome
michael@0 212 * only.
michael@0 213 */
michael@0 214 [Throws, ChromeOnly]
michael@0 215 void drawWindow(Window window, double x, double y, double w, double h,
michael@0 216 DOMString bgColor, optional unsigned long flags = 0);
michael@0 217 [Throws, ChromeOnly]
michael@0 218 void asyncDrawXULElement(XULElement elem, double x, double y, double w,
michael@0 219 double h, DOMString bgColor,
michael@0 220 optional unsigned long flags = 0);
michael@0 221 /**
michael@0 222 * This causes a context that is currently using a hardware-accelerated
michael@0 223 * backend to fallback to a software one. All state should be preserved.
michael@0 224 */
michael@0 225 [ChromeOnly]
michael@0 226 void demote();
michael@0 227 };
michael@0 228 CanvasRenderingContext2D implements CanvasDrawingStyles;
michael@0 229 CanvasRenderingContext2D implements CanvasPathMethods;
michael@0 230
michael@0 231 [NoInterfaceObject]
michael@0 232 interface CanvasDrawingStyles {
michael@0 233 // line caps/joins
michael@0 234 [LenientFloat]
michael@0 235 attribute double lineWidth; // (default 1)
michael@0 236 attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
michael@0 237 [GetterThrows]
michael@0 238 attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
michael@0 239 [LenientFloat]
michael@0 240 attribute double miterLimit; // (default 10)
michael@0 241
michael@0 242 // dashed lines
michael@0 243 [LenientFloat] void setLineDash(sequence<double> segments); // default empty
michael@0 244 sequence<double> getLineDash();
michael@0 245 [LenientFloat] attribute double lineDashOffset;
michael@0 246
michael@0 247 // text
michael@0 248 [SetterThrows]
michael@0 249 attribute DOMString font; // (default 10px sans-serif)
michael@0 250 attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start")
michael@0 251 attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic")
michael@0 252 };
michael@0 253
michael@0 254 [NoInterfaceObject]
michael@0 255 interface CanvasPathMethods {
michael@0 256 // shared path API methods
michael@0 257 void closePath();
michael@0 258 [LenientFloat]
michael@0 259 void moveTo(double x, double y);
michael@0 260 [LenientFloat]
michael@0 261 void lineTo(double x, double y);
michael@0 262 [LenientFloat]
michael@0 263 void quadraticCurveTo(double cpx, double cpy, double x, double y);
michael@0 264
michael@0 265 [LenientFloat]
michael@0 266 void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
michael@0 267
michael@0 268 [Throws, LenientFloat]
michael@0 269 void arcTo(double x1, double y1, double x2, double y2, double radius);
michael@0 270 // NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation);
michael@0 271
michael@0 272 [LenientFloat]
michael@0 273 void rect(double x, double y, double w, double h);
michael@0 274
michael@0 275 [Throws, LenientFloat]
michael@0 276 void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false);
michael@0 277 // NOT IMPLEMENTED [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise);
michael@0 278 };
michael@0 279
michael@0 280 interface CanvasGradient {
michael@0 281 // opaque object
michael@0 282 [Throws]
michael@0 283 // addColorStop should take a double
michael@0 284 void addColorStop(float offset, DOMString color);
michael@0 285 };
michael@0 286
michael@0 287 interface CanvasPattern {
michael@0 288 // opaque object
michael@0 289 // void setTransform(SVGMatrix transform);
michael@0 290 };
michael@0 291
michael@0 292 interface TextMetrics {
michael@0 293
michael@0 294 // x-direction
michael@0 295 readonly attribute double width; // advance width
michael@0 296
michael@0 297 /*
michael@0 298 * NOT IMPLEMENTED YET
michael@0 299
michael@0 300 readonly attribute double actualBoundingBoxLeft;
michael@0 301 readonly attribute double actualBoundingBoxRight;
michael@0 302
michael@0 303 // y-direction
michael@0 304 readonly attribute double fontBoundingBoxAscent;
michael@0 305 readonly attribute double fontBoundingBoxDescent;
michael@0 306 readonly attribute double actualBoundingBoxAscent;
michael@0 307 readonly attribute double actualBoundingBoxDescent;
michael@0 308 readonly attribute double emHeightAscent;
michael@0 309 readonly attribute double emHeightDescent;
michael@0 310 readonly attribute double hangingBaseline;
michael@0 311 readonly attribute double alphabeticBaseline;
michael@0 312 readonly attribute double ideographicBaseline;
michael@0 313 */
michael@0 314
michael@0 315 };
michael@0 316
michael@0 317 [Pref="canvas.path.enabled",
michael@0 318 Constructor,
michael@0 319 Constructor(Path2D other),
michael@0 320 Constructor(DOMString pathString)]
michael@0 321 interface Path2D
michael@0 322 {};
michael@0 323 Path2D implements CanvasPathMethods;

mercurial