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 script_ref_element; | 5 library script_ref_element; |
6 | 6 |
7 import 'package:polymer/polymer.dart'; | 7 import 'dart:html'; |
8 import 'package:observatory/service.dart'; | 8 import 'dart:async'; |
9 import 'service_ref.dart'; | 9 import 'package:observatory/models.dart' show IsolateRef, ScriptRef; |
| 10 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 11 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
10 | 12 |
11 @CustomTag('script-ref') | 13 class ScriptRefElement extends HtmlElement implements Renderable{ |
12 class ScriptRefElement extends ServiceRefElement { | 14 static const tag = const Tag<ScriptRefElement>('script-ref-wrapped'); |
13 @published int pos; | |
14 | 15 |
15 String get hoverText { | 16 RenderingScheduler _r; |
16 if (ref == null) { | |
17 return super.hoverText; | |
18 } | |
19 return ref.vmName; | |
20 } | |
21 | 17 |
22 void posChanged(oldValue) { | 18 Stream<RenderedEvent<ScriptRefElement>> get onRendered => _r.onRendered; |
23 _updateProperties(null); | |
24 } | |
25 | 19 |
26 void _updateProperties(_) { | |
27 if (ref != null && ref.loaded) { | |
28 notifyPropertyChange(#name, 0, 1); | |
29 notifyPropertyChange(#url, 0, 1); | |
30 } | |
31 } | |
32 | 20 |
33 String get name { | 21 IsolateRef _isolate; |
34 if (ref == null) { | 22 ScriptRef _script; |
35 return super.name; | |
36 } | |
37 if ((pos != null) && (pos >= 0)) { | |
38 if (ref.loaded) { | |
39 // Script is loaded, get the line number. | |
40 Script script = ref; | |
41 return '${super.name}:${script.tokenToLine(pos)}:' | |
42 '${script.tokenToCol(pos)}'; | |
43 } else { | |
44 ref.load().then(_updateProperties); | |
45 } | |
46 } | |
47 return super.name; | |
48 } | |
49 | 23 |
50 String get url { | 24 IsolateRef get isolate => _isolate; |
51 if (ref == null) { | 25 ScriptRef get script => _script; |
52 return super.url; | 26 |
53 } | 27 factory ScriptRefElement(IsolateRef isolate, ScriptRef script, |
54 if ((pos != null) && (pos >= 0)) { | 28 {RenderingQueue queue}) { |
55 if (ref.loaded) { | 29 assert(isolate != null); |
56 return '${super.url}---pos=${pos}'; | 30 assert(script != null); |
57 } else { | 31 ScriptRefElement e = document.createElement(tag.name); |
58 ref.load().then(_updateProperties); | 32 e._r = new RenderingScheduler(e, queue: queue); |
59 } | 33 e._isolate = isolate; |
60 } | 34 e._script = script; |
61 return super.url; | 35 return e; |
62 } | 36 } |
63 | 37 |
64 ScriptRefElement.created() : super.created(); | 38 ScriptRefElement.created() : super.created(); |
| 39 |
| 40 @override |
| 41 void attached() { super.attached(); assert(script != null); _r.enable(); } |
| 42 |
| 43 @override |
| 44 void detached() { super.detached(); children = []; _r.disable(notify: true); } |
| 45 |
| 46 void render() { |
| 47 children = [ |
| 48 new AnchorElement(href: '#/inspect?' |
| 49 'isolateId=${Uri.encodeComponent(isolate.id)}&' |
| 50 'objectId=${Uri.encodeComponent(script.id)}') |
| 51 ..title = script.uri |
| 52 ..text = script.uri.split('/').last |
| 53 ]; |
| 54 } |
65 } | 55 } |
66 | |
67 @CustomTag('source-link') | |
68 class SourceLinkElement extends PolymerElement { | |
69 SourceLinkElement.created() : super.created(); | |
70 | |
71 @published SourceLocation location; | |
72 } | |
OLD | NEW |