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

Side by Side Diff: runtime/observatory/lib/src/elements/containers/virtual_collection.dart

Issue 2997823002: Fix virtual-collection header flickering (Closed)
Patch Set: Created 3 years, 4 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 | 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
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:html'; 6 import 'dart:html';
7 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; 7 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart';
8 import 'package:observatory/src/elements/helpers/tag.dart'; 8 import 'package:observatory/src/elements/helpers/tag.dart';
9 9
10 typedef HtmlElement VirtualCollectionCreateCallback(); 10 typedef HtmlElement VirtualCollectionCreateCallback();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 if (index >= 0) { 146 if (index >= 0) {
147 final minScrollTop = _itemHeight * (index + 1) - _height; 147 final minScrollTop = _itemHeight * (index + 1) - _height;
148 final maxScrollTop = _itemHeight * index; 148 final maxScrollTop = _itemHeight * index;
149 scrollTop = ((maxScrollTop - minScrollTop) / 2 + minScrollTop).floor(); 149 scrollTop = ((maxScrollTop - minScrollTop) / 2 + minScrollTop).floor();
150 } 150 }
151 _takeIntoView = null; 151 _takeIntoView = null;
152 } 152 }
153 153
154 final top = (scrollTop / _itemHeight).floor(); 154 final top = (scrollTop / _itemHeight).floor();
155 155
156 _header.style.top = '${scrollTop}px'; 156 _updateHeader();
157 _scroller.style.height = '${_itemHeight*(_items.length)+_headerHeight}px'; 157 _scroller.style.height = '${_itemHeight*(_items.length)+_headerHeight}px';
158 final tail_length = (_height / _itemHeight / _preload).ceil(); 158 final tail_length = (_height / _itemHeight / _preload).ceil();
159 final length = tail_length * 2 + tail_length * _preload; 159 final length = tail_length * 2 + tail_length * _preload;
160 160
161 if (_container.children.length < length) { 161 if (_container.children.length < length) {
162 while (_container.children.length != length) { 162 while (_container.children.length != length) {
163 var e = _create(); 163 var e = _create();
164 e..style.display = 'hidden'; 164 e..style.display = 'hidden';
165 _container.children.add(e); 165 _container.children.add(e);
166 } 166 }
167 _top = null; // force update; 167 _top = null; // force update;
168 } 168 }
169 169
170 if ((_top == null) || ((top - _top).abs() >= tail_length)) { 170 if ((_top == null) || ((top - _top).abs() >= tail_length)) {
171 _shifter.style.top = '${_itemHeight*(top-tail_length)}px'; 171 _shifter.style.top = '${_itemHeight*(top-tail_length)}px';
172 int i = top - tail_length; 172 int i = top - tail_length;
173 for (final HtmlElement e in _container.children) { 173 for (final HtmlElement e in _container.children) {
174 if (0 <= i && i < _items.length) { 174 if (0 <= i && i < _items.length) {
175 e..style.display = null; 175 e..style.display = null;
176 _update(e, _items[i], i); 176 _update(e, _items[i], i);
177 } else { 177 } else {
178 e.style.display = 'hidden'; 178 e.style.display = 'hidden';
179 } 179 }
180 i++; 180 i++;
181 } 181 }
182 _top = top; 182 _top = top;
183 } 183 }
184 } 184 }
185 185
186 void _updateHeader() {
187 _header.style.top = '${scrollTop}px';
188 }
189
186 void _onScroll(_) { 190 void _onScroll(_) {
191 // needed to avoid flickering
192 _updateHeader();
187 _r.dirty(); 193 _r.dirty();
188 } 194 }
189 195
190 void _onResize(_) { 196 void _onResize(_) {
191 final newHeight = getBoundingClientRect().height; 197 final newHeight = getBoundingClientRect().height;
192 if (newHeight > _height) { 198 if (newHeight > _height) {
193 _height = newHeight; 199 _height = newHeight;
194 _r.dirty(); 200 _r.dirty();
195 } 201 }
196 } 202 }
197 } 203 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698