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