Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / common / api / app_window.idl
blobf75978ec2688f6bf9c394d7e99f461214023fdd8
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. See the <a
8 // href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/window-state">
9 // Window State Sample</a> for a demonstration of these options.
10 namespace app.window {
12 // Previously named Bounds.
13 dictionary ContentBounds {
14 long? left;
15 long? top;
16 long? width;
17 long? height;
20 dictionary BoundsSpecification {
21 // The X coordinate of the content or window.
22 long? left;
24 // The Y coordinate of the content or window.
25 long? top;
27 // The width of the content or window.
28 long? width;
30 // The height of the content or window.
31 long? height;
33 // The minimum width of the content or window.
34 long? minWidth;
36 // The minimum height of the content or window.
37 long? minHeight;
39 // The maximum width of the content or window.
40 long? maxWidth;
42 // The maximum height of the content or window.
43 long? maxHeight;
46 dictionary Bounds {
47 // This property can be used to read or write the current X coordinate of
48 // the content or window.
49 long left;
51 // This property can be used to read or write the current Y coordinate of
52 // the content or window.
53 long top;
55 // This property can be used to read or write the current width of the
56 // content or window.
57 long width;
59 // This property can be used to read or write the current height of the
60 // content or window.
61 long height;
63 // This property can be used to read or write the current minimum width of
64 // the content or window. A value of <code>null</code> indicates
65 // 'unspecified'.
66 long? minWidth;
68 // This property can be used to read or write the current minimum height of
69 // the content or window. A value of <code>null</code> indicates
70 // 'unspecified'.
71 long? minHeight;
73 // This property can be used to read or write the current maximum width of
74 // the content or window. A value of <code>null</code> indicates
75 // 'unspecified'.
76 long? maxWidth;
78 // This property can be used to read or write the current maximum height of
79 // the content or window. A value of <code>null</code> indicates
80 // 'unspecified'.
81 long? maxHeight;
83 // Set the left and top position of the content or window.
84 static void setPosition(long left, long top);
86 // Set the width and height of the content or window.
87 static void setSize(long width, long height);
89 // Set the minimum size constraints of the content or window. The minimum
90 // width or height can be set to <code>null</code> to remove the constraint.
91 // A value of <code>undefined</code> will leave a constraint unchanged.
92 static void setMinimumSize(long minWidth, long minHeight);
94 // Set the maximum size constraints of the content or window. The maximum
95 // width or height can be set to <code>null</code> to remove the constraint.
96 // A value of <code>undefined</code> will leave a constraint unchanged.
97 static void setMaximumSize(long maxWidth, long maxHeight);
100 dictionary FrameOptions {
101 // Frame type: <code>none</code> or <code>chrome</code> (defaults to
102 // <code>chrome</code>).
104 // For <code>none</code>, the <code>-webkit-app-region</code> CSS property
105 // can be used to apply draggability to the app's window.
107 // <code>-webkit-app-region: drag</code> can be used to mark regions
108 // draggable. <code>no-drag</code> can be used to disable this style on
109 // nested elements.
110 DOMString? type;
111 // Allows the frame color to be set. Frame coloring is only available if the
112 // frame type is <code>chrome</code>.
114 // Frame coloring is new in Chrome 36.
115 DOMString? color;
116 // Allows the frame color of the window when active to be set. Frame
117 // coloring is only available if the frame type is <code>chrome</code>.
119 // Frame coloring is only available if the frame type is
120 // <code>chrome</code>.
122 // Frame coloring is new in Chrome 36.
123 DOMString? activeColor;
124 // Allows the frame color of the window when inactive to be set differently
125 // to the active color. Frame
126 // coloring is only available if the frame type is <code>chrome</code>.
128 // <code>inactiveColor</code> must be used in conjunction with <code>
129 // color</code>.
131 // Frame coloring is new in Chrome 36.
132 DOMString? inactiveColor;
135 // State of a window: normal, fullscreen, maximized, minimized.
136 enum State { normal, fullscreen, maximized, minimized };
138 // Specifies the type of window to create.
139 enum WindowType {
140 // Default window type.
141 shell,
142 // OS managed window (Chrome OS only).
143 panel
146 [noinline_doc] dictionary CreateWindowOptions {
147 // Id to identify the window. This will be used to remember the size
148 // and position of the window and restore that geometry when a window
149 // with the same id is later opened.
150 // If a window with a given id is created while another window with the same
151 // id already exists, the currently opened window will be focused instead of
152 // creating a new window.
153 DOMString? id;
155 // Used to specify the initial position, initial size and constraints of the
156 // window's content (excluding window decorations).
157 // If an <code>id</code> is also specified and a window with a matching
158 // <code>id</code> has been shown before, the remembered bounds will be used
159 // instead.
161 // Note that the padding between the inner and outer bounds is determined by
162 // the OS. Therefore setting the same bounds property for both the
163 // <code>innerBounds</code> and <code>outerBounds</code> will result in an
164 // error.
166 // This property is new in Chrome 36.
167 BoundsSpecification? innerBounds;
169 // Used to specify the initial position, initial size and constraints of the
170 // window (including window decorations such as the title bar and frame).
171 // If an <code>id</code> is also specified and a window with a matching
172 // <code>id</code> has been shown before, the remembered bounds will be used
173 // instead.
175 // Note that the padding between the inner and outer bounds is determined by
176 // the OS. Therefore setting the same bounds property for both the
177 // <code>innerBounds</code> and <code>outerBounds</code> will result in an
178 // error.
180 // This property is new in Chrome 36.
181 BoundsSpecification? outerBounds;
183 // Default width of the window.
184 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultWidth;
186 // Default height of the window.
187 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultHeight;
189 // Default X coordinate of the window.
190 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultLeft;
192 // Default Y coordinate of the window.
193 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultTop;
195 // Width of the window.
196 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? width;
198 // Height of the window.
199 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? height;
201 // X coordinate of the window.
202 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? left;
204 // Y coordinate of the window.
205 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? top;
207 // Minimum width of the window.
208 [deprecated="Use innerBounds or outerBounds."] long? minWidth;
210 // Minimum height of the window.
211 [deprecated="Use innerBounds or outerBounds."] long? minHeight;
213 // Maximum width of the window.
214 [deprecated="Use innerBounds or outerBounds."] long? maxWidth;
216 // Maximum height of the window.
217 [deprecated="Use innerBounds or outerBounds."] long? maxHeight;
219 // Type of window to create.
220 WindowType? type;
222 // Creates a special ime window. This window is not focusable and can be
223 // stacked above virtual keyboard window. This is restriced to component ime
224 // extensions.
225 // Requires the <code>app.window.ime</code> API permission.
226 [nodoc] boolean? ime;
228 // Frame type: <code>none</code> or <code>chrome</code> (defaults to
229 // <code>chrome</code>). For <code>none</code>, the
230 // <code>-webkit-app-region</code> CSS property can be used to apply
231 // draggability to the app's window. <code>-webkit-app-region: drag</code>
232 // can be used to mark regions draggable. <code>no-drag</code> can be used
233 // to disable this style on nested elements.
235 // Use of <code>FrameOptions</code> is new in M36.
236 (DOMString or FrameOptions)? frame;
238 // Size and position of the content in the window (excluding the titlebar).
239 // If an id is also specified and a window with a matching id has been shown
240 // before, the remembered bounds of the window will be used instead.
241 [deprecated="Use innerBounds or outerBounds."] ContentBounds? bounds;
243 // Enable window background transparency.
244 // Only supported in ash. Requires the <code>app.window.alpha</code> API
245 // permission.
246 [nodoc] boolean? alphaEnabled;
248 // The initial state of the window, allowing it to be created already
249 // fullscreen, maximized, or minimized. Defaults to 'normal'.
250 State? state;
252 // If true, the window will be created in a hidden state. Call show() on
253 // the window to show it once it has been created. Defaults to false.
254 boolean? hidden;
256 // If true, the window will be resizable by the user. Defaults to true.
257 boolean? resizable;
259 // By default if you specify an id for the window, the window will only be
260 // created if another window with the same id doesn't already exist. If a
261 // window with the same id already exists that window is activated instead.
262 // If you do want to create multiple windows with the same id, you can
263 // set this property to false.
264 [deprecated="Multiple windows with the same id is no longer supported."] boolean? singleton;
266 // If true, the window will stay above most other windows. If there are
267 // multiple windows of this kind, the currently focused window will be in
268 // the foreground. Requires the <code>alwaysOnTopWindows</code>
269 // permission. Defaults to false.
271 // Call <code>setAlwaysOnTop()</code> on the window to change this property
272 // after creation.
273 boolean? alwaysOnTop;
275 // If true, the window will be focused when created. Defaults to true.
276 boolean? focused;
278 // If true, and supported by the platform, the window will be visible on all
279 // workspaces.
280 boolean? visibleOnAllWorkspaces;
283 // Called in the creating window (parent) before the load event is called in
284 // the created window (child). The parent can set fields or functions on the
285 // child usable from onload. E.g. background.js:
287 // <code>function(createdWindow) { createdWindow.contentWindow.foo =
288 // function () { }; };</code>
290 // window.js:
292 // <code>window.onload = function () { foo(); }</code>
293 callback CreateWindowCallback =
294 void ([instanceOf=AppWindow] object createdWindow);
296 [noinline_doc] dictionary AppWindow {
297 // Focus the window.
298 static void focus();
300 // Fullscreens the window.
302 // The user will be able to restore the window by pressing ESC. An
303 // application can prevent the fullscreen state to be left when ESC is
304 // pressed by requesting the <code>app.window.fullscreen.overrideEsc</code>
305 // permission and canceling the event by calling .preventDefault(), in the
306 // keydown and keyup handlers, like this:
308 // <code>window.onkeydown = window.onkeyup = function(e) { if (e.keyCode ==
309 // 27 /* ESC */) { e.preventDefault(); } };</code>
311 // Note <code>window.fullscreen()</code> will cause the entire window to
312 // become fullscreen and does not require a user gesture. The HTML5
313 // fullscreen API can also be used to enter fullscreen mode (see
314 // <a href="http://developer.chrome.com/apps/api_other.html">Web APIs</a>
315 // for more details).
316 static void fullscreen();
318 // Is the window fullscreen? This will be true if the window has been
319 // created fullscreen or was made fullscreen via the
320 // <code>AppWindow</code> or HTML5 fullscreen APIs.
321 static boolean isFullscreen();
323 // Minimize the window.
324 static void minimize();
326 // Is the window minimized?
327 static boolean isMinimized();
329 // Maximize the window.
330 static void maximize();
332 // Is the window maximized?
333 static boolean isMaximized();
335 // Restore the window, exiting a maximized, minimized, or fullscreen state.
336 static void restore();
338 // Move the window to the position (|left|, |top|).
339 [deprecated="Use outerBounds."] static void moveTo(long left, long top);
341 // Resize the window to |width|x|height| pixels in size.
342 [deprecated="Use outerBounds."] static void resizeTo(long width, long height);
344 // Draw attention to the window.
345 static void drawAttention();
347 // Clear attention to the window.
348 static void clearAttention();
350 // Close the window.
351 static void close();
353 // Show the window. Does nothing if the window is already visible.
354 // Focus the window if |focused| is set to true or omitted.
355 static void show(optional boolean focused);
357 // Hide the window. Does nothing if the window is already hidden.
358 static void hide();
360 // Get the window's inner bounds as a $(ref:ContentBounds) object.
361 [nocompile, deprecated="Use innerBounds or outerBounds."] static ContentBounds getBounds();
363 // Set the window's inner bounds.
364 [nocompile, deprecated="Use innerBounds or outerBounds."] static void setBounds(ContentBounds bounds);
366 // Set the app icon for the window (experimental).
367 // Currently this is only being implemented on Ash.
368 // TODO(stevenjb): Investigate implementing this on Windows and OSX.
369 [nodoc] static void setIcon(DOMString iconUrl);
371 // Is the window always on top?
372 static boolean isAlwaysOnTop();
374 // Accessors for testing.
375 [nodoc] boolean hasFrameColor;
376 [nodoc] long activeFrameColor;
377 [nodoc] long inactiveFrameColor;
378 [nodoc] boolean? firstShowHasHappened;
380 // Set whether the window should stay above most other windows. Requires the
381 // <code>alwaysOnTopWindows</code> permission.
382 static void setAlwaysOnTop(boolean alwaysOnTop);
384 // Can the window use alpha transparency?
385 // TODO(jackhou): Document this properly before going to stable.
386 [nodoc] static boolean alphaEnabled();
388 // Set whether the window is visible on all workspaces. (Only for platforms
389 // that support this).
390 static void setVisibleOnAllWorkspaces(boolean alwaysVisible);
392 // The JavaScript 'window' object for the created child.
393 [instanceOf=Window] object contentWindow;
395 // The id the window was created with.
396 DOMString id;
398 // The position, size and constraints of the window's content, which does
399 // not include window decorations.
400 // This property is new in Chrome 36.
401 Bounds innerBounds;
403 // The position, size and constraints of the window, which includes window
404 // decorations, such as the title bar and frame.
405 // This property is new in Chrome 36.
406 Bounds outerBounds;
409 interface Functions {
410 // The size and position of a window can be specified in a number of
411 // different ways. The most simple option is not specifying anything at
412 // all, in which case a default size and platform dependent position will
413 // be used.
415 // To set the position, size and constraints of the window, use the
416 // <code>innerBounds</code> or <code>outerBounds</code> properties. Inner
417 // bounds do not include window decorations. Outer bounds include the
418 // window's title bar and frame. Note that the padding between the inner and
419 // outer bounds is determined by the OS. Therefore setting the same property
420 // for both inner and outer bounds is considered an error (for example,
421 // setting both <code>innerBounds.left</code> and
422 // <code>outerBounds.left</code>).
424 // To automatically remember the positions of windows you can give them ids.
425 // If a window has an id, This id is used to remember the size and position
426 // of the window whenever it is moved or resized. This size and position is
427 // then used instead of the specified bounds on subsequent opening of a
428 // window with the same id. If you need to open a window with an id at a
429 // location other than the remembered default, you can create it hidden,
430 // move it to the desired location, then show it.
431 static void create(DOMString url,
432 optional CreateWindowOptions options,
433 optional CreateWindowCallback callback);
435 // Returns an $(ref:AppWindow) object for the
436 // current script context (ie JavaScript 'window' object). This can also be
437 // called on a handle to a script context for another page, for example:
438 // otherWindow.chrome.app.window.current().
439 [nocompile] static AppWindow current();
440 [nocompile, nodoc] static void initializeAppWindow(object state);
442 // Gets an array of all currently created app windows. This method is new in
443 // Chrome 33.
444 [nocompile] static AppWindow[] getAll();
446 // Gets an $(ref:AppWindow) with the given id. If no window with the given id
447 // exists null is returned. This method is new in Chrome 33.
448 [nocompile] static AppWindow get(DOMString id);
450 // Whether the current platform supports windows being visible on all
451 // workspaces.
452 [nocompile] static boolean canSetVisibleOnAllWorkspaces();
455 interface Events {
456 // Fired when the window is resized.
457 [nocompile] static void onBoundsChanged();
459 // Fired when the window is closed. Note, this should be listened to from
460 // a window other than the window being closed, for example from the
461 // background page. This is because the window being closed will be in the
462 // process of being torn down when the event is fired, which means not all
463 // APIs in the window's script context will be functional.
464 [nocompile] static void onClosed();
466 // Fired when the window is fullscreened (either via the
467 // <code>AppWindow</code> or HTML5 APIs).
468 [nocompile] static void onFullscreened();
470 // Fired when the window is maximized.
471 [nocompile] static void onMaximized();
473 // Fired when the window is minimized.
474 [nocompile] static void onMinimized();
476 // Fired when the window is restored from being minimized or maximized.
477 [nocompile] static void onRestored();
479 // Fired when the window's ability to use alpha transparency changes.
480 [nocompile, nodoc] static void onAlphaEnabledChanged();
482 // Event for testing. Lets tests wait until a window has been shown.
483 [nocompile, nodoc] static void onWindowFirstShown();