Upstream version 7.36.149.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>.<br>
109     // Frame coloring is new in Chrome 36.
110     DOMString? color;
111     // Allows the frame color of the window when active to be set. Frame
112     // coloring is only available if the frame type is <code>chrome</code>.<br>
113     // Frame coloring is only available if the frame type is
114     // <code>chrome</code>.<br>
115     // Frame coloring is new in Chrome 36.
116     DOMString? activeColor;
117     // Allows the frame color of the window when inactive to be set differently
118     // to the active color. Frame
119     // coloring is only available if the frame type is <code>chrome</code>.<br>
120     // <code>inactiveColor</code> must be used in conjunction with <code>
121     // color</code>.<br>
122     // Frame coloring is new in Chrome 36.
123     DOMString? inactiveColor;
124   };
125
126   // State of a window: normal, fullscreen, maximized, minimized.
127   enum State { normal, fullscreen, maximized, minimized };
128
129   // 'shell' is the default window type. 'panel' is managed by the OS
130   // (Currently experimental, Ash only).
131   [nodoc] enum WindowType { shell, panel };
132
133   [noinline_doc] dictionary CreateWindowOptions {
134     // Id to identify the window. This will be used to remember the size
135     // and position of the window and restore that geometry when a window
136     // with the same id is later opened.
137     // If a window with a given id is created while another window with the same
138     // id already exists, the currently opened window will be focused instead of
139     // creating a new window.
140     DOMString? id;
141
142     // Used to specify the initial position, initial size and constraints of the
143     // window's content (excluding window decorations).
144     // If an <code>id</code> is also specified and a window with a matching
145     // <code>id</code> has been shown before, the remembered bounds will be used
146     // instead.
147     //
148     // Note that the padding between the inner and outer bounds is determined by
149     // the OS. Therefore setting the same bounds property for both the
150     // <code>innerBounds</code> and <code>outerBounds</code> will result in an
151     // error.
152     //
153     // This property is new in Chrome 36.
154     BoundsSpecification? innerBounds;
155
156     // Used to specify the initial position, initial size and constraints of the
157     // window (including window decorations such as the title bar and frame).
158     // If an <code>id</code> is also specified and a window with a matching
159     // <code>id</code> has been shown before, the remembered bounds will be used
160     // instead.
161     //
162     // Note that the padding between the inner and outer bounds is determined by
163     // the OS. Therefore setting the same bounds property for both the
164     // <code>innerBounds</code> and <code>outerBounds</code> will result in an
165     // error.
166     //
167     // This property is new in Chrome 36.
168     BoundsSpecification? outerBounds;
169
170     // Default width of the window.
171     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultWidth;
172
173     // Default height of the window.
174     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultHeight;
175
176     // Default X coordinate of the window.
177     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultLeft;
178
179     // Default Y coordinate of the window.
180     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultTop;
181
182     // Width of the window.
183     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? width;
184
185     // Height of the window.
186     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? height;
187
188     // X coordinate of the window.
189     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? left;
190
191     // Y coordinate of the window.
192     [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? top;
193
194     // Minimum width of the window.
195     [deprecated="Use innerBounds or outerBounds."] long? minWidth;
196
197     // Minimum height of the window.
198     [deprecated="Use innerBounds or outerBounds."] long? minHeight;
199
200     // Maximum width of the window.
201     [deprecated="Use innerBounds or outerBounds."] long? maxWidth;
202
203     // Maximum height of the window.
204     [deprecated="Use innerBounds or outerBounds."] long? maxHeight;
205
206     // Type of window to create.
207     [nodoc] WindowType? type;
208
209     // Frame type: <code>none</code> or <code>chrome</code> (defaults to
210     // <code>chrome</code>). For <code>none</code>, the
211     // <code>-webkit-app-region</code> CSS property can be used to apply
212     // draggability to the app's window. <code>-webkit-app-region: drag</code>
213     // can be used to mark regions draggable. <code>no-drag</code> can be used
214     // to disable this style on nested elements.<br>
215     // Use of <code>FrameOptions</code> is new in M36.
216     (DOMString or FrameOptions)? frame;
217
218     // Size and position of the content in the window (excluding the titlebar).
219     // If an id is also specified and a window with a matching id has been shown
220     // before, the remembered bounds of the window will be used instead.
221     [deprecated="Use innerBounds or outerBounds."] ContentBounds? bounds;
222
223     // Enable window background transparency.
224     // Only supported in ash. Requires experimental API permission.
225     boolean? transparentBackground;
226
227     // The initial state of the window, allowing it to be created already
228     // fullscreen, maximized, or minimized. Defaults to 'normal'.
229     State? state;
230
231     // If true, the window will be created in a hidden state. Call show() on
232     // the window to show it once it has been created. Defaults to false.
233     boolean? hidden;
234
235     // If true, the window will be resizable by the user. Defaults to true.
236     boolean? resizable;
237
238     // By default if you specify an id for the window, the window will only be
239     // created if another window with the same id doesn't already exist. If a
240     // window with the same id already exists that window is activated instead.
241     // If you do want to create multiple windows with the same id, you can
242     // set this property to false.
243     [deprecated="Multiple windows with the same id is no longer supported."] boolean? singleton;
244
245     // If true, the window will stay above most other windows. If there are
246     // multiple windows of this kind, the currently focused window will be in
247     // the foreground. Requires the <code>"alwaysOnTopWindows"</code>
248     // permission. Defaults to false.<br>
249     // Call <code>setAlwaysOnTop()</code> on the window to change this property
250     // after creation.<br>
251     boolean? alwaysOnTop;
252
253     // If true, the window will be focused when created. Defaults to true.
254     boolean? focused;
255   };
256
257   // Called in the creating window (parent) before the load event is called in
258   // the created window (child). The parent can set fields or functions on the
259   // child usable from onload. E.g. background.js:<br>
260   // <code>function(createdWindow) { createdWindow.contentWindow.foo =
261   // function () { }; };</code>
262   // <br>window.js:<br>
263   // <code>window.onload = function () { foo(); }</code>
264   callback CreateWindowCallback =
265       void ([instanceOf=AppWindow] object createdWindow);
266
267   [noinline_doc] dictionary AppWindow {
268     // Focus the window.
269     static void focus();
270
271     // Fullscreens the window.<br>
272     // The user will be able to restore the window by pressing ESC. An
273     // application can prevent the fullscreen state to be left when ESC is
274     // pressed by requesting the <b>overrideEscFullscreen</b> permission and
275     // canceling the event by calling .preventDefault(), like this:<br>
276     // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) {
277     // e.preventDefault(); } };</code>
278     static void fullscreen();
279
280     // Is the window fullscreen?
281     static boolean isFullscreen();
282
283     // Minimize the window.
284     static void minimize();
285
286     // Is the window minimized?
287     static boolean isMinimized();
288
289     // Maximize the window.
290     static void maximize();
291
292     // Is the window maximized?
293     static boolean isMaximized();
294
295     // Restore the window, exiting a maximized, minimized, or fullscreen state.
296     static void restore();
297
298     // Move the window to the position (|left|, |top|).
299     static void moveTo(long left, long top);
300
301     // Resize the window to |width|x|height| pixels in size.
302     static void resizeTo(long width, long height);
303
304     // Draw attention to the window.
305     static void drawAttention();
306
307     // Clear attention to the window.
308     static void clearAttention();
309
310     // Close the window.
311     static void close();
312
313     // Show the window. Does nothing if the window is already visible.
314     // Focus the window if |focused| is set to true or omitted.
315     static void show(optional boolean focused);
316
317     // Hide the window. Does nothing if the window is already hidden.
318     static void hide();
319
320     // Get the window's inner bounds as a $(ref:ContentBounds) object.
321     [nocompile, deprecated="Use innerBounds or outerBounds."] static ContentBounds getBounds();
322
323     // Set the window's inner bounds.
324     [nocompile, deprecated="Use innerBounds or outerBounds."] static void setBounds(ContentBounds bounds);
325
326     // Set the app icon for the window (experimental).
327     // Currently this is only being implemented on Ash.
328     // TODO(stevenjb): Investigate implementing this on Windows and OSX.
329     [nodoc] static void setIcon(DOMString iconUrl);
330
331     // Set a badge icon for the window.
332     // TODO(benwells): Document this properly before going to stable.
333     [nodoc] static void setBadgeIcon(DOMString iconUrl);
334
335     // Clear the current for the window.
336     // TODO(benwells): Document this properly before going to stable.
337     [nodoc] static void clearBadge();
338
339     // Is the window always on top?
340     static boolean isAlwaysOnTop();
341
342     // Accessors for testing.
343     [nodoc] boolean hasFrameColor;
344     [nodoc] long activeFrameColor;
345     [nodoc] long inactiveFrameColor;
346
347     // Set whether the window should stay above most other windows. Requires the
348     // <code>"alwaysOnTopWindows"</code> permission.
349     static void setAlwaysOnTop(boolean alwaysOnTop);
350
351     // The JavaScript 'window' object for the created child.
352     [instanceOf=Window] object contentWindow;
353
354     // The id the window was created with.
355     DOMString id;
356
357     // The position, size and constraints of the window's content, which does
358     // not include window decorations.
359     // This property is new in Chrome 36.
360     Bounds innerBounds;
361
362     // The position, size and constraints of the window, which includes window
363     // decorations, such as the title bar and frame.
364     // This property is new in Chrome 36.
365     Bounds outerBounds;
366   };
367
368   interface Functions {
369     // The size and position of a window can be specified in a number of
370     // different ways. The most simple option is not specifying anything at
371     // all, in which case a default size and platform dependent position will
372     // be used.
373     //
374     // To set the position, size and constraints of the window, use the
375     // <code>innerBounds</code> or <code>outerBounds</code> properties. Inner
376     // bounds do not include window decorations. Outer bounds include the
377     // window's title bar and frame. Note that the padding between the inner and
378     // outer bounds is determined by the OS. Therefore setting the same property
379     // for both inner and outer bounds is considered an error (for example,
380     // setting both <code>innerBounds.left</code> and
381     // <code>outerBounds.left</code>).
382     //
383     // To automatically remember the positions of windows you can give them ids.
384     // If a window has an id, This id is used to remember the size and position
385     // of the window whenever it is moved or resized. This size and position is
386     // then used instead of the specified bounds on subsequent opening of a
387     // window with the same id. If you need to open a window with an id at a
388     // location other than the remembered default, you can create it hidden,
389     // move it to the desired location, then show it.
390     static void create(DOMString url,
391                        optional CreateWindowOptions options,
392                        optional CreateWindowCallback callback);
393
394     // Returns an $(ref:AppWindow) object for the
395     // current script context (ie JavaScript 'window' object). This can also be
396     // called on a handle to a script context for another page, for example:
397     // otherWindow.chrome.app.window.current().
398     [nocompile] static AppWindow current();
399     [nocompile, nodoc] static void initializeAppWindow(object state);
400
401     // Gets an array of all currently created app windows. This method is new in
402     // Chrome 33.
403     [nocompile] static AppWindow[] getAll();
404
405     // Gets an $(ref:AppWindow) with the given id. If no window with the given id
406     // exists null is returned. This method is new in Chrome 33.
407     [nocompile] static AppWindow get(DOMString id);
408   };
409
410   interface Events {
411     // Fired when the window is resized.
412     [nocompile] static void onBoundsChanged();
413
414     // Fired when the window is closed.
415     [nocompile] static void onClosed();
416
417     // Fired when the window is fullscreened.
418     [nocompile] static void onFullscreened();
419
420     // Fired when the window is maximized.
421     [nocompile] static void onMaximized();
422
423     // Fired when the window is minimized.
424     [nocompile] static void onMinimized();
425
426     // Fired when the window is restored from being minimized or maximized.
427     [nocompile] static void onRestored();
428   };
429 };