Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / api / app_window.idl
blob9f6a6acb7992efff7cb3fef7a4754139a0c2f84b
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.
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 dictionary Bounds {
10 long? left;
11 long? top;
12 long? width;
13 long? height;
16 // State of a window: normal, fullscreen, maximized, minimized.
17 enum State { normal, fullscreen, maximized, minimized };
19 // 'shell' is the default window type. 'panel' is managed by the OS
20 // (Currently experimental, Ash only).
21 [nodoc] enum WindowType { shell, panel };
23 dictionary CreateWindowOptions {
24 // Id to identify the window. This will be used to remember the size
25 // and position of the window and restore that geometry when a window
26 // with the same id is later opened.
27 // If a window with a given id is created while another window with the same
28 // id already exists, the currently opened window will be focused instead of
29 // creating a new window.
30 DOMString? id;
32 // Default width of the window. (Deprecated; regular bounds act like this
33 // now.)
34 [nodoc] long? defaultWidth;
36 // Default height of the window. (Deprecated; regular bounds act like this
37 // now.)
38 [nodoc] long? defaultHeight;
40 // Default X coordinate of the window. (Deprecated; regular bounds act like
41 // this now.)
42 [nodoc] long? defaultLeft;
44 // Default Y coordinate of the window. (Deprecated; regular bounds act like
45 // this now.)
46 [nodoc] long? defaultTop;
48 // Width of the window. (Deprecated; use 'bounds'.)
49 [nodoc] long? width;
51 // Height of the window. (Deprecated; use 'bounds'.)
52 [nodoc] long? height;
54 // X coordinate of the window. (Deprecated; use 'bounds'.)
55 [nodoc] long? left;
57 // Y coordinate of the window. (Deprecated; use 'bounds'.)
58 [nodoc] long? top;
60 // Minimum width of the window.
61 long? minWidth;
63 // Minimum height of the window.
64 long? minHeight;
66 // Maximum width of the window.
67 long? maxWidth;
69 // Maximum height of the window.
70 long? maxHeight;
72 // Type of window to create.
73 [nodoc] WindowType? type;
75 // Frame type: <code>none</code> or <code>chrome</code> (defaults to
76 // <code>chrome</code>). For <code>none</code>, the
77 // <code>-webkit-app-region</code> CSS property can be used to apply
78 // draggability to the app's window. <code>-webkit-app-region: drag</code>
79 // can be used to mark regions draggable. <code>no-drag</code> can be used
80 // to disable this style on nested elements.
81 DOMString? frame;
83 // Size and position of the content in the window (excluding the titlebar).
84 // If an id is also specified and a window with a matching id has been shown
85 // before, the remembered bounds of the window will be used instead.
86 Bounds? bounds;
88 // Enable window background transparency.
89 // Only supported in ash. Requires experimental API permission.
90 boolean? transparentBackground;
92 // The initial state of the window, allowing it to be created already
93 // fullscreen, maximized, or minimized. Defaults to 'normal'.
94 State? state;
96 // If true, the window will be created in a hidden state. Call show() on
97 // the window to show it once it has been created. Defaults to false.
98 boolean? hidden;
100 // If true, the window will be resizable by the user. Defaults to true.
101 boolean? resizable;
103 // By default if you specify an id for the window, the window will only be
104 // created if another window with the same id doesn't already exist. If a
105 // window with the same id already exists that window is activated instead.
106 // If you do want to create multiple windows with the same id, you can
107 // set this property to false.
108 // (Deprecated; multiple windows with the same id is no longer supported.)
109 [nodoc] boolean? singleton;
111 // If true, the window will stay above most other windows. If there are
112 // multiple windows of this kind, the currently focused window will be in
113 // the foreground. Requires the <code>"alwaysOnTopWindows"</code>
114 // permission. Defaults to false.<br>
115 // Call <code>setAlwaysOnTop()</code> on the window to change this property
116 // after creation.<br>
117 // Currently only available on Dev channel.
118 boolean? alwaysOnTop;
120 // If true, the window will be focused when created. Defaults to true.
121 boolean? focused;
124 // Called in the creating window (parent) before the load event is called in
125 // the created window (child). The parent can set fields or functions on the
126 // child usable from onload. E.g. background.js:<br>
127 // <code>function(createdWindow) { createdWindow.contentWindow.foo =
128 // function () { }; };</code>
129 // <br>window.js:<br>
130 // <code>window.onload = function () { foo(); }</code>
131 callback CreateWindowCallback =
132 void ([instanceOf=AppWindow] object createdWindow);
134 [noinline_doc] dictionary AppWindow {
135 // Focus the window.
136 static void focus();
138 // Fullscreens the window.<br>
139 // The user will be able to restore the window by pressing ESC. An
140 // application can prevent the fullscreen state to be left when ESC is
141 // pressed by requesting the <b>overrideEscFullscreen</b> permission and
142 // canceling the event by calling .preventDefault(), like this:<br>
143 // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) {
144 // e.preventDefault(); } };</code>
145 static void fullscreen();
147 // Is the window fullscreen?
148 static boolean isFullscreen();
150 // Minimize the window.
151 static void minimize();
153 // Is the window minimized?
154 static boolean isMinimized();
156 // Maximize the window.
157 static void maximize();
159 // Is the window maximized?
160 static boolean isMaximized();
162 // Restore the window, exiting a maximized, minimized, or fullscreen state.
163 static void restore();
165 // Move the window to the position (|left|, |top|).
166 static void moveTo(long left, long top);
168 // Resize the window to |width|x|height| pixels in size.
169 static void resizeTo(long width, long height);
171 // Draw attention to the window.
172 static void drawAttention();
174 // Clear attention to the window.
175 static void clearAttention();
177 // Close the window.
178 static void close();
180 // Show the window. Does nothing if the window is already visible.
181 // Focus the window if |focused| is set to true or omitted.
182 static void show(optional boolean focused);
184 // Hide the window. Does nothing if the window is already hidden.
185 static void hide();
187 // Get the window's bounds as a $ref:Bounds object.
188 [nocompile] static Bounds getBounds();
190 // Set the window's bounds.
191 static void setBounds(Bounds bounds);
193 // Get the current minimum width of the window. Returns |undefined| if there
194 // is no minimum.
195 [nocompile] static long getMinWidth();
197 // Get the current minimum height of the window. Returns |undefined| if
198 // there is no minimum.
199 [nocompile] static long getMinHeight();
201 // Get the current maximum width of the window. Returns |undefined| if there
202 // is no maximum.
203 [nocompile] static long getMaxWidth();
205 // Get the current maximum height of the window. Returns |undefined| if
206 // there is no maximum.
207 [nocompile] static long getMaxHeight();
209 // Set the current minimum width of the window. Set to |null| to remove the
210 // constraint.
211 static void setMinWidth(optional long minWidth);
213 // Set the current minimum height of the window. Set to |null| to remove the
214 // constraint.
215 static void setMinHeight(optional long minHeight);
217 // Set the current maximum width of the window. Set to |null| to remove the
218 // constraint.
219 static void setMaxWidth(optional long maxWidth);
221 // Set the current maximum height of the window. Set to |null| to remove the
222 // constraint.
223 static void setMaxHeight(optional long maxHeight);
225 // Set the app icon for the window (experimental).
226 // Currently this is only being implemented on Ash.
227 // TODO(stevenjb): Investigate implementing this on Windows and OSX.
228 [nodoc] static void setIcon(DOMString iconUrl);
230 // Is the window always on top?
231 static boolean isAlwaysOnTop();
233 // Set whether the window should stay above most other windows. Requires the
234 // <code>"alwaysOnTopWindows"</code> permission.
235 // Currently only available on Dev channel.
236 static void setAlwaysOnTop(boolean alwaysOnTop);
238 // The JavaScript 'window' object for the created child.
239 [instanceOf=Window] object contentWindow;
241 // The id the window was created with.
242 DOMString id;
245 interface Functions {
246 // The size and position of a window can be specified in a number of
247 // different ways. The most simple option is not specifying anything at
248 // all, in which case a default size and platform dependent position will
249 // be used.
251 // Another option is to use the bounds property, which will put the window
252 // at the specified coordinates with the specified size. If the window has
253 // a frame, it's total size will be the size given plus the size of the
254 // frame; that is, the size in bounds is the content size, not the window
255 // size.
257 // To automatically remember the positions of windows you can give them ids.
258 // If a window has an id, This id is used to remember the size and position
259 // of the window whenever it is moved or resized. This size and position is
260 // then used instead of the specified bounds on subsequent opening of a
261 // window with the same id. If you need to open a window with an id at a
262 // location other than the remembered default, you can create it hidden,
263 // move it to the desired location, then show it.
264 static void create(DOMString url,
265 optional CreateWindowOptions options,
266 optional CreateWindowCallback callback);
268 // Returns an $ref:AppWindow object for the
269 // current script context (ie JavaScript 'window' object). This can also be
270 // called on a handle to a script context for another page, for example:
271 // otherWindow.chrome.app.window.current().
272 [nocompile] static AppWindow current();
273 [nocompile, nodoc] static void initializeAppWindow(object state);
275 // Gets an array of all currently created app windows. This method is new in
276 // Chrome 33.
277 [nocompile] static AppWindow[] getAll();
279 // Gets an $ref:AppWindow with the given id. If no window with the given id
280 // exists null is returned. This method is new in Chrome 33.
281 [nocompile] static AppWindow get(DOMString id);
284 interface Events {
285 // Fired when the window is resized.
286 [nocompile] static void onBoundsChanged();
288 // Fired when the window is closed.
289 [nocompile] static void onClosed();
291 // Fired when the window is fullscreened.
292 [nocompile] static void onFullscreened();
294 // Fired when the window is maximized.
295 [nocompile] static void onMaximized();
297 // Fired when the window is minimized.
298 [nocompile] static void onMinimized();
300 // Fired when the window is restored from being minimized or maximized.
301 [nocompile] static void onRestored();