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

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: 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
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";
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 ViewConfiguration config = new ViewConfiguration();
64 // This is not documented anywhere, but the scrollbar appears to only paint
65 // 3px even though it's official width is 10px?
66 // Chrome appears 3px wide with a 3px outer spacing.
67 // Contacts appears 3px wide with a 5px runner and 5px outer spacing.
68 // Settings appears 4px wide with no outer spacing.
69 double paintPercent = 0.3;
70 double outerGapPercent = 0.3;
71 double innerGapPercent = 0.4;
72 double paintWidth = paintPercent * config.kScrollbarSize;
73 _vbar.style['width'] = "${paintWidth}px";
74 _vbar.style['margin-right'] = "${outerGapPercent * config.kScrollbarSize}px" ;
75 _vbar.style['margin-left'] ="${innerGapPercent * config.kScrollbarSize}px";
76 // The scroll thumb never quite makes it to the top or bottom in gmail
77 // or chrome (in chrome more from the bottom than the top).
78 _vbar.style['margin-top'] = "${config.kScrollbarSize}px";
79 _vbar.style['margin-bottom'] = "${config.kScrollbarSize}px";
80
81 // Some android apps round their scrollbars, some don't, not rounding for no w.
82 //_vbar.style['border-radius'] = "${paintWidth / 2}px";
abarth-chromium 2015/02/24 21:48:25 Remove commented out code?
83
84 double msToSeconds = 1.0 / 1000.0;
85 _vbar.style['transition-duration'] = "${msToSeconds * config.kScrollbarFadeD uration}s";
86 _vbar.style['transition-delay'] = "${msToSeconds * config.kScrollbarFadeDela y}s";
abarth-chromium 2015/02/24 21:48:25 Can we make these strings all compile-time constan
62 } 87 }
63 88
64 double get scrollOffset => _scrollOffset; 89 double get scrollOffset => _scrollOffset;
65 90
66 set scrollOffset(double value) { 91 set scrollOffset(double value) {
67 // TODO(abarth): Can we get these values without forcing a synchronous layou t? 92 // TODO(abarth): Can we get these values without forcing a synchronous layou t?
68 double outerHeight = clientHeight.toDouble(); 93 double outerHeight = clientHeight.toDouble();
69 double innerHeight = _scrollable.clientHeight.toDouble(); 94 double innerHeight = _scrollable.clientHeight.toDouble();
70 double scrollRange = innerHeight - outerHeight; 95 double scrollRange = innerHeight - outerHeight;
71 double newScrollOffset = math.max(0.0, math.min(scrollRange, value)); 96 double newScrollOffset = math.max(0.0, math.min(scrollRange, value));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 153 }
129 154
130 void _handleWheel(WheelEvent event) { 155 void _handleWheel(WheelEvent event) {
131 scrollBy(-event.offsetY); 156 scrollBy(-event.offsetY);
132 } 157 }
133 } 158 }
134 159
135 _init(script) => register(script, SkyScrollable); 160 _init(script) => register(script, SkyScrollable);
136 </script> 161 </script>
137 </sky-element> 162 </sky-element>
OLDNEW
« no previous file with comments | « no previous file | sky/framework/view-configuration.dart » ('j') | sky/framework/view-configuration.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698