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

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

Issue 2255613002: Converted Observatory heap-profile element (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Better sorting tests Created 4 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 side-by-side diff with in-line comments
Download patch
Index: runtime/observatory/lib/src/elements/containers/virtual_collection.dart
diff --git a/runtime/observatory/lib/src/elements/containers/virtual_collection.dart b/runtime/observatory/lib/src/elements/containers/virtual_collection.dart
index 049081de046459ab7645d5eaf4b26fa08eb985f6..b6f91b96661e63c525cdf4136b9ee12abbeaf86c 100644
--- a/runtime/observatory/lib/src/elements/containers/virtual_collection.dart
+++ b/runtime/observatory/lib/src/elements/containers/virtual_collection.dart
@@ -21,6 +21,7 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
_r.onRendered;
VirtualCollectionCreateCallback _create;
+ VirtualCollectionCreateCallback _createHeader;
VirtualCollectionUpdateCallback _update;
double _itemHeight;
int _top;
@@ -33,12 +34,14 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
set items(Iterable value) {
_items = new List.unmodifiable(value);
+ _top = null;
_r.dirty();
}
factory VirtualCollectionElement(VirtualCollectionCreateCallback create,
VirtualCollectionUpdateCallback update, {Iterable items: const [],
+ VirtualCollectionCreateCallback createHeader,
RenderingQueue queue}) {
assert(create != null);
assert(update != null);
@@ -46,6 +49,7 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
VirtualCollectionElement e = document.createElement(tag.name);
e._r = new RenderingScheduler(e, queue: queue);
e._create = create;
+ e._createHeader = createHeader;
e._update = update;
e._items = new List.unmodifiable(items);
return e;
@@ -57,9 +61,8 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
attached() {
super.attached();
_r.enable();
- _top = 0;
- _height = getBoundingClientRect().height;
- _itemHeight = _computeItemHeight();
+ _top = null;
+ _itemHeight = null;
_onScrollSubscription = onScroll.listen(_onScroll);
_onResizeSubscription = window.onResize.listen(_onResize);
}
@@ -73,6 +76,7 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
_onResizeSubscription.cancel();
}
+ final DivElement _header = new DivElement()..classes = const ['header'];
final DivElement _scroller = new DivElement()..classes = const ['scroller'];
final DivElement _shifter = new DivElement()..classes = const ['shifter'];
@@ -103,11 +107,26 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
static const double _inverse_preload = 1 / (_preload + 2);
void render() {
- _top = (scrollTop / _itemHeight).floor();
+ if (children.isEmpty) {
+ children = [
+ _scroller
+ ..children = [
+ _shifter
+ ..children = [_create()]
+ ],
+ ];
+ if (_createHeader != null) {
+ _header.children = [_createHeader()];
+ _scroller.children.insert(0, _header);
+ }
+ _itemHeight = _shifter.children[0].getBoundingClientRect().height;
+ _height = getBoundingClientRect().height;
+ }
+ final top = (scrollTop / _itemHeight).floor();
+ _header.style.top = '${scrollTop}px';
_scroller.style.height = '${_itemHeight*(_items.length)}px';
final tail_length = (_height / _itemHeight / _preload).ceil();
- _shifter.style.top = '${_itemHeight*(_top - tail_length)}px';
final length = tail_length * 2 + tail_length * _preload;
if (_shifter.children.length < length) {
@@ -116,38 +135,27 @@ class VirtualCollectionElement extends HtmlElement implements Renderable {
e..style.display = 'hidden';
_shifter.children.add(e);
}
- children = [
- _scroller
- ..children = [_shifter]
- ];
+ _top = null; // force update;
}
- int i = _top - tail_length;
- for (final HtmlElement e in _shifter.children) {
- if (0 <= i && i < _items.length) {
- e..style.display = null;
- _update(e, _items[i], i);
- } else {
- e.style.display = 'hidden';
+ if ((_top == null) || ((top - _top).abs() >= tail_length)) {
+ _shifter.style.top = '${_itemHeight*(top-tail_length)}px';
+ int i = top - tail_length;
+ for (final HtmlElement e in _shifter.children) {
+ if (0 <= i && i < _items.length) {
+ e..style.display = null;
+ _update(e, _items[i], i);
+ } else {
+ e.style.display = 'hidden';
+ }
+ i++;
}
- i++;
+ _top = top;
}
}
- double _computeItemHeight() {
- final c = children;
- children = [_create()];
- final height = children[0].getBoundingClientRect().height;
- children = c;
- return height;
- }
-
void _onScroll(_) {
- if(_r.isDirty) return;
- if ((scrollTop - _top * _itemHeight).abs() >=
- _shifter.children.length * _inverse_preload * _itemHeight) {
- _r.dirty();
- }
+ _r.dirty();
}
void _onResize(_) {
« no previous file with comments | « runtime/observatory/lib/src/elements/allocation_profile.dart ('k') | runtime/observatory/lib/src/elements/cpu_profile.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698