Home | History | Annotate | Download | only in api
      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     DOMString? id;
     28 
     29     // Default width of the window. (Deprecated; regular bounds act like this
     30     // now.)
     31     [nodoc] long? defaultWidth;
     32 
     33     // Default height of the window. (Deprecated; regular bounds act like this
     34     // now.)
     35     [nodoc] long? defaultHeight;
     36 
     37     // Default X coordinate of the window. (Deprecated; regular bounds act like
     38     // this now.)
     39     [nodoc] long? defaultLeft;
     40 
     41     // Default Y coordinate of the window. (Deprecated; regular bounds act like
     42     // this now.)
     43     [nodoc] long? defaultTop;
     44 
     45     // Width of the window. (Deprecated; use 'bounds'.)
     46     [nodoc] long? width;
     47 
     48     // Height of the window. (Deprecated; use 'bounds'.)
     49     [nodoc] long? height;
     50 
     51     // X coordinate of the window. (Deprecated; use 'bounds'.)
     52     [nodoc] long? left;
     53 
     54     // Y coordinate of the window. (Deprecated; use 'bounds'.)
     55     [nodoc] long? top;
     56 
     57     // Minimum width for the lifetime of the window.
     58     long? minWidth;
     59 
     60     // Minimum height for the lifetime of the window.
     61     long? minHeight;
     62 
     63     // Maximum width for the lifetime of the window.
     64     long? maxWidth;
     65 
     66     // Maximum height for the lifetime of the window.
     67     long? maxHeight;
     68 
     69     // Type of window to create.
     70     [nodoc] WindowType? type;
     71 
     72     // Frame type: 'none' or 'chrome' (defaults to 'chrome').
     73     DOMString? frame;
     74 
     75     // Size and position of the content in the window (excluding the titlebar).
     76     // If an id is also specified and a window with a matching id has been shown
     77     // before, the remembered bounds of the window will be used instead.
     78     Bounds? bounds;
     79 
     80     // Enable window background transparency.
     81     // Only supported in ash. Requires experimental API permission.
     82     boolean? transparentBackground;
     83 
     84     // The initial state of the window, allowing it to be created already
     85     // fullscreen, maximized, or minimized. Defaults to 'normal'.
     86     State? state;
     87 
     88     // If true, the window will be created in a hidden state. Call show() on
     89     // the window to show it once it has been created. Defaults to false.
     90     boolean? hidden;
     91 
     92     // If true, the window will be resizable by the user. Defaults to true.
     93     boolean? resizable;
     94 
     95     // By default if you specify an id for the window, the window will only be
     96     // created if another window with the same id doesn't already exist. If a
     97     // window with the same id already exists that window is activated instead.
     98     // If you do want to create multiple windows with the same id, you can
     99     // set this property to false.
    100     boolean? singleton;
    101   };
    102 
    103   // Called in the creating window (parent) before the load event is called in
    104   // the created window (child). The parent can set fields or functions on the
    105   // child usable from onload. E.g. background.js:<br>
    106   // <code>function(created_window) { created_window.contentWindow.foo =
    107   // function () { }; };</code>
    108   // <br>window.js:<br>
    109   // <code>window.onload = function () { foo(); }</code>
    110   callback CreateWindowCallback =
    111       void ([instanceOf=AppWindow] object created_window);
    112 
    113   [noinline_doc] dictionary AppWindow {
    114     // Focus the window.
    115     static void focus();
    116 
    117     // Fullscreens the window.
    118     static void fullscreen();
    119 
    120     // Is the window fullscreen?
    121     static boolean isFullscreen();
    122 
    123     // Minimize the window.
    124     static void minimize();
    125 
    126     // Is the window minimized?
    127     static boolean isMinimized();
    128 
    129     // Maximize the window.
    130     static void maximize();
    131 
    132     // Is the window maximized?
    133     static boolean isMaximized();
    134 
    135     // Restore the window, exiting a maximized, minimized, or fullscreen state.
    136     static void restore();
    137 
    138     // Move the window to the position (|left|, |top|).
    139     static void moveTo(long left, long top);
    140 
    141     // Resize the window to |width|x|height| pixels in size.
    142     static void resizeTo(long width, long height);
    143 
    144     // Draw attention to the window.
    145     static void drawAttention();
    146 
    147     // Clear attention to the window.
    148     static void clearAttention();
    149 
    150     // Close the window.
    151     static void close();
    152 
    153     // Show the window. Does nothing if the window is already visible.
    154     static void show();
    155 
    156     // Hide the window. Does nothing if the window is already hidden.
    157     static void hide();
    158 
    159     // Get the window's bounds as a $ref:Bounds object.
    160     [nocompile] static Bounds getBounds();
    161 
    162     // Set the window's bounds.
    163     static void setBounds(Bounds bounds);
    164 
    165     // Set the app icon for the window (experimental).
    166     // Currently this is only being implemented on Ash.
    167     // TODO(stevenjb): Investigate implementing this on Windows and OSX.
    168     [nodoc] static void setIcon(DOMString icon_url);
    169 
    170     // The JavaScript 'window' object for the created child.
    171     [instanceOf=Window] object contentWindow;
    172   };
    173 
    174   interface Functions {
    175     // The size and position of a window can be specified in a number of
    176     // different ways. The most simple option is not specifying anything at
    177     // all, in which case a default size and platform dependent position will
    178     // be used.
    179     //
    180     // Another option is to use the bounds property, which will put the window
    181     // at the specified coordinates with the specified size. If the window has
    182     // a frame, it's total size will be the size given plus the size of the
    183     // frame; that is, the size in bounds is the content size, not the window
    184     // size.
    185     //
    186     // To automatically remember the positions of windows you can give them ids.
    187     // If a window has an id, This id is used to remember the size and position
    188     // of the window whenever it is moved or resized. This size and position is
    189     // then used instead of the specified bounds on subsequent opening of a
    190     // window with the same id. If you need to open a window with an id at a
    191     // location other than the remembered default, you can create it hidden,
    192     // move it to the desired location, then show it.
    193     static void create(DOMString url,
    194                        optional CreateWindowOptions options,
    195                        optional CreateWindowCallback callback);
    196 
    197     // Returns an $ref:AppWindow object for the
    198     // current script context (ie JavaScript 'window' object). This can also be
    199     // called on a handle to a script context for another page, for example:
    200     // otherWindow.chrome.app.window.current().
    201     [nocompile] static AppWindow current();
    202     [nocompile, nodoc] static void initializeAppWindow(object state);
    203   };
    204 
    205   interface Events {
    206     // Fired when the window is resized.
    207     [nocompile] static void onBoundsChanged();
    208 
    209     // Fired when the window is closed.
    210     [nocompile] static void onClosed();
    211 
    212     // Fired when the window is fullscreened.
    213     [nocompile] static void onFullscreened();
    214 
    215     // Fired when the window is maximized.
    216     [nocompile] static void onMaximized();
    217 
    218     // Fired when the window is minimized.
    219     [nocompile] static void onMinimized();
    220 
    221     // Fired when the window is restored from being minimized or maximized.
    222     [nocompile] static void onRestored();
    223   };
    224 };
    225