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 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 * scrollLeft properties don't work. | 1323 * scrollLeft properties don't work. |
1324 * @param {number} dx The amount by which to scroll horizontally. Positive to | 1324 * @param {number} dx The amount by which to scroll horizontally. Positive to |
1325 * scroll right; negative to scroll left. | 1325 * scroll right; negative to scroll left. |
1326 * @param {number} dy The amount by which to scroll vertically. Positive to | 1326 * @param {number} dy The amount by which to scroll vertically. Positive to |
1327 * scroll down; negative to scroll up. | 1327 * scroll down; negative to scroll up. |
1328 * @return {boolean} True if the requested scroll had no effect because both | 1328 * @return {boolean} True if the requested scroll had no effect because both |
1329 * vertical and horizontal edges of the screen have been reached. | 1329 * vertical and horizontal edges of the screen have been reached. |
1330 * @private | 1330 * @private |
1331 */ | 1331 */ |
1332 remoting.ClientSession.prototype.scroll_ = function(dx, dy) { | 1332 remoting.ClientSession.prototype.scroll_ = function(dx, dy) { |
1333 var plugin = this.plugin_.element(); | |
1334 var style = plugin.style; | |
1335 | |
1336 /** | 1333 /** |
1337 * Helper function for x- and y-scrolling | 1334 * Helper function for x- and y-scrolling |
1338 * @param {number|string} curr The current margin, eg. "10px". | 1335 * @param {number|string} curr The current margin, eg. "10px". |
1339 * @param {number} delta The requested scroll amount. | 1336 * @param {number} delta The requested scroll amount. |
1340 * @param {number} windowBound The size of the window, in pixels. | 1337 * @param {number} windowBound The size of the window, in pixels. |
1341 * @param {number} pluginBound The size of the plugin, in pixels. | 1338 * @param {number} pluginBound The size of the plugin, in pixels. |
1342 * @param {{stop: boolean}} stop Reference parameter used to indicate when | 1339 * @param {{stop: boolean}} stop Reference parameter used to indicate when |
1343 * the scroll has reached one of the edges and can be stopped in that | 1340 * the scroll has reached one of the edges and can be stopped in that |
1344 * direction. | 1341 * direction. |
1345 * @return {string} The new margin value. | 1342 * @return {string} The new margin value. |
1346 */ | 1343 */ |
1347 var adjustMargin = function(curr, delta, windowBound, pluginBound, stop) { | 1344 var adjustMargin = function(curr, delta, windowBound, pluginBound, stop) { |
1348 var minMargin = Math.min(0, windowBound - pluginBound); | 1345 var minMargin = Math.min(0, windowBound - pluginBound); |
1349 var result = (curr ? parseFloat(curr) : 0) - delta; | 1346 var result = (curr ? parseFloat(curr) : 0) - delta; |
1350 result = Math.min(0, Math.max(minMargin, result)); | 1347 result = Math.min(0, Math.max(minMargin, result)); |
1351 stop.stop = (result == 0 || result == minMargin); | 1348 stop.stop = (result == 0 || result == minMargin); |
1352 return result + 'px'; | 1349 return result + 'px'; |
1353 }; | 1350 }; |
1354 | 1351 |
| 1352 var plugin = this.plugin_.element(); |
| 1353 var style = this.container_.style; |
| 1354 |
1355 var stopX = { stop: false }; | 1355 var stopX = { stop: false }; |
1356 var clientArea = this.getClientArea_(); | 1356 var clientArea = this.getClientArea_(); |
1357 style.marginLeft = adjustMargin(style.marginLeft, dx, clientArea.width, | 1357 style.marginLeft = adjustMargin(style.marginLeft, dx, clientArea.width, |
1358 this.pluginWidthForBumpScrollTesting || plugin.clientWidth, stopX); | 1358 this.pluginWidthForBumpScrollTesting || plugin.clientWidth, stopX); |
1359 | 1359 |
1360 var stopY = { stop: false }; | 1360 var stopY = { stop: false }; |
1361 style.marginTop = adjustMargin( | 1361 style.marginTop = adjustMargin( |
1362 style.marginTop, dy, clientArea.height, | 1362 style.marginTop, dy, clientArea.height, |
1363 this.pluginHeightForBumpScrollTesting || plugin.clientHeight, stopY); | 1363 this.pluginHeightForBumpScrollTesting || plugin.clientHeight, stopY); |
1364 return stopX.stop && stopY.stop; | 1364 return stopX.stop && stopY.stop; |
1365 }; | 1365 }; |
1366 | 1366 |
1367 remoting.ClientSession.prototype.resetScroll_ = function() { | 1367 remoting.ClientSession.prototype.resetScroll_ = function() { |
1368 if (this.plugin_) { | 1368 this.container_.style.marginTop = '0px'; |
1369 var plugin = this.plugin_.element(); | 1369 this.container_.style.marginLeft = '0px'; |
1370 plugin.style.marginTop = '0px'; | |
1371 plugin.style.marginLeft = '0px'; | |
1372 } | |
1373 }; | 1370 }; |
1374 | 1371 |
1375 /** | 1372 /** |
1376 * Enable or disable bump-scrolling. When disabling bump scrolling, also reset | 1373 * Enable or disable bump-scrolling. When disabling bump scrolling, also reset |
1377 * the scroll offsets to (0, 0). | 1374 * the scroll offsets to (0, 0). |
1378 * @private | 1375 * @private |
1379 * @param {boolean} enable True to enable bump-scrolling, false to disable it. | 1376 * @param {boolean} enable True to enable bump-scrolling, false to disable it. |
1380 */ | 1377 */ |
1381 remoting.ClientSession.prototype.enableBumpScroll_ = function(enable) { | 1378 remoting.ClientSession.prototype.enableBumpScroll_ = function(enable) { |
1382 var element = /*@type{HTMLElement} */ document.documentElement; | 1379 var element = /*@type{HTMLElement} */ document.documentElement; |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; | 1522 this.mouseCursorOverlay_.style.marginLeft = '-' + hotspotX + 'px'; |
1526 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; | 1523 this.mouseCursorOverlay_.style.marginTop = '-' + hotspotY + 'px'; |
1527 this.mouseCursorOverlay_.src = url; | 1524 this.mouseCursorOverlay_.src = url; |
1528 } | 1525 } |
1529 }; | 1526 }; |
1530 | 1527 |
1531 /** | 1528 /** |
1532 * @return {{top: number, left:number}} The top-left corner of the plugin. | 1529 * @return {{top: number, left:number}} The top-left corner of the plugin. |
1533 */ | 1530 */ |
1534 remoting.ClientSession.prototype.getPluginPositionForTesting = function() { | 1531 remoting.ClientSession.prototype.getPluginPositionForTesting = function() { |
1535 var plugin = this.plugin_.element(); | 1532 var style = this.container_.style; |
1536 var style = plugin.style; | |
1537 return { | 1533 return { |
1538 top: parseFloat(style.marginTop), | 1534 top: parseFloat(style.marginTop), |
1539 left: parseFloat(style.marginLeft) | 1535 left: parseFloat(style.marginLeft) |
1540 }; | 1536 }; |
1541 }; | 1537 }; |
1542 | 1538 |
1543 /** | 1539 /** |
1544 * Send a Cast extension message to the host. | 1540 * Send a Cast extension message to the host. |
1545 * @param {Object} data The cast message data. | 1541 * @param {Object} data The cast message data. |
1546 */ | 1542 */ |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1613 * @param {string} data Contents of the extension message. | 1609 * @param {string} data Contents of the extension message. |
1614 * @return {boolean} True if the message was recognized, false otherwise. | 1610 * @return {boolean} True if the message was recognized, false otherwise. |
1615 */ | 1611 */ |
1616 remoting.ClientSession.prototype.handleExtensionMessage = | 1612 remoting.ClientSession.prototype.handleExtensionMessage = |
1617 function(type, data) { | 1613 function(type, data) { |
1618 if (this.videoFrameRecorder_) { | 1614 if (this.videoFrameRecorder_) { |
1619 return this.videoFrameRecorder_.handleMessage(type, data); | 1615 return this.videoFrameRecorder_.handleMessage(type, data); |
1620 } | 1616 } |
1621 return false; | 1617 return false; |
1622 } | 1618 } |
OLD | NEW |