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 '../theme/shadows.dart'; | 6 import '../theme/shadows.dart'; |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 import 'dart:sky' as sky; | 8 import 'dart:sky' as sky; |
9 import 'ink_splash.dart'; | 9 import 'ink_splash.dart'; |
10 | 10 |
11 class Material extends Component { | 11 class Material extends Component { |
12 static final Style _splashesStyle = new Style(''' | |
13 transform: translateX(0); | |
14 position: absolute; | |
15 top: 0; | |
16 left: 0; | |
17 right: 0; | |
18 bottom: 0''' | |
19 ); | |
20 | |
21 static final List<Style> shadowStyle = [ | 12 static final List<Style> shadowStyle = [ |
22 null, | 13 null, |
23 new Style('box-shadow: ${Shadow[1]}'), | 14 new Style('box-shadow: ${Shadow[1]}'), |
24 new Style('box-shadow: ${Shadow[2]}'), | 15 new Style('box-shadow: ${Shadow[2]}'), |
25 new Style('box-shadow: ${Shadow[3]}'), | 16 new Style('box-shadow: ${Shadow[3]}'), |
26 new Style('box-shadow: ${Shadow[4]}'), | 17 new Style('box-shadow: ${Shadow[4]}'), |
27 new Style('box-shadow: ${Shadow[5]}'), | 18 new Style('box-shadow: ${Shadow[5]}'), |
28 ]; | 19 ]; |
29 | 20 |
30 LinkedHashSet<SplashAnimation> _splashes; | 21 LinkedHashSet<SplashAnimation> _splashes; |
(...skipping 11 matching lines...) Expand all Loading... |
42 this.level: 0 }) : super(key: key) { | 33 this.level: 0 }) : super(key: key) { |
43 events.listen('gesturescrollstart', _cancelSplashes); | 34 events.listen('gesturescrollstart', _cancelSplashes); |
44 events.listen('wheel', _cancelSplashes); | 35 events.listen('wheel', _cancelSplashes); |
45 events.listen('pointerdown', _startSplash); | 36 events.listen('pointerdown', _startSplash); |
46 } | 37 } |
47 | 38 |
48 Node build() { | 39 Node build() { |
49 List<Node> childrenIncludingSplashes = []; | 40 List<Node> childrenIncludingSplashes = []; |
50 | 41 |
51 if (_splashes != null) { | 42 if (_splashes != null) { |
52 childrenIncludingSplashes.add(new Container( | 43 childrenIncludingSplashes.addAll( |
53 style: _splashesStyle, | 44 _splashes.map((s) => new InkSplash(s.onStyleChanged))); |
54 children: new List.from(_splashes.map( | |
55 (s) => new InkSplash(s.onStyleChanged))), | |
56 key: 'Splashes' | |
57 )); | |
58 } | 45 } |
59 | 46 |
60 if (children != null) | 47 if (children != null) |
61 childrenIncludingSplashes.addAll(children); | 48 childrenIncludingSplashes.addAll(children); |
62 | 49 |
63 return new Container( | 50 return new Container( |
64 key: 'Material', | |
65 style: level > 0 ? style.extend(shadowStyle[level]) : style, | 51 style: level > 0 ? style.extend(shadowStyle[level]) : style, |
66 inlineStyle: inlineStyle, | 52 inlineStyle: inlineStyle, |
67 children: childrenIncludingSplashes | 53 children: childrenIncludingSplashes); |
68 ); | |
69 } | 54 } |
70 | 55 |
71 sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingCli
entRect(); | 56 sky.ClientRect _getBoundingRect() => (getRoot() as sky.Element).getBoundingCli
entRect(); |
72 | 57 |
73 void _startSplash(sky.PointerEvent event) { | 58 void _startSplash(sky.PointerEvent event) { |
74 setState(() { | 59 setState(() { |
75 if (_splashes == null) { | 60 if (_splashes == null) { |
76 _splashes = new LinkedHashSet<SplashAnimation>(); | 61 _splashes = new LinkedHashSet<SplashAnimation>(); |
77 } | 62 } |
78 | 63 |
(...skipping 27 matching lines...) Expand all Loading... |
106 } | 91 } |
107 | 92 |
108 setState(() { | 93 setState(() { |
109 _splashes.remove(splash); | 94 _splashes.remove(splash); |
110 if (_splashes.length == 0) { | 95 if (_splashes.length == 0) { |
111 _splashes = null; | 96 _splashes = null; |
112 } | 97 } |
113 }); | 98 }); |
114 } | 99 } |
115 } | 100 } |
OLD | NEW |