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

Side by Side Diff: remoting/webapp/client_session.js

Issue 421433002: Implement bump-scroll browser-test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implementation Created 6 years, 4 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 (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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 this.remapKeys_ = ''; 98 this.remapKeys_ = '';
99 /** @private */ 99 /** @private */
100 this.hasReceivedFrame_ = false; 100 this.hasReceivedFrame_ = false;
101 this.logToServer = new remoting.LogToServer(); 101 this.logToServer = new remoting.LogToServer();
102 102
103 /** @type {number?} @private */ 103 /** @type {number?} @private */
104 this.notifyClientResolutionTimer_ = null; 104 this.notifyClientResolutionTimer_ = null;
105 /** @type {number?} @private */ 105 /** @type {number?} @private */
106 this.bumpScrollTimer_ = null; 106 this.bumpScrollTimer_ = null;
107 107
108 // Bump-scroll test variables. Override to use a fake value for the width
109 // and height of the client plugin so that bump-scrolling can be tested
110 // without relying on the actual size of the host desktop.
111 /** @type {number} @private */
112 this.pluginWidthForBumpScrollTesting = 0;
113 /** @type {number} @private */
114 this.pluginHeightForBumpScrollTesting = 0;
115
108 /** 116 /**
109 * Allow host-offline error reporting to be suppressed in situations where it 117 * Allow host-offline error reporting to be suppressed in situations where it
110 * would not be useful, for example, when using a cached host JID. 118 * would not be useful, for example, when using a cached host JID.
111 * 119 *
112 * @type {boolean} @private 120 * @type {boolean} @private
113 */ 121 */
114 this.logHostOfflineErrors_ = true; 122 this.logHostOfflineErrors_ = true;
115 123
116 /** @private */ 124 /** @private */
117 this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this); 125 this.callPluginLostFocus_ = this.pluginLostFocus_.bind(this);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 this.fullScreenButton_.addEventListener( 176 this.fullScreenButton_.addEventListener(
169 'click', this.callToggleFullScreen_, false); 177 'click', this.callToggleFullScreen_, false);
170 this.defineEvents(Object.keys(remoting.ClientSession.Events)); 178 this.defineEvents(Object.keys(remoting.ClientSession.Events));
171 }; 179 };
172 180
173 base.extend(remoting.ClientSession, base.EventSource); 181 base.extend(remoting.ClientSession, base.EventSource);
174 182
175 /** @enum {string} */ 183 /** @enum {string} */
176 remoting.ClientSession.Events = { 184 remoting.ClientSession.Events = {
177 stateChanged: 'stateChanged', 185 stateChanged: 'stateChanged',
178 videoChannelStateChanged: 'videoChannelStateChanged' 186 videoChannelStateChanged: 'videoChannelStateChanged',
187 bumpScrollStarted: 'bumpScrollStarted',
188 bumpScrollStopped: 'bumpScrollStopped'
179 }; 189 };
180 190
181 /** 191 /**
182 * Get host display name. 192 * Get host display name.
183 * 193 *
184 * @return {string} 194 * @return {string}
185 */ 195 */
186 remoting.ClientSession.prototype.getHostDisplayName = function() { 196 remoting.ClientSession.prototype.getHostDisplayName = function() {
187 return this.hostDisplayName_; 197 return this.hostDisplayName_;
188 }; 198 };
(...skipping 1186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 var adjustMargin = function(curr, delta, windowBound, pluginBound, stop) { 1385 var adjustMargin = function(curr, delta, windowBound, pluginBound, stop) {
1376 var minMargin = Math.min(0, windowBound - pluginBound); 1386 var minMargin = Math.min(0, windowBound - pluginBound);
1377 var result = (curr ? parseFloat(curr) : 0) - delta; 1387 var result = (curr ? parseFloat(curr) : 0) - delta;
1378 result = Math.min(0, Math.max(minMargin, result)); 1388 result = Math.min(0, Math.max(minMargin, result));
1379 stop.stop = (result == 0 || result == minMargin); 1389 stop.stop = (result == 0 || result == minMargin);
1380 return result + 'px'; 1390 return result + 'px';
1381 }; 1391 };
1382 1392
1383 var stopX = { stop: false }; 1393 var stopX = { stop: false };
1384 var clientArea = this.getClientArea_(); 1394 var clientArea = this.getClientArea_();
1385 style.marginLeft = adjustMargin(style.marginLeft, dx, 1395 style.marginLeft = adjustMargin(style.marginLeft, dx, clientArea.width,
1386 clientArea.width, plugin.clientWidth, stopX); 1396 this.pluginWidthForBumpScrollTesting || plugin.clientWidth, stopX);
1387 1397
1388 var stopY = { stop: false }; 1398 var stopY = { stop: false };
1389 style.marginTop = adjustMargin( 1399 style.marginTop = adjustMargin(
1390 style.marginTop, dy, clientArea.height, plugin.clientHeight, stopY); 1400 style.marginTop, dy, clientArea.height,
1401 this.pluginHeightForBumpScrollTesting || plugin.clientHeight, stopY);
1391 return stopX.stop && stopY.stop; 1402 return stopX.stop && stopY.stop;
1392 }; 1403 };
1393 1404
1394 remoting.ClientSession.prototype.resetScroll_ = function() { 1405 remoting.ClientSession.prototype.resetScroll_ = function() {
1395 if (this.plugin_) { 1406 if (this.plugin_) {
1396 var plugin = this.plugin_.element(); 1407 var plugin = this.plugin_.element();
1397 plugin.style.marginTop = '0px'; 1408 plugin.style.marginTop = '0px';
1398 plugin.style.marginLeft = '0px'; 1409 plugin.style.marginLeft = '0px';
1399 } 1410 }
1400 }; 1411 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 return -1 - 5 * (threshold - mousePos) / threshold; 1453 return -1 - 5 * (threshold - mousePos) / threshold;
1443 } 1454 }
1444 return 0; 1455 return 0;
1445 }; 1456 };
1446 1457
1447 var clientArea = this.getClientArea_(); 1458 var clientArea = this.getClientArea_();
1448 var dx = computeDelta(event.x, clientArea.width); 1459 var dx = computeDelta(event.x, clientArea.width);
1449 var dy = computeDelta(event.y, clientArea.height); 1460 var dy = computeDelta(event.y, clientArea.height);
1450 1461
1451 if (dx != 0 || dy != 0) { 1462 if (dx != 0 || dy != 0) {
1463 this.raiseEvent(remoting.ClientSession.Events.bumpScrollStarted);
1452 /** @type {remoting.ClientSession} */ 1464 /** @type {remoting.ClientSession} */
1453 var that = this; 1465 var that = this;
1454 /** 1466 /**
1455 * Scroll the view, and schedule a timer to do so again unless we've hit 1467 * Scroll the view, and schedule a timer to do so again unless we've hit
1456 * the edges of the screen. This timer is cancelled when the mouse moves. 1468 * the edges of the screen. This timer is cancelled when the mouse moves.
1457 * @param {number} expected The time at which we expect to be called. 1469 * @param {number} expected The time at which we expect to be called.
1458 */ 1470 */
1459 var repeatScroll = function(expected) { 1471 var repeatScroll = function(expected) {
1460 /** @type {number} */ 1472 /** @type {number} */
1461 var now = new Date().getTime(); 1473 var now = new Date().getTime();
1462 /** @type {number} */ 1474 /** @type {number} */
1463 var timeout = 10; 1475 var timeout = 10;
1464 var lateAdjustment = 1 + (now - expected) / timeout; 1476 var lateAdjustment = 1 + (now - expected) / timeout;
1465 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { 1477 if (that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) {
1478 that.raiseEvent(remoting.ClientSession.Events.bumpScrollStopped);
1479 } else {
1466 that.bumpScrollTimer_ = window.setTimeout( 1480 that.bumpScrollTimer_ = window.setTimeout(
1467 function() { repeatScroll(now + timeout); }, 1481 function() { repeatScroll(now + timeout); },
1468 timeout); 1482 timeout);
1469 } 1483 }
1470 }; 1484 };
1471 repeatScroll(new Date().getTime()); 1485 repeatScroll(new Date().getTime());
1472 } 1486 }
1473 }; 1487 };
1474 1488
1475 /** 1489 /**
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1543 * @param {number} hotspotY 1557 * @param {number} hotspotY
1544 */ 1558 */
1545 remoting.ClientSession.prototype.updateMouseCursorImage_ = 1559 remoting.ClientSession.prototype.updateMouseCursorImage_ =
1546 function(url, hotspotX, hotspotY) { 1560 function(url, hotspotX, hotspotY) {
1547 this.mouseCursorOverlay_.hidden = !url; 1561 this.mouseCursorOverlay_.hidden = !url;
1548 if (url) { 1562 if (url) {
1549 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; 1563 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px';
1550 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; 1564 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px';
1551 this.mouseCursorOverlay_.src = url; 1565 this.mouseCursorOverlay_.src = url;
1552 } 1566 }
1553 }; 1567 };
1568
1569 /**
1570 * @return {{top: number, left:number}} The top-left corner of the plugin.
1571 */
1572 remoting.ClientSession.prototype.getPluginPositionForTesting = function() {
1573 var plugin = this.plugin_.element();
1574 var style = plugin.style;
1575 return {
1576 top: parseFloat(style.marginTop),
1577 left: parseFloat(style.marginLeft)
1578 };
1579 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698