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.
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.
13 /** @suppress {duplicate} */
14 var remoting
= remoting
|| {};
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_
= [];
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';
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();
45 * Set the region associated with the remote desktop windows.
47 * @param {Array<{left: number, top: number, width: number, height: number}>}
50 remoting
.WindowShape
.prototype.setDesktopRects = function(rects
) {
51 this.desktopRects_
= rects
;
52 this.updateClientWindowShape();
56 * Update the client window shape.
58 remoting
.WindowShape
.prototype.updateClientWindowShape = function() {
59 if (!remoting
.WindowShape
.isSupported()) {
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
,
76 height
: bottom
- top
};
78 chrome
.app
.window
.current().setShape({rects
: rects
});
85 remoting
.WindowShape
.ClientUI = function () {
89 * Add the context menu's bounding rectangle to the specified region.
91 * @param {Array<{left: number, top: number, width: number, height: number}>}
94 remoting
.WindowShape
.ClientUI
.prototype.addToRegion = function(rects
) {};
97 /** @type {remoting.WindowShape} */
98 remoting
.windowShape
= new remoting
.WindowShape();