| OLD | NEW |
| 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 /** | 5 /** |
| 6 * Implementation of a custom scrolling behavior. | 6 * Implementation of a custom scrolling behavior. |
| 7 * This behavior overrides native scrolling for an area. This area can be a | 7 * This behavior overrides native scrolling for an area. This area can be a |
| 8 * single defined part of a page, the entire page, or several different parts | 8 * single defined part of a page, the entire page, or several different parts |
| 9 * of a page. | 9 * of a page. |
| 10 * | 10 * |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 if (snappedTarget != currentTarget) { | 313 if (snappedTarget != currentTarget) { |
| 314 _momentum.abort(); | 314 _momentum.abort(); |
| 315 reconfigure(); | 315 reconfigure(); |
| 316 | 316 |
| 317 _startDeceleration( | 317 _startDeceleration( |
| 318 _momentum.calculateVelocity( | 318 _momentum.calculateVelocity( |
| 319 _contentOffset, | 319 _contentOffset, |
| 320 snappedTarget, | 320 snappedTarget, |
| 321 decelerationFactor), | 321 decelerationFactor), |
| 322 decelerationFactor); | 322 decelerationFactor); |
| 323 onDecelStart.dispatch( | 323 onDecelStart.dispatch(new Event(ScrollerEventType.DECEL_START)); |
| 324 EventUtil.createEvent(ScrollerEventType.DECEL_START)); | |
| 325 return true; | 324 return true; |
| 326 } else { | 325 } else { |
| 327 return false; | 326 return false; |
| 328 } | 327 } |
| 329 } | 328 } |
| 330 | 329 |
| 331 bool throwDelta(num deltaX, num deltaY, [num decelerationFactor = null]) { | 330 bool throwDelta(num deltaX, num deltaY, [num decelerationFactor = null]) { |
| 332 Coordinate start = _contentOffset; | 331 Coordinate start = _contentOffset; |
| 333 Coordinate end = currentTarget; | 332 Coordinate end = currentTarget; |
| 334 int x = end.x.toInt(); | 333 int x = end.x.toInt(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 String timingFunction = null]) { | 422 String timingFunction = null]) { |
| 424 // TODO(jacobr): remove once dartc fixes default args. | 423 // TODO(jacobr): remove once dartc fixes default args. |
| 425 if (duration === null) { | 424 if (duration === null) { |
| 426 duration = 0; | 425 duration = 0; |
| 427 } | 426 } |
| 428 animateTo(x, y, duration, timingFunction); | 427 animateTo(x, y, duration, timingFunction); |
| 429 } | 428 } |
| 430 | 429 |
| 431 void onDecelerationEnd() { | 430 void onDecelerationEnd() { |
| 432 _setWebkitTransition(_element, 0); | 431 _setWebkitTransition(_element, 0); |
| 433 onScrollerEnd.dispatch( | 432 onScrollerEnd.dispatch(new Event(ScrollerEventType.SCROLLER_END)); |
| 434 EventUtil.createEvent(ScrollerEventType.SCROLLER_END)); | |
| 435 _started = false; | 433 _started = false; |
| 436 } | 434 } |
| 437 | 435 |
| 438 void onDragEnd() { | 436 void onDragEnd() { |
| 439 _dragInProgress = false; | 437 _dragInProgress = false; |
| 440 | 438 |
| 441 bool decelerating = false; | 439 bool decelerating = false; |
| 442 if (_activeGesture) { | 440 if (_activeGesture) { |
| 443 if (_momentumEnabled && !_activeTransition) { | 441 if (_momentumEnabled && !_activeTransition) { |
| 444 decelerating = _startDeceleration(_touchHandler.getEndVelocity()); | 442 decelerating = _startDeceleration(_touchHandler.getEndVelocity()); |
| 445 } | 443 } |
| 446 } | 444 } |
| 447 | 445 |
| 448 onScrollerDragEnd.dispatch( | 446 onScrollerDragEnd.dispatch(new Event(ScrollerEventType.DRAG_END)); |
| 449 EventUtil.createEvent(ScrollerEventType.DRAG_END)); | |
| 450 | 447 |
| 451 if (!decelerating) { | 448 if (!decelerating) { |
| 452 _snapContentOffsetToBounds(); | 449 _snapContentOffsetToBounds(); |
| 453 onScrollerEnd.dispatch( | 450 onScrollerEnd.dispatch(new Event(ScrollerEventType.SCROLLER_END)); |
| 454 EventUtil.createEvent(ScrollerEventType.SCROLLER_END)); | |
| 455 _started = false; | 451 _started = false; |
| 456 } else { | 452 } else { |
| 457 onDecelStart.dispatch( | 453 onDecelStart.dispatch(new Event(ScrollerEventType.DECEL_START)); |
| 458 EventUtil.createEvent(ScrollerEventType.DECEL_START)); | |
| 459 } | 454 } |
| 460 _activeGesture = false; | 455 _activeGesture = false; |
| 461 } | 456 } |
| 462 | 457 |
| 463 void onDragMove() { | 458 void onDragMove() { |
| 464 if (_isStopping || (!_activeGesture && _dragInProgress)) { | 459 if (_isStopping || (!_activeGesture && _dragInProgress)) { |
| 465 return; | 460 return; |
| 466 } | 461 } |
| 467 | 462 |
| 468 assert(_contentStartOffset != null); // Content start not set | 463 assert(_contentStartOffset != null); // Content start not set |
| 469 Coordinate contentStart = _contentStartOffset; | 464 Coordinate contentStart = _contentStartOffset; |
| 470 num newX = contentStart.x + _touchHandler.getDragDeltaX(); | 465 num newX = contentStart.x + _touchHandler.getDragDeltaX(); |
| 471 num newY = contentStart.y + _touchHandler.getDragDeltaY(); | 466 num newY = contentStart.y + _touchHandler.getDragDeltaY(); |
| 472 newY = _shouldScrollVertically() ? | 467 newY = _shouldScrollVertically() ? |
| 473 _adjustValue(newY, _minPoint.y, _maxPoint.y) : 0; | 468 _adjustValue(newY, _minPoint.y, _maxPoint.y) : 0; |
| 474 newX = _shouldScrollHorizontally() ? | 469 newX = _shouldScrollHorizontally() ? |
| 475 _adjustValue(newX, _minPoint.x, _maxPoint.x) : 0; | 470 _adjustValue(newX, _minPoint.x, _maxPoint.x) : 0; |
| 476 if (!_activeGesture) { | 471 if (!_activeGesture) { |
| 477 _activeGesture = true; | 472 _activeGesture = true; |
| 478 _dragInProgress = true; | 473 _dragInProgress = true; |
| 479 } | 474 } |
| 480 if (!_started) { | 475 if (!_started) { |
| 481 _started = true; | 476 _started = true; |
| 482 onScrollerStart.dispatch( | 477 onScrollerStart.dispatch(new Event(ScrollerEventType.SCROLLER_START)); |
| 483 EventUtil.createEvent(ScrollerEventType.SCROLLER_START)); | |
| 484 } | 478 } |
| 485 _setContentOffset(newX, newY); | 479 _setContentOffset(newX, newY); |
| 486 } | 480 } |
| 487 | 481 |
| 488 bool onDragStart(TouchEvent e) { | 482 bool onDragStart(TouchEvent e) { |
| 489 if (e.touches.length > 1) { | 483 if (e.touches.length > 1) { |
| 490 return false; | 484 return false; |
| 491 } | 485 } |
| 492 bool shouldHorizontal = _shouldScrollHorizontally(); | 486 bool shouldHorizontal = _shouldScrollHorizontally(); |
| 493 bool shouldVertical = _shouldScrollVertically(); | 487 bool shouldVertical = _shouldScrollVertically(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 return new Coordinate(clampX, clampY); | 566 return new Coordinate(clampX, clampY); |
| 573 } | 567 } |
| 574 | 568 |
| 575 /** | 569 /** |
| 576 * Translate the content to a new position specified in px. | 570 * Translate the content to a new position specified in px. |
| 577 */ | 571 */ |
| 578 void _setContentOffset(num x, num y) { | 572 void _setContentOffset(num x, num y) { |
| 579 _contentOffset.x = x; | 573 _contentOffset.x = x; |
| 580 _contentOffset.y = y; | 574 _contentOffset.y = y; |
| 581 _setOffsetFunction(_element, x, y); | 575 _setOffsetFunction(_element, x, y); |
| 582 onContentMoved.dispatch( | 576 onContentMoved.dispatch(new Event(ScrollerEventType.CONTENT_MOVED)); |
| 583 EventUtil.createEvent(ScrollerEventType.CONTENT_MOVED)); | |
| 584 } | 577 } |
| 585 | 578 |
| 586 /** | 579 /** |
| 587 * Sets the offset to subtract from the maximum coordinate that the left upper | 580 * Sets the offset to subtract from the maximum coordinate that the left upper |
| 588 * corner of the content can scroll to. | 581 * corner of the content can scroll to. |
| 589 */ | 582 */ |
| 590 void setMaxOffset(num x, num y) { | 583 void setMaxOffset(num x, num y) { |
| 591 _maxOffset.x = x; | 584 _maxOffset.x = x; |
| 592 _maxOffset.y = y; | 585 _maxOffset.y = y; |
| 593 _resize(); | 586 _resize(); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 for (EventListener listener in _listeners) { | 789 for (EventListener listener in _listeners) { |
| 797 listener(evt); | 790 listener(evt); |
| 798 } | 791 } |
| 799 } | 792 } |
| 800 } | 793 } |
| 801 | 794 |
| 802 class ScrollerScrollTechnique { | 795 class ScrollerScrollTechnique { |
| 803 static final TRANSFORM_3D = 1; | 796 static final TRANSFORM_3D = 1; |
| 804 static final RELATIVE_POSITIONING = 2; | 797 static final RELATIVE_POSITIONING = 2; |
| 805 } | 798 } |
| OLD | NEW |