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 dictionary Bounds { 10 long? left; 11 long? top; 12 long? width; 13 long? height; 14 }; 15 16 // State of a window: normal, fullscreen, maximized, minimized. 17 enum State { normal, fullscreen, maximized, minimized }; 18 19 // 'shell' is the default window type. 'panel' is managed by the OS 20 // (Currently experimental, Ash only). 21 [nodoc] enum WindowType { shell, panel }; 22 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; 31 32 // Default width of the window. (Deprecated; regular bounds act like this 33 // now.) 34 [nodoc] long? defaultWidth; 35 36 // Default height of the window. (Deprecated; regular bounds act like this 37 // now.) 38 [nodoc] long? defaultHeight; 39 40 // Default X coordinate of the window. (Deprecated; regular bounds act like 41 // this now.) 42 [nodoc] long? defaultLeft; 43 44 // Default Y coordinate of the window. (Deprecated; regular bounds act like 45 // this now.) 46 [nodoc] long? defaultTop; 47 48 // Width of the window. (Deprecated; use 'bounds'.) 49 [nodoc] long? width; 50 51 // Height of the window. (Deprecated; use 'bounds'.) 52 [nodoc] long? height; 53 54 // X coordinate of the window. (Deprecated; use 'bounds'.) 55 [nodoc] long? left; 56 57 // Y coordinate of the window. (Deprecated; use 'bounds'.) 58 [nodoc] long? top; 59 60 // Minimum width of the window. 61 long? minWidth; 62 63 // Minimum height of the window. 64 long? minHeight; 65 66 // Maximum width of the window. 67 long? maxWidth; 68 69 // Maximum height of the window. 70 long? maxHeight; 71 72 // Type of window to create. 73 [nodoc] WindowType? type; 74 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; 82 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; 87 88 // Enable window background transparency. 89 // Only supported in ash. Requires experimental API permission. 90 boolean? transparentBackground; 91 92 // The initial state of the window, allowing it to be created already 93 // fullscreen, maximized, or minimized. Defaults to 'normal'. 94 State? state; 95 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; 99 100 // If true, the window will be resizable by the user. Defaults to true. 101 boolean? resizable; 102 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; 110 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; 119 120 // If true, the window will be focused when created. Defaults to true. 121 boolean? focused; 122 }; 123 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); 133 134 [noinline_doc] dictionary AppWindow { 135 // Focus the window. 136 static void focus(); 137 138 // Fullscreens the window. 139 static void fullscreen(); 140 141 // Is the window fullscreen? 142 static boolean isFullscreen(); 143 144 // Minimize the window. 145 static void minimize(); 146 147 // Is the window minimized? 148 static boolean isMinimized(); 149 150 // Maximize the window. 151 static void maximize(); 152 153 // Is the window maximized? 154 static boolean isMaximized(); 155 156 // Restore the window, exiting a maximized, minimized, or fullscreen state. 157 static void restore(); 158 159 // Move the window to the position (|left|, |top|). 160 static void moveTo(long left, long top); 161 162 // Resize the window to |width|x|height| pixels in size. 163 static void resizeTo(long width, long height); 164 165 // Draw attention to the window. 166 static void drawAttention(); 167 168 // Clear attention to the window. 169 static void clearAttention(); 170 171 // Close the window. 172 static void close(); 173 174 // Show the window. Does nothing if the window is already visible. 175 static void show(); 176 177 // Hide the window. Does nothing if the window is already hidden. 178 static void hide(); 179 180 // Get the window's bounds as a $ref:Bounds object. 181 [nocompile] static Bounds getBounds(); 182 183 // Set the window's bounds. 184 static void setBounds(Bounds bounds); 185 186 // Get the current minimum width of the window. Returns |undefined| if there 187 // is no minimum. 188 [nocompile] static long getMinWidth(); 189 190 // Get the current minimum height of the window. Returns |undefined| if 191 // there is no minimum. 192 [nocompile] static long getMinHeight(); 193 194 // Get the current maximum width of the window. Returns |undefined| if there 195 // is no maximum. 196 [nocompile] static long getMaxWidth(); 197 198 // Get the current maximum height of the window. Returns |undefined| if 199 // there is no maximum. 200 [nocompile] static long getMaxHeight(); 201 202 // Set the current minimum width of the window. Set to |null| to remove the 203 // constraint. 204 static void setMinWidth(optional long minWidth); 205 206 // Set the current minimum height of the window. Set to |null| to remove the 207 // constraint. 208 static void setMinHeight(optional long minHeight); 209 210 // Set the current maximum width of the window. Set to |null| to remove the 211 // constraint. 212 static void setMaxWidth(optional long maxWidth); 213 214 // Set the current maximum height of the window. Set to |null| to remove the 215 // constraint. 216 static void setMaxHeight(optional long maxHeight); 217 218 // Set the app icon for the window (experimental). 219 // Currently this is only being implemented on Ash. 220 // TODO(stevenjb): Investigate implementing this on Windows and OSX. 221 [nodoc] static void setIcon(DOMString iconUrl); 222 223 // Is the window always on top? 224 static boolean isAlwaysOnTop(); 225 226 // Set whether the window should stay above most other windows. Requires the 227 // <code>"alwaysOnTopWindows"</code> permission. 228 // Currently only available on Dev channel. 229 static void setAlwaysOnTop(boolean alwaysOnTop); 230 231 // The JavaScript 'window' object for the created child. 232 [instanceOf=Window] object contentWindow; 233 234 // The id the window was created with. 235 DOMString id; 236 }; 237 238 interface Functions { 239 // The size and position of a window can be specified in a number of 240 // different ways. The most simple option is not specifying anything at 241 // all, in which case a default size and platform dependent position will 242 // be used. 243 // 244 // Another option is to use the bounds property, which will put the window 245 // at the specified coordinates with the specified size. If the window has 246 // a frame, it's total size will be the size given plus the size of the 247 // frame; that is, the size in bounds is the content size, not the window 248 // size. 249 // 250 // To automatically remember the positions of windows you can give them ids. 251 // If a window has an id, This id is used to remember the size and position 252 // of the window whenever it is moved or resized. This size and position is 253 // then used instead of the specified bounds on subsequent opening of a 254 // window with the same id. If you need to open a window with an id at a 255 // location other than the remembered default, you can create it hidden, 256 // move it to the desired location, then show it. 257 static void create(DOMString url, 258 optional CreateWindowOptions options, 259 optional CreateWindowCallback callback); 260 261 // Returns an $ref:AppWindow object for the 262 // current script context (ie JavaScript 'window' object). This can also be 263 // called on a handle to a script context for another page, for example: 264 // otherWindow.chrome.app.window.current(). 265 [nocompile] static AppWindow current(); 266 [nocompile, nodoc] static void initializeAppWindow(object state); 267 268 // Gets an array of all currently created app windows. This method is new in 269 // Chrome 33. 270 [nocompile] static AppWindow[] getAll(); 271 272 // Gets an $ref:AppWindow with the given id. If no window with the given id 273 // exists null is returned. This method is new in Chrome 33. 274 [nocompile] static AppWindow get(DOMString id); 275 }; 276 277 interface Events { 278 // Fired when the window is resized. 279 [nocompile] static void onBoundsChanged(); 280 281 // Fired when the window is closed. 282 [nocompile] static void onClosed(); 283 284 // Fired when the window is fullscreened. 285 [nocompile] static void onFullscreened(); 286 287 // Fired when the window is maximized. 288 [nocompile] static void onMaximized(); 289 290 // Fired when the window is minimized. 291 [nocompile] static void onMinimized(); 292 293 // Fired when the window is restored from being minimized or maximized. 294 [nocompile] static void onRestored(); 295 }; 296 }; 297