| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 interface ScrollListener { | |
| 6 /** | |
| 7 * The callback invoked for a scroll event. | |
| 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 | |
| 10 * user is dragging the content. | |
| 11 */ | |
| 12 void onScrollerMoved(double scrollX, double scrollY, bool decelerating); | |
| 13 } | |
| 14 | |
| 15 /** | |
| 16 * The scroll watcher is intended to provide a single way to | |
| 17 * listen for scroll events from instances of Scroller. | |
| 18 * TODO(jacobr): this class is obsolete. | |
| 19 */ | |
| 20 class ScrollWatcher { | |
| 21 Scroller _scroller; | |
| 22 | |
| 23 List<ScrollListener> _listeners; | |
| 24 | |
| 25 Element _scrollerEl; | |
| 26 | |
| 27 ScrollWatcher(Scroller scroller) | |
| 28 : _scroller = scroller, _listeners = new List<ScrollListener>() { | |
| 29 } | |
| 30 | |
| 31 void addListener(ScrollListener listener) { | |
| 32 _listeners.add(listener); | |
| 33 } | |
| 34 | |
| 35 /** | |
| 36 * Send the scroll event to all listeners. | |
| 37 * [decelerating] is true if the offset is changing because of deceleration. | |
| 38 */ | |
| 39 void _dispatchScroll(num scrollX, num scrollY, | |
| 40 [bool decelerating = false]) { | |
| 41 for (final listener in _listeners) { | |
| 42 listener.onScrollerMoved(scrollX, scrollY, decelerating); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 /** | |
| 47 * Initializes elements and event handlers. Must be called after construction | |
| 48 * and before usage. | |
| 49 */ | |
| 50 void initialize() { | |
| 51 _scrollerEl = _scroller.getElement(); | |
| 52 _scroller.onContentMoved.add((e) { _onContentMoved(e); }); | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * This callback is invoked any time the scroller content offset changes. | |
| 57 */ | |
| 58 void _onContentMoved(Event e) { | |
| 59 num scrollX = _scroller.getHorizontalOffset(); | |
| 60 num scrollY = _scroller.getVerticalOffset(); | |
| 61 _dispatchScroll(scrollX, scrollY); | |
| 62 } | |
| 63 } | |
| OLD | NEW |