1ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch// Use the <code>system.display</code> API to query display metadata.
6ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdochnamespace system.display {
72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  dictionary Bounds {
92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The x-coordinate of the upper-left corner.
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    long left;
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The y-coordinate of the upper-left corner.
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    long top;
147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The width of the display in pixels.
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    long width;
177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The height of the display in pixels.
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    long height;
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  dictionary Insets {
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The x-axis distance from the left bound.
247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long left;
257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The y-axis distance from the top bound.
277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long top;
287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The x-axis distance from the right bound.
307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long right;
317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The y-axis distance from the bottom bound.
337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long bottom;
347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  };
357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  dictionary DisplayUnitInfo {
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The unique identifier of the display.
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DOMString id;
39eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The user-friendly name (e.g. "HP LCD monitor").
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    DOMString name;
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Identifier of the display that is being mirrored on the display unit.
447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If mirroring is not in progress, set to an empty string.
457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Currently exposed only on ChromeOS. Will be empty string on other
467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // platforms.
477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DOMString mirroringSourceId;
48eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // True if this is the primary display.
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    boolean isPrimary;
517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // True if this is an internal display.
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    boolean isInternal;
547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // True if this display is enabled.
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    boolean isEnabled;
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The number of pixels per inch along the x-axis.
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    double dpiX;
607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // The number of pixels per inch along the y-axis.
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    double dpiY;
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The display's clockwise rotation in degrees relative to the vertical
657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // position.
667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Currently exposed only on ChromeOS. Will be set to 0 on other platforms.
677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long rotation;
687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The display's logical bounds.
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Bounds bounds;
717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The display's insets within its screen's bounds.
737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Currently exposed only on ChromeOS. Will be set to empty insets on
747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // other platforms.
757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    Insets overscan;
767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The usable work area of the display within the display bounds. The work
787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // area excludes areas of the display reserved for OS, for example taskbar
797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // and launcher.
802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    Bounds workArea;
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  dictionary DisplayProperties {
847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set and not empty, starts mirroring between this and the display with
857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // the provided id (the system will determine which of the displays is
867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // actually mirrored).
877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set and not empty, stops mirroring between this and the display with
887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // the specified id (if mirroring is in progress).
897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set, no other parameter may be set.
907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    DOMString? mirroringSourceId;
91eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set to true, makes the display primary. No-op if set to false.
937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    boolean? isPrimary;
94eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set, sets the display's overscan insets to the provided values. Note
967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // that overscan values may not be negative or larger than a half of the
977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // screen's size. Overscan cannot be changed on the internal monitor.
987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // It's applied after <code>isPrimary</code> parameter.
997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    Insets? overscan;
100eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set, updates the display's rotation.
1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Legal values are [0, 90, 180, 270]. The rotation is set clockwise,
1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // relative to the display's vertical position.
1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // It's applied after <code>overscan</code> paramter.
1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long? rotation;
106eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set, updates the display's logical bounds origin along x-axis. Applied
1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // together with <code>boundsOriginY</code>, if <code>boundsOriginY</code>
1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // is set. Note that, when updating the display origin, some constraints
1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // will be applied, so the final bounds origin may be different than the one
11123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    // set. The final bounds can be retrieved using $(ref:getInfo).
1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The bounds origin is applied after <code>rotation</code>.
1137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // The bounds origin cannot be changed on the primary display. Note that is
1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // also invalid to set bounds origin values if <code>isPrimary</code> is
1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // also set (as <code>isPrimary</code> parameter is applied first).
1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long? boundsOriginX;
117eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // If set, updates the display's logical bounds origin along y-axis.
1197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // See documentation for <code>boundsOriginX</code> parameter.
1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    long? boundsOriginY;
1217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  };
122eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  callback DisplayInfoCallback = void (DisplayUnitInfo[] displayInfo);
1247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  callback SetDisplayUnitInfoCallback = void();
1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interface Functions {
1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Get the information of all attached display devices.
128ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch    static void getInfo(DisplayInfoCallback callback);
1297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // Updates the properties for the display specified by |id|, according to
13123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    // the information provided in |info|. On failure, $(ref:runtime.lastError)
1327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // will be set.
1337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // |id|: The display's unique identifier.
1347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // |info|: The information about display properties that should be changed.
1357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    //     A property will be changed only if a new value for it is specified in
1367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    //     |info|.
1377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    // |callback|: Empty function called when the function finishes. To find out
13823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    //     whether the function succeeded, $(ref:runtime.lastError) should be
139eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    //     queried.
1407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    static void setDisplayProperties(
1417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        DOMString id,
1427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        DisplayProperties info,
1437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        optional SetDisplayUnitInfoCallback callback);
1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
145eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch
1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  interface Events {
1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    // Fired when anything changes to the display configuration.
1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    static void onDisplayChanged();
1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  };
1502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
151