OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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. | |
4 | |
5 /** | |
6 * @fileoverview | |
7 * Provides an interface to manage the Host Desktop of a remoting session. | |
8 */ | |
9 | |
10 var remoting = remoting || {}; | |
11 remoting.ClientPlugin = remoting.ClientPlugin || {}; | |
12 | |
13 (function() { | |
14 | |
15 'use strict'; | |
16 | |
17 /** | |
18 * @param {remoting.ClientPluginImpl} plugin | |
19 * @param {function(Object):void} postMessageCallback Callback to post a message | |
20 * to the Client Plugin. | |
21 * | |
22 * @implements {remoting.HostDesktop} | |
23 * @extends {base.EventSourceImpl} | |
24 * @constructor | |
25 */ | |
26 remoting.ClientPlugin.HostDesktopImpl = function(plugin, postMessageCallback) { | |
27 /** @private */ | |
28 this.plugin_ = plugin; | |
29 /** @private */ | |
30 this.width_ = 0; | |
31 /** @private */ | |
32 this.height_ = 0; | |
33 /** @private */ | |
34 this.xDpi_ = 96; | |
35 /** @private */ | |
36 this.yDpi_ = 96; | |
37 /** @private */ | |
38 this.hasResizeRateLimit_ = false; | |
Jamie
2015/02/19 22:44:04
You don't need this (or the accessor) anymore.
kelvinp
2015/02/19 23:36:20
Done.
| |
39 /** @private */ | |
40 this.postMessageCallback_ = postMessageCallback; | |
41 | |
42 this.defineEvents(base.values(remoting.HostDesktop.Events)); | |
43 }; | |
44 base.extend(remoting.ClientPlugin.HostDesktopImpl, base.EventSourceImpl); | |
45 | |
46 /** @return {boolean} */ | |
47 remoting.ClientPlugin.HostDesktopImpl.prototype.hasResizeRateLimit = | |
48 function() { | |
49 return this.hasResizeRateLimit_; | |
50 }; | |
51 | |
52 /** @return {boolean} Whether the host supports desktop resizing. */ | |
53 remoting.ClientPlugin.HostDesktopImpl.prototype.isResizable = function() { | |
54 return this.plugin_.hasFeature( | |
55 remoting.ClientPlugin.Feature.NOTIFY_CLIENT_RESOLUTION); | |
56 }; | |
57 | |
58 /** @return {{width:number, height:number, xDpi:number, yDpi:number}} */ | |
59 remoting.ClientPlugin.HostDesktopImpl.prototype.getDimensions = function() { | |
60 return { | |
61 width: this.width_, | |
62 height: this.height_, | |
63 xDpi: this.xDpi_, | |
64 yDpi: this.yDpi_ | |
65 }; | |
66 }; | |
67 | |
68 /** | |
69 * @param {number} width | |
70 * @param {number} height | |
71 * @param {number} deviceScale | |
72 */ | |
73 remoting.ClientPlugin.HostDesktopImpl.prototype.resize = function( | |
74 width, height, deviceScale) { | |
75 if (this.isResizable()) { | |
76 var dpi = Math.floor(deviceScale * 96); | |
77 this.postMessageCallback_({ | |
78 method: 'notifyClientResolution', | |
79 data: { | |
80 width: Math.floor(width * deviceScale), | |
81 height: Math.floor(height * deviceScale), | |
82 x_dpi: dpi, | |
83 y_dpi: dpi | |
84 } | |
85 }); | |
86 } | |
87 }; | |
88 | |
89 /** | |
90 * This function is called by |this.plugin_| when the size of the host | |
91 * desktop is changed. | |
92 * | |
93 * @param {remoting.ClientPluginMessage} message | |
94 */ | |
95 remoting.ClientPlugin.HostDesktopImpl.prototype.onSizeUpdated = function( | |
96 message) { | |
97 this.width_ = getNumberAttr(message.data, 'width'); | |
98 this.height_ = getNumberAttr(message.data, 'height'); | |
99 this.xDpi_ = getNumberAttr(message.data, 'x_dpi', 96); | |
100 this.yDpi_ = getNumberAttr(message.data, 'y_dpi', 96); | |
101 this.raiseEvent(remoting.HostDesktop.Events.sizeChanged, | |
102 this.getDimensions()); | |
103 }; | |
104 | |
105 /** | |
106 * This function is called by |this.plugin_| when the shape of the host | |
107 * desktop is changed. | |
108 * | |
109 * @param {remoting.ClientPluginMessage} message | |
110 * @return {Array<{left:number, top:number, width:number, height:number}>} | |
111 * rectangles of the desktop shape. | |
112 */ | |
113 remoting.ClientPlugin.HostDesktopImpl.prototype.onShapeUpdated = | |
114 function(message) { | |
115 var shapes = getArrayAttr(message.data, 'rects'); | |
116 var rects = shapes.map( | |
117 /** @param {Array.<number>} shape */ | |
118 function(shape) { | |
119 if (!Array.isArray(shape) || shape.length != 4) { | |
120 throw 'Received invalid onDesktopShape message'; | |
121 } | |
122 | |
123 // Convert the values to integers. | |
124 var left = Math.floor(shape[0]); | |
125 var right = Math.ceil(shape[0] + shape[2]); | |
126 var top = Math.floor(shape[1]); | |
127 var bottom = Math.ceil(shape[1] + shape[3]); | |
128 | |
129 return { | |
130 left: left, | |
131 top: top, | |
132 width: right - left, | |
133 height: bottom - top | |
134 }; | |
135 }); | |
136 | |
137 this.raiseEvent(remoting.HostDesktop.Events.shapeChanged, rects); | |
138 return rects; | |
139 }; | |
140 | |
141 }()); | |
OLD | NEW |