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

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

Issue 955653005: Add ViewConfiguration and make our scrollbar size match Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Updated per review Created 5 years, 9 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
« no previous file with comments | « no previous file | sky/framework/view-configuration.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 :host { 11 :host {
12 overflow: hidden; 12 overflow: hidden;
13 position: relative; 13 position: relative;
14 will-change: transform; 14 will-change: transform;
15 } 15 }
16 #scrollable { 16 #scrollable {
17 will-change: transform; 17 will-change: transform;
18 } 18 }
19 #vbar { 19 #vbar {
20 position: absolute; 20 position: absolute;
21 right: 0; 21 right: 0;
22 width: 3px;
23 background-color: lightgray; 22 background-color: lightgray;
24 pointer-events: none; 23 pointer-events: none;
25 top: 0; 24 top: 0;
26 height: 0; 25 height: 0;
27 will-change: opacity; 26 will-change: opacity;
28 opacity: 0; 27 opacity: 0;
29 transition: opacity 0.2s ease-in-out; 28 transition-property: opacity;
29 transition-function: ease-in-out;
30 } 30 }
31 </style> 31 </style>
32 <div id="scrollable"> 32 <div id="scrollable">
33 <content /> 33 <content />
34 </div> 34 </div>
35 <div id="vbar" /> 35 <div id="vbar" />
36 </template> 36 </template>
37 <script> 37 <script>
38 import "dart:math" as math; 38 import "dart:math" as math;
39 import "dart:sky"; 39 import "dart:sky";
40 import "fling-curve.dart"; 40 import "fling-curve.dart";
41 import "view-configuration.dart" as config;
41 42
42 @Tagname('sky-scrollable') 43 @Tagname('sky-scrollable')
43 class SkyScrollable extends SkyElement { 44 class SkyScrollable extends SkyElement {
44 Element _scrollable; 45 Element _scrollable;
45 Element _vbar; 46 Element _vbar;
46 double _scrollOffset = 0.0; 47 double _scrollOffset = 0.0;
47 FlingCurve _flingCurve; 48 FlingCurve _flingCurve;
48 int _flingAnimationId; 49 int _flingAnimationId;
49 50
50 SkyScrollable() { 51 SkyScrollable() {
51 addEventListener('gesturescrollstart', _handleScrollStart); 52 addEventListener('gesturescrollstart', _handleScrollStart);
52 addEventListener('gesturescrollend', _handleScrollEnd); 53 addEventListener('gesturescrollend', _handleScrollEnd);
53 addEventListener('gesturescrollupdate', _handleScrollUpdate); 54 addEventListener('gesturescrollupdate', _handleScrollUpdate);
54 addEventListener('gestureflingstart', _handleFlingStart); 55 addEventListener('gestureflingstart', _handleFlingStart);
55 addEventListener('gestureflingcancel', _handleFlingCancel); 56 addEventListener('gestureflingcancel', _handleFlingCancel);
56 addEventListener('wheel', _handleWheel); 57 addEventListener('wheel', _handleWheel);
57 } 58 }
58 59
59 void shadowRootReady() { 60 void shadowRootReady() {
60 _scrollable = shadowRoot.getElementById('scrollable'); 61 _scrollable = shadowRoot.getElementById('scrollable');
61 _vbar = shadowRoot.getElementById('vbar'); 62 _vbar = shadowRoot.getElementById('vbar');
63 // This is not documented anywhere, but the scrollbar appears to only paint
64 // 3px even though it's official width is 10px?
65 // Chrome appears 3px wide with a 3px outer spacing.
66 // Contacts appears 3px wide with a 5px runner and 5px outer spacing.
67 // Settings appears 4px wide with no outer spacing.
68 const double paintPercent = 0.3;
69 const double outerGapPercent = 0.3;
70 const double innerGapPercent = 0.4;
71 const double paintWidth = paintPercent * config.kScrollbarSize;
72 _vbar.style['width'] = "${paintWidth}px";
73 _vbar.style['margin-right'] = "${outerGapPercent * config.kScrollbarSize}px" ;
74 _vbar.style['margin-left'] ="${innerGapPercent * config.kScrollbarSize}px";
75 // The scroll thumb never quite makes it to the top or bottom in gmail
76 // or chrome (in chrome more from the bottom than the top).
77 _vbar.style['margin-top'] = "${config.kScrollbarSize}px";
78 _vbar.style['margin-bottom'] = "${config.kScrollbarSize}px";
79
80 // Some android apps round their scrollbars, some don't, not rounding for no w.
81
82 const double msToSeconds = 1.0 / 1000.0;
83 _vbar.style['transition-duration'] = "${msToSeconds * config.kScrollbarFadeD uration}s";
84 _vbar.style['transition-delay'] = "${msToSeconds * config.kScrollbarFadeDela y}s";
62 } 85 }
63 86
64 double get scrollOffset => _scrollOffset; 87 double get scrollOffset => _scrollOffset;
65 88
66 set scrollOffset(double value) { 89 set scrollOffset(double value) {
67 // TODO(abarth): Can we get these values without forcing a synchronous layou t? 90 // TODO(abarth): Can we get these values without forcing a synchronous layou t?
68 double outerHeight = clientHeight.toDouble(); 91 double outerHeight = clientHeight.toDouble();
69 double innerHeight = _scrollable.clientHeight.toDouble(); 92 double innerHeight = _scrollable.clientHeight.toDouble();
70 double scrollRange = innerHeight - outerHeight; 93 double scrollRange = innerHeight - outerHeight;
71 double newScrollOffset = math.max(0.0, math.min(scrollRange, value)); 94 double newScrollOffset = math.max(0.0, math.min(scrollRange, value));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 151 }
129 152
130 void _handleWheel(WheelEvent event) { 153 void _handleWheel(WheelEvent event) {
131 scrollBy(-event.offsetY); 154 scrollBy(-event.offsetY);
132 } 155 }
133 } 156 }
134 157
135 _init(script) => register(script, SkyScrollable); 158 _init(script) => register(script, SkyScrollable);
136 </script> 159 </script>
137 </sky-element> 160 </sky-element>
OLDNEW
« no previous file with comments | « no previous file | sky/framework/view-configuration.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698