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

Side by Side Diff: client/touch/ScrollWatcher.dart

Issue 8363040: Implement measurement using futures (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove duplicated imports from html.dart Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « client/touch/Momentum.dart ('k') | client/touch/Scrollbar.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 interface ScrollListener { 5 interface ScrollListener {
6 /** 6 /**
7 * The callback invoked for a scroll event. 7 * The callback invoked for a scroll event.
8 * [decelerating] specifies whether or not the content is moving due 8 * [decelerating] specifies whether or not the content is moving due
9 * to deceleration. It should be false if the content is moving because the 9 * to deceleration. It should be false if the content is moving because the
10 * user is dragging the content. 10 * user is dragging the content.
11 */ 11 */
12 void onScrollerMoved(double scrollX, double scrollY, bool decelerating); 12 void onScrollerMoved(double scrollX, double scrollY, bool decelerating);
13 } 13 }
14 14
15 /** 15 /**
16 * The scroll watcher is intended to provide a single way to 16 * The scroll watcher is intended to provide a single way to
17 * listen for scroll events from instances of Scroller, abstracting the 17 * listen for scroll events from instances of Scroller.
18 * various nuances between momentum strategies that require different scroll 18 * TODO(jacobr): this class is obsolete.
19 * listening strategies.
20 */ 19 */
21 class ScrollWatcher { 20 class ScrollWatcher {
22 Scroller _scroller; 21 Scroller _scroller;
23 22
24 List<ScrollListener> _listeners; 23 List<ScrollListener> _listeners;
25 24
26 TimeoutHandler _boundOnDecel;
27 Element _scrollerEl; 25 Element _scrollerEl;
28 int _decelIntervalId;
29 26
30 ScrollWatcher(Scroller scroller) 27 ScrollWatcher(Scroller scroller)
31 : _scroller = scroller, _listeners = new List<ScrollListener>() { 28 : _scroller = scroller, _listeners = new List<ScrollListener>() {
32 _boundOnDecel = () { _onDecelerate(); };
33 } 29 }
34 30
35 void addListener(ScrollListener listener) { 31 void addListener(ScrollListener listener) {
36 _listeners.add(listener); 32 _listeners.add(listener);
37 } 33 }
38 34
39 /** 35 /**
40 * Send the scroll event to all listeners. 36 * Send the scroll event to all listeners.
41 * [decelerating] is true if the offset is changing because of deceleration. 37 * [decelerating] is true if the offset is changing because of deceleration.
42 */ 38 */
(...skipping 14 matching lines...) Expand all
57 } 53 }
58 54
59 /** 55 /**
60 * This callback is invoked any time the scroller content offset changes. 56 * This callback is invoked any time the scroller content offset changes.
61 */ 57 */
62 void _onContentMoved(Event e) { 58 void _onContentMoved(Event e) {
63 num scrollX = _scroller.getHorizontalOffset(); 59 num scrollX = _scroller.getHorizontalOffset();
64 num scrollY = _scroller.getVerticalOffset(); 60 num scrollY = _scroller.getVerticalOffset();
65 _dispatchScroll(scrollX, scrollY); 61 _dispatchScroll(scrollX, scrollY);
66 } 62 }
67
68 /**
69 * This callback is invoked every 30ms while deceleration is happening.
70 */
71 void _onDecelerate() {
72 final transform = StyleUtil.getCurrentTransformMatrix(_scrollerEl);
73 num scrollX = transform.m41;
74 num scrollY = transform.m42;
75 _dispatchScroll(scrollX, scrollY, true);
76 }
77
78 /**
79 * When deceleration begins, clear the interval if it already exists and set
80 * up a new one.
81 */
82 void _onDecelerationStart(Event e) {
83 if (_decelIntervalId !== null) {
84 window.clearInterval(_decelIntervalId);
85 }
86 // TODO(jacobr): use Env.requestAnimationFrame and renable this.
87 // Right now this would kill our performance and is not relevant given
88 // we are using timeout based momentum.
89 // _decelIntervalId = window.setInterval(_boundOnDecel, 30);
90 }
91
92 /**
93 * When scrolling ends, clear the interval if it exists.
94 */
95 void _onScrollerEnd(Event e) {
96 if (_decelIntervalId !== null) {
97 window.clearInterval(_decelIntervalId);
98 }
99 _onContentMoved(e);
100 }
101 } 63 }
OLDNEW
« no previous file with comments | « client/touch/Momentum.dart ('k') | client/touch/Scrollbar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698