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 function_ref_element; | 5 library function_ref_element; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'package:polymer/polymer.dart'; | 8 import 'dart:async'; |
9 import 'package:observatory/service.dart'; | 9 import 'package:observatory/models.dart' as M |
10 import 'service_ref.dart'; | 10 show IsolateRef, FunctionRef, isSyntheticFunction, ClassRef, ObjectRef; |
| 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/helpers/uris.dart'; |
11 | 14 |
12 @CustomTag('function-ref') | 15 class FunctionRefElement extends HtmlElement implements Renderable { |
13 class FunctionRefElement extends ServiceRefElement { | 16 static const tag = const Tag<FunctionRefElement>('function-ref-wrapped'); |
14 @published bool qualified = true; | 17 |
| 18 RenderingScheduler<FunctionRefElement> _r; |
| 19 |
| 20 Stream<RenderedEvent<FunctionRefElement>> get onRendered => _r.onRendered; |
| 21 |
| 22 M.IsolateRef _isolate; |
| 23 M.FunctionRef _function; |
| 24 bool _qualified; |
| 25 |
| 26 M.IsolateRef get isolate => _isolate; |
| 27 M.FunctionRef get function => _function; |
| 28 bool get qualified => _qualified; |
| 29 |
| 30 factory FunctionRefElement(M.IsolateRef isolate, M.FunctionRef function, |
| 31 {bool qualified: true, RenderingQueue queue}) { |
| 32 assert(isolate != null); |
| 33 assert(function != null); |
| 34 assert(qualified != null); |
| 35 FunctionRefElement e = document.createElement(tag.name); |
| 36 e._r = new RenderingScheduler(e, queue: queue); |
| 37 e._isolate = isolate; |
| 38 e._function = function; |
| 39 e._qualified = qualified; |
| 40 return e; |
| 41 } |
15 | 42 |
16 FunctionRefElement.created() : super.created(); | 43 FunctionRefElement.created() : super.created(); |
17 | 44 |
18 refChanged(oldValue) { | 45 @override |
19 super.refChanged(oldValue); | 46 void attached() { |
20 _updateShadowDom(); | 47 super.attached(); |
| 48 _r.enable(); |
21 } | 49 } |
22 | 50 |
23 ServiceFunction get function => ref; | 51 @override |
24 void _updateShadowDom() { | 52 void detached() { |
25 clearShadowRoot(); | 53 super.detached(); |
26 if (ref == null) { | 54 _r.disable(notify: true); |
27 return; | 55 children = []; |
28 } | 56 } |
29 if (!function.kind.isDart()) { | 57 |
30 insertTextSpanIntoShadowRoot(name); | 58 void render() { |
31 return; | 59 var content = <Element>[ |
32 } | 60 new AnchorElement(href: M.isSyntheticFunction(function.kind) ? null |
| 61 : Uris.inspect(_isolate, object: _function)) |
| 62 ..text = _function.name |
| 63 ]; |
33 if (qualified) { | 64 if (qualified) { |
34 if (function.dartOwner is ServiceFunction) { | 65 M.ObjectRef owner = _function.dartOwner; |
35 var functionRef = new Element.tag('function-ref'); | 66 while (owner is M.FunctionRef) { |
36 functionRef.ref = function.dartOwner; | 67 M.FunctionRef function = (owner as M.FunctionRef); |
37 functionRef.qualified = true; | 68 content.addAll([ |
38 shadowRoot.children.add(functionRef); | 69 new SpanElement()..text = '.', |
39 insertTextSpanIntoShadowRoot('.'); | 70 new AnchorElement(href: M.isSyntheticFunction(function.kind) ? null |
40 } else if (function.dartOwner is Class) { | 71 : Uris.inspect(_isolate, object: function)) |
41 var classRef = new Element.tag('class-ref'); | 72 ..text = function.name |
42 classRef.ref = function.dartOwner; | 73 ]); |
43 shadowRoot.children.add(classRef); | 74 owner = function.dartOwner; |
44 insertTextSpanIntoShadowRoot('.'); | 75 } |
| 76 if (owner is M.ClassRef) { |
| 77 content.addAll([ |
| 78 new SpanElement()..text = '.', |
| 79 new AnchorElement(href: Uris.inspect(_isolate, object: owner)) |
| 80 ..text = owner.name |
| 81 ]); |
45 } | 82 } |
46 } | 83 } |
47 insertLinkIntoShadowRoot(name, url, hoverText); | 84 children = content.reversed.toList(growable: false); |
48 } | 85 } |
49 } | 86 } |
OLD | NEW |