| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
| 8 * | 8 * |
| 9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
| 10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 /** | 147 /** |
| 148 * @param {?function(remoting.ClientSession.State, | 148 * @param {?function(remoting.ClientSession.State, |
| 149 remoting.ClientSession.State):void} onStateChange | 149 remoting.ClientSession.State):void} onStateChange |
| 150 * The callback to invoke when the session changes state. | 150 * The callback to invoke when the session changes state. |
| 151 */ | 151 */ |
| 152 remoting.ClientSession.prototype.setOnStateChange = function(onStateChange) { | 152 remoting.ClientSession.prototype.setOnStateChange = function(onStateChange) { |
| 153 this.onStateChange_ = onStateChange; | 153 this.onStateChange_ = onStateChange; |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 /** | 156 /** |
| 157 * Called when the connection has been established to set the initial scroll- | 157 * Called when the window or desktop size or the scaling settings change, |
| 158 * bar visibility correctly. | 158 * to set the scroll-bar visibility. |
| 159 * | 159 * |
| 160 * TODO(jamiewalch): crbug.com/252796: Remove this once crbug.com/240772 is | 160 * TODO(jamiewalch): crbug.com/252796: Remove this once crbug.com/240772 is |
| 161 * fixed. | 161 * fixed. |
| 162 */ | 162 */ |
| 163 remoting.ClientSession.prototype.setScrollbarVisibility = function() { | 163 remoting.ClientSession.prototype.updateScrollbarVisibility = function() { |
| 164 var needsVerticalScroll = false; |
| 165 var needsHorizontalScroll = false; |
| 166 if (!this.shrinkToFit_) { |
| 167 // Determine whether or not horizontal or vertical scrollbars are |
| 168 // required, taking into account their width. |
| 169 needsVerticalScroll = window.innerHeight < this.plugin.desktopHeight; |
| 170 needsHorizontalScroll = window.innerWidth < this.plugin.desktopWidth; |
| 171 var kScrollBarWidth = 16; |
| 172 if (needsHorizontalScroll && !needsVerticalScroll) { |
| 173 needsVerticalScroll = |
| 174 window.innerHeight - kScrollBarWidth < this.plugin.desktopHeight; |
| 175 } else if (!needsHorizontalScroll && needsVerticalScroll) { |
| 176 needsHorizontalScroll = |
| 177 window.innerWidth - kScrollBarWidth < this.plugin.desktopWidth; |
| 178 } |
| 179 } |
| 180 |
| 164 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); | 181 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); |
| 165 if (this.shrinkToFit_) { | 182 if (needsHorizontalScroll) { |
| 166 htmlNode.classList.add('no-scroll'); | 183 htmlNode.classList.remove('no-horizontal-scroll'); |
| 167 } else { | 184 } else { |
| 168 htmlNode.classList.remove('no-scroll'); | 185 htmlNode.classList.add('no-horizontal-scroll'); |
| 186 } |
| 187 if (needsVerticalScroll) { |
| 188 htmlNode.classList.remove('no-vertical-scroll'); |
| 189 } else { |
| 190 htmlNode.classList.add('no-vertical-scroll'); |
| 169 } | 191 } |
| 170 }; | 192 }; |
| 171 | 193 |
| 172 // Note that the positive values in both of these enums are copied directly | 194 // Note that the positive values in both of these enums are copied directly |
| 173 // from chromoting_scriptable_object.h and must be kept in sync. The negative | 195 // from chromoting_scriptable_object.h and must be kept in sync. The negative |
| 174 // values represent state transitions that occur within the web-app that have | 196 // values represent state transitions that occur within the web-app that have |
| 175 // no corresponding plugin state transition. | 197 // no corresponding plugin state transition. |
| 176 /** @enum {number} */ | 198 /** @enum {number} */ |
| 177 remoting.ClientSession.State = { | 199 remoting.ClientSession.State = { |
| 178 CONNECTION_CANCELED: -5, // Connection closed (gracefully) before connecting. | 200 CONNECTION_CANCELED: -5, // Connection closed (gracefully) before connecting. |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 this.plugin.notifyClientResolution(window.innerWidth, | 676 this.plugin.notifyClientResolution(window.innerWidth, |
| 655 window.innerHeight, | 677 window.innerHeight, |
| 656 window.devicePixelRatio); | 678 window.devicePixelRatio); |
| 657 } | 679 } |
| 658 | 680 |
| 659 // If enabling shrink, reset bump-scroll offsets. | 681 // If enabling shrink, reset bump-scroll offsets. |
| 660 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; | 682 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; |
| 661 | 683 |
| 662 this.shrinkToFit_ = shrinkToFit; | 684 this.shrinkToFit_ = shrinkToFit; |
| 663 this.resizeToClient_ = resizeToClient; | 685 this.resizeToClient_ = resizeToClient; |
| 664 this.setScrollbarVisibility(); | 686 this.updateScrollbarVisibility(); |
| 665 | 687 |
| 666 if (this.hostId != '') { | 688 if (this.hostId != '') { |
| 667 var options = {}; | 689 var options = {}; |
| 668 options[remoting.ClientSession.KEY_SHRINK_TO_FIT] = this.shrinkToFit_; | 690 options[remoting.ClientSession.KEY_SHRINK_TO_FIT] = this.shrinkToFit_; |
| 669 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT] = this.resizeToClient_; | 691 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT] = this.resizeToClient_; |
| 670 remoting.HostSettings.save(this.hostId, options); | 692 remoting.HostSettings.save(this.hostId, options); |
| 671 } | 693 } |
| 672 | 694 |
| 673 this.updateDimensions(); | 695 this.updateDimensions(); |
| 674 if (needsScrollReset) { | 696 if (needsScrollReset) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 this.plugin.notifyClientResolution.bind(this.plugin, | 945 this.plugin.notifyClientResolution.bind(this.plugin, |
| 924 window.innerWidth, | 946 window.innerWidth, |
| 925 window.innerHeight, | 947 window.innerHeight, |
| 926 window.devicePixelRatio), | 948 window.devicePixelRatio), |
| 927 kResizeRateLimitMs); | 949 kResizeRateLimitMs); |
| 928 } | 950 } |
| 929 | 951 |
| 930 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize | 952 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize |
| 931 // the new window area. | 953 // the new window area. |
| 932 this.scroll_(0, 0); | 954 this.scroll_(0, 0); |
| 955 |
| 956 this.updateScrollbarVisibility(); |
| 933 }; | 957 }; |
| 934 | 958 |
| 935 /** | 959 /** |
| 936 * Requests that the host pause or resume video updates. | 960 * Requests that the host pause or resume video updates. |
| 937 * | 961 * |
| 938 * @param {boolean} pause True to pause video, false to resume. | 962 * @param {boolean} pause True to pause video, false to resume. |
| 939 * @return {void} Nothing. | 963 * @return {void} Nothing. |
| 940 */ | 964 */ |
| 941 remoting.ClientSession.prototype.pauseVideo = function(pause) { | 965 remoting.ClientSession.prototype.pauseVideo = function(pause) { |
| 942 if (this.plugin) { | 966 if (this.plugin) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 963 * @private | 987 * @private |
| 964 * @return {void} Nothing. | 988 * @return {void} Nothing. |
| 965 */ | 989 */ |
| 966 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { | 990 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { |
| 967 console.log('desktop size changed: ' + | 991 console.log('desktop size changed: ' + |
| 968 this.plugin.desktopWidth + 'x' + | 992 this.plugin.desktopWidth + 'x' + |
| 969 this.plugin.desktopHeight +' @ ' + | 993 this.plugin.desktopHeight +' @ ' + |
| 970 this.plugin.desktopXDpi + 'x' + | 994 this.plugin.desktopXDpi + 'x' + |
| 971 this.plugin.desktopYDpi + ' DPI'); | 995 this.plugin.desktopYDpi + ' DPI'); |
| 972 this.updateDimensions(); | 996 this.updateDimensions(); |
| 997 this.updateScrollbarVisibility(); |
| 973 }; | 998 }; |
| 974 | 999 |
| 975 /** | 1000 /** |
| 976 * Refreshes the plugin's dimensions, taking into account the sizes of the | 1001 * Refreshes the plugin's dimensions, taking into account the sizes of the |
| 977 * remote desktop and client window, and the current scale-to-fit setting. | 1002 * remote desktop and client window, and the current scale-to-fit setting. |
| 978 * | 1003 * |
| 979 * @return {void} Nothing. | 1004 * @return {void} Nothing. |
| 980 */ | 1005 */ |
| 981 remoting.ClientSession.prototype.updateDimensions = function() { | 1006 remoting.ClientSession.prototype.updateDimensions = function() { |
| 982 if (this.plugin.desktopWidth == 0 || | 1007 if (this.plugin.desktopWidth == 0 || |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1256 var lateAdjustment = 1 + (now - expected) / timeout; | 1281 var lateAdjustment = 1 + (now - expected) / timeout; |
| 1257 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1282 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
| 1258 that.bumpScrollTimer_ = window.setTimeout( | 1283 that.bumpScrollTimer_ = window.setTimeout( |
| 1259 function() { repeatScroll(now + timeout); }, | 1284 function() { repeatScroll(now + timeout); }, |
| 1260 timeout); | 1285 timeout); |
| 1261 } | 1286 } |
| 1262 }; | 1287 }; |
| 1263 repeatScroll(new Date().getTime()); | 1288 repeatScroll(new Date().getTime()); |
| 1264 } | 1289 } |
| 1265 }; | 1290 }; |
| OLD | NEW |