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

Side by Side Diff: sky/framework/components/fixed_height_scrollable.dart

Issue 1117143003: [Effen] Port fn.dart from the legacy sky.Node backend to the RenderNode backend, which is currently… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Tweak debug functions as suggested Created 5 years, 7 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/components/ink_splash.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 // 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 '../animation/scroll_behavior.dart'; 5 import '../animation/scroll_behavior.dart';
6 import '../debug/tracing.dart'; 6 import '../debug/tracing.dart';
7 import '../fn.dart'; 7 import '../fn.dart';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 import 'dart:sky' as sky;
10 import 'dart:async'; 9 import 'dart:async';
11 import 'scrollable.dart'; 10 import 'scrollable.dart';
12 11
13 abstract class FixedHeightScrollable extends Scrollable { 12 abstract class FixedHeightScrollable extends Scrollable {
14 static final Style _style = new Style(''' 13 static final Style _style = new Style('''
15 overflow: hidden; 14 overflow: hidden;
16 position: relative; 15 position: relative;
17 will-change: transform;''' 16 will-change: transform;'''
18 ); 17 );
19 18
(...skipping 25 matching lines...) Expand all
45 void _measureHeights() { 44 void _measureHeights() {
46 trace('FixedHeightScrollable::_measureHeights', () { 45 trace('FixedHeightScrollable::_measureHeights', () {
47 if (_itemHeight != null) 46 if (_itemHeight != null)
48 return; 47 return;
49 var root = getRoot(); 48 var root = getRoot();
50 if (root == null) 49 if (root == null)
51 return; 50 return;
52 var item = root.firstChild.firstChild; 51 var item = root.firstChild.firstChild;
53 if (item == null) 52 if (item == null)
54 return; 53 return;
55 sky.ClientRect scrollRect = root.getBoundingClientRect();
56 sky.ClientRect itemRect = item.getBoundingClientRect();
57 assert(scrollRect.height > 0);
58 assert(itemRect.height > 0);
59
60 setState(() { 54 setState(() {
61 _height = scrollRect.height; 55 _height = root.height;
62 _itemHeight = itemRect.height; 56 assert(_height > 0);
57 _itemHeight = item.height;
58 assert(_itemHeight > 0);
63 scrollBehavior.containerHeight = _height; 59 scrollBehavior.containerHeight = _height;
64 scrollBehavior.contentsHeight = _itemHeight * _itemCount; 60 scrollBehavior.contentsHeight = _itemHeight * _itemCount;
65 }); 61 });
66 }); 62 });
67 } 63 }
68 64
69 UINode buildContent() { 65 UINode buildContent() {
70 var itemNumber = 0; 66 var itemNumber = 0;
71 var drawCount = 1; 67 var drawCount = 1;
72 var transformStyle = ''; 68 var transformStyle = '';
73 69
74 if (_itemHeight == null) 70 if (_itemHeight == null)
75 new Future.microtask(_measureHeights); 71 new Future.microtask(_measureHeights);
76 72
77 if (_height > 0.0 && _itemHeight != null) { 73 if (_height > 0.0 && _itemHeight != null) {
78 if (scrollOffset < 0.0) { 74 if (scrollOffset < 0.0) {
79 double visibleHeight = _height + scrollOffset; 75 double visibleHeight = _height + scrollOffset;
80 drawCount = (visibleHeight / _itemHeight).round() + 1; 76 drawCount = (visibleHeight / _itemHeight).round() + 1;
81 transformStyle = 77 transformStyle =
82 'transform: translateY(${(-scrollOffset).toStringAsFixed(2)}px)'; 78 'transform: translateY(${(-scrollOffset).toStringAsFixed(2)}px)';
83 } else { 79 } else {
84 drawCount = (_height / _itemHeight).round() + 1; 80 drawCount = (_height / _itemHeight).round() + 1;
85 double alignmentOffset = math.max(0.0, scrollOffset);
86 double alignmentDelta = -scrollOffset % _itemHeight; 81 double alignmentDelta = -scrollOffset % _itemHeight;
87 if (alignmentDelta != 0.0) 82 if (alignmentDelta != 0.0)
88 alignmentDelta -= _itemHeight; 83 alignmentDelta -= _itemHeight;
89 84
90 double drawStart = scrollOffset + alignmentDelta; 85 double drawStart = scrollOffset + alignmentDelta;
91 itemNumber = math.max(0, (drawStart / _itemHeight).floor()); 86 itemNumber = math.max(0, (drawStart / _itemHeight).floor());
92 87
93 transformStyle = 88 transformStyle =
94 'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)'; 89 'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)';
95 } 90 }
96 } 91 }
97 92
98 return new Container( 93 return new Container(
99 style: _style, 94 style: _style,
100 children: [ 95 children: [
101 new Container( 96 new Container(
102 style: _scrollAreaStyle, 97 style: _scrollAreaStyle,
103 inlineStyle: transformStyle, 98 inlineStyle: transformStyle,
104 children: buildItems(itemNumber, drawCount) 99 children: buildItems(itemNumber, drawCount)
105 ) 100 )
106 ] 101 ]
107 ); 102 );
108 } 103 }
109 104
110 List<UINode> buildItems(int start, int count); 105 List<UINode> buildItems(int start, int count);
111 } 106 }
OLDNEW
« no previous file with comments | « no previous file | sky/framework/components/ink_splash.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698