Skip to content

Commit

Permalink
Disable expansion of VirtualTree and VirtualCollection items
Browse files Browse the repository at this point in the history
VirtualTree and VirtualCollection must have fixed size children.
Expandable Ref Elements are by default able to expand.
Added flag to disable the expansion when required.

[email protected]

Review-Url: https://codereview.chromium.org/2970443002 .
  • Loading branch information
B3rn475 committed Jun 29, 2017
1 parent 24f9478 commit a845024
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
41 changes: 24 additions & 17 deletions runtime/observatory/lib/src/elements/context_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ class ContextRefElement extends HtmlElement implements Renderable {
M.ContextRef _context;
M.ObjectRepository _objects;
M.Context _loadedContext;
bool _expandable;
bool _expanded = false;

M.IsolateRef get isolate => _isolate;
M.ContextRef get context => _context;

factory ContextRefElement(
M.IsolateRef isolate, M.ContextRef context, M.ObjectRepository objects,
{RenderingQueue queue}) {
{RenderingQueue queue, bool expandable: true}) {
assert(isolate != null);
assert(context != null);
assert(objects != null);
Expand All @@ -39,6 +40,7 @@ class ContextRefElement extends HtmlElement implements Renderable {
e._isolate = isolate;
e._context = context;
e._objects = objects;
e._expandable = expandable;
return e;
}

Expand All @@ -63,30 +65,35 @@ class ContextRefElement extends HtmlElement implements Renderable {
}

void render() {
children = [
var children = [
new AnchorElement(href: Uris.inspect(_isolate, object: _context))
..children = [
new SpanElement()
..classes = ['emphasize']
..text = 'Context',
new SpanElement()..text = ' (${_context.length})',
],
new SpanElement()..text = ' ',
new CurlyBlockElement(expanded: _expanded, queue: _r.queue)
..content = [
new DivElement()
..classes = ['indent']
..children = _createValue()
]
..onToggle.listen((e) async {
_expanded = e.control.expanded;
if (_expanded) {
e.control.disabled = true;
await _refresh();
e.control.disabled = false;
}
})
];
if (_expandable) {
children.addAll([
new SpanElement()..text = ' ',
new CurlyBlockElement(expanded: _expanded, queue: _r.queue)
..content = [
new DivElement()
..classes = ['indent']
..children = _createValue()
]
..onToggle.listen((e) async {
_expanded = e.control.expanded;
if (_expanded) {
e.control.disabled = true;
await _refresh();
e.control.disabled = false;
}
})
]);
}
this.children = children;
}

List<Element> _createValue() {
Expand Down
6 changes: 4 additions & 2 deletions runtime/observatory/lib/src/elements/field_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ class FieldRefElement extends HtmlElement implements Renderable {
M.IsolateRef _isolate;
M.FieldRef _field;
M.ObjectRepository _objects;
bool _expandable;

M.IsolateRef get isolate => _isolate;
M.FieldRef get field => _field;

factory FieldRefElement(
M.IsolateRef isolate, M.FieldRef field, M.ObjectRepository objects,
{RenderingQueue queue}) {
{RenderingQueue queue, bool expandable: true}) {
assert(isolate != null);
assert(field != null);
assert(objects != null);
Expand All @@ -36,6 +37,7 @@ class FieldRefElement extends HtmlElement implements Renderable {
e._isolate = isolate;
e._field = field;
e._objects = objects;
e._expandable = expandable;
return e;
}

Expand Down Expand Up @@ -80,7 +82,7 @@ class FieldRefElement extends HtmlElement implements Renderable {
children = [
new SpanElement()..text = header,
new InstanceRefElement(_isolate, _field.declaredType, _objects,
queue: _r.queue),
queue: _r.queue, expandable: _expandable),
new SpanElement()..text = ' ',
new AnchorElement(href: Uris.inspect(_isolate, object: _field))
..text = _field.name
Expand Down
8 changes: 6 additions & 2 deletions runtime/observatory/lib/src/elements/heap_snapshot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ class HeapSnapshotElement extends HtmlElement implements Renderable {
node.object.then((object) {
wrapper
..text = ''
..children = [anyRef(_isolate, object, _objects, queue: _r.queue)];
..children = [
anyRef(_isolate, object, _objects,
queue: _r.queue, expandable: false)
];
});
}
}
Expand Down Expand Up @@ -450,7 +453,8 @@ class HeapSnapshotElement extends HtmlElement implements Renderable {
..text = ''
..children = [
new SpanElement()..text = '${node.instanceCount} instances of ',
anyRef(_isolate, klass, _objects, queue: _r.queue)
anyRef(_isolate, klass, _objects,
queue: _r.queue, expandable: false)
];
});
}
Expand Down
17 changes: 11 additions & 6 deletions runtime/observatory/lib/src/elements/helpers/any_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,35 @@ import 'package:observatory/src/elements/unknown_ref.dart';
import 'package:observatory/src/elements/unlinkedcall_ref.dart';

Element anyRef(M.IsolateRef isolate, ref, M.ObjectRepository objects,
{RenderingQueue queue}) {
{RenderingQueue queue, bool expandable: true}) {
if (ref is M.Guarded) {
if (ref.isSentinel) {
return anyRef(isolate, ref.asSentinel, objects, queue: queue);
return anyRef(isolate, ref.asSentinel, objects,
queue: queue, expandable: expandable);
} else {
return anyRef(isolate, ref.asValue, objects, queue: queue);
return anyRef(isolate, ref.asValue, objects,
queue: queue, expandable: expandable);
}
} else if (ref is M.ObjectRef) {
if (ref is M.ClassRef) {
return new ClassRefElement(isolate, ref, queue: queue);
} else if (ref is M.CodeRef) {
return new CodeRefElement(isolate, ref, queue: queue);
} else if (ref is M.ContextRef) {
return new ContextRefElement(isolate, ref, objects, queue: queue);
return new ContextRefElement(isolate, ref, objects,
queue: queue, expandable: expandable);
} else if (ref is M.Error) {
return new ErrorRefElement(ref, queue: queue);
} else if (ref is M.FieldRef) {
return new FieldRefElement(isolate, ref, objects, queue: queue);
return new FieldRefElement(isolate, ref, objects,
queue: queue, expandable: expandable);
} else if (ref is M.FunctionRef) {
return new FunctionRefElement(isolate, ref, queue: queue);
} else if (ref is M.ICDataRef) {
return new ICDataRefElement(isolate, ref, queue: queue);
} else if (ref is M.InstanceRef) {
return new InstanceRefElement(isolate, ref, objects, queue: queue);
return new InstanceRefElement(isolate, ref, objects,
queue: queue, expandable: expandable);
} else if (ref is M.LibraryRef) {
return new LibraryRefElement(isolate, ref, queue: queue);
} else if (ref is M.LocalVarDescriptorsRef) {
Expand Down
6 changes: 4 additions & 2 deletions runtime/observatory/lib/src/elements/instance_ref.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class InstanceRefElement extends HtmlElement implements Renderable {
M.InstanceRef _instance;
M.ObjectRepository _objects;
M.Instance _loadedInstance;
bool _expandable;
bool _expanded = false;

M.IsolateRef get isolate => _isolate;
M.InstanceRef get instance => _instance;

factory InstanceRefElement(
M.IsolateRef isolate, M.InstanceRef instance, M.ObjectRepository objects,
{RenderingQueue queue}) {
{RenderingQueue queue, bool expandable: true}) {
assert(isolate != null);
assert(instance != null);
assert(objects != null);
Expand All @@ -41,6 +42,7 @@ class InstanceRefElement extends HtmlElement implements Renderable {
e._isolate = isolate;
e._instance = instance;
e._objects = objects;
e._expandable = expandable;
return e;
}

Expand All @@ -62,7 +64,7 @@ class InstanceRefElement extends HtmlElement implements Renderable {
void render() {
final content = _createLink();

if (_hasValue()) {
if (_expandable && _hasValue()) {
content.addAll([
new SpanElement()..text = ' ',
new CurlyBlockElement(expanded: _expanded, queue: _r.queue)
Expand Down

0 comments on commit a845024

Please sign in to comment.