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. 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. 10namespace app.window { 11 12 // Previously named Bounds. 13 dictionary ContentBounds { 14 long? left; 15 long? top; 16 long? width; 17 long? height; 18 }; 19 20 dictionary BoundsSpecification { 21 // The X coordinate of the content or window. 22 long? left; 23 24 // The Y coordinate of the content or window. 25 long? top; 26 27 // The width of the content or window. 28 long? width; 29 30 // The height of the content or window. 31 long? height; 32 33 // The minimum width of the content or window. 34 long? minWidth; 35 36 // The minimum height of the content or window. 37 long? minHeight; 38 39 // The maximum width of the content or window. 40 long? maxWidth; 41 42 // The maximum height of the content or window. 43 long? maxHeight; 44 }; 45 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; 50 51 // This property can be used to read or write the current Y coordinate of 52 // the content or window. 53 long top; 54 55 // This property can be used to read or write the current width of the 56 // content or window. 57 long width; 58 59 // This property can be used to read or write the current height of the 60 // content or window. 61 long height; 62 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; 67 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; 72 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; 77 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; 82 83 // Set the left and top position of the content or window. 84 static void setPosition(long left, long top); 85 86 // Set the width and height of the content or window. 87 static void setSize(long width, long height); 88 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); 93 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); 98 }; 99 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> 108 DOMString? type; 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. 112 DOMString? color; 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> 123 // color</code>.<br> 124 // Frame coloring is new in Chrome 36. 125 DOMString? inactiveColor; 126 }; 127 128 // State of a window: normal, fullscreen, maximized, minimized. 129 enum State { normal, fullscreen, maximized, minimized }; 130 131 // 'shell' is the default window type. 'panel' is managed by the OS 132 // (Currently experimental, Ash only). 133 [nodoc] enum WindowType { shell, panel }; 134 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. 142 DOMString? id; 143 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 148 // instead. 149 // 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 153 // error. 154 // 155 // This property is new in Chrome 36. 156 BoundsSpecification? innerBounds; 157 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 162 // instead. 163 // 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 167 // error. 168 // 169 // This property is new in Chrome 36. 170 BoundsSpecification? outerBounds; 171 172 // Default width of the window. 173 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultWidth; 174 175 // Default height of the window. 176 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultHeight; 177 178 // Default X coordinate of the window. 179 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultLeft; 180 181 // Default Y coordinate of the window. 182 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultTop; 183 184 // Width of the window. 185 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? width; 186 187 // Height of the window. 188 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? height; 189 190 // X coordinate of the window. 191 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? left; 192 193 // Y coordinate of the window. 194 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? top; 195 196 // Minimum width of the window. 197 [deprecated="Use innerBounds or outerBounds."] long? minWidth; 198 199 // Minimum height of the window. 200 [deprecated="Use innerBounds or outerBounds."] long? minHeight; 201 202 // Maximum width of the window. 203 [deprecated="Use innerBounds or outerBounds."] long? maxWidth; 204 205 // Maximum height of the window. 206 [deprecated="Use innerBounds or outerBounds."] long? maxHeight; 207 208 // Type of window to create. 209 [nodoc] WindowType? type; 210 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; 219 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; 224 225 // Enable window background transparency. 226 // Only supported in ash. Requires experimental API permission. 227 boolean? transparentBackground; 228 229 // The initial state of the window, allowing it to be created already 230 // fullscreen, maximized, or minimized. Defaults to 'normal'. 231 State? state; 232 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. 235 boolean? hidden; 236 237 // If true, the window will be resizable by the user. Defaults to true. 238 boolean? resizable; 239 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; 246 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; 254 255 // If true, the window will be focused when created. Defaults to true. 256 boolean? focused; 257 }; 258 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); 268 269 [noinline_doc] dictionary AppWindow { 270 // Focus the window. 271 static void focus(); 272 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(); 281 282 // Is the window fullscreen? 283 static boolean isFullscreen(); 284 285 // Minimize the window. 286 static void minimize(); 287 288 // Is the window minimized? 289 static boolean isMinimized(); 290 291 // Maximize the window. 292 static void maximize(); 293 294 // Is the window maximized? 295 static boolean isMaximized(); 296 297 // Restore the window, exiting a maximized, minimized, or fullscreen state. 298 static void restore(); 299 300 // Move the window to the position (|left|, |top|). 301 static void moveTo(long left, long top); 302 303 // Resize the window to |width|x|height| pixels in size. 304 static void resizeTo(long width, long height); 305 306 // Draw attention to the window. 307 static void drawAttention(); 308 309 // Clear attention to the window. 310 static void clearAttention(); 311 312 // Close the window. 313 static void close(); 314 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); 318 319 // Hide the window. Does nothing if the window is already hidden. 320 static void hide(); 321 322 // Get the window's inner bounds as a $(ref:ContentBounds) object. 323 [nocompile, deprecated="Use innerBounds or outerBounds."] static ContentBounds getBounds(); 324 325 // Set the window's inner bounds. 326 [nocompile, deprecated="Use innerBounds or outerBounds."] static void setBounds(ContentBounds bounds); 327 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); 332 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); 336 337 // Clear the current for the window. 338 // TODO(benwells): Document this properly before going to stable. 339 [nodoc] static void clearBadge(); 340 341 // Is the window always on top? 342 static boolean isAlwaysOnTop(); 343 344 // Accessors for testing. 345 [nodoc] boolean hasFrameColor; 346 [nodoc] long activeFrameColor; 347 [nodoc] long inactiveFrameColor; 348 [nodoc] boolean? firstShowHasHappened; 349 350 // Set whether the window should stay above most other windows. Requires the 351 // <code>"alwaysOnTopWindows"</code> permission. 352 static void setAlwaysOnTop(boolean alwaysOnTop); 353 354 // Can the window use alpha transparency? 355 // TODO(jackhou): Document this properly before going to stable. 356 [nodoc] static boolean alphaEnabled(); 357 358 // The JavaScript 'window' object for the created child. 359 [instanceOf=Window] object contentWindow; 360 361 // The id the window was created with. 362 DOMString id; 363 364 // The position, size and constraints of the window's content, which does 365 // not include window decorations. 366 // This property is new in Chrome 36. 367 Bounds innerBounds; 368 369 // The position, size and constraints of the window, which includes window 370 // decorations, such as the title bar and frame. 371 // This property is new in Chrome 36. 372 Bounds outerBounds; 373 }; 374 375 interface Functions { 376 // The size and position of a window can be specified in a number of 377 // different ways. The most simple option is not specifying anything at 378 // all, in which case a default size and platform dependent position will 379 // be used. 380 // 381 // To set the position, size and constraints of the window, use the 382 // <code>innerBounds</code> or <code>outerBounds</code> properties. Inner 383 // bounds do not include window decorations. Outer bounds include the 384 // window's title bar and frame. Note that the padding between the inner and 385 // outer bounds is determined by the OS. Therefore setting the same property 386 // for both inner and outer bounds is considered an error (for example, 387 // setting both <code>innerBounds.left</code> and 388 // <code>outerBounds.left</code>). 389 // 390 // To automatically remember the positions of windows you can give them ids. 391 // If a window has an id, This id is used to remember the size and position 392 // of the window whenever it is moved or resized. This size and position is 393 // then used instead of the specified bounds on subsequent opening of a 394 // window with the same id. If you need to open a window with an id at a 395 // location other than the remembered default, you can create it hidden, 396 // move it to the desired location, then show it. 397 static void create(DOMString url, 398 optional CreateWindowOptions options, 399 optional CreateWindowCallback callback); 400 401 // Returns an $(ref:AppWindow) object for the 402 // current script context (ie JavaScript 'window' object). This can also be 403 // called on a handle to a script context for another page, for example: 404 // otherWindow.chrome.app.window.current(). 405 [nocompile] static AppWindow current(); 406 [nocompile, nodoc] static void initializeAppWindow(object state); 407 408 // Gets an array of all currently created app windows. This method is new in 409 // Chrome 33. 410 [nocompile] static AppWindow[] getAll(); 411 412 // Gets an $(ref:AppWindow) with the given id. If no window with the given id 413 // exists null is returned. This method is new in Chrome 33. 414 [nocompile] static AppWindow get(DOMString id); 415 }; 416 417 interface Events { 418 // Fired when the window is resized. 419 [nocompile] static void onBoundsChanged(); 420 421 // Fired when the window is closed. Note, this should be listened to from 422 // a window other than the window being closed, for example from the 423 // background page. This is because the window being closed will be in the 424 // process of being torn down when the event is fired, which means not all 425 // APIs in the window's script context will be functional. 426 [nocompile] static void onClosed(); 427 428 // Fired when the window is fullscreened. 429 [nocompile] static void onFullscreened(); 430 431 // Fired when the window is maximized. 432 [nocompile] static void onMaximized(); 433 434 // Fired when the window is minimized. 435 [nocompile] static void onMinimized(); 436 437 // Fired when the window is restored from being minimized or maximized. 438 [nocompile] static void onRestored(); 439 440 // Fired when the window's ability to use alpha transparency changes. 441 [nocompile, nodoc] static void onAlphaEnabledChanged(); 442 443 // Event for testing. Lets tests wait until a window has been shown. 444 [nocompile, nodoc] static void onWindowFirstShown(); 445 }; 446}; 447