1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is mozilla.org code.
16 *
17 * The Initial Developer of the Original Code is
18 * Vladimir Vukicevic <vladimir@pobox.com>
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38 #include "nsISupports.idl"
39 #include "nsIVariant.idl"
40
41 interface nsIDOMWindow;
42 interface nsIDOMHTMLElement;
43 interface nsIDOMHTMLImageElement;
44 interface nsIDOMHTMLCanvasElement;
45
46 [scriptable, uuid(bbb20a59-524e-4662-981e-5e142814b20c)]
47 interface nsIDOMCanvasGradient : nsISupports
48 {
49 void addColorStop(in float offset, in DOMString color);
50 };
51
52 [scriptable, uuid(21dea65c-5c08-4eb1-ac82-81fe95be77b8)]
53 interface nsIDOMCanvasPattern : nsISupports
54 {
55 };
56
57 [scriptable, uuid(87d2b1c4-b64e-41f6-98f7-7ac4244ce9bf)]
58 interface nsIDOMCanvasRenderingContext2D : nsISupports
59 {
60 // back-reference to the canvas element for which
61 // this context was created
62 readonly attribute nsIDOMHTMLCanvasElement canvas;
63
64 // state
65 void save();
66 void restore();
67
68 // transformations
69 void scale(in float x, in float y);
70 void rotate(in float angle);
71 void translate(in float x, in float y);
72 void transform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);
73 void setTransform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);
74
75 // compositing
76 attribute float globalAlpha; /* default 1.0 -- opaque */
77 attribute DOMString globalCompositeOperation; /* default "over" */
78
79 // colors and styles
80 attribute nsIVariant strokeStyle;
81 attribute nsIVariant fillStyle;
82
83 nsIDOMCanvasGradient createLinearGradient (in float x0, in float y0, in float x1, in float y1);
84 nsIDOMCanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1);
85 //nsIDOMCanvasPattern createPattern(in nsIDOMHTMLImageElement image, in DOMString repetition);
86 nsIDOMCanvasPattern createPattern(in nsIDOMHTMLElement image, in DOMString repetition);
87 attribute float lineWidth; /* default 1 */
88 attribute DOMString lineCap; /* "butt", "round", "square" (default) */
89 attribute DOMString lineJoin; /* "round", "bevel", "miter" (default) */
90 attribute float miterLimit; /* default 10 */
91
92 // shadows
93 attribute float shadowOffsetX;
94 attribute float shadowOffsetY;
95 attribute float shadowBlur;
96 attribute DOMString shadowColor;
97
98 // rects
99 void clearRect(in float x, in float y, in float w, in float h);
100 void fillRect(in float x, in float y, in float w, in float h);
101 void strokeRect(in float x, in float y, in float w, in float h);
102
103 // path API
104 void beginPath();
105 void closePath();
106
107 void moveTo(in float x, in float y);
108 void lineTo(in float x, in float y);
109 void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
110 void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
111 void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius);
112 void arc(in float x, in float y, in float r, in float startAngle, in float endAngle, in boolean clockwise);
113 void rect(in float x, in float y, in float w, in float h);
114
115 void fill();
116 void stroke();
117 void clip();
118
119 // text api
120 attribute DOMString mozTextStyle;
121 void mozDrawText(in DOMString textToDraw);
122 float mozMeasureText(in DOMString textToMeasure);
123 void mozPathText(in DOMString textToPath);
124 void mozTextAlongPath(in DOMString textToDraw, in boolean stroke);
125
126 // image api
127 void drawImage();
128 /*
129 void drawImage(in HTMLImageElement image, in float dx, in float dy);
130 void drawImage(in HTMLImageElement image, in float dx, in float dy, in float sw, in float sh);
131 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);
132 */
133
134 // point-membership test
135 boolean isPointInPath(in float x, in float y);
136
137 // pixel manipulation
138 // ImageData getImageData (in float x, in float y, in float width, in float height);
139 // void putImageData (in ImageData d, in float x, in float y);
140 // ImageData = { width: #, height: #, data: [r, g, b, a, ...] }
141
142 void getImageData();
143 void putImageData();
144
145 /**
146 * Renders a region of a window into the canvas. The contents of
147 * the window's viewport are rendered, ignoring viewport clipping
148 * and scrolling.
149 *
150 * @param x
151 * @param y
152 * @param w
153 * @param h specify the area of the window to render, in CSS
154 * pixels.
155 *
156 * @param backgroundColor the canvas is filled with this color
157 * before we render the window into it. This color may be
158 * transparent/translucent. It is given as a CSS color string
159 * (e.g., rgb() or rgba()).
160 *
161 * Of course, the rendering obeys the current scale, transform and
162 * globalAlpha values.
163 *
164 * Hints:
165 * -- If 'rgba(0,0,0,0)' is used for the background color, the
166 * drawing will be transparent wherever the window is transparent.
167 * -- Top-level browsed documents are usually not transparent
168 * because the user's background-color preference is applied,
169 * but IFRAMEs are transparent if the page doesn't set a background.
170 * -- If an opaque color is used for the background color, rendering
171 * will be faster because we won't have to compute the window's
172 * transparency.
173 *
174 * This API cannot currently be used by Web content. It is chrome
175 * only.
176 */
177 void drawWindow(in nsIDOMWindow window, in long x, in long y,
178 in long w, in long h, in DOMString bgColor);
179 };