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.
10 // Previously named Bounds.
11 dictionary ContentBounds
{
18 dictionary BoundsSpecification
{
19 // The X coordinate of the content or window.
22 // The Y coordinate of the content or window.
25 // The width of the content or window.
28 // The height of the content or window.
31 // The minimum width of the content or window.
34 // The minimum height of the content or window.
37 // The maximum width of the content or window.
40 // The maximum height of the content or window.
45 // This property can be used to read or write the current X coordinate of
46 // the content or window.
49 // This property can be used to read or write the current Y coordinate of
50 // the content or window.
53 // This property can be used to read or write the current width of the
57 // This property can be used to read or write the current height of the
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
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
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
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
81 // Set the left and top position of the content or window.
82 static
void setPosition
(long left
, long top
);
84 // Set the width and height of the content or window.
85 static
void setSize
(long width
, long height
);
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
);
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
);
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>
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 experimental and only available in dev channel.
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 experimental and only available in dev channel.
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>
122 // Frame coloring is experimental and only available in dev channel.
123 DOMString? inactiveColor
;
126 // State of a window: normal, fullscreen, maximized, minimized.
127 enum State
{ normal
, fullscreen
, maximized
, minimized
};
129 // 'shell' is the default window type. 'panel' is managed by the OS
130 // (Currently experimental, Ash only).
131 [nodoc
] enum WindowType
{ shell
, panel
};
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.
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
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
153 // This property is new in Chrome 36.
154 BoundsSpecification? innerBounds
;
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
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
167 // This property is new in Chrome 36.
168 BoundsSpecification? outerBounds
;
170 // Default width of the window.
171 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? defaultWidth
;
173 // Default height of the window.
174 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? defaultHeight
;
176 // Default X coordinate of the window.
177 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? defaultLeft
;
179 // Default Y coordinate of the window.
180 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? defaultTop
;
182 // Width of the window.
183 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? width
;
185 // Height of the window.
186 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? height
;
188 // X coordinate of the window.
189 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? left
;
191 // Y coordinate of the window.
192 [nodoc
, deprecated
="Use $(ref:BoundsSpecification)."] long? top
;
194 // Minimum width of the window.
195 [deprecated
="Use innerBounds or outerBounds."] long? minWidth
;
197 // Minimum height of the window.
198 [deprecated
="Use innerBounds or outerBounds."] long? minHeight
;
200 // Maximum width of the window.
201 [deprecated
="Use innerBounds or outerBounds."] long? maxWidth
;
203 // Maximum height of the window.
204 [deprecated
="Use innerBounds or outerBounds."] long? maxHeight
;
206 // Type of window to create.
207 [nodoc
] WindowType? type
;
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 only supported in dev channel.
216 (DOMString or FrameOptions
)? frame
;
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
;
223 // Enable window background transparency.
224 // Only supported in ash. Requires experimental API permission.
225 boolean? transparentBackground
;
227 // The initial state of the window, allowing it to be created already
228 // fullscreen, maximized, or minimized. Defaults to 'normal'.
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.
235 // If true, the window will be resizable by the user. Defaults to true.
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
;
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>"app.window.alwaysOnTop"</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
;
253 // If true, the window will be focused when created. Defaults to true.
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
);
267 [noinline_doc
] dictionary AppWindow
{
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>app.window.fullscreen.overrideEsc</b>
275 // permission and canceling the event by calling .preventDefault(), like
277 // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) {
278 // e.preventDefault(); } };</code>
279 static
void fullscreen
();
281 // Is the window fullscreen?
282 static
boolean isFullscreen
();
284 // Minimize the window.
285 static
void minimize
();
287 // Is the window minimized?
288 static
boolean isMinimized
();
290 // Maximize the window.
291 static
void maximize
();
293 // Is the window maximized?
294 static
boolean isMaximized
();
296 // Restore the window, exiting a maximized, minimized, or fullscreen state.
297 static
void restore
();
299 // Move the window to the position (|left|, |top|).
300 static
void moveTo
(long left
, long top
);
302 // Resize the window to |width|x|height| pixels in size.
303 static
void resizeTo
(long width
, long height
);
305 // Draw attention to the window.
306 static
void drawAttention
();
308 // Clear attention to the window.
309 static
void clearAttention
();
314 // Show the window. Does nothing if the window is already visible.
315 // Focus the window if |focused| is set to true or omitted.
316 static
void show
(optional boolean focused
);
318 // Hide the window. Does nothing if the window is already hidden.
321 // Get the window's inner bounds as a $(ref:ContentBounds) object.
322 [nocompile
, deprecated
="Use innerBounds or outerBounds."] static ContentBounds getBounds
();
324 // Set the window's inner bounds.
325 [nocompile
, deprecated
="Use innerBounds or outerBounds."] static
void setBounds
(ContentBounds bounds
);
327 // Set the app icon for the window (experimental).
328 // Currently this is only being implemented on Ash.
329 // TODO(stevenjb): Investigate implementing this on Windows and OSX.
330 [nodoc
] static
void setIcon
(DOMString iconUrl
);
332 // Set a badge icon for the window.
333 // TODO(benwells): Document this properly before going to stable.
334 [nodoc
] static
void setBadgeIcon
(DOMString iconUrl
);
336 // Clear the current for the window.
337 // TODO(benwells): Document this properly before going to stable.
338 [nodoc
] static
void clearBadge
();
340 // Is the window always on top?
341 static
boolean isAlwaysOnTop
();
343 // Accessors for testing.
344 [nodoc
] boolean hasFrameColor
;
345 [nodoc
] long activeFrameColor
;
346 [nodoc
] long inactiveFrameColor
;
348 // Set whether the window should stay above most other windows. Requires the
349 // <code>"app.window.alwaysOnTop"</code> permission.
350 static
void setAlwaysOnTop
(boolean alwaysOnTop
);
352 // The JavaScript 'window' object for the created child.
353 [instanceOf
=Window
] object contentWindow
;
355 // The id the window was created with.
358 // The position, size and constraints of the window's content, which does
359 // not include window decorations.
360 // This property is new in Chrome 36.
363 // The position, size and constraints of the window, which includes window
364 // decorations, such as the title bar and frame.
365 // This property is new in Chrome 36.
369 interface Functions
{
370 // The size and position of a window can be specified in a number of
371 // different ways. The most simple option is not specifying anything at
372 // all, in which case a default size and platform dependent position will
375 // To set the position, size and constraints of the window, use the
376 // <code>innerBounds</code> or <code>outerBounds</code> properties. Inner
377 // bounds do not include window decorations. Outer bounds include the
378 // window's title bar and frame. Note that the padding between the inner and
379 // outer bounds is determined by the OS. Therefore setting the same property
380 // for both inner and outer bounds is considered an error (for example,
381 // setting both <code>innerBounds.left</code> and
382 // <code>outerBounds.left</code>).
384 // To automatically remember the positions of windows you can give them ids.
385 // If a window has an id, This id is used to remember the size and position
386 // of the window whenever it is moved or resized. This size and position is
387 // then used instead of the specified bounds on subsequent opening of a
388 // window with the same id. If you need to open a window with an id at a
389 // location other than the remembered default, you can create it hidden,
390 // move it to the desired location, then show it.
391 static
void create
(DOMString url
,
392 optional CreateWindowOptions options
,
393 optional CreateWindowCallback
callback);
395 // Returns an $(ref:AppWindow) object for the
396 // current script context (ie JavaScript 'window' object). This can also be
397 // called on a handle to a script context for another page, for example:
398 // otherWindow.chrome.app.window.current().
399 [nocompile
] static AppWindow current
();
400 [nocompile
, nodoc
] static
void initializeAppWindow
(object state
);
402 // Gets an array of all currently created app windows. This method is new in
404 [nocompile
] static AppWindow
[] getAll
();
406 // Gets an $(ref:AppWindow) with the given id. If no window with the given id
407 // exists null is returned. This method is new in Chrome 33.
408 [nocompile
] static AppWindow get
(DOMString
id);
412 // Fired when the window is resized.
413 [nocompile
] static
void onBoundsChanged
();
415 // Fired when the window is closed.
416 [nocompile
] static
void onClosed
();
418 // Fired when the window is fullscreened.
419 [nocompile
] static
void onFullscreened
();
421 // Fired when the window is maximized.
422 [nocompile
] static
void onMaximized
();
424 // Fired when the window is minimized.
425 [nocompile
] static
void onMinimized
();
427 // Fired when the window is restored from being minimized or maximized.
428 [nocompile
] static
void onRestored
();