4aa31cae745a60c3f26ef7c257795345d09268cd
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / html / canvas / CanvasRenderingContext2D.idl
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 enum CanvasWindingRule { "nonzero", "evenodd" };
27
28 [
29     TypeChecking=Interface|Nullable|Unrestricted,
30     WillBeGarbageCollected,
31 ] interface CanvasRenderingContext2D {
32
33     readonly attribute HTMLCanvasElement canvas;
34
35     void save();
36     void restore();
37
38     [RuntimeEnabled=ExperimentalCanvasFeatures] attribute SVGMatrix currentTransform;
39     void scale(unrestricted float sx, unrestricted float sy);
40     void rotate(unrestricted float angle);
41     void translate(unrestricted float tx, unrestricted float ty);
42     void transform(unrestricted float m11, unrestricted float m12, unrestricted float m21, unrestricted float m22, unrestricted float dx, unrestricted float dy);
43     void setTransform(unrestricted float m11, unrestricted float m12, unrestricted float m21, unrestricted float m22, unrestricted float dx, unrestricted float dy);
44     void resetTransform();
45
46     attribute unrestricted float globalAlpha;
47     [TreatNullAs=NullString] attribute DOMString globalCompositeOperation;
48
49     CanvasGradient createLinearGradient(float x0, float y0, float x1, float y1);
50     [RaisesException] CanvasGradient createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1);
51
52     attribute unrestricted float lineWidth;
53     [TreatNullAs=NullString] attribute DOMString lineCap;
54     [TreatNullAs=NullString] attribute DOMString lineJoin;
55     attribute unrestricted float miterLimit;
56
57     attribute unrestricted float shadowOffsetX;
58     attribute unrestricted float shadowOffsetY;
59     attribute unrestricted float shadowBlur;
60     [TreatNullAs=NullString] attribute DOMString shadowColor;
61
62     void setLineDash(sequence<unrestricted float> dash);
63     sequence<unrestricted float> getLineDash();
64     attribute unrestricted float lineDashOffset;
65
66     void clearRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
67     void fillRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
68
69     void beginPath();
70
71     // FIXME: Simplify these using optional CanvasWindingRule once crbug.com/339000 gets fixed.
72     void fill();
73     [RuntimeEnabled=Path2D] void fill(Path2D path);
74     void fill(CanvasWindingRule winding);
75     [RuntimeEnabled=Path2D] void fill(Path2D path, CanvasWindingRule winding);
76     void stroke();
77     [RuntimeEnabled=Path2D] void stroke(Path2D path);
78     // FIXME: Simplify these using optional CanvasWindingRule once crbug.com/339000 gets fixed.
79     void clip();
80     [RuntimeEnabled=Path2D] void clip(Path2D path);
81     void clip(CanvasWindingRule winding);
82     [RuntimeEnabled=Path2D] void clip(Path2D path, CanvasWindingRule winding);
83
84     // FIXME: Simplify these using optional CanvasWindingRule once crbug.com/339000 gets fixed.
85     boolean isPointInPath(unrestricted float x, unrestricted float y);
86     [RuntimeEnabled=Path2D] boolean isPointInPath(Path2D path, unrestricted float x, unrestricted float y);
87     boolean isPointInPath(unrestricted float x, unrestricted float y, CanvasWindingRule winding);
88     [RuntimeEnabled=Path2D] boolean isPointInPath(Path2D path, unrestricted float x, unrestricted float y, CanvasWindingRule winding);
89     boolean isPointInStroke(unrestricted float x, unrestricted float y);
90     [RuntimeEnabled=Path2D] boolean isPointInStroke(Path2D path, unrestricted float x, unrestricted float y);
91
92     [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView();
93     [RuntimeEnabled=ExperimentalCanvasFeatures] void scrollPathIntoView(Path2D path);
94
95     // text
96     attribute DOMString font;
97     attribute DOMString textAlign;
98     attribute DOMString textBaseline;
99     void fillText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);
100     void strokeText(DOMString text, unrestricted float x, unrestricted float y, optional unrestricted float maxWidth);
101
102     TextMetrics measureText(DOMString text);
103
104     // Context state
105     // Should be merged with WebGL counterpart in CanvasRenderingContext, once no-longer experimental
106     [RuntimeEnabled=ExperimentalCanvasFeatures] boolean isContextLost();
107
108     void strokeRect(unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
109
110     [RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y);
111     [RaisesException] void drawImage(HTMLImageElement image, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
112     [RaisesException] void drawImage(HTMLImageElement image, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
113     [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float x, unrestricted float y);
114     [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
115     [RaisesException] void drawImage(HTMLCanvasElement canvas, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
116     [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float x, unrestricted float y);
117     [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
118     [RaisesException] void drawImage(HTMLVideoElement video, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
119     [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float x, unrestricted float y);
120     [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float x, unrestricted float y, unrestricted float width, unrestricted float height);
121     [RuntimeEnabled=ExperimentalCanvasFeatures, RaisesException] void drawImage(ImageBitmap imageBitmap, unrestricted float sx, unrestricted float sy, unrestricted float sw, unrestricted float sh, unrestricted float dx, unrestricted float dy, unrestricted float dw, unrestricted float dh);
122
123     void putImageData(ImageData imagedata, float dx, float dy);
124     void putImageData(ImageData imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight);
125
126     [RaisesException] CanvasPattern createPattern(HTMLCanvasElement canvas, [TreatNullAs=NullString] DOMString repetitionType);
127     [RaisesException] CanvasPattern createPattern(HTMLImageElement image, [TreatNullAs=NullString] DOMString repetitionType);
128     [RaisesException] CanvasPattern createPattern(HTMLVideoElement image, [TreatNullAs=NullString] DOMString repetitionType);
129     ImageData createImageData(ImageData imagedata);
130     [RaisesException] ImageData createImageData(float sw, float sh);
131
132     [Custom] attribute object strokeStyle;
133     [Custom] attribute object fillStyle;
134
135     // pixel manipulation
136     [RaisesException] ImageData getImageData(float sx, float sy, float sw, float sh);
137
138     // Focus rings
139     [RuntimeEnabled=ExperimentalCanvasFeatures] void drawFocusIfNeeded(Element element);
140     [RuntimeEnabled=ExperimentalCanvasFeatures] void drawFocusIfNeeded(Path2D path, Element element);
141     [RuntimeEnabled=ExperimentalCanvasFeatures] boolean drawCustomFocusRing(Element element);
142
143     [ImplementedAs=imageSmoothingEnabled, MeasureAs=PrefixedImageSmoothingEnabled] attribute boolean webkitImageSmoothingEnabled;
144     [MeasureAs=UnprefixedImageSmoothingEnabled] attribute boolean imageSmoothingEnabled;
145
146     Canvas2DContextAttributes getContextAttributes();
147
148     // Non-standard APIs. Candidates for deprecation
149     [MeasureAs=CanvasRenderingContext2DSetAlpha] void setAlpha(unrestricted float alpha);
150     [MeasureAs=CanvasRenderingContext2DSetCompositeOperation] void setCompositeOperation(DOMString compositeOperation);
151     [MeasureAs=CanvasRenderingContext2DSetLineWidth] void setLineWidth(unrestricted float width);
152     [MeasureAs=CanvasRenderingContext2DSetLineCap] void setLineCap(DOMString cap);
153     [MeasureAs=CanvasRenderingContext2DSetLineJoin] void setLineJoin(DOMString join);
154     [MeasureAs=CanvasRenderingContext2DSetMiterLimit] void setMiterLimit(unrestricted float limit);
155     [MeasureAs=CanvasRenderingContext2DClearShadow] void clearShadow();
156     [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor([LegacyOverloadString] DOMString color, optional unrestricted float alpha);
157     [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(unrestricted float grayLevel, optional unrestricted float alpha);
158     [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
159     [MeasureAs=CanvasRenderingContext2DSetStrokeColor] void setStrokeColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
160     [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor([LegacyOverloadString] DOMString color, optional unrestricted float alpha);
161     [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(unrestricted float grayLevel, optional unrestricted float alpha);
162     [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
163     [MeasureAs=CanvasRenderingContext2DSetFillColor] void setFillColor(unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
164     [MeasureAs=CanvasRenderingContext2DDrawImageFromRect] void drawImageFromRect(
165         HTMLImageElement? image, optional unrestricted float sx, optional unrestricted float sy, optional unrestricted float sw, optional unrestricted float sh,
166         optional unrestricted float dx, optional unrestricted float dy, optional unrestricted float dw, optional unrestricted float dh, optional DOMString compositeOperation);
167     [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, [LegacyOverloadString] optional DOMString color, optional unrestricted float alpha);
168     [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float grayLevel, optional unrestricted float alpha);
169     [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float r, unrestricted float g, unrestricted float b, unrestricted float a);
170     [MeasureAs=CanvasRenderingContext2DSetShadow] void setShadow(unrestricted float width, unrestricted float height, unrestricted float blur, unrestricted float c, unrestricted float m, unrestricted float y, unrestricted float k, unrestricted float a);
171 };
172
173 CanvasRenderingContext2D implements CanvasPathMethods;