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 console.log('Checking for scrollbars: window height = ' + | |
168 window.innerHeight + "; plugin height = " + this.plugin.desktopHeight); | |
Wez
2013/08/03 02:48:49
Won't this result in a lot of logging, and potenti
Jamie
2013/08/05 18:33:05
Left-over debugging; removed.
| |
169 // Determine whether or not horizontal or vertical scrollbars are | |
170 // required, taking into account their width. | |
171 needsVerticalScroll = window.innerHeight < this.plugin.desktopHeight; | |
172 needsHorizontalScroll = window.innerWidth < this.plugin.desktopWidth; | |
173 var kScrollBarWidth = 16; | |
174 if (needsHorizontalScroll && !needsVerticalScroll) { | |
175 needsVerticalScroll = | |
176 window.innerHeight - kScrollBarWidth < this.plugin.desktopHeight; | |
177 } else if (!needsHorizontalScroll && needsVerticalScroll) { | |
178 needsHorizontalScroll = | |
179 window.innerWidth - kScrollBarWidth < this.plugin.desktopWidth; | |
180 } | |
181 } | |
182 | |
164 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); | 183 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); |
165 if (this.shrinkToFit_) { | 184 if (needsHorizontalScroll) { |
166 htmlNode.classList.add('no-scroll'); | 185 htmlNode.classList.remove('no-horizontal-scroll'); |
167 } else { | 186 } else { |
168 htmlNode.classList.remove('no-scroll'); | 187 htmlNode.classList.add('no-horizontal-scroll'); |
188 } | |
189 if (needsVerticalScroll) { | |
190 htmlNode.classList.remove('no-vertical-scroll'); | |
191 } else { | |
192 htmlNode.classList.add('no-vertical-scroll'); | |
169 } | 193 } |
170 }; | 194 }; |
171 | 195 |
172 // Note that the positive values in both of these enums are copied directly | 196 // 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 | 197 // 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 | 198 // values represent state transitions that occur within the web-app that have |
175 // no corresponding plugin state transition. | 199 // no corresponding plugin state transition. |
176 /** @enum {number} */ | 200 /** @enum {number} */ |
177 remoting.ClientSession.State = { | 201 remoting.ClientSession.State = { |
178 CONNECTION_CANCELED: -5, // Connection closed (gracefully) before connecting. | 202 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, | 678 this.plugin.notifyClientResolution(window.innerWidth, |
655 window.innerHeight, | 679 window.innerHeight, |
656 window.devicePixelRatio); | 680 window.devicePixelRatio); |
657 } | 681 } |
658 | 682 |
659 // If enabling shrink, reset bump-scroll offsets. | 683 // If enabling shrink, reset bump-scroll offsets. |
660 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; | 684 var needsScrollReset = shrinkToFit && !this.shrinkToFit_; |
661 | 685 |
662 this.shrinkToFit_ = shrinkToFit; | 686 this.shrinkToFit_ = shrinkToFit; |
663 this.resizeToClient_ = resizeToClient; | 687 this.resizeToClient_ = resizeToClient; |
664 this.setScrollbarVisibility(); | 688 this.updateScrollbarVisibility(); |
665 | 689 |
666 if (this.hostId != '') { | 690 if (this.hostId != '') { |
667 var options = {}; | 691 var options = {}; |
668 options[remoting.ClientSession.KEY_SHRINK_TO_FIT] = this.shrinkToFit_; | 692 options[remoting.ClientSession.KEY_SHRINK_TO_FIT] = this.shrinkToFit_; |
669 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT] = this.resizeToClient_; | 693 options[remoting.ClientSession.KEY_RESIZE_TO_CLIENT] = this.resizeToClient_; |
670 remoting.HostSettings.save(this.hostId, options); | 694 remoting.HostSettings.save(this.hostId, options); |
671 } | 695 } |
672 | 696 |
673 this.updateDimensions(); | 697 this.updateDimensions(); |
674 if (needsScrollReset) { | 698 if (needsScrollReset) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 this.plugin.notifyClientResolution.bind(this.plugin, | 947 this.plugin.notifyClientResolution.bind(this.plugin, |
924 window.innerWidth, | 948 window.innerWidth, |
925 window.innerHeight, | 949 window.innerHeight, |
926 window.devicePixelRatio), | 950 window.devicePixelRatio), |
927 kResizeRateLimitMs); | 951 kResizeRateLimitMs); |
928 } | 952 } |
929 | 953 |
930 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize | 954 // If bump-scrolling is enabled, adjust the plugin margins to fully utilize |
931 // the new window area. | 955 // the new window area. |
932 this.scroll_(0, 0); | 956 this.scroll_(0, 0); |
957 | |
958 this.updateScrollbarVisibility(); | |
933 }; | 959 }; |
934 | 960 |
935 /** | 961 /** |
936 * Requests that the host pause or resume video updates. | 962 * Requests that the host pause or resume video updates. |
937 * | 963 * |
938 * @param {boolean} pause True to pause video, false to resume. | 964 * @param {boolean} pause True to pause video, false to resume. |
939 * @return {void} Nothing. | 965 * @return {void} Nothing. |
940 */ | 966 */ |
941 remoting.ClientSession.prototype.pauseVideo = function(pause) { | 967 remoting.ClientSession.prototype.pauseVideo = function(pause) { |
942 if (this.plugin) { | 968 if (this.plugin) { |
(...skipping 20 matching lines...) Expand all Loading... | |
963 * @private | 989 * @private |
964 * @return {void} Nothing. | 990 * @return {void} Nothing. |
965 */ | 991 */ |
966 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { | 992 remoting.ClientSession.prototype.onDesktopSizeChanged_ = function() { |
967 console.log('desktop size changed: ' + | 993 console.log('desktop size changed: ' + |
968 this.plugin.desktopWidth + 'x' + | 994 this.plugin.desktopWidth + 'x' + |
969 this.plugin.desktopHeight +' @ ' + | 995 this.plugin.desktopHeight +' @ ' + |
970 this.plugin.desktopXDpi + 'x' + | 996 this.plugin.desktopXDpi + 'x' + |
971 this.plugin.desktopYDpi + ' DPI'); | 997 this.plugin.desktopYDpi + ' DPI'); |
972 this.updateDimensions(); | 998 this.updateDimensions(); |
999 this.updateScrollbarVisibility(); | |
973 }; | 1000 }; |
974 | 1001 |
975 /** | 1002 /** |
976 * Refreshes the plugin's dimensions, taking into account the sizes of the | 1003 * 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. | 1004 * remote desktop and client window, and the current scale-to-fit setting. |
978 * | 1005 * |
979 * @return {void} Nothing. | 1006 * @return {void} Nothing. |
980 */ | 1007 */ |
981 remoting.ClientSession.prototype.updateDimensions = function() { | 1008 remoting.ClientSession.prototype.updateDimensions = function() { |
982 if (this.plugin.desktopWidth == 0 || | 1009 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; | 1283 var lateAdjustment = 1 + (now - expected) / timeout; |
1257 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { | 1284 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { |
1258 that.bumpScrollTimer_ = window.setTimeout( | 1285 that.bumpScrollTimer_ = window.setTimeout( |
1259 function() { repeatScroll(now + timeout); }, | 1286 function() { repeatScroll(now + timeout); }, |
1260 timeout); | 1287 timeout); |
1261 } | 1288 } |
1262 }; | 1289 }; |
1263 repeatScroll(new Date().getTime()); | 1290 repeatScroll(new Date().getTime()); |
1264 } | 1291 } |
1265 }; | 1292 }; |
OLD | NEW |