Home | History | Annotate | Download | only in canvas
      1 /*
      2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 module html {
     27 
     28     interface [
     29         InterfaceUUID=98fb48ae-7216-489c-862b-8e1217fc4443,
     30         ImplementationUUID=ab4f0781-152f-450e-9546-5b3987491a54
     31     ] CanvasRenderingContext2D : CanvasRenderingContext {
     32 
     33         // Web Applications 1.0 draft
     34 
     35         void save();
     36         void restore();
     37 
     38         void scale(in float sx, in float sy);
     39         void rotate(in float angle);
     40         void translate(in float tx, in float ty);
     41         void transform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);
     42         void setTransform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);
     43 
     44         attribute float globalAlpha;
     45         attribute [ConvertNullToNullString] DOMString globalCompositeOperation;
     46 
     47         CanvasGradient createLinearGradient(in float x0, in float y0, in float x1, in float y1)
     48             raises (DOMException);
     49         CanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1)
     50             raises (DOMException);
     51 
     52         attribute float lineWidth;
     53         attribute [ConvertNullToNullString] DOMString lineCap;
     54         attribute [ConvertNullToNullString] DOMString lineJoin;
     55         attribute float miterLimit;
     56 
     57         attribute float shadowOffsetX;
     58         attribute float shadowOffsetY;
     59         attribute float shadowBlur;
     60         attribute [ConvertNullToNullString] DOMString shadowColor;
     61 
     62         void clearRect(in float x, in float y, in float width, in float height);
     63         void fillRect(in float x, in float y, in float width, in float height);
     64 
     65         void beginPath();
     66         void closePath();
     67         void moveTo(in float x, in float y);
     68         void lineTo(in float x, in float y);
     69         void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
     70         void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
     71         void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius)
     72             raises (DOMException);
     73         void rect(in float x, in float y, in float width, in float height);
     74         void arc(in float x, in float y, in float radius, in float startAngle, in float endAngle, in boolean anticlockwise)
     75             raises (DOMException);
     76         void fill();
     77         void stroke();
     78         void clip();
     79         boolean isPointInPath(in float x, in float y);
     80 
     81         // text
     82         attribute DOMString font;
     83         attribute DOMString textAlign;
     84         attribute DOMString textBaseline;
     85 
     86         TextMetrics measureText(in DOMString text);
     87 
     88         // other
     89 
     90         void setAlpha(in float alpha);
     91         void setCompositeOperation(in DOMString compositeOperation);
     92 
     93 #if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP
     94         void setLineWidth(in float width);
     95         void setLineCap(in DOMString cap);
     96         void setLineJoin(in DOMString join);
     97         void setMiterLimit(in float limit);
     98 #endif
     99 
    100         void clearShadow();
    101 
    102 #if defined(V8_BINDING) && V8_BINDING
    103         void fillText(in DOMString text, in float x, in float y, in [Optional] float maxWidth);
    104         void strokeText(in DOMString text, in float x, in float y, in [Optional] float maxWidth);
    105 
    106         void setStrokeColor(in DOMString color, in [Optional] float alpha);
    107         void setStrokeColor(in float grayLevel, in [Optional] float alpha);
    108         void setStrokeColor(in float r, in float g, in float b, in float a);
    109         void setStrokeColor(in float c, in float m, in float y, in float k, in float a);
    110 
    111         void setFillColor(in DOMString color, in [Optional] float alpha);
    112         void setFillColor(in float grayLevel, in [Optional] float alpha);
    113         void setFillColor(in float r, in float g, in float b, in float a);
    114         void setFillColor(in float c, in float m, in float y, in float k, in float a);
    115 
    116         void strokeRect(in float x, in float y, in float width, in float height, in [Optional] float lineWidth);
    117 
    118         void drawImage(in HTMLImageElement image, in float x, in float y)
    119             raises (DOMException);
    120         void drawImage(in HTMLImageElement image, in float x, in float y, in float width, in float height)
    121             raises (DOMException);
    122         void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
    123             raises (DOMException);
    124         void drawImage(in HTMLCanvasElement canvas, in float x, in float y)
    125             raises (DOMException);
    126         void drawImage(in HTMLCanvasElement canvas, in float x, in float y, in float width, in float height)
    127             raises (DOMException);
    128         void drawImage(in HTMLCanvasElement canvas, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
    129             raises (DOMException);
    130 #if defined(ENABLE_VIDEO) && ENABLE_VIDEO
    131         void drawImage(in HTMLVideoElement video, in float x, in float y)
    132             raises (DOMException);
    133         void drawImage(in HTMLVideoElement video, in float x, in float y, in float width, in float height)
    134             raises (DOMException);
    135         void drawImage(in HTMLVideoElement video, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh)
    136             raises (DOMException);
    137 #endif
    138         void drawImageFromRect(in HTMLImageElement image,
    139                                in float sx, in float sy, in float sw, in float sh,
    140                                in float dx, in float dy, in float dw, in float dh, in DOMString compositeOperation);
    141 
    142         void setShadow(in float width, in float height, in float blur, in [Optional] DOMString color, in [Optional] float alpha);
    143         void setShadow(in float width, in float height, in float blur, in float grayLevel, in [Optional] float alpha);
    144         void setShadow(in float width, in float height, in float blur, in float r, in float g, in float b, in float a);
    145         void setShadow(in float width, in float height, in float blur, in float c, in float m, in float y, in float k, in float a);
    146 
    147         CanvasPattern createPattern(in HTMLCanvasElement canvas, in [ConvertNullToNullString] DOMString repetitionType)
    148             raises (DOMException);
    149         CanvasPattern createPattern(in HTMLImageElement image, in [ConvertNullToNullString] DOMString repetitionType)
    150             raises (DOMException);
    151         void putImageData(in ImageData imagedata, in float dx, in float dy, in [Optional] float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight)
    152             raises(DOMException);
    153         ImageData createImageData(in ImageData imagedata)
    154             raises (DOMException);
    155         ImageData createImageData(in float sw, in float sh)
    156             raises (DOMException);
    157 #else
    158         // FIXME: Remove 'else' once JSC supports overloads too.
    159         [Custom] void fillText(/* 4 */);
    160         [Custom] void strokeText(/* 4 */);
    161         [Custom] void setStrokeColor(/* 1  */);
    162         [Custom] void setFillColor(/* 1 */);
    163         [Custom] void strokeRect(/* 4 */);
    164         [Custom] void drawImage(/* 3 */);
    165         [Custom] void drawImageFromRect(/* 10 */);
    166         [Custom] void setShadow(/* 3 */);
    167         [Custom] void createPattern(/* 2 */);
    168         [Custom] void putImageData(/* in ImageData imagedata, in float dx, in float dy [, in float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight] */);
    169         [Custom] ImageData createImageData(/* 3 */);
    170 #endif // defined(V8_BINDING)
    171 
    172         attribute [Custom] custom strokeStyle;
    173         attribute [Custom] custom fillStyle;
    174 
    175         // pixel manipulation
    176         ImageData getImageData(in float sx, in float sy, in float sw, in float sh)
    177             raises(DOMException);
    178     };
    179 
    180 }
    181 
    182