Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / remoting / webapp / base / js / window_shape.js
blobee15a0f436c85c13ed0ad815cdc4cda1cebeef66
1 // Copyright 2014 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.
5 /**
6 * @fileoverview
7 * Class handling setting of the local app window shape to account for windows
8 * on the remote desktop, as well as any client-side UI.
9 */
11 'use strict';
13 /** @suppress {duplicate} */
14 var remoting = remoting || {};
16 /** @constructor */
17 remoting.WindowShape = function() {
18 /** @private {Array<{left: number, top: number,
19 width: number, height: number}>} */
20 this.desktopRects_ = [];
22 /** @private {Array<remoting.WindowShape.ClientUI>} */
23 this.clientUICallbacks_ = [];
26 /**
27 * @return {boolean} True if setShape is available and implemented for the
28 * current platform.
30 remoting.WindowShape.isSupported = function() {
31 return base.isAppsV2() &&
32 typeof(chrome.app.window.current().setShape) != 'undefined' &&
33 !remoting.platformIsMac();
36 /**
37 * Add a client-side UI measurement callback.
39 * @param {remoting.WindowShape.ClientUI} callback
41 remoting.WindowShape.prototype.addCallback = function(callback) {
42 this.clientUICallbacks_.push(callback);
43 this.updateClientWindowShape();
46 /**
47 * Set the region associated with the remote desktop windows.
49 * @param {Array<{left: number, top: number, width: number, height: number}>}
50 * rects
52 remoting.WindowShape.prototype.setDesktopRects = function(rects) {
53 this.desktopRects_ = rects;
54 this.updateClientWindowShape();
57 /**
58 * Update the client window shape.
60 remoting.WindowShape.prototype.updateClientWindowShape = function() {
61 if (!remoting.WindowShape.isSupported()) {
62 return;
65 var rects = this.desktopRects_.slice();
66 for (var i = 0; i < this.clientUICallbacks_.length; ++i) {
67 this.clientUICallbacks_[i].addToRegion(rects);
69 for (var i = 0; i < rects.length; ++i) {
70 var rect = /** @type {ClientRect} */ (rects[i]);
71 var left = Math.floor(rect.left);
72 var right = Math.ceil(rect.left + rect.width);
73 var top = Math.floor(rect.top);
74 var bottom = Math.ceil(rect.top + rect.height);
75 rects[i] = { left: left,
76 top: top,
77 width: right - left,
78 height: bottom - top };
80 chrome.app.window.current().setShape({rects: rects});
84 /**
85 * @interface
87 remoting.WindowShape.ClientUI = function () {
90 /**
91 * Add the context menu's bounding rectangle to the specified region.
93 * @param {Array<{left: number, top: number, width: number, height: number}>}
94 * rects
96 remoting.WindowShape.ClientUI.prototype.addToRegion = function(rects) {};
99 /** @type {remoting.WindowShape} */
100 remoting.windowShape = new remoting.WindowShape();