michael@0: /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: * michael@0: * The origin of this IDL file is michael@0: * http://www.whatwg.org/specs/web-apps/current-work/ michael@0: * michael@0: * © Copyright 2004-2011 Apple Computer, Inc., Mozilla Foundation, and michael@0: * Opera Software ASA. You are granted a license to use, reproduce michael@0: * and create derivative works of this document. michael@0: */ michael@0: michael@0: enum CanvasWindingRule { "nonzero", "evenodd" }; michael@0: michael@0: dictionary ContextAttributes2D { michael@0: // whether or not we're planning to do a lot of readback operations michael@0: boolean willReadFrequently = false; michael@0: // signal if the canvas contains an alpha channel michael@0: boolean alpha = true; michael@0: }; michael@0: michael@0: dictionary HitRegionOptions { michael@0: DOMString id = ""; michael@0: Element? control = null; michael@0: }; michael@0: michael@0: interface CanvasRenderingContext2D { michael@0: michael@0: // back-reference to the canvas. Might be null if we're not michael@0: // associated with a canvas. michael@0: readonly attribute HTMLCanvasElement? canvas; michael@0: michael@0: // state michael@0: void save(); // push state on state stack michael@0: void restore(); // pop state stack and restore state michael@0: michael@0: // transformations (default transform is the identity matrix) michael@0: // NOT IMPLEMENTED attribute SVGMatrix currentTransform; michael@0: [Throws, LenientFloat] michael@0: void scale(double x, double y); michael@0: [Throws, LenientFloat] michael@0: void rotate(double angle); michael@0: [Throws, LenientFloat] michael@0: void translate(double x, double y); michael@0: [Throws, LenientFloat] michael@0: void transform(double a, double b, double c, double d, double e, double f); michael@0: [Throws, LenientFloat] michael@0: void setTransform(double a, double b, double c, double d, double e, double f); michael@0: // NOT IMPLEMENTED void resetTransform(); michael@0: michael@0: // compositing michael@0: attribute unrestricted double globalAlpha; // (default 1.0) michael@0: [Throws] michael@0: attribute DOMString globalCompositeOperation; // (default source-over) michael@0: michael@0: // colors and styles (see also the CanvasDrawingStyles interface) michael@0: attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default black) michael@0: attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default black) michael@0: [NewObject] michael@0: CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); michael@0: [NewObject, Throws] michael@0: CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1); michael@0: [NewObject, Throws] michael@0: CanvasPattern createPattern((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, [TreatNullAs=EmptyString] DOMString repetition); michael@0: michael@0: // shadows michael@0: [LenientFloat] michael@0: attribute double shadowOffsetX; // (default 0) michael@0: [LenientFloat] michael@0: attribute double shadowOffsetY; // (default 0) michael@0: [LenientFloat] michael@0: attribute double shadowBlur; // (default 0) michael@0: attribute DOMString shadowColor; // (default transparent black) michael@0: michael@0: // rects michael@0: [LenientFloat] michael@0: void clearRect(double x, double y, double w, double h); michael@0: [LenientFloat] michael@0: void fillRect(double x, double y, double w, double h); michael@0: [LenientFloat] michael@0: void strokeRect(double x, double y, double w, double h); michael@0: michael@0: // path API (see also CanvasPathMethods) michael@0: void beginPath(); michael@0: void fill(optional CanvasWindingRule winding = "nonzero"); michael@0: void fill(Path2D path, optional CanvasWindingRule winding = "nonzero"); michael@0: void stroke(); michael@0: void stroke(Path2D path); michael@0: [Pref="canvas.focusring.enabled"] void drawFocusIfNeeded(Element element); michael@0: // NOT IMPLEMENTED void drawSystemFocusRing(Path path, HTMLElement element); michael@0: [Pref="canvas.customfocusring.enabled"] boolean drawCustomFocusRing(Element element); michael@0: // NOT IMPLEMENTED boolean drawCustomFocusRing(Path path, HTMLElement element); michael@0: // NOT IMPLEMENTED void scrollPathIntoView(); michael@0: // NOT IMPLEMENTED void scrollPathIntoView(Path path); michael@0: void clip(optional CanvasWindingRule winding = "nonzero"); michael@0: void clip(Path2D path, optional CanvasWindingRule winding = "nonzero"); michael@0: // NOT IMPLEMENTED void resetClip(); michael@0: boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero"); michael@0: boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasWindingRule winding = "nonzero"); michael@0: boolean isPointInStroke(double x, double y); michael@0: boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y); michael@0: michael@0: // text (see also the CanvasDrawingStyles interface) michael@0: [Throws, LenientFloat] michael@0: void fillText(DOMString text, double x, double y, optional double maxWidth); michael@0: [Throws, LenientFloat] michael@0: void strokeText(DOMString text, double x, double y, optional double maxWidth); michael@0: [NewObject, Throws] michael@0: TextMetrics measureText(DOMString text); michael@0: michael@0: // drawing images michael@0: // NOT IMPLEMENTED attribute boolean imageSmoothingEnabled; // (default true) michael@0: [Throws, LenientFloat] michael@0: void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy); michael@0: [Throws, LenientFloat] michael@0: void drawImage((HTMLImageElement or HTMLCanvasElement or HTMLVideoElement) image, double dx, double dy, double dw, double dh); michael@0: [Throws, LenientFloat] michael@0: 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: michael@0: // hit regions michael@0: [Pref="canvas.hitregions.enabled", Throws] void addHitRegion(optional HitRegionOptions options); michael@0: [Pref="canvas.hitregions.enabled"] void removeHitRegion(DOMString id); michael@0: michael@0: // pixel manipulation michael@0: [NewObject, Throws] michael@0: ImageData createImageData(double sw, double sh); michael@0: [NewObject, Throws] michael@0: ImageData createImageData(ImageData imagedata); michael@0: [NewObject, Throws] michael@0: ImageData getImageData(double sx, double sy, double sw, double sh); michael@0: [Throws] michael@0: void putImageData(ImageData imagedata, double dx, double dy); michael@0: [Throws] michael@0: void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight); michael@0: michael@0: // Mozilla-specific stuff michael@0: // FIXME Bug 768048 mozCurrentTransform/mozCurrentTransformInverse should return a WebIDL array. michael@0: [Throws] michael@0: attribute object mozCurrentTransform; // [ m11, m12, m21, m22, dx, dy ], i.e. row major michael@0: [Throws] michael@0: attribute object mozCurrentTransformInverse; michael@0: michael@0: attribute DOMString mozFillRule; /* "evenodd", "nonzero" (default) */ michael@0: michael@0: [Throws] michael@0: attribute any mozDash; /* default |null| */ michael@0: michael@0: [LenientFloat] michael@0: attribute double mozDashOffset; /* default 0.0 */ michael@0: michael@0: [SetterThrows] michael@0: attribute DOMString mozTextStyle; michael@0: michael@0: // image smoothing mode -- if disabled, images won't be smoothed michael@0: // if scaled. michael@0: attribute boolean mozImageSmoothingEnabled; michael@0: michael@0: // Show the caret if appropriate when drawing michael@0: [ChromeOnly] michael@0: const unsigned long DRAWWINDOW_DRAW_CARET = 0x01; michael@0: // Don't flush pending layout notifications that could otherwise michael@0: // be batched up michael@0: [ChromeOnly] michael@0: const unsigned long DRAWWINDOW_DO_NOT_FLUSH = 0x02; michael@0: // Draw scrollbars and scroll the viewport if they are present michael@0: [ChromeOnly] michael@0: const unsigned long DRAWWINDOW_DRAW_VIEW = 0x04; michael@0: // Use the widget layer manager if available. This means hardware michael@0: // acceleration may be used, but it might actually be slower or michael@0: // lower quality than normal. It will however more accurately reflect michael@0: // the pixels rendered to the screen. michael@0: [ChromeOnly] michael@0: const unsigned long DRAWWINDOW_USE_WIDGET_LAYERS = 0x08; michael@0: // Don't synchronously decode images - draw what we have michael@0: [ChromeOnly] michael@0: const unsigned long DRAWWINDOW_ASYNC_DECODE_IMAGES = 0x10; michael@0: michael@0: /** michael@0: * Renders a region of a window into the canvas. The contents of michael@0: * the window's viewport are rendered, ignoring viewport clipping michael@0: * and scrolling. michael@0: * michael@0: * @param x michael@0: * @param y michael@0: * @param w michael@0: * @param h specify the area of the window to render, in CSS michael@0: * pixels. michael@0: * michael@0: * @param backgroundColor the canvas is filled with this color michael@0: * before we render the window into it. This color may be michael@0: * transparent/translucent. It is given as a CSS color string michael@0: * (e.g., rgb() or rgba()). michael@0: * michael@0: * @param flags Used to better control the drawWindow call. michael@0: * Flags can be ORed together. michael@0: * michael@0: * Of course, the rendering obeys the current scale, transform and michael@0: * globalAlpha values. michael@0: * michael@0: * Hints: michael@0: * -- If 'rgba(0,0,0,0)' is used for the background color, the michael@0: * drawing will be transparent wherever the window is transparent. michael@0: * -- Top-level browsed documents are usually not transparent michael@0: * because the user's background-color preference is applied, michael@0: * but IFRAMEs are transparent if the page doesn't set a background. michael@0: * -- If an opaque color is used for the background color, rendering michael@0: * will be faster because we won't have to compute the window's michael@0: * transparency. michael@0: * michael@0: * This API cannot currently be used by Web content. It is chrome michael@0: * only. michael@0: */ michael@0: [Throws, ChromeOnly] michael@0: void drawWindow(Window window, double x, double y, double w, double h, michael@0: DOMString bgColor, optional unsigned long flags = 0); michael@0: [Throws, ChromeOnly] michael@0: void asyncDrawXULElement(XULElement elem, double x, double y, double w, michael@0: double h, DOMString bgColor, michael@0: optional unsigned long flags = 0); michael@0: /** michael@0: * This causes a context that is currently using a hardware-accelerated michael@0: * backend to fallback to a software one. All state should be preserved. michael@0: */ michael@0: [ChromeOnly] michael@0: void demote(); michael@0: }; michael@0: CanvasRenderingContext2D implements CanvasDrawingStyles; michael@0: CanvasRenderingContext2D implements CanvasPathMethods; michael@0: michael@0: [NoInterfaceObject] michael@0: interface CanvasDrawingStyles { michael@0: // line caps/joins michael@0: [LenientFloat] michael@0: attribute double lineWidth; // (default 1) michael@0: attribute DOMString lineCap; // "butt", "round", "square" (default "butt") michael@0: [GetterThrows] michael@0: attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter") michael@0: [LenientFloat] michael@0: attribute double miterLimit; // (default 10) michael@0: michael@0: // dashed lines michael@0: [LenientFloat] void setLineDash(sequence segments); // default empty michael@0: sequence getLineDash(); michael@0: [LenientFloat] attribute double lineDashOffset; michael@0: michael@0: // text michael@0: [SetterThrows] michael@0: attribute DOMString font; // (default 10px sans-serif) michael@0: attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start") michael@0: attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic") michael@0: }; michael@0: michael@0: [NoInterfaceObject] michael@0: interface CanvasPathMethods { michael@0: // shared path API methods michael@0: void closePath(); michael@0: [LenientFloat] michael@0: void moveTo(double x, double y); michael@0: [LenientFloat] michael@0: void lineTo(double x, double y); michael@0: [LenientFloat] michael@0: void quadraticCurveTo(double cpx, double cpy, double x, double y); michael@0: michael@0: [LenientFloat] michael@0: void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y); michael@0: michael@0: [Throws, LenientFloat] michael@0: void arcTo(double x1, double y1, double x2, double y2, double radius); michael@0: // NOT IMPLEMENTED [LenientFloat] void arcTo(double x1, double y1, double x2, double y2, double radiusX, double radiusY, double rotation); michael@0: michael@0: [LenientFloat] michael@0: void rect(double x, double y, double w, double h); michael@0: michael@0: [Throws, LenientFloat] michael@0: void arc(double x, double y, double radius, double startAngle, double endAngle, optional boolean anticlockwise = false); michael@0: // NOT IMPLEMENTED [LenientFloat] void ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, boolean anticlockwise); michael@0: }; michael@0: michael@0: interface CanvasGradient { michael@0: // opaque object michael@0: [Throws] michael@0: // addColorStop should take a double michael@0: void addColorStop(float offset, DOMString color); michael@0: }; michael@0: michael@0: interface CanvasPattern { michael@0: // opaque object michael@0: // void setTransform(SVGMatrix transform); michael@0: }; michael@0: michael@0: interface TextMetrics { michael@0: michael@0: // x-direction michael@0: readonly attribute double width; // advance width michael@0: michael@0: /* michael@0: * NOT IMPLEMENTED YET michael@0: michael@0: readonly attribute double actualBoundingBoxLeft; michael@0: readonly attribute double actualBoundingBoxRight; michael@0: michael@0: // y-direction michael@0: readonly attribute double fontBoundingBoxAscent; michael@0: readonly attribute double fontBoundingBoxDescent; michael@0: readonly attribute double actualBoundingBoxAscent; michael@0: readonly attribute double actualBoundingBoxDescent; michael@0: readonly attribute double emHeightAscent; michael@0: readonly attribute double emHeightDescent; michael@0: readonly attribute double hangingBaseline; michael@0: readonly attribute double alphabeticBaseline; michael@0: readonly attribute double ideographicBaseline; michael@0: */ michael@0: michael@0: }; michael@0: michael@0: [Pref="canvas.path.enabled", michael@0: Constructor, michael@0: Constructor(Path2D other), michael@0: Constructor(DOMString pathString)] michael@0: interface Path2D michael@0: {}; michael@0: Path2D implements CanvasPathMethods;