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 and implemented for the
30 remoting
.WindowShape
.isSupported = function() {
31 return base
.isAppsV2() &&
32 typeof(chrome
.app
.window
.current().setShape
) != 'undefined' &&
33 !remoting
.platformIsMac();
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();
47 * Set the region associated with the remote desktop windows.
49 * @param {Array<{left: number, top: number, width: number, height: number}>}
52 remoting
.WindowShape
.prototype.setDesktopRects = function(rects
) {
53 this.desktopRects_
= rects
;
54 this.updateClientWindowShape();
58 * Update the client window shape.
60 remoting
.WindowShape
.prototype.updateClientWindowShape = function() {
61 if (!remoting
.WindowShape
.isSupported()) {
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
,
78 height
: bottom
- top
};
80 chrome
.app
.window
.current().setShape({rects
: rects
});
87 remoting
.WindowShape
.ClientUI = function () {
91 * Add the context menu's bounding rectangle to the specified region.
93 * @param {Array<{left: number, top: number, width: number, height: number}>}
96 remoting
.WindowShape
.ClientUI
.prototype.addToRegion = function(rects
) {};
99 /** @type {remoting.WindowShape} */
100 remoting
.windowShape
= new remoting
.WindowShape();