OLD | NEW |
1 <!-- | 1 <!-- |
2 // Copyright 2015 The Chromium Authors. All rights reserved. | 2 // Copyright 2015 The Chromium Authors. All rights reserved. |
3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
5 --> | 5 --> |
6 <import src="sky-element.sky" /> | 6 <import src="sky-element.sky" /> |
7 | 7 |
8 <sky-element> | 8 <sky-element> |
9 <template> | 9 <template> |
10 <style> | 10 <style> |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 </style> | 30 </style> |
31 <div id="splash" /> | 31 <div id="splash" /> |
32 </template> | 32 </template> |
33 <script> | 33 <script> |
34 import "animation/controller.dart"; | 34 import "animation/controller.dart"; |
35 import "animation/curves.dart"; | 35 import "animation/curves.dart"; |
36 import "animation/timer.dart"; | 36 import "animation/timer.dart"; |
37 import "dart:math" as math; | 37 import "dart:math" as math; |
38 import "dart:sky"; | 38 import "dart:sky"; |
| 39 import "dart:async"; |
39 | 40 |
40 const double _kSplashSize = 400.0; | 41 const double _kSplashSize = 400.0; |
41 const double _kSplashDuration = 500.0; | 42 const double _kSplashDuration = 500.0; |
42 | 43 |
43 @Tagname('sky-ink-splash') | 44 @Tagname('sky-ink-splash') |
44 class SkyInkSplash extends SkyElement implements AnimationDelegate { | 45 class SkyInkSplash extends SkyElement implements AnimationDelegate { |
45 AnimationController _animation; | 46 AnimationController _animation; |
46 Element _splash; | 47 Element _splash; |
47 double _offsetX; | 48 double _offsetX; |
48 double _offsetY; | 49 double _offsetY; |
| 50 Completer<SkyInkSplash> _completer = new Completer(); |
49 | 51 |
50 SkyInkSplash() { | 52 SkyInkSplash() { |
51 _animation = new AnimationController(this); | 53 _animation = new AnimationController(this); |
52 } | 54 } |
53 | 55 |
54 void shadowRootReady() { | 56 void shadowRootReady() { |
55 _splash = shadowRoot.getElementById('splash'); | 57 _splash = shadowRoot.getElementById('splash'); |
56 } | 58 } |
57 | 59 |
58 void start(double x, double y, ClientRect rect) { | 60 Future start(double x, double y, ClientRect rect) { |
59 _offsetX = x - rect.left; | 61 _offsetX = x - rect.left; |
60 _offsetY = y - rect.top; | 62 _offsetY = y - rect.top; |
61 _animation.start( | 63 _animation.start( |
62 begin: 0.0, | 64 begin: 0.0, |
63 end: _kSplashSize, | 65 end: _kSplashSize, |
64 duration: _kSplashDuration, | 66 duration: _kSplashDuration, |
65 curve: easeOut); | 67 curve: easeOut); |
| 68 return _completer.future; |
| 69 } |
| 70 |
| 71 void _done() { |
| 72 remove(); |
| 73 _completer.complete(this); |
| 74 } |
| 75 |
| 76 void cancel() { |
| 77 // TODO(eseidel): Should fade away instead of stopping immediately. |
| 78 _animation.stop(); |
| 79 _done(); |
66 } | 80 } |
67 | 81 |
68 void updateAnimation(double p) { | 82 void updateAnimation(double p) { |
69 if (p == _kSplashSize) { | 83 if (p == _kSplashSize) { |
70 remove(); | 84 _done(); |
71 return; | 85 return; |
72 } | 86 } |
73 _splash.style['top'] = '${_offsetY - p/2}px'; | 87 _splash.style['top'] = '${_offsetY - p/2}px'; |
74 _splash.style['left'] = '${_offsetX - p/2}px'; | 88 _splash.style['left'] = '${_offsetX - p/2}px'; |
75 _splash.style['width'] = '${p}px'; | 89 _splash.style['width'] = '${p}px'; |
76 _splash.style['height'] = '${p}px'; | 90 _splash.style['height'] = '${p}px'; |
77 _splash.style['border-radius'] = '${p}px'; | 91 _splash.style['border-radius'] = '${p}px'; |
78 _splash.style['opacity'] = '${1.0 - (p / _kSplashSize)}'; | 92 _splash.style['opacity'] = '${1.0 - (p / _kSplashSize)}'; |
79 } | 93 } |
80 } | 94 } |
81 | 95 |
82 _init(script) => register(script, SkyInkSplash); | 96 _init(script) => register(script, SkyInkSplash); |
83 </script> | 97 </script> |
84 </sky-element> | 98 </sky-element> |
OLD | NEW |