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