Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(591)

Side by Side Diff: remoting/webapp/crd/js/desktop_connected_view.js

Issue 929323003: Separate host desktop related functionality into remoting.HostDesktop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Separating from https://codereview.chromium.org/918783002/ Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Class handling user-facing aspects of the client session. 7 * Class handling user-facing aspects of the client session.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 // Bump-scroll test variables. Override to use a fake value for the width 107 // Bump-scroll test variables. Override to use a fake value for the width
108 // and height of the client plugin so that bump-scrolling can be tested 108 // and height of the client plugin so that bump-scrolling can be tested
109 // without relying on the actual size of the host desktop. 109 // without relying on the actual size of the host desktop.
110 /** @type {number} @private */ 110 /** @type {number} @private */
111 this.pluginWidthForBumpScrollTesting = 0; 111 this.pluginWidthForBumpScrollTesting = 0;
112 /** @type {number} @private */ 112 /** @type {number} @private */
113 this.pluginHeightForBumpScrollTesting = 0; 113 this.pluginHeightForBumpScrollTesting = 0;
114 114
115 /** @type {remoting.VideoFrameRecorder} @private */ 115 /** @type {remoting.VideoFrameRecorder} @private */
116 this.videoFrameRecorder_ = null; 116 this.videoFrameRecorder_ = null;
117
118 /** @private {base.Disposables} */
119 this.eventHooks_ = null;
117 }; 120 };
118 121
119 base.extend(remoting.DesktopConnectedView, base.EventSourceImpl); 122 base.extend(remoting.DesktopConnectedView, base.EventSourceImpl);
120 123
121 /** @enum {string} */ 124 /** @enum {string} */
122 remoting.DesktopConnectedView.Events = { 125 remoting.DesktopConnectedView.Events = {
123 bumpScrollStarted: 'bumpScrollStarted', 126 bumpScrollStarted: 'bumpScrollStarted',
124 bumpScrollStopped: 'bumpScrollStopped' 127 bumpScrollStopped: 'bumpScrollStopped'
125 }; 128 };
126 129
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 { 'width': window.innerWidth, 'height': window.innerHeight }; 190 { 'width': window.innerWidth, 'height': window.innerHeight };
188 }; 191 };
189 192
190 /** 193 /**
191 * Notifies the host of the client's current dimensions and DPI. 194 * Notifies the host of the client's current dimensions and DPI.
192 * Also takes into account per-host scaling factor, if configured. 195 * Also takes into account per-host scaling factor, if configured.
193 * TODO: private 196 * TODO: private
194 */ 197 */
195 remoting.DesktopConnectedView.prototype.notifyClientResolution_ = function() { 198 remoting.DesktopConnectedView.prototype.notifyClientResolution_ = function() {
196 var clientArea = this.getClientArea_(); 199 var clientArea = this.getClientArea_();
197 this.plugin_.notifyClientResolution(clientArea.width * this.desktopScale_, 200 this.plugin_.hostDesktop().resize(clientArea.width * this.desktopScale_,
198 clientArea.height * this.desktopScale_, 201 clientArea.height * this.desktopScale_,
199 window.devicePixelRatio); 202 window.devicePixelRatio);
200 }; 203 };
201 204
202 /** 205 /**
203 * Adds <embed> element to the UI container and readies the session object. 206 * Adds <embed> element to the UI container and readies the session object.
204 * 207 *
205 * @param {function(string, string):boolean} onExtensionMessage The handler for 208 * @param {function(string, string):boolean} onExtensionMessage The handler for
206 * protocol extension messages. Returns true if a message is recognized; 209 * protocol extension messages. Returns true if a message is recognized;
207 * false otherwise. 210 * false otherwise.
208 * @param {Array<string>} requiredCapabilities A list of capabilities 211 * @param {Array<string>} requiredCapabilities A list of capabilities
209 * required by this application. 212 * required by this application.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 this.applyRemapKeys_(true); 289 this.applyRemapKeys_(true);
287 } 290 }
288 291
289 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission. 292 // TODO(wez): Only allow mouse lock if the app has the pointerLock permission.
290 // Enable automatic mouse-lock. 293 // Enable automatic mouse-lock.
291 if (remoting.enableMouseLock && 294 if (remoting.enableMouseLock &&
292 this.plugin_.hasFeature(remoting.ClientPlugin.Feature.ALLOW_MOUSE_LOCK)) { 295 this.plugin_.hasFeature(remoting.ClientPlugin.Feature.ALLOW_MOUSE_LOCK)) {
293 this.plugin_.allowMouseLock(); 296 this.plugin_.allowMouseLock();
294 } 297 }
295 298
296 this.plugin_.setDesktopShapeUpdateHandler( 299 base.dispose(this.eventHooks_);
297 this.onDesktopShapeChanged_.bind(this)); 300 var hostDesktop = this.plugin_.hostDesktop();
298 this.plugin_.setDesktopSizeUpdateHandler( 301 this.eventHooks_ = new base.Disposables(
299 this.onDesktopSizeChanged_.bind(this)); 302 new base.EventHook(
303 hostDesktop, remoting.HostDesktop.Events.sizeChanged,
304 this.onDesktopSizeChanged_.bind(this)),
305 new base.EventHook(
306 hostDesktop, remoting.HostDesktop.Events.shapeChanged,
307 this.onDesktopShapeChanged_.bind(this)));
308
300 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this)); 309 this.plugin_.setMouseCursorHandler(this.updateMouseCursorImage_.bind(this));
301 310
302 this.onInitialized_(remoting.Error.NONE, this.plugin_); 311 this.onInitialized_(remoting.Error.NONE, this.plugin_);
303 }; 312 };
304 313
305 /** 314 /**
306 * This is a callback that gets called when the plugin notifies us of a change 315 * This is a callback that gets called when the plugin notifies us of a change
307 * in the size of the remote desktop. 316 * in the size of the remote desktop.
308 * 317 *
309 * @return {void} Nothing. 318 * @return {void} Nothing.
310 * @private 319 * @private
311 */ 320 */
312 remoting.DesktopConnectedView.prototype.onDesktopSizeChanged_ = function() { 321 remoting.DesktopConnectedView.prototype.onDesktopSizeChanged_ = function() {
322 var desktop = this.plugin_.hostDesktop().getDimensions();
313 console.log('desktop size changed: ' + 323 console.log('desktop size changed: ' +
314 this.plugin_.getDesktopWidth() + 'x' + 324 desktop.width + 'x' +
315 this.plugin_.getDesktopHeight() +' @ ' + 325 desktop.height +' @ ' +
316 this.plugin_.getDesktopXDpi() + 'x' + 326 desktop.xDpi + 'x' +
317 this.plugin_.getDesktopYDpi() + ' DPI'); 327 desktop.yDpi + ' DPI');
318 this.updateDimensions(); 328 this.updateDimensions();
319 this.updateScrollbarVisibility(); 329 this.updateScrollbarVisibility();
320 }; 330 };
321 331
322 /** 332 /**
323 * Sets the non-click-through area of the client in response to notifications 333 * Sets the non-click-through area of the client in response to notifications
324 * from the plugin of desktop shape changes. 334 * from the plugin of desktop shape changes.
325 * 335 *
326 * @param {Array<Array<number>>} rects List of rectangles comprising the 336 * @param {Array<Array<number>>} rects List of rectangles comprising the
327 * desktop shape. 337 * desktop shape.
(...skipping 26 matching lines...) Expand all
354 364
355 if (this.notifyClientResolutionTimer_) { 365 if (this.notifyClientResolutionTimer_) {
356 window.clearTimeout(this.notifyClientResolutionTimer_); 366 window.clearTimeout(this.notifyClientResolutionTimer_);
357 this.notifyClientResolutionTimer_ = null; 367 this.notifyClientResolutionTimer_ = null;
358 } 368 }
359 369
360 // Defer notifying the host of the change until the window stops resizing, to 370 // Defer notifying the host of the change until the window stops resizing, to
361 // avoid overloading the control channel with notifications. 371 // avoid overloading the control channel with notifications.
362 if (this.resizeToClient_) { 372 if (this.resizeToClient_) {
363 var kResizeRateLimitMs = 1000; 373 var kResizeRateLimitMs = 1000;
364 if (this.session_.hasCapability( 374 if (this.plugin_.hostDesktop().hasResizeRateLimit()) {
365 remoting.ClientSession.Capability.RATE_LIMIT_RESIZE_REQUESTS)) {
366 kResizeRateLimitMs = 250; 375 kResizeRateLimitMs = 250;
367 } 376 }
368 var clientArea = this.getClientArea_(); 377 var clientArea = this.getClientArea_();
369 this.notifyClientResolutionTimer_ = window.setTimeout( 378 this.notifyClientResolutionTimer_ = window.setTimeout(
370 this.notifyClientResolution_.bind(this), 379 this.notifyClientResolution_.bind(this),
371 kResizeRateLimitMs); 380 kResizeRateLimitMs);
372 } 381 }
373 382
374 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize 383 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize
375 // the new window area. 384 // the new window area.
(...skipping 18 matching lines...) Expand all
394 403
395 /** 404 /**
396 * Deletes the <embed> element from the container, without sending a 405 * Deletes the <embed> element from the container, without sending a
397 * session_terminate request. This is to be called when the session was 406 * session_terminate request. This is to be called when the session was
398 * disconnected by the Host. 407 * disconnected by the Host.
399 * 408 *
400 * @return {void} Nothing. 409 * @return {void} Nothing.
401 */ 410 */
402 remoting.DesktopConnectedView.prototype.removePlugin = function() { 411 remoting.DesktopConnectedView.prototype.removePlugin = function() {
403 if (this.plugin_) { 412 if (this.plugin_) {
413 base.dispose(this.eventHooks_);
414 this.eventHooks_ = null;
404 this.plugin_.element().removeEventListener( 415 this.plugin_.element().removeEventListener(
405 'focus', this.callPluginGotFocus_, false); 416 'focus', this.callPluginGotFocus_, false);
406 this.plugin_.element().removeEventListener( 417 this.plugin_.element().removeEventListener(
407 'blur', this.callPluginLostFocus_, false); 418 'blur', this.callPluginLostFocus_, false);
408 this.plugin_.dispose(); 419 this.plugin_.dispose();
409 this.plugin_ = null; 420 this.plugin_ = null;
410 } 421 }
411 422
412 this.updateClientSessionUi_(null); 423 this.updateClientSessionUi_(null);
413 }; 424 };
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 return stopX.stop && stopY.stop; 738 return stopX.stop && stopY.stop;
728 }; 739 };
729 740
730 /** 741 /**
731 * Refreshes the plugin's dimensions, taking into account the sizes of the 742 * Refreshes the plugin's dimensions, taking into account the sizes of the
732 * remote desktop and client window, and the current scale-to-fit setting. 743 * remote desktop and client window, and the current scale-to-fit setting.
733 * 744 *
734 * @return {void} Nothing. 745 * @return {void} Nothing.
735 */ 746 */
736 remoting.DesktopConnectedView.prototype.updateDimensions = function() { 747 remoting.DesktopConnectedView.prototype.updateDimensions = function() {
737 if (this.plugin_.getDesktopWidth() == 0 || 748 var desktopSize = this.plugin_.hostDesktop().getDimensions();
738 this.plugin_.getDesktopHeight() == 0) { 749
750 if (desktopSize.width === 0 ||
751 desktopSize.height === 0) {
739 return; 752 return;
740 } 753 }
741 754
742 var desktopSize = { width: this.plugin_.getDesktopWidth(), 755 var desktopDpi = { x: desktopSize.xDpi,
743 height: this.plugin_.getDesktopHeight() }; 756 y: desktopSize.yDpi };
744 var desktopDpi = { x: this.plugin_.getDesktopXDpi(),
745 y: this.plugin_.getDesktopYDpi() };
746 var newSize = remoting.DesktopConnectedView.choosePluginSize( 757 var newSize = remoting.DesktopConnectedView.choosePluginSize(
747 this.getClientArea_(), window.devicePixelRatio, 758 this.getClientArea_(), window.devicePixelRatio,
748 desktopSize, desktopDpi, this.desktopScale_, 759 desktopSize, desktopDpi, this.desktopScale_,
749 remoting.fullscreen.isActive(), this.shrinkToFit_); 760 remoting.fullscreen.isActive(), this.shrinkToFit_);
750 761
751 // Resize the plugin if necessary. 762 // Resize the plugin if necessary.
752 console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height); 763 console.log('plugin dimensions:' + newSize.width + 'x' + newSize.height);
753 this.plugin_.element().style.width = newSize.width + 'px'; 764 this.plugin_.element().style.width = newSize.width + 'px';
754 this.plugin_.element().style.height = newSize.height + 'px'; 765 this.plugin_.element().style.height = newSize.height + 'px';
755 766
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 if (!scroller) { 914 if (!scroller) {
904 return; 915 return;
905 } 916 }
906 917
907 var needsVerticalScroll = false; 918 var needsVerticalScroll = false;
908 var needsHorizontalScroll = false; 919 var needsHorizontalScroll = false;
909 if (!this.shrinkToFit_) { 920 if (!this.shrinkToFit_) {
910 // Determine whether or not horizontal or vertical scrollbars are 921 // Determine whether or not horizontal or vertical scrollbars are
911 // required, taking into account their width. 922 // required, taking into account their width.
912 var clientArea = this.getClientArea_(); 923 var clientArea = this.getClientArea_();
913 needsVerticalScroll = clientArea.height < this.plugin_.getDesktopHeight(); 924 var desktopSize = this.plugin_.hostDesktop().getDimensions();
914 needsHorizontalScroll = clientArea.width < this.plugin_.getDesktopWidth(); 925 needsVerticalScroll = clientArea.height < desktopSize.height;
926 needsHorizontalScroll = clientArea.width < desktopSize.width;
915 var kScrollBarWidth = 16; 927 var kScrollBarWidth = 16;
916 if (needsHorizontalScroll && !needsVerticalScroll) { 928 if (needsHorizontalScroll && !needsVerticalScroll) {
917 needsVerticalScroll = 929 needsVerticalScroll =
918 clientArea.height - kScrollBarWidth < this.plugin_.getDesktopHeight(); 930 clientArea.height - kScrollBarWidth < desktopSize.height;
919 } else if (!needsHorizontalScroll && needsVerticalScroll) { 931 } else if (!needsHorizontalScroll && needsVerticalScroll) {
920 needsHorizontalScroll = 932 needsHorizontalScroll =
921 clientArea.width - kScrollBarWidth < this.plugin_.getDesktopWidth(); 933 clientArea.width - kScrollBarWidth < desktopSize.width;
922 } 934 }
923 } 935 }
924 936
925 if (needsHorizontalScroll) { 937 if (needsHorizontalScroll) {
926 scroller.classList.remove('no-horizontal-scroll'); 938 scroller.classList.remove('no-horizontal-scroll');
927 } else { 939 } else {
928 scroller.classList.add('no-horizontal-scroll'); 940 scroller.classList.add('no-horizontal-scroll');
929 } 941 }
930 if (needsVerticalScroll) { 942 if (needsVerticalScroll) {
931 scroller.classList.remove('no-vertical-scroll'); 943 scroller.classList.remove('no-vertical-scroll');
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 * @param {Object} message The parsed extension message data. 1100 * @param {Object} message The parsed extension message data.
1089 * @return {boolean} True if the message was recognized, false otherwise. 1101 * @return {boolean} True if the message was recognized, false otherwise.
1090 */ 1102 */
1091 remoting.DesktopConnectedView.prototype.handleExtensionMessage = 1103 remoting.DesktopConnectedView.prototype.handleExtensionMessage =
1092 function(type, message) { 1104 function(type, message) {
1093 if (this.videoFrameRecorder_) { 1105 if (this.videoFrameRecorder_) {
1094 return this.videoFrameRecorder_.handleMessage(type, message); 1106 return this.videoFrameRecorder_.handleMessage(type, message);
1095 } 1107 }
1096 return false; 1108 return false;
1097 }; 1109 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698