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

Side by Side Diff: sky/framework/sky-drawer.sky

Issue 886723002: Add sky-drawer to the framework (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: nit Created 5 years, 10 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 unified diff | Download patch
« sky/framework/animation/timer.sky ('K') | « sky/framework/sky-box.sky ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!--
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
4 // found in the LICENSE file.
5 -->
6 <import src="animation/controller.sky" as="AnimationController" />
7 <import src="animation/curves.sky" as="Curves" />
8 <import src="sky-element/sky-element.sky" as="SkyElement" />
9 <import src="sky-scrollable.sky" />
10
11 <sky-element
12 name="sky-drawer"
13 on-pointerdown="handlePointerDown"
14 on-pointermove="handlePointerMove"
15 on-pointerup="handlePointerUp"
16 on-pointercancel="handlePointerCancel">
17 <template>
18 <style>
19 :host {
20 position: absolute;
esprehn 2015/01/29 19:03:57 This is fine for now, but I sort of feel like the
abarth-chromium 2015/01/29 19:16:45 Ok. I'll move this into the scaffold.
21 top: 0;
22 left: 0;
23 bottom: 0;
24 right: 0;
25 }
26 #mask {
27 background-color: black;
28 will-change: opacity;
29 position: absolute;
30 top: 0;
31 left: 0;
32 bottom: 0;
33 right: 0;
34 }
35 #overlay {
esprehn 2015/01/29 19:03:57 Is the overlay the glass effect?
abarth-chromium 2015/01/29 19:16:45 I should probably rename it to "content". It's th
36 background-color: yellow;
37 will-change: transform;
38 position: absolute;
39 width: 256px;
40 top: 0;
41 left: 0;
42 bottom: 0;
43 }
44 </style>
45 <div id="mask" on-click="handleMaskClick" />
46 <div id="overlay">
47 <content/>
48 </div>
49 </template>
50 <script>
51 const kWidth = 256;
52 const kMinAnimationDurationMS = 120;
53 const kMaxAnimationDurationMS = 500;
54 const kAnimationCurve = Curves.easeInOut;
55
56 module.exports = class extends SkyElement {
57 created() {
58 this.previousX_ = 0;
59 this.position_ = 0;
60 this.mask_ = null;
61 this.overlay_ = null;
62 this.animation_ = new AnimationController(this);
esprehn 2015/01/29 19:03:57 This way to having the delegate only works when wi
abarth-chromium 2015/01/29 19:16:45 Yeah.
63 }
64
65 shadowRootReady() {
66 this.mask_ = this.shadowRoot.getElementById('mask');
67 this.overlay_ = this.shadowRoot.getElementById('overlay');
68 this.position = -kWidth;
69 }
70
71 toggle() {
72 if (this.isMostlyClosed)
73 this.open();
74 else
75 this.close();
76 }
77
78 open() {
79 this.animateToPosition_(0);
80 }
81
82 close() {
83 this.animateToPosition_(-kWidth);
84 }
85
86 get isClosed() {
87 return this.position_ <= -kWidth;
88 }
89
90 get isMostlyClosed() {
91 return this.position_ <= -kWidth / 2;
92 }
93
94 get position() {
95 return this.position_;
96 }
97
98 set position(value) {
99 var newPosition = Math.min(0, Math.max(value, -kWidth));
100 this.position_ = newPosition;
101 this.overlay_.style.transform = 'translateX(' + newPosition + 'px)';
102 this.mask_.style.opacity = (newPosition / kWidth + 1) * 0.25;
103 this.style.display = this.isClosed ? 'none' : '';
104 }
105
106 settle_() {
107 if (this.isMostlyClosed)
108 this.close();
109 else
110 this.open();
111 }
112
113 animateToPosition_(targetPosition) {
114 var currentPosition = this.position_;
115 var animationDistance = Math.abs(targetPosition - currentPosition);
116 var duration = kMaxAnimationDurationMS * animationDistance / kWidth;
117 this.animation_.start({
118 begin: currentPosition,
119 end: targetPosition,
120 duration: Math.max(kMinAnimationDurationMS, duration),
121 curve: kAnimationCurve,
122 });
123 }
124
125 updateAnimation(position) {
126 this.position = position;
127 }
128
129 handleMaskClick() {
130 this.close();
131 }
132
133 handlePointerDown(event) {
134 this.animation_.stop();
135 this.previousX_ = event.x;
136 }
137
138 handlePointerMove(event) {
139 // TODO(abarth): Implement event.dx;
140 var deltaX = event.x - this.previousX_;
141 this.previousX_ = event.x;
142 this.position += deltaX;
143 }
144
145 handlePointerUp(event) {
146 if (!this.animation_.isAnimating)
147 this.settle_();
148 }
149
150 handlePointerCancel(event) {
151 if (!this.animation_.isAnimating)
152 this.settle_();
153 }
154 }.register();
155 </script>
156 </sky-element>
OLDNEW
« sky/framework/animation/timer.sky ('K') | « sky/framework/sky-box.sky ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698