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/samples/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>). 103 // 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. 106 // 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>. 113 // 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>. 118 // 119 // Frame coloring is only available if the frame type is 120 // <code>chrome</code>. 121 // 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>. 127 // 128 // <code>inactiveColor</code> must be used in conjunction with <code> 129 // color</code>. 130 // 131 // Frame coloring is new in Chrome 36. 132 DOMString? inactiveColor; 133 }; 134 135 // State of a window: normal, fullscreen, maximized, minimized. 136 enum State { normal, fullscreen, maximized, minimized }; 137 138 // 'shell' is the default window type. 'panel' is managed by the OS 139 // (Currently experimental, Ash only). 140 [nodoc] enum WindowType { shell, panel }; 141 142 [noinline_doc] dictionary CreateWindowOptions { 143 // Id to identify the window. This will be used to remember the size 144 // and position of the window and restore that geometry when a window 145 // with the same id is later opened. 146 // If a window with a given id is created while another window with the same 147 // id already exists, the currently opened window will be focused instead of 148 // creating a new window. 149 DOMString? id; 150 151 // Used to specify the initial position, initial size and constraints of the 152 // window's content (excluding window decorations). 153 // If an <code>id</code> is also specified and a window with a matching 154 // <code>id</code> has been shown before, the remembered bounds will be used 155 // instead. 156 // 157 // Note that the padding between the inner and outer bounds is determined by 158 // the OS. Therefore setting the same bounds property for both the 159 // <code>innerBounds</code> and <code>outerBounds</code> will result in an 160 // error. 161 // 162 // This property is new in Chrome 36. 163 BoundsSpecification? innerBounds; 164 165 // Used to specify the initial position, initial size and constraints of the 166 // window (including window decorations such as the title bar and frame). 167 // If an <code>id</code> is also specified and a window with a matching 168 // <code>id</code> has been shown before, the remembered bounds will be used 169 // instead. 170 // 171 // Note that the padding between the inner and outer bounds is determined by 172 // the OS. Therefore setting the same bounds property for both the 173 // <code>innerBounds</code> and <code>outerBounds</code> will result in an 174 // error. 175 // 176 // This property is new in Chrome 36. 177 BoundsSpecification? outerBounds; 178 179 // Default width of the window. 180 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultWidth; 181 182 // Default height of the window. 183 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultHeight; 184 185 // Default X coordinate of the window. 186 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultLeft; 187 188 // Default Y coordinate of the window. 189 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? defaultTop; 190 191 // Width of the window. 192 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? width; 193 194 // Height of the window. 195 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? height; 196 197 // X coordinate of the window. 198 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? left; 199 200 // Y coordinate of the window. 201 [nodoc, deprecated="Use $(ref:BoundsSpecification)."] long? top; 202 203 // Minimum width of the window. 204 [deprecated="Use innerBounds or outerBounds."] long? minWidth; 205 206 // Minimum height of the window. 207 [deprecated="Use innerBounds or outerBounds."] long? minHeight; 208 209 // Maximum width of the window. 210 [deprecated="Use innerBounds or outerBounds."] long? maxWidth; 211 212 // Maximum height of the window. 213 [deprecated="Use innerBounds or outerBounds."] long? maxHeight; 214 215 // Type of window to create. 216 [nodoc] WindowType? type; 217 218 // Frame type: <code>none</code> or <code>chrome</code> (defaults to 219 // <code>chrome</code>). For <code>none</code>, the 220 // <code>-webkit-app-region</code> CSS property can be used to apply 221 // draggability to the app's window. <code>-webkit-app-region: drag</code> 222 // can be used to mark regions draggable. <code>no-drag</code> can be used 223 // to disable this style on nested elements. 224 // 225 // Use of <code>FrameOptions</code> is new in M36. 226 (DOMString or FrameOptions)? frame; 227 228 // Size and position of the content in the window (excluding the titlebar). 229 // If an id is also specified and a window with a matching id has been shown 230 // before, the remembered bounds of the window will be used instead. 231 [deprecated="Use innerBounds or outerBounds."] ContentBounds? bounds; 232 233 // Enable window background transparency. 234 // Only supported in ash. Requires app.window.alpha API permission. 235 boolean? alphaEnabled; 236 237 // The initial state of the window, allowing it to be created already 238 // fullscreen, maximized, or minimized. Defaults to 'normal'. 239 State? state; 240 241 // If true, the window will be created in a hidden state. Call show() on 242 // the window to show it once it has been created. Defaults to false. 243 boolean? hidden; 244 245 // If true, the window will be resizable by the user. Defaults to true. 246 boolean? resizable; 247 248 // By default if you specify an id for the window, the window will only be 249 // created if another window with the same id doesn't already exist. If a 250 // window with the same id already exists that window is activated instead. 251 // If you do want to create multiple windows with the same id, you can 252 // set this property to false. 253 [deprecated="Multiple windows with the same id is no longer supported."] boolean? singleton; 254 255 // If true, the window will stay above most other windows. If there are 256 // multiple windows of this kind, the currently focused window will be in 257 // the foreground. Requires the <code>"alwaysOnTopWindows"</code> 258 // permission. Defaults to false. 259 // 260 // Call <code>setAlwaysOnTop()</code> on the window to change this property 261 // after creation. 262 boolean? alwaysOnTop; 263 264 // If true, the window will be focused when created. Defaults to true. 265 boolean? focused; 266 267 // If true, the window will be visible on all workspaces. 268 // This is only available on dev channel. 269 boolean? visibleOnAllWorkspaces; 270 }; 271 272 // Called in the creating window (parent) before the load event is called in 273 // the created window (child). The parent can set fields or functions on the 274 // child usable from onload. E.g. background.js: 275 // 276 // <code>function(createdWindow) { createdWindow.contentWindow.foo = 277 // function () { }; };</code> 278 // 279 // window.js: 280 // 281 // <code>window.onload = function () { foo(); }</code> 282 callback CreateWindowCallback = 283 void ([instanceOf=AppWindow] object createdWindow); 284 285 [noinline_doc] dictionary AppWindow { 286 // Focus the window. 287 static void focus(); 288 289 // Fullscreens the window. 290 // 291 // The user will be able to restore the window by pressing ESC. An 292 // application can prevent the fullscreen state to be left when ESC is 293 // pressed by requesting the <b>overrideEscFullscreen</b> permission and 294 // canceling the event by calling .preventDefault(), like this: 295 // 296 // <code>window.onKeyDown = function(e) { if (e.keyCode == 27 /* ESC */) { 297 // e.preventDefault(); } };</code> 298 static void fullscreen(); 299 300 // Is the window fullscreen? 301 static boolean isFullscreen(); 302 303 // Minimize the window. 304 static void minimize(); 305 306 // Is the window minimized? 307 static boolean isMinimized(); 308 309 // Maximize the window. 310 static void maximize(); 311 312 // Is the window maximized? 313 static boolean isMaximized(); 314 315 // Restore the window, exiting a maximized, minimized, or fullscreen state. 316 static void restore(); 317 318 // Move the window to the position (|left|, |top|). 319 static void moveTo(long left, long top); 320 321 // Resize the window to |width|x|height| pixels in size. 322 static void resizeTo(long width, long height); 323 324 // Draw attention to the window. 325 static void drawAttention(); 326 327 // Clear attention to the window. 328 static void clearAttention(); 329 330 // Close the window. 331 static void close(); 332 333 // Show the window. Does nothing if the window is already visible. 334 // Focus the window if |focused| is set to true or omitted. 335 static void show(optional boolean focused); 336 337 // Hide the window. Does nothing if the window is already hidden. 338 static void hide(); 339 340 // Get the window's inner bounds as a $(ref:ContentBounds) object. 341 [nocompile, deprecated="Use innerBounds or outerBounds."] static ContentBounds getBounds(); 342 343 // Set the window's inner bounds. 344 [nocompile, deprecated="Use innerBounds or outerBounds."] static void setBounds(ContentBounds bounds); 345 346 // Set the app icon for the window (experimental). 347 // Currently this is only being implemented on Ash. 348 // TODO(stevenjb): Investigate implementing this on Windows and OSX. 349 [nodoc] static void setIcon(DOMString iconUrl); 350 351 // Set a badge icon for the window. 352 // TODO(benwells): Document this properly before going to stable. 353 [nodoc] static void setBadgeIcon(DOMString iconUrl); 354 355 // Clear the current for the window. 356 // TODO(benwells): Document this properly before going to stable. 357 [nodoc] static void clearBadge(); 358 359 // Is the window always on top? 360 static boolean isAlwaysOnTop(); 361 362 // Accessors for testing. 363 [nodoc] boolean hasFrameColor; 364 [nodoc] long activeFrameColor; 365 [nodoc] long inactiveFrameColor; 366 [nodoc] boolean? firstShowHasHappened; 367 368 // Set whether the window should stay above most other windows. Requires the 369 // <code>"alwaysOnTopWindows"</code> permission. 370 static void setAlwaysOnTop(boolean alwaysOnTop); 371 372 // Can the window use alpha transparency? 373 // TODO(jackhou): Document this properly before going to stable. 374 [nodoc] static boolean alphaEnabled(); 375 376 // For platforms that support multiple workspaces, is this window visible on 377 // all of them? 378 // This is only available on dev channel. 379 static void setVisibleOnAllWorkspaces(boolean alwaysVisible); 380 381 // The JavaScript 'window' object for the created child. 382 [instanceOf=Window] object contentWindow; 383 384 // The id the window was created with. 385 DOMString id; 386 387 // The position, size and constraints of the window's content, which does 388 // not include window decorations. 389 // This property is new in Chrome 36. 390 Bounds innerBounds; 391 392 // The position, size and constraints of the window, which includes window 393 // decorations, such as the title bar and frame. 394 // This property is new in Chrome 36. 395 Bounds outerBounds; 396 }; 397 398 interface Functions { 399 // The size and position of a window can be specified in a number of 400 // different ways. The most simple option is not specifying anything at 401 // all, in which case a default size and platform dependent position will 402 // be used. 403 // 404 // To set the position, size and constraints of the window, use the 405 // <code>innerBounds</code> or <code>outerBounds</code> properties. Inner 406 // bounds do not include window decorations. Outer bounds include the 407 // window's title bar and frame. Note that the padding between the inner and 408 // outer bounds is determined by the OS. Therefore setting the same property 409 // for both inner and outer bounds is considered an error (for example, 410 // setting both <code>innerBounds.left</code> and 411 // <code>outerBounds.left</code>). 412 // 413 // To automatically remember the positions of windows you can give them ids. 414 // If a window has an id, This id is used to remember the size and position 415 // of the window whenever it is moved or resized. This size and position is 416 // then used instead of the specified bounds on subsequent opening of a 417 // window with the same id. If you need to open a window with an id at a 418 // location other than the remembered default, you can create it hidden, 419 // move it to the desired location, then show it. 420 static void create(DOMString url, 421 optional CreateWindowOptions options, 422 optional CreateWindowCallback callback); 423 424 // Returns an $(ref:AppWindow) object for the 425 // current script context (ie JavaScript 'window' object). This can also be 426 // called on a handle to a script context for another page, for example: 427 // otherWindow.chrome.app.window.current(). 428 [nocompile] static AppWindow current(); 429 [nocompile, nodoc] static void initializeAppWindow(object state); 430 431 // Gets an array of all currently created app windows. This method is new in 432 // Chrome 33. 433 [nocompile] static AppWindow[] getAll(); 434 435 // Gets an $(ref:AppWindow) with the given id. If no window with the given id 436 // exists null is returned. This method is new in Chrome 33. 437 [nocompile] static AppWindow get(DOMString id); 438 439 // Does the current platform support windows being visible on all 440 // workspaces? 441 [nocompile] static boolean canSetVisibleOnAllWorkspaces(); 442 }; 443 444 interface Events { 445 // Fired when the window is resized. 446 [nocompile] static void onBoundsChanged(); 447 448 // Fired when the window is closed. Note, this should be listened to from 449 // a window other than the window being closed, for example from the 450 // background page. This is because the window being closed will be in the 451 // process of being torn down when the event is fired, which means not all 452 // APIs in the window's script context will be functional. 453 [nocompile] static void onClosed(); 454 455 // Fired when the window is fullscreened. 456 [nocompile] static void onFullscreened(); 457 458 // Fired when the window is maximized. 459 [nocompile] static void onMaximized(); 460 461 // Fired when the window is minimized. 462 [nocompile] static void onMinimized(); 463 464 // Fired when the window is restored from being minimized or maximized. 465 [nocompile] static void onRestored(); 466 467 // Fired when the window's ability to use alpha transparency changes. 468 [nocompile, nodoc] static void onAlphaEnabledChanged(); 469 470 // Event for testing. Lets tests wait until a window has been shown. 471 [nocompile, nodoc] static void onWindowFirstShown(); 472 }; 473}; 474