OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library context_view_element; | 5 import 'dart:async'; |
| 6 import 'dart:html'; |
| 7 import 'package:observatory/models.dart' as M; |
| 8 import 'package:observatory/src/elements/context_ref.dart'; |
| 9 import 'package:observatory/src/elements/curly_block.dart'; |
| 10 import 'package:observatory/src/elements/helpers/any_ref.dart'; |
| 11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
| 12 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 13 import 'package:observatory/src/elements/nav/bar.dart'; |
| 14 import 'package:observatory/src/elements/nav/class_menu.dart'; |
| 15 import 'package:observatory/src/elements/nav/isolate_menu.dart'; |
| 16 import 'package:observatory/src/elements/nav/menu.dart'; |
| 17 import 'package:observatory/src/elements/nav/notify.dart'; |
| 18 import 'package:observatory/src/elements/nav/refresh.dart'; |
| 19 import 'package:observatory/src/elements/nav/top_menu.dart'; |
| 20 import 'package:observatory/src/elements/nav/vm_menu.dart'; |
| 21 import 'package:observatory/src/elements/object_common.dart'; |
6 | 22 |
7 import 'dart:async'; | 23 class ContextViewElement extends HtmlElement implements Renderable { |
8 import 'observatory_element.dart'; | 24 static const tag = const Tag<ContextViewElement>('context-view', |
9 import 'package:observatory/service.dart'; | 25 dependencies: const [ |
10 import 'package:polymer/polymer.dart'; | 26 ContextRefElement.tag, |
| 27 CurlyBlockElement.tag, |
| 28 NavBarElement.tag, |
| 29 NavClassMenuElement.tag, |
| 30 NavTopMenuElement.tag, |
| 31 NavVMMenuElement.tag, |
| 32 NavIsolateMenuElement.tag, |
| 33 NavMenuElement.tag, |
| 34 NavRefreshElement.tag, |
| 35 NavNotifyElement.tag, |
| 36 ObjectCommonElement.tag |
| 37 ]); |
11 | 38 |
12 @CustomTag('context-view') | 39 RenderingScheduler<ContextViewElement> _r; |
13 class ContextViewElement extends ObservatoryElement { | 40 |
14 @published Context context; | 41 Stream<RenderedEvent<ContextViewElement>> get onRendered => _r.onRendered; |
| 42 |
| 43 M.VM _vm; |
| 44 M.IsolateRef _isolate; |
| 45 M.EventRepository _events; |
| 46 M.NotificationRepository _notifications; |
| 47 M.Context _context; |
| 48 M.ContextRepository _contexts; |
| 49 M.RetainedSizeRepository _retainedSizes; |
| 50 M.ReachableSizeRepository _reachableSizes; |
| 51 M.InboundReferencesRepository _references; |
| 52 M.RetainingPathRepository _retainingPaths; |
| 53 M.InstanceRepository _instances; |
| 54 |
| 55 |
| 56 M.VMRef get vm => _vm; |
| 57 M.IsolateRef get isolate => _isolate; |
| 58 M.NotificationRepository get notifications => _notifications; |
| 59 M.Context get context => _context; |
| 60 |
| 61 factory ContextViewElement(M.VM vm, M.IsolateRef isolate, M.Context context, |
| 62 M.EventRepository events, |
| 63 M.NotificationRepository notifications, |
| 64 M.ContextRepository contexts, |
| 65 M.RetainedSizeRepository retainedSizes, |
| 66 M.ReachableSizeRepository reachableSizes, |
| 67 M.InboundReferencesRepository references, |
| 68 M.RetainingPathRepository retainingPaths, |
| 69 M.InstanceRepository instances, |
| 70 {RenderingQueue queue}) { |
| 71 assert(vm != null); |
| 72 assert(isolate != null); |
| 73 assert(events != null); |
| 74 assert(notifications != null); |
| 75 assert(context != null); |
| 76 assert(contexts != null); |
| 77 assert(retainedSizes != null); |
| 78 assert(reachableSizes != null); |
| 79 assert(references != null); |
| 80 assert(retainingPaths != null); |
| 81 assert(instances != null); |
| 82 ContextViewElement e = document.createElement(tag.name); |
| 83 e._r = new RenderingScheduler(e, queue: queue); |
| 84 e._vm = vm; |
| 85 e._isolate = isolate; |
| 86 e._events = events; |
| 87 e._notifications = notifications; |
| 88 e._context = context; |
| 89 e._contexts = contexts; |
| 90 e._retainedSizes = retainedSizes; |
| 91 e._reachableSizes = reachableSizes; |
| 92 e._references = references; |
| 93 e._retainingPaths = retainingPaths; |
| 94 e._instances = instances; |
| 95 return e; |
| 96 } |
15 | 97 |
16 ContextViewElement.created() : super.created(); | 98 ContextViewElement.created() : super.created(); |
17 | 99 |
18 Future refresh() { | 100 @override |
19 return context.reload(); | 101 attached() { |
| 102 super.attached(); |
| 103 _r.enable(); |
| 104 } |
| 105 |
| 106 @override |
| 107 detached() { |
| 108 super.detached(); |
| 109 _r.disable(notify: true); |
| 110 children = []; |
| 111 } |
| 112 |
| 113 void render() { |
| 114 var content = [ |
| 115 new NavBarElement(queue: _r.queue) |
| 116 ..children = [ |
| 117 new NavTopMenuElement(queue: _r.queue), |
| 118 new NavVMMenuElement(_vm, _events, queue: _r.queue), |
| 119 new NavIsolateMenuElement(_isolate, _events, queue: _r.queue), |
| 120 new NavClassMenuElement(_isolate, _context.clazz, queue: _r.queue), |
| 121 new NavMenuElement('instance', last: true, queue: _r.queue), |
| 122 new NavRefreshElement(queue: _r.queue) |
| 123 ..onRefresh.listen((e) async { |
| 124 e.element.disabled = true; |
| 125 _context = await _contexts.get(_isolate, _context.id); |
| 126 _r.dirty(); |
| 127 }), |
| 128 new NavNotifyElement(_notifications, queue: _r.queue) |
| 129 ], |
| 130 new DivElement()..classes = const ['content-centered-big'] |
| 131 ..children = [ |
| 132 new HeadingElement.h2()..text = 'Allocation Profile', |
| 133 new HRElement(), |
| 134 new ObjectCommonElement(_isolate, _context, _retainedSizes, |
| 135 _reachableSizes, _references, _retainingPaths, |
| 136 _instances, queue: _r.queue) |
| 137 ] |
| 138 ]; |
| 139 if (_context.parentContext != null) { |
| 140 content.addAll([ |
| 141 new BRElement(), |
| 142 new DivElement()..classes = const ['content-centered-big'] |
| 143 ..children = [ |
| 144 new DivElement()..classes = ['memberList'] |
| 145 ..children = [ |
| 146 new DivElement()..classes = ['memberItem'] |
| 147 ..children = [ |
| 148 new DivElement()..classes = ['memberName'] |
| 149 ..text = 'parent context', |
| 150 new DivElement()..classes = ['memberName'] |
| 151 ..children = [ |
| 152 new ContextRefElement(_isolate, _context.parentContext, |
| 153 queue: _r.queue) |
| 154 ] |
| 155 ] |
| 156 ] |
| 157 ] |
| 158 ]); |
| 159 } |
| 160 content.add(new HRElement()); |
| 161 if (_context.variables.isNotEmpty) { |
| 162 int index = 0; |
| 163 content.addAll([ |
| 164 new DivElement()..classes = const ['content-centered-big'] |
| 165 ..children = [ |
| 166 new SpanElement()..text = 'Variables ', |
| 167 new CurlyBlockElement(expanded: _context.variables.length > 8, |
| 168 queue: _r.queue) |
| 169 ..children = [ |
| 170 new DivElement()..classes = ['memberList'] |
| 171 ..children = _context.variables.map((variable) |
| 172 => new DivElement()..classes = ['memberItem'] |
| 173 ..children = [ |
| 174 new DivElement()..classes = ['memberName'] |
| 175 ..text = '[ ${++index} ]', |
| 176 new DivElement()..classes = ['memberName'] |
| 177 ..children = [ |
| 178 anyRef(_isolate, variable.value, _instances, |
| 179 queue: _r.queue) |
| 180 ] |
| 181 ]).toList() |
| 182 ] |
| 183 ] |
| 184 ]); |
| 185 } |
| 186 children = content; |
20 } | 187 } |
21 } | 188 } |
OLD | NEW |