1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @fileoverview
* Class handling setting of the local app window shape to account for windows
* on the remote desktop, as well as any client-side UI.
*/
'use strict';
/** @suppress {duplicate} */
var remoting = remoting || {};
/** @constructor */
remoting.WindowShape = function() {
/**
* @type {Array<{left: number, top: number, width: number, height: number}>}
* @private
*/
this.desktopRects_ = [];
/**
* @type {Array<remoting.WindowShape.ClientUI>}
* @private
*/
this.clientUICallbacks_ = [];
};
/**
* @return {boolean} True if setShape is available.
*/
remoting.WindowShape.isSupported = function() {
return base.isAppsV2() &&
typeof(chrome.app.window.current().setShape) != 'undefined';
}
/**
* Add a client-side UI measurement callback.
*
* @param {remoting.WindowShape.ClientUI} callback
*/
remoting.WindowShape.prototype.addCallback = function(callback) {
this.clientUICallbacks_.push(callback);
this.updateClientWindowShape();
};
/**
* Set the region associated with the remote desktop windows.
*
* @param {Array<{left: number, top: number, width: number, height: number}>}
* rects
*/
remoting.WindowShape.prototype.setDesktopRects = function(rects) {
this.desktopRects_ = rects;
this.updateClientWindowShape();
};
/**
* Update the client window shape.
*/
remoting.WindowShape.prototype.updateClientWindowShape = function() {
if (!remoting.WindowShape.isSupported()) {
return;
}
var rects = this.desktopRects_.slice();
for (var i = 0; i < this.clientUICallbacks_.length; ++i) {
this.clientUICallbacks_[i].addToRegion(rects);
}
for (var i = 0; i < rects.length; ++i) {
var rect = /** @type {ClientRect} */ (rects[i]);
var left = Math.floor(rect.left);
var right = Math.ceil(rect.left + rect.width);
var top = Math.floor(rect.top);
var bottom = Math.ceil(rect.top + rect.height);
rects[i] = { left: left,
top: top,
width: right - left,
height: bottom - top };
}
chrome.app.window.current().setShape({rects: rects});
};
/**
* @interface
*/
remoting.WindowShape.ClientUI = function () {
};
/**
* Add the context menu's bounding rectangle to the specified region.
*
* @param {Array<{left: number, top: number, width: number, height: number}>}
* rects
*/
remoting.WindowShape.ClientUI.prototype.addToRegion = function(rects) {};
/** @type {remoting.WindowShape} */
remoting.windowShape = new remoting.WindowShape();
|