Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / remoting / webapp / base / js / window_shape.js
blobaa21a84e9a8cf20f6d9abdec368b8bfcd55bb7ce
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.
29 remoting.WindowShape.isSupported = function() {
30 return base.isAppsV2() &&
31 typeof(chrome.app.window.current().setShape) != 'undefined';
34 /**
35 * Add a client-side UI measurement callback.
37 * @param {remoting.WindowShape.ClientUI} callback
39 remoting.WindowShape.prototype.addCallback = function(callback) {
40 this.clientUICallbacks_.push(callback);
41 this.updateClientWindowShape();
44 /**
45 * Set the region associated with the remote desktop windows.
47 * @param {Array<{left: number, top: number, width: number, height: number}>}
48 * rects
50 remoting.WindowShape.prototype.setDesktopRects = function(rects) {
51 this.desktopRects_ = rects;
52 this.updateClientWindowShape();
55 /**
56 * Update the client window shape.
58 remoting.WindowShape.prototype.updateClientWindowShape = function() {
59 if (!remoting.WindowShape.isSupported()) {
60 return;
63 var rects = this.desktopRects_.slice();
64 for (var i = 0; i < this.clientUICallbacks_.length; ++i) {
65 this.clientUICallbacks_[i].addToRegion(rects);
67 for (var i = 0; i < rects.length; ++i) {
68 var rect = /** @type {ClientRect} */ (rects[i]);
69 var left = Math.floor(rect.left);
70 var right = Math.ceil(rect.left + rect.width);
71 var top = Math.floor(rect.top);
72 var bottom = Math.ceil(rect.top + rect.height);
73 rects[i] = { left: left,
74 top: top,
75 width: right - left,
76 height: bottom - top };
78 chrome.app.window.current().setShape({rects: rects});
82 /**
83 * @interface
85 remoting.WindowShape.ClientUI = function () {
88 /**
89 * Add the context menu's bounding rectangle to the specified region.
91 * @param {Array<{left: number, top: number, width: number, height: number}>}
92 * rects
94 remoting.WindowShape.ClientUI.prototype.addToRegion = function(rects) {};
97 /** @type {remoting.WindowShape} */
98 remoting.windowShape = new remoting.WindowShape();