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

Side by Side Diff: remoting/webapp/crd/js/bump_scroller.js

Issue 918783002: CRD Viewport Management refactor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase error Created 5 years, 9 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * This class allows enables the scrolling of the DestkopViewport in fullscreen
8 * mode by moving the mouse to the edge of the screen.
9 */
10
11 /** @suppress {duplicate} */
12 var remoting = remoting || {};
13
14 (function() {
15
16 'use strict';
17
18 /**
19 * @param {remoting.DesktopViewport} viewport
20 *
21 * @constructor
22 * @implements {base.Disposable}
23 * @extends {base.EventSourceImpl}
24 */
25 remoting.BumpScroller = function(viewport) {
26 /** @private */
27 this.viewport_ = viewport;
28 /** @private {number?} */
29 this.bumpScrollTimer_ = null;
30 /** @private */
31 this.eventHook_ = new base.DomEventHook(document.documentElement, 'mousemove',
32 this.onMouseMove_.bind(this), false);
33
34 this.defineEvents(Object.keys(remoting.BumpScroller.Events));
Jamie 2015/02/23 21:22:51 base.values
kelvinp 2015/02/23 23:42:30 Done.
35 };
36 base.extend(remoting.BumpScroller, base.EventSourceImpl);
37
38 /** @enum {string} */
39 remoting.BumpScroller.Events = {
40 bumpScrollStarted: 'bumpScrollStarted',
41 bumpScrollStopped: 'bumpScrollStopped'
42 };
43
44 remoting.BumpScroller.prototype.dispose = function() {
45 base.dispose(this.eventHook_);
46 this.eventHook_ = null;
47 };
48
49 /**
50 * @param {Event} event The mouse event.
51 * @private
52 */
53 remoting.BumpScroller.prototype.onMouseMove_ = function(event) {
54 if (this.bumpScrollTimer_ !== null) {
55 window.clearTimeout(this.bumpScrollTimer_);
56 this.bumpScrollTimer_ = null;
57 }
58
59 /**
60 * Compute the scroll speed based on how close the mouse is to the edge.
61 *
62 * @param {number} mousePos The mouse x- or y-coordinate
63 * @param {number} size The width or height of the content area.
64 * @return {number} The scroll delta, in pixels.
65 */
66 var computeDelta = function(mousePos, size) {
67 var threshold = 10;
68 if (mousePos >= size - threshold) {
69 return 1 + 5 * (mousePos - (size - threshold)) / threshold;
70 } else if (mousePos <= threshold) {
71 return -1 - 5 * (threshold - mousePos) / threshold;
72 }
73 return 0;
74 };
75
76 var clientArea = this.viewport_.getClientArea();
77 var dx = computeDelta(event.x, clientArea.width);
78 var dy = computeDelta(event.y, clientArea.height);
79
80 if (dx !== 0 || dy !== 0) {
81 this.raiseEvent(remoting.BumpScroller.Events.bumpScrollStarted);
82 this.repeatScroll_(dx, dy, new Date().getTime());
83 }
84 };
85
86 /**
87 * Scroll the view, and schedule a timer to do so again unless we've hit
88 * the edges of the screen. This timer is cancelled when the mouse moves.
89 *
90 * @param {number} dx
91 * @param {number} dy
92 * @param {number} expected The time at which we expect to be called.
93 * @private
94 */
95 remoting.BumpScroller.prototype.repeatScroll_ = function(dx, dy, expected) {
96 /** @type {number} */
97 var now = new Date().getTime();
98 var timeout = 10;
99 var lateAdjustment = 1 + (now - expected) / timeout;
100 if (!this.viewport_.scroll(lateAdjustment * dx, lateAdjustment * dy)) {
101 this.raiseEvent(remoting.BumpScroller.Events.bumpScrollStopped);
102 } else {
103 this.bumpScrollTimer_ = window.setTimeout(
104 this.repeatScroll_.bind(this, dx, dy, now + timeout), timeout);
105 }
106 };
107
108 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698