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

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: Rebase 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 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 var adjustMargin = function(curr, delta, windowBound, pluginBound, stop) { 1386 var adjustMargin = function(curr, delta, windowBound, pluginBound, stop) {
1377 var minMargin = Math.min(0, windowBound - pluginBound); 1387 var minMargin = Math.min(0, windowBound - pluginBound);
1378 var result = (curr ? parseFloat(curr) : 0) - delta; 1388 var result = (curr ? parseFloat(curr) : 0) - delta;
1379 result = Math.min(0, Math.max(minMargin, result)); 1389 result = Math.min(0, Math.max(minMargin, result));
1380 stop.stop = (result == 0 || result == minMargin); 1390 stop.stop = (result == 0 || result == minMargin);
1381 return result + 'px'; 1391 return result + 'px';
1382 }; 1392 };
1383 1393
1384 var stopX = { stop: false }; 1394 var stopX = { stop: false };
1385 var clientArea = this.getClientArea_(); 1395 var clientArea = this.getClientArea_();
1386 style.marginLeft = adjustMargin(style.marginLeft, dx, 1396 style.marginLeft = adjustMargin(style.marginLeft, dx, clientArea.width,
1387 clientArea.width, plugin.clientWidth, stopX); 1397 this.pluginWidthForBumpScrollTesting || plugin.clientWidth, stopX);
1388 1398
1389 var stopY = { stop: false }; 1399 var stopY = { stop: false };
1390 style.marginTop = adjustMargin( 1400 style.marginTop = adjustMargin(
1391 style.marginTop, dy, clientArea.height, plugin.clientHeight, stopY); 1401 style.marginTop, dy, clientArea.height,
1402 this.pluginHeightForBumpScrollTesting || plugin.clientHeight, stopY);
1392 return stopX.stop && stopY.stop; 1403 return stopX.stop && stopY.stop;
1393 }; 1404 };
1394 1405
1395 remoting.ClientSession.prototype.resetScroll_ = function() { 1406 remoting.ClientSession.prototype.resetScroll_ = function() {
1396 if (this.plugin_) { 1407 if (this.plugin_) {
1397 var plugin = this.plugin_.element(); 1408 var plugin = this.plugin_.element();
1398 plugin.style.marginTop = '0px'; 1409 plugin.style.marginTop = '0px';
1399 plugin.style.marginLeft = '0px'; 1410 plugin.style.marginLeft = '0px';
1400 } 1411 }
1401 }; 1412 };
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 return -1 - 5 * (threshold - mousePos) / threshold; 1454 return -1 - 5 * (threshold - mousePos) / threshold;
1444 } 1455 }
1445 return 0; 1456 return 0;
1446 }; 1457 };
1447 1458
1448 var clientArea = this.getClientArea_(); 1459 var clientArea = this.getClientArea_();
1449 var dx = computeDelta(event.x, clientArea.width); 1460 var dx = computeDelta(event.x, clientArea.width);
1450 var dy = computeDelta(event.y, clientArea.height); 1461 var dy = computeDelta(event.y, clientArea.height);
1451 1462
1452 if (dx != 0 || dy != 0) { 1463 if (dx != 0 || dy != 0) {
1464 this.raiseEvent(remoting.ClientSession.Events.bumpScrollStarted);
1453 /** @type {remoting.ClientSession} */ 1465 /** @type {remoting.ClientSession} */
1454 var that = this; 1466 var that = this;
1455 /** 1467 /**
1456 * Scroll the view, and schedule a timer to do so again unless we've hit 1468 * Scroll the view, and schedule a timer to do so again unless we've hit
1457 * the edges of the screen. This timer is cancelled when the mouse moves. 1469 * the edges of the screen. This timer is cancelled when the mouse moves.
1458 * @param {number} expected The time at which we expect to be called. 1470 * @param {number} expected The time at which we expect to be called.
1459 */ 1471 */
1460 var repeatScroll = function(expected) { 1472 var repeatScroll = function(expected) {
1461 /** @type {number} */ 1473 /** @type {number} */
1462 var now = new Date().getTime(); 1474 var now = new Date().getTime();
1463 /** @type {number} */ 1475 /** @type {number} */
1464 var timeout = 10; 1476 var timeout = 10;
1465 var lateAdjustment = 1 + (now - expected) / timeout; 1477 var lateAdjustment = 1 + (now - expected) / timeout;
1466 if (!that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) { 1478 if (that.scroll_(lateAdjustment * dx, lateAdjustment * dy)) {
1479 that.raiseEvent(remoting.ClientSession.Events.bumpScrollStopped);
1480 } else {
1467 that.bumpScrollTimer_ = window.setTimeout( 1481 that.bumpScrollTimer_ = window.setTimeout(
1468 function() { repeatScroll(now + timeout); }, 1482 function() { repeatScroll(now + timeout); },
1469 timeout); 1483 timeout);
1470 } 1484 }
1471 }; 1485 };
1472 repeatScroll(new Date().getTime()); 1486 repeatScroll(new Date().getTime());
1473 } 1487 }
1474 }; 1488 };
1475 1489
1476 /** 1490 /**
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 * @param {number} hotspotY 1558 * @param {number} hotspotY
1545 */ 1559 */
1546 remoting.ClientSession.prototype.updateMouseCursorImage_ = 1560 remoting.ClientSession.prototype.updateMouseCursorImage_ =
1547 function(url, hotspotX, hotspotY) { 1561 function(url, hotspotX, hotspotY) {
1548 this.mouseCursorOverlay_.hidden = !url; 1562 this.mouseCursorOverlay_.hidden = !url;
1549 if (url) { 1563 if (url) {
1550 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; 1564 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px';
1551 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; 1565 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px';
1552 this.mouseCursorOverlay_.src = url; 1566 this.mouseCursorOverlay_.src = url;
1553 } 1567 }
1554 }; 1568 };
1569
1570 /**
1571 * @return {{top: number, left:number}} The top-left corner of the plugin.
1572 */
1573 remoting.ClientSession.prototype.getPluginPositionForTesting = function() {
1574 var plugin = this.plugin_.element();
1575 var style = plugin.style;
1576 return {
1577 top: parseFloat(style.marginTop),
1578 left: parseFloat(style.marginLeft)
1579 };
1580 };
OLDNEW
« no previous file with comments | « remoting/webapp/browser_test/bump_scroll_browser_test.js ('k') | remoting/webapp/js_proto/dom_proto.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698