| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import '../fn.dart'; | 5 import '../fn.dart'; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'ink_splash.dart'; | 8 import 'ink_splash.dart'; |
| 9 | 9 |
| 10 abstract class Material extends Component { | 10 class Material extends Component { |
| 11 static const _splashesKey = const Object(); | 11 static const _splashesKey = const Object(); |
| 12 | 12 |
| 13 static final Style _style = new Style(''' | 13 static final Style _splashesStyle = new Style(''' |
| 14 transform: translateX(0); | 14 transform: translateX(0); |
| 15 position: absolute; | 15 position: absolute; |
| 16 top: 0; | 16 top: 0; |
| 17 left: 0; | 17 left: 0; |
| 18 right: 0; | 18 right: 0; |
| 19 bottom: 0''' | 19 bottom: 0''' |
| 20 ); | 20 ); |
| 21 | 21 |
| 22 LinkedHashSet<SplashAnimation> _splashes; | 22 LinkedHashSet<SplashAnimation> _splashes; |
| 23 | 23 |
| 24 Material({ Object key }) : super(key: key) { | 24 Style style; |
| 25 List<Node> children; |
| 26 |
| 27 Material({ Object key, this.style, this.children }) : super(key: key) { |
| 25 events.listen('gesturescrollstart', _cancelSplashes); | 28 events.listen('gesturescrollstart', _cancelSplashes); |
| 26 events.listen('wheel', _cancelSplashes); | 29 events.listen('wheel', _cancelSplashes); |
| 27 events.listen('pointerdown', _startSplash); | 30 events.listen('pointerdown', _startSplash); |
| 28 } | 31 } |
| 29 | 32 |
| 30 Node build() { | 33 Node build() { |
| 31 List<Node> children = []; | 34 List<Node> childrenIncludingSplashes = []; |
| 32 | 35 |
| 33 if (_splashes != null) { | 36 if (_splashes != null) { |
| 34 children.addAll(_splashes.map((s) => new InkSplash(s.onStyleChanged))); | 37 childrenIncludingSplashes.add(new Container( |
| 38 style: _splashesStyle, |
| 39 children: new List.from(_splashes.map( |
| 40 (s) => new InkSplash(s.onStyleChanged))), |
| 41 key: 'Splashes' |
| 42 )); |
| 35 } | 43 } |
| 36 | 44 |
| 37 return new Container( | 45 if (children != null) |
| 38 style: _style, | 46 childrenIncludingSplashes.addAll(children); |
| 39 children: children, | 47 |
| 40 key: _splashesKey | 48 return new Container(key: 'Material', style: style, |
| 41 ); | 49 children: childrenIncludingSplashes); |
| 42 } | 50 } |
| 43 | 51 |
| 44 sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingCli
entRect(); | 52 sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingCli
entRect(); |
| 45 | 53 |
| 46 void _startSplash(sky.PointerEvent event) { | 54 void _startSplash(sky.PointerEvent event) { |
| 47 setState(() { | 55 setState(() { |
| 48 if (_splashes == null) { | 56 if (_splashes == null) { |
| 49 _splashes = new LinkedHashSet<SplashAnimation>(); | 57 _splashes = new LinkedHashSet<SplashAnimation>(); |
| 50 } | 58 } |
| 51 | 59 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 79 } | 87 } |
| 80 | 88 |
| 81 setState(() { | 89 setState(() { |
| 82 _splashes.remove(splash); | 90 _splashes.remove(splash); |
| 83 if (_splashes.length == 0) { | 91 if (_splashes.length == 0) { |
| 84 _splashes = null; | 92 _splashes = null; |
| 85 } | 93 } |
| 86 }); | 94 }); |
| 87 } | 95 } |
| 88 } | 96 } |
| OLD | NEW |