1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/webidl/CanvasRenderingContext2D.webidl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,323 @@ 1.4 +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + * 1.9 + * The origin of this IDL file is 1.10 + * http://www.whatwg.org/specs/web-apps/current-work/ 1.11 + * 1.12 + * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and 1.13 + * Opera Software ASA. You are granted a license to use, reproduce 1.14 + * and create derivative works of this document. 1.15 + */ 1.16 + 1.17 +enum CanvasWindingRule { "nonzero", "evenodd" }; 1.18 + 1.19 +dictionary ContextAttributes2D { 1.20 + // whether or not we're planning to do a lot of readback operations 1.21 + boolean willReadFrequently = false; 1.22 + // signal if the canvas contains an alpha channel 1.23 + boolean alpha = true; 1.24 +}; 1.25 + 1.26 +dictionary HitRegionOptions { 1.27 + DOMString id = ""; 1.28 + Element? control = null; 1.29 +}; 1.30 + 1.31 +interface CanvasRenderingContext2D { 1.32 + 1.33 + // back-reference to the canvas. Might be null if we're not 1.34 + // associated with a canvas. 1.35 + readonly attribute HTMLCanvasElement? canvas; 1.36 + 1.37 + // state 1.38 + void save(); // push state on state stack 1.39 + void restore(); // pop state stack and restore state 1.40 + 1.41 + // transformations (default transform is the identity matrix) 1.42 +// NOT IMPLEMENTED attribute SVGMatrix currentTransform; 1.43 + [Throws, LenientFloat] 1.44 + void scale(double x, double y); 1.45 + [Throws, LenientFloat] 1.46 + void rotate(double angle); 1.47 + [Throws, LenientFloat] 1.48 + void translate(double x, double y); 1.49 + [Throws, LenientFloat] 1.50 + void transform(double a, double b, double c, double d, double e, double f); 1.51 + [Throws, LenientFloat] 1.52 + void setTransform(double a, double b, double c, double d, double e, double f); 1.53 +// NOT IMPLEMENTED void resetTransform(); 1.54 + 1.55 + // compositing 1.56 + attribute unrestricted double globalAlpha; // (default 1.0) 1.57 + [Throws] 1.58 + attribute DOMString globalCompositeOperation; // (default source-over) 1.59 + 1.60 + // colors and styles (see also the CanvasDrawingStyles interface) 1.61 + attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black) 1.62 + attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black) 1.63 + [NewObject] 1.64 + CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); 1.65 + [NewObject, Throws] 1.66 + CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1); 1.67 + [NewObject, Throws] 1.68 + CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, [TreatNullAs=EmptyString] DOMString repetition); 1.69 + 1.70 + // shadows 1.71 + [LenientFloat] 1.72 + attribute double shadowOffsetX; // (default 0) 1.73 + [LenientFloat] 1.74 + attribute double shadowOffsetY; // (default 0) 1.75 + [LenientFloat] 1.76 + attribute double shadowBlur; // (default 0) 1.77 + attribute DOMString shadowColor; // (default transparent black) 1.78 + 1.79 + // rects 1.80 + [LenientFloat] 1.81 + void clearRect(double x, double y, double w, double h); 1.82 + [LenientFloat] 1.83 + void fillRect(double x, double y, double w, double h); 1.84 + [LenientFloat] 1.85 + void strokeRect(double x, double y, double w, double h); 1.86 + 1.87 + // path API (see also CanvasPathMethods) 1.88 + void beginPath(); 1.89 + void fill(optional CanvasWindingRule winding = "nonzero"); 1.90 + void fill(Path2D path, optional CanvasWindingRule winding = "nonzero"); 1.91 + void stroke(); 1.92 + void stroke(Path2D path); 1.93 + [Pref="canvas.focusring.enabled"] void drawFocusIfNeeded(Element element); 1.94 +// NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element); 1.95 + [Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element); 1.96 +// NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element); 1.97 +// NOT IMPLEMENTED void scrollPathIntoView(); 1.98 +// NOT IMPLEMENTED void scrollPathIntoView(Path path); 1.99 + void clip(optional CanvasWindingRule winding = "nonzero"); 1.100 + void clip(Path2D path, optional CanvasWindingRule winding = "nonzero"); 1.101 +// NOT IMPLEMENTED void resetClip(); 1.102 + boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero"); 1.103 + boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero"); 1.104 + boolean isPointInStroke(double x, double y); 1.105 + boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y); 1.106 + 1.107 + // text (see also the CanvasDrawingStyles interface) 1.108 + [Throws, LenientFloat] 1.109 + void fillText(DOMString text, double x, double y, optional double maxWidth); 1.110 + [Throws, LenientFloat] 1.111 + void strokeText(DOMString text, double x, double y, optional double maxWidth); 1.112 + [NewObject, Throws] 1.113 + TextMetrics measureText(DOMString text); 1.114 + 1.115 + // drawing images 1.116 +// NOT IMPLEMENTED attribute boolean imageSmoothingEnabled; // (default true) 1.117 + [Throws, LenientFloat] 1.118 + void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy); 1.119 + [Throws, LenientFloat] 1.120 + void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy, double dw, double dh); 1.121 + [Throws, LenientFloat] 1.122 + void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh); 1.123 + 1.124 + // hit regions 1.125 + [Pref="canvas.hitregions.enabled", Throws] void addHitRegion(optional HitRegionOptions options); 1.126 + [Pref="canvas.hitregions.enabled"] void removeHitRegion(DOMString id); 1.127 + 1.128 + // pixel manipulation 1.129 + [NewObject, Throws] 1.130 + ImageData createImageData(double sw, double sh); 1.131 + [NewObject, Throws] 1.132 + ImageData createImageData(ImageData imagedata); 1.133 + [NewObject, Throws] 1.134 + ImageData getImageData(double sx, double sy, double sw, double sh); 1.135 + [Throws] 1.136 + void putImageData(ImageData imagedata, double dx, double dy); 1.137 + [Throws] 1.138 + void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight); 1.139 + 1.140 + // Mozilla-specific stuff 1.141 + // FIXME Bug 768048 mozCurrentTransform/mozCurrentTransformInverse should return a WebIDL array. 1.142 + [Throws] 1.143 + attribute object mozCurrentTransform; // [ m11, m12, m21, m22, dx, dy ], i.e. row major 1.144 + [Throws] 1.145 + attribute object mozCurrentTransformInverse; 1.146 + 1.147 + attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */ 1.148 + 1.149 + [Throws] 1.150 + attribute any mozDash; /* default |null| */ 1.151 + 1.152 + [LenientFloat] 1.153 + attribute double mozDashOffset; /* default 0.0 */ 1.154 + 1.155 + [SetterThrows] 1.156 + attribute DOMString mozTextStyle; 1.157 + 1.158 + // image smoothing mode -- if disabled, images won't be smoothed 1.159 + // if scaled. 1.160 + attribute boolean mozImageSmoothingEnabled; 1.161 + 1.162 + // Show the caret if appropriate when drawing 1.163 + [ChromeOnly] 1.164 + const unsigned long DRAWWINDOW_DRAW_CARET = 0x01; 1.165 + // Don't flush pending layout notifications that could otherwise 1.166 + // be batched up 1.167 + [ChromeOnly] 1.168 + const unsigned long DRAWWINDOW_DO_NOT_FLUSH = 0x02; 1.169 + // Draw scrollbars and scroll the viewport if they are present 1.170 + [ChromeOnly] 1.171 + const unsigned long DRAWWINDOW_DRAW_VIEW = 0x04; 1.172 + // Use the widget layer manager if available. This means hardware 1.173 + // acceleration may be used, but it might actually be slower or 1.174 + // lower quality than normal. It will however more accurately reflect 1.175 + // the pixels rendered to the screen. 1.176 + [ChromeOnly] 1.177 + const unsigned long DRAWWINDOW_USE_WIDGET_LAYERS = 0x08; 1.178 + // Don't synchronously decode images - draw what we have 1.179 + [ChromeOnly] 1.180 + const unsigned long DRAWWINDOW_ASYNC_DECODE_IMAGES = 0x10; 1.181 + 1.182 + /** 1.183 + * Renders a region of a window into the canvas. The contents of 1.184 + * the window's viewport are rendered, ignoring viewport clipping 1.185 + * and scrolling. 1.186 + * 1.187 + * @param x 1.188 + * @param y 1.189 + * @param w 1.190 + * @param h specify the area of the window to render, in CSS 1.191 + * pixels. 1.192 + * 1.193 + * @param backgroundColor the canvas is filled with this color 1.194 + * before we render the window into it. This color may be 1.195 + * transparent/translucent. It is given as a CSS color string 1.196 + * (e.g., rgb() or rgba()). 1.197 + * 1.198 + * @param flags Used to better control the drawWindow call. 1.199 + * Flags can be ORed together. 1.200 + * 1.201 + * Of course, the rendering obeys the current scale, transform and 1.202 + * globalAlpha values. 1.203 + * 1.204 + * Hints: 1.205 + * -- If 'rgba(0,0,0,0)' is used for the background color, the 1.206 + * drawing will be transparent wherever the window is transparent. 1.207 + * -- Top-level browsed documents are usually not transparent 1.208 + * because the user's background-color preference is applied, 1.209 + * but IFRAMEs are transparent if the page doesn't set a background. 1.210 + * -- If an opaque color is used for the background color, rendering 1.211 + * will be faster because we won't have to compute the window's 1.212 + * transparency. 1.213 + * 1.214 + * This API cannot currently be used by Web content. It is chrome 1.215 + * only. 1.216 + */ 1.217 + [Throws, ChromeOnly] 1.218 + void drawWindow(Window window, double x, double y, double w, double h, 1.219 + DOMString bgColor, optional unsigned long flags = 0); 1.220 + [Throws, ChromeOnly] 1.221 + void asyncDrawXULElement(XULElement elem, double x, double y, double w, 1.222 + double h, DOMString bgColor, 1.223 + optional unsigned long flags = 0); 1.224 + /** 1.225 + * This causes a context that is currently using a hardware-accelerated 1.226 + * backend to fallback to a software one. All state should be preserved. 1.227 + */ 1.228 + [ChromeOnly] 1.229 + void demote(); 1.230 +}; 1.231 +CanvasRenderingContext2D implements CanvasDrawingStyles; 1.232 +CanvasRenderingContext2D implements CanvasPathMethods; 1.233 + 1.234 +[NoInterfaceObject] 1.235 +interface CanvasDrawingStyles { 1.236 + // line caps/joins 1.237 + [LenientFloat] 1.238 + attribute double lineWidth; // (default 1) 1.239 + attribute DOMString lineCap; // "butt", "round", "square" (default "butt") 1.240 + [GetterThrows] 1.241 + attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") 1.242 + [LenientFloat] 1.243 + attribute double miterLimit; // (default 10) 1.244 + 1.245 + // dashed lines 1.246 + [LenientFloat] void setLineDash(sequence<double> segments); // default empty 1.247 + sequence<double> getLineDash(); 1.248 + [LenientFloat] attribute double lineDashOffset; 1.249 + 1.250 + // text 1.251 + [SetterThrows] 1.252 + attribute DOMString font; // (default 10px sans-serif) 1.253 + attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start") 1.254 + attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic") 1.255 +}; 1.256 + 1.257 +[NoInterfaceObject] 1.258 +interface CanvasPathMethods { 1.259 + // shared path API methods 1.260 + void closePath(); 1.261 + [LenientFloat] 1.262 + void moveTo(double x, double y); 1.263 + [LenientFloat] 1.264 + void lineTo(double x, double y); 1.265 + [LenientFloat] 1.266 + void quadraticCurveTo(double cpx, double cpy, double x, double y); 1.267 + 1.268 + [LenientFloat] 1.269 + void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); 1.270 + 1.271 + [Throws, LenientFloat] 1.272 + void arcTo(double x1, double y1, double x2, double y2, double radius); 1.273 +// NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation); 1.274 + 1.275 + [LenientFloat] 1.276 + void rect(double x, double y, double w, double h); 1.277 + 1.278 + [Throws, LenientFloat] 1.279 + void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false); 1.280 +// NOT IMPLEMENTED [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise); 1.281 +}; 1.282 + 1.283 +interface CanvasGradient { 1.284 + // opaque object 1.285 + [Throws] 1.286 + // addColorStop should take a double 1.287 + void addColorStop(float offset, DOMString color); 1.288 +}; 1.289 + 1.290 +interface CanvasPattern { 1.291 + // opaque object 1.292 + // void setTransform(SVGMatrix transform); 1.293 +}; 1.294 + 1.295 +interface TextMetrics { 1.296 + 1.297 + // x-direction 1.298 + readonly attribute double width; // advance width 1.299 + 1.300 + /* 1.301 + * NOT IMPLEMENTED YET 1.302 + 1.303 + readonly attribute double actualBoundingBoxLeft; 1.304 + readonly attribute double actualBoundingBoxRight; 1.305 + 1.306 + // y-direction 1.307 + readonly attribute double fontBoundingBoxAscent; 1.308 + readonly attribute double fontBoundingBoxDescent; 1.309 + readonly attribute double actualBoundingBoxAscent; 1.310 + readonly attribute double actualBoundingBoxDescent; 1.311 + readonly attribute double emHeightAscent; 1.312 + readonly attribute double emHeightDescent; 1.313 + readonly attribute double hangingBaseline; 1.314 + readonly attribute double alphabeticBaseline; 1.315 + readonly attribute double ideographicBaseline; 1.316 + */ 1.317 + 1.318 +}; 1.319 + 1.320 +[Pref="canvas.path.enabled", 1.321 + Constructor, 1.322 + Constructor(Path2D other), 1.323 + Constructor(DOMString pathString)] 1.324 +interface Path2D 1.325 +{}; 1.326 +Path2D implements CanvasPathMethods;