/*
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

module html {

    interface CanvasRenderingContext2D {

        // Web Applications 1.0 draft

        readonly attribute HTMLCanvasElement canvas;

        void save();
        void restore();

        void scale(in float sx, in float sy);
        void rotate(in float angle);
        void translate(in float tx, in float ty);

        attribute float globalAlpha;
        attribute [ConvertNullToNullString] DOMString globalCompositeOperation;

        CanvasGradient createLinearGradient(in float x0, in float y0, in float x1, in float y1);
        CanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1);

        attribute float lineWidth;
        attribute [ConvertNullToNullString] DOMString lineCap;
        attribute [ConvertNullToNullString] DOMString lineJoin;
        attribute float miterLimit;

        attribute float shadowOffsetX;
        attribute float shadowOffsetY;
        attribute float shadowBlur;
        attribute [ConvertNullToNullString] DOMString shadowColor;

        void clearRect(in float x, in float y, in float width, in float height)
            raises (DOMException);
        void fillRect(in float x, in float y, in float width, in float height)
            raises (DOMException);

        void beginPath();
        void closePath();
        void moveTo(in float x, in float y);
        void lineTo(in float x, in float y);
        void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
        void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
        void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius)
            raises (DOMException);
        void rect(in float x, in float y, in float width, in float height)
            raises (DOMException);
        void arc(in float x, in float y, in float radius, in float startAngle, in float endAngle, in boolean clockwise)
            raises (DOMException);
        void fill();
        void stroke();
        void clip();

        // other

        void setAlpha(in float alpha);
        void setCompositeOperation(in DOMString compositeOperation);

        void setLineWidth(in float width);
        void setLineCap(in DOMString cap);
        void setLineJoin(in DOMString join);
        void setMiterLimit(in float limit);

        void clearShadow();

        [Custom] void setStrokeColor(/* 1  */);
        [Custom] void setFillColor(/* 1 */);
        [Custom] void strokeRect(/* 4 */);
        [Custom] void drawImage(/* 3 */);
        [Custom] void drawImageFromRect(/* 10 */);
        [Custom] void setShadow(/* 3 */);
        [Custom] void createPattern(/* 2 */);
        
        attribute [Custom] custom strokeStyle;
        attribute [Custom] custom fillStyle;        
    };

}

