dom/webidl/CanvasRenderingContext2D.webidl

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial