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

Unified Diff: sky/framework/animation/scroll_behavior.dart

Issue 1132063007: Rationalize Dart mojo and sky package structure (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/framework/animation/mechanics.dart ('k') | sky/framework/components/action_bar.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/framework/animation/scroll_behavior.dart
diff --git a/sky/framework/animation/scroll_behavior.dart b/sky/framework/animation/scroll_behavior.dart
deleted file mode 100644
index 1c456f2027d3db7e9fc39a39173f89a6f847f336..0000000000000000000000000000000000000000
--- a/sky/framework/animation/scroll_behavior.dart
+++ /dev/null
@@ -1,114 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-import 'dart:math' as math;
-import 'mechanics.dart';
-import 'generators.dart';
-
-const double _kScrollFriction = 0.005;
-const double _kOverscrollFriction = 0.075;
-const double _kBounceSlopeAngle = math.PI / 512.0; // radians
-
-abstract class ScrollBehavior {
- Simulation release(Particle particle) => null;
-
- // Returns the new scroll offset.
- double applyCurve(double scrollOffset, double scrollDelta);
-}
-
-class BoundedScrollBehavior extends ScrollBehavior {
- double minOffset;
- double maxOffset;
-
- BoundedScrollBehavior({this.minOffset: 0.0, this.maxOffset});
-
- double applyCurve(double scrollOffset, double scrollDelta) {
- double newScrollOffset = scrollOffset + scrollDelta;
- if (minOffset != null)
- newScrollOffset = math.max(minOffset, newScrollOffset);
- if (maxOffset != null)
- newScrollOffset = math.min(maxOffset, newScrollOffset);
- return newScrollOffset;
- }
-}
-
-class OverscrollBehavior extends ScrollBehavior {
-
- double _contentsHeight;
- double get contentsHeight => _contentsHeight;
- void set contentsHeight (double value) {
- if (_contentsHeight != value) {
- _contentsHeight = value;
- // TODO(ianh) now what? what if we have a simulation ongoing?
- }
- }
-
- double _containerHeight;
- double get containerHeight => _containerHeight;
- void set containerHeight (double value) {
- if (_containerHeight != value) {
- _containerHeight = value;
- // TODO(ianh) now what? what if we have a simulation ongoing?
- }
- }
-
- OverscrollBehavior({double contentsHeight: 0.0, double containerHeight: 0.0})
- : _contentsHeight = contentsHeight,
- _containerHeight = containerHeight;
-
- double get maxScroll => math.max(0.0, _contentsHeight - _containerHeight);
-
- Simulation release(Particle particle) {
- System system;
- if ((particle.position >= 0.0) && (particle.position < maxScroll)) {
- if (particle.velocity == 0.0)
- return null;
- System slowdownSystem = new ParticleInBoxWithFriction(
- particle: particle,
- friction: _kScrollFriction,
- box: new GeofenceBox(min: 0.0, max: maxScroll, onEscape: () {
- (system as Multisystem).transitionToSystem(new ParticleInBoxWithFriction(
- particle: particle,
- friction: _kOverscrollFriction,
- box: new ClosedBox(),
- onStop: () => (system as Multisystem).transitionToSystem(getBounceBackSystem(particle))
- ));
- }));
- system = new Multisystem(particle: particle, system: slowdownSystem);
- } else {
- system = getBounceBackSystem(particle);
- }
- return new Simulation(system, terminationCondition: () => particle.position == 0.0);
- }
-
- System getBounceBackSystem(Particle particle) {
- if (particle.position < 0.0)
- return new ParticleClimbingRamp(
- particle: particle,
- box: new ClosedBox(max: 0.0),
- theta: _kBounceSlopeAngle,
- targetPosition: 0.0);
- return new ParticleClimbingRamp(
- particle: particle,
- box: new ClosedBox(min: maxScroll),
- theta: _kBounceSlopeAngle,
- targetPosition: maxScroll);
- }
-
- double applyCurve(double scrollOffset, double scrollDelta) {
- double newScrollOffset = scrollOffset + scrollDelta;
- // If we're overscrolling, we want move the scroll offset 2x
- // slower than we would otherwise. Therefore, we "rewind" the
- // newScrollOffset by half the amount that we moved it above.
- // Notice that we clap the "old" value to 0.0 so that we only
- // reduce the portion of scrollDelta that's applied beyond 0.0. We
- // do similar things for overscroll in the other direction.
- if (newScrollOffset < 0.0) {
- newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0;
- } else if (newScrollOffset > maxScroll) {
- newScrollOffset -= (newScrollOffset - math.max(maxScroll, scrollOffset)) / 2.0;
- }
- return newScrollOffset;
- }
-}
« no previous file with comments | « sky/framework/animation/mechanics.dart ('k') | sky/framework/components/action_bar.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698