Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / chrome / common / extensions / api / app_window.idl
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Use the <code>chrome.app.window</code> API to create windows. Windows
6 // have an optional frame with title bar and size controls. They are not
7 // associated with any Chrome browser windows.
8 namespace app.window {
9
10   // Previously named Bounds.
11   dictionary ContentBounds {
12     long? left;
13     long? top;
14     long? width;
15     long? height;
16   };
17
18   dictionary BoundsSpecification {
19     // The X coordinate of the content or window.
20     long? left;
21
22     // The Y coordinate of the content or window.
23     long? top;
24
25     // The width of the content or window.
26     long? width;
27
28     // The height of the content or window.
29     long? height;
30
31     // The minimum width of the content or window.
32     long? minWidth;
33
34     // The minimum height of the content or window.
35     long? minHeight;
36
37     // The maximum width of the content or window.
38     long? maxWidth;
39
40     // The maximum height of the content or window.
41     long? maxHeight;
42   };
43
44   dictionary Bounds {
45     // This property can be used to read or write the current X coordinate of
46     // the content or window.
47     long left;
48
49     // This property can be used to read or write the current Y coordinate of
50     // the content or window.
51     long top;
52
53     // This property can be used to read or write the current width of the
54     // content or window.
55     long width;
56
57     // This property can be used to read or write the current height of the
58     // content or window.
59     long height;
60
61     // This property can be used to read or write the current minimum width of
62     // the content or window. A value of <code>null</code> indicates
63     // 'unspecified'.
64     long? minWidth;
65
66     // This property can be used to read or write the current minimum height of
67     // the content or window. A value of <code>null</code> indicates
68     // 'unspecified'.
69     long? minHeight;
70
71     // This property can be used to read or write the current maximum width of
72     // the content or window. A value of <code>null</code> indicates
73     // 'unspecified'.
74     long? maxWidth;
75
76     // This property can be used to read or write the current maximum height of
77     // the content or window. A value of <code>null</code> indicates
78     // 'unspecified'.
79     long? maxHeight;
80
81     // Set the left and top position of the content or window.
82     static void setPosition(long left, long top);
83
84     // Set the width and height of the content or window.
85     static void setSize(long width, long height);
86
87     // Set the minimum size constraints of the content or window. The minimum
88     // width or height can be set to <code>null</code> to remove the constraint.
89     // A value of <code>undefined</code> will leave a constraint unchanged.
90     static void setMinimumSize(long minWidth, long minHeight);
91
92     // Set the maximum size constraints of the content or window. The maximum
93     // width or height can be set to <code>null</code> to remove the constraint.
94     // A value of <code>undefined</code> will leave a constraint unchanged.
95     static void setMaximumSize(long maxWidth, long maxHeight);
96   };
97
98   dictionary FrameOptions {
99     // Frame type: <code>none</code> or <code>chrome</code> (defaults to
100     // <code>chrome</code>).<br>
101     // For <code>none</code>, the <code>-webkit-app-region</code> CSS property
102     // can be used to apply draggability to the app's window.
103     // <code>-webkit-app-region: drag</code> can be used to mark regions
104     // draggable. <code>no-drag</code> can be used to disable this style on
105     // nested elements.<br>
106     DOMString? type;
107     // Allows the frame color to be set. Frame coloring is only available if the
108     // frame type is <code>chrome</code>.
109     // Frame coloring is experimental and only available in dev channel.
110     DOMString? color;
111   };
112
113   // State of a window: normal, fullscreen, maximized, minimized.
114   enum State { normal, fullscreen, maximized, minimized };
115
116   // 'shell' is the default window type. 'panel' is managed by the OS
117   // (Currently experimental, Ash only).
118   [nodoc] enum WindowType { shell, panel };
119
120   dictionary CreateWindowOptions {
121     // Id to identify the window. This will be used to remember the size
122     // and position of the window and restore that geometry when a window
123     // with the same id is later opened.
124     // If a window with a given id is created while another window with the same
125     // id already exists, the currently opened window will be focused instead of
126     // creating a new window.
127     DOMString? id;
128
129     // Used to specify the initial position, initial size and constraints of the
130     // window's content (excluding window decorations).
131     // If an <code>id</code> is also specified and a window with a matching
132     // <code>id</code> has been shown before, the remembered bounds will be used
133     // instead.
134     //
135     // Note that the padding between the inner and outer bounds is determined by
136     // the OS. Therefore setting the same bounds property for both the
137     // <code>innerBounds</code> and <code>outerBounds</code> will result in an
138     // error.
139     //
140     // Currently only available on the Dev channel from Chrome 35.
141     BoundsSpecification? innerBounds;
142
143     // Used to specify the initial position, initial size and constraints of the
144     // window (including window decorations such as the title bar and frame).
145     // If an <code>id</code> is also specified and a window with a matching
146     // <code>id</code> has been shown before, the remembered bounds will be used
147     // instead.
148     //
149     // Note that the padding between the inner and outer bounds is determined by
150     // the OS. Therefore setting the same bounds property for both the
151     // <code>innerBounds</code> and <code>outerBounds</code> will result in an
152     // error.
153     //
154     // Currently only available on the Dev channel from Chrome 35.
155     BoundsSpecification? outerBounds;
156
157     // Default width of the window.
158     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultWidth;
159
160     // Default height of the window.
161     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultHeight;
162
163     // Default X coordinate of the window.
164     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultLeft;
165
166     // Default Y coordinate of the window.
167     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultTop;
168
169     // Width of the window.
170     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? width;
171
172     // Height of the window.
173     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? height;
174
175     // X coordinate of the window.
176     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? left;
177
178     // Y coordinate of the window.
179     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? top;
180
181     // Minimum width of the window.
182     long? minWidth;
183
184     // Minimum height of the window.
185     long? minHeight;
186
187     // Maximum width of the window.
188     long? maxWidth;
189
190     // Maximum height of the window.
191     long? maxHeight;
192
193     // Type of window to create.
194     [nodoc] WindowType? type;
195
196     // Frame type: <code>none</code> or <code>chrome</code> (defaults to
197     // <code>chrome</code>). For <code>none</code>, the
198     // <code>-webkit-app-region</code> CSS property can be used to apply
199     // draggability to the app's window. <code>-webkit-app-region: drag</code>
200     // can be used to mark regions draggable. <code>no-drag</code> can be used
201     // to disable this style on nested elements.<br>
202     // Use of <code>FrameOptions</code> is only supported in dev channel.
203     (DOMString or FrameOptions)? frame;
204
205     // Size and position of the content in the window (excluding the titlebar).
206     // If an id is also specified and a window with a matching id has been shown
207     // before, the remembered bounds of the window will be used instead.
208     ContentBounds? bounds;
209
210     // Enable window background transparency.
211     // Only supported in ash. Requires experimental API permission.
212     boolean? transparentBackground;
213
214     // The initial state of the window, allowing it to be created already
215     // fullscreen, maximized, or minimized. Defaults to 'normal'.
216     State? state;
217
218     // If true, the window will be created in a hidden state. Call show() on
219     // the window to show it once it has been created. Defaults to false.
220     boolean? hidden;
221
222     // If true, the window will be resizable by the user. Defaults to true.
223     boolean? resizable;
224
225     // By default if you specify an id for the window, the window will only be
226     // created if another window with the same id doesn't already exist. If a
227     // window with the same id already exists that window is activated instead.
228     // If you do want to create multiple windows with the same id, you can
229     // set this property to false.
230     [deprecated="Multiple windows with the same id is no longer supported."] boolean? singleton;
231
232     // If true, the window will stay above most other windows. If there are
233     // multiple windows of this kind, the currently focused window will be in
234     // the foreground. Requires the <code>"app.window.alwaysOnTop"</code>
235     // permission. Defaults to false.<br>
236     // Call <code>setAlwaysOnTop()</code> on the window to change this property
237     // after creation.<br>
238     boolean? alwaysOnTop;
239
240     // If true, the window will be focused when created. Defaults to true.
241     boolean? focused;
242   };
243
244   // Called in the creating window (parent) before the load event is called in
245   // the created window (child). The parent can set fields or functions on the
246   // child usable from onload. E.g. background.js:<br>
247   // <code>function(createdWindow) { createdWindow.contentWindow.foo =
248   // function () { }; };</code>
249   // <br>window.js:<br>
250   // <code>window.onload = function () { foo(); }</code>
251   callback CreateWindowCallback =
252       void ([instanceOf=AppWindow] object createdWindow);
253
254   [noinline_doc] dictionary AppWindow {
255     // Focus the window.
256     static void focus();
257
258     // Fullscreens the window.<br>
259     // The user will be able to restore the window by pressing ESC. An
260     // application can prevent the fullscreen state to be left when ESC is
261     // pressed by requesting the <b>app.window.fullscreen.overrideEsc</b>
262     // permission and canceling the event by calling .preventDefault(), like
263     // this:<br>
264     // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) {
265     // e.preventDefault(); } };</code>
266     static void fullscreen();
267
268     // Is the window fullscreen?
269     static boolean isFullscreen();
270
271     // Minimize the window.
272     static void minimize();
273
274     // Is the window minimized?
275     static boolean isMinimized();
276
277     // Maximize the window.
278     static void maximize();
279
280     // Is the window maximized?
281     static boolean isMaximized();
282
283     // Restore the window, exiting a maximized, minimized, or fullscreen state.
284     static void restore();
285
286     // Move the window to the position (|left|, |top|).
287     static void moveTo(long left, long top);
288
289     // Resize the window to |width|x|height| pixels in size.
290     static void resizeTo(long width, long height);
291
292     // Draw attention to the window.
293     static void drawAttention();
294
295     // Clear attention to the window.
296     static void clearAttention();
297
298     // Close the window.
299     static void close();
300
301     // Show the window. Does nothing if the window is already visible.
302     // Focus the window if |focused| is set to true or omitted.
303     static void show(optional boolean focused);
304
305     // Hide the window. Does nothing if the window is already hidden.
306     static void hide();
307
308     // Get the window's inner bounds as a $(ref:ContentBounds) object.
309     [nocompile] static ContentBounds getBounds();
310
311     // Set the window's inner bounds.
312     [nocompile] static void setBounds(ContentBounds bounds);
313
314     // Set the app icon for the window (experimental).
315     // Currently this is only being implemented on Ash.
316     // TODO(stevenjb): Investigate implementing this on Windows and OSX.
317     [nodoc] static void setIcon(DOMString iconUrl);
318
319     // Set a badge icon for the window.
320     // TODO(benwells): Document this properly before going to stable.
321     [nodoc] static void setBadgeIcon(DOMString iconUrl);
322
323     // Clear the current for the window.
324     // TODO(benwells): Document this properly before going to stable.
325     [nodoc] static void clearBadge();
326
327     // Is the window always on top?
328     static boolean isAlwaysOnTop();
329
330     // Accessors for testing.
331     [nodoc] boolean hasFrameColor;
332     [nodoc] long frameColor;
333
334     // Set whether the window should stay above most other windows. Requires the
335     // <code>"app.window.alwaysOnTop"</code> permission.
336     static void setAlwaysOnTop(boolean alwaysOnTop);
337
338     // The JavaScript 'window' object for the created child.
339     [instanceOf=Window] object contentWindow;
340
341     // The id the window was created with.
342     DOMString id;
343
344     // The position, size and constraints of the window's content, which does
345     // not include window decorations.
346     // Currently only available on the Dev channel from Chrome 35.
347     Bounds innerBounds;
348
349     // The position, size and constraints of the window, which includes window
350     // decorations, such as the title bar and frame.
351     // Currently only available on the Dev channel from Chrome 35.
352     Bounds outerBounds;
353   };
354
355   interface Functions {
356     // The size and position of a window can be specified in a number of
357     // different ways. The most simple option is not specifying anything at
358     // all, in which case a default size and platform dependent position will
359     // be used.
360     //
361     // Another option is to use the <code>bounds</code> property, which will put
362     // the window at the specified coordinates with the specified size. If the
363     // window has a frame, it's total size will be the size given plus the size
364     // of the frame; that is, the size in bounds is the content size, not the
365     // window size.
366     //
367     // To automatically remember the positions of windows you can give them ids.
368     // If a window has an id, This id is used to remember the size and position
369     // of the window whenever it is moved or resized. This size and position is
370     // then used instead of the specified bounds on subsequent opening of a
371     // window with the same id. If you need to open a window with an id at a
372     // location other than the remembered default, you can create it hidden,
373     // move it to the desired location, then show it.
374     static void create(DOMString url,
375                        optional CreateWindowOptions options,
376                        optional CreateWindowCallback callback);
377
378     // Returns an $(ref:AppWindow) object for the
379     // current script context (ie JavaScript 'window' object). This can also be
380     // called on a handle to a script context for another page, for example:
381     // otherWindow.chrome.app.window.current().
382     [nocompile] static AppWindow current();
383     [nocompile, nodoc] static void initializeAppWindow(object state);
384
385     // Gets an array of all currently created app windows. This method is new in
386     // Chrome 33.
387     [nocompile] static AppWindow[] getAll();
388
389     // Gets an $(ref:AppWindow) with the given id. If no window with the given id
390     // exists null is returned. This method is new in Chrome 33.
391     [nocompile] static AppWindow get(DOMString id);
392   };
393
394   interface Events {
395     // Fired when the window is resized.
396     [nocompile] static void onBoundsChanged();
397
398     // Fired when the window is closed.
399     [nocompile] static void onClosed();
400
401     // Fired when the window is fullscreened.
402     [nocompile] static void onFullscreened();
403
404     // Fired when the window is maximized.
405     [nocompile] static void onMaximized();
406
407     // Fired when the window is minimized.
408     [nocompile] static void onMinimized();
409
410     // Fired when the window is restored from being minimized or maximized.
411     [nocompile] static void onRestored();
412   };
413 };