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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/elements/script_inset.dart

Issue 378113002: Improve script display in the observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_inset_element; 5 library script_inset_element;
6 6
7 import 'dart:html';
7 import 'observatory_element.dart'; 8 import 'observatory_element.dart';
8 import 'package:observatory/service.dart'; 9 import 'package:observatory/service.dart';
9 import 'package:polymer/polymer.dart'; 10 import 'package:polymer/polymer.dart';
10 11
11 /// Box with script source code in it. 12 /// Box with script source code in it.
12 @CustomTag('script-inset') 13 @CustomTag('script-inset')
13 class ScriptInsetElement extends ObservatoryElement { 14 class ScriptInsetElement extends ObservatoryElement {
14 @published Script script; 15 @published Script script;
15 @published int pos; 16
17 /// Set the height to make the script inset scroll. Otherwise it
18 /// will show from startPos to endPos.
19 @published String height = null;
20
21 @published int currentPos;
22 @published int startPos;
16 @published int endPos; 23 @published int endPos;
17 final List<int> lineNumbers = new ObservableList<int>(); 24
25 @observable int currentLine;
18 @observable int startLine; 26 @observable int startLine;
19 @observable int endLine; 27 @observable int endLine;
20 28
21 @observable List<ScriptLine> lines = toObservable([]); 29 @observable List<ScriptLine> lines = toObservable([]);
22 30
31 String makeLineId(int line) {
32 return 'line-$line';
33 }
34
35 MutationObserver _observer;
36
37 void _onMutation(mutations, observer) {
38 var line = shadowRoot.querySelector('#line-$currentLine');
39 if (line != null) {
40 line.scrollIntoView();
41 }
42 }
43
23 void attached() { 44 void attached() {
24 super.attached(); 45 super.attached();
46 var table = shadowRoot.querySelector('.sourceTable');
47 if (table != null) {
48 _observer = new MutationObserver(_onMutation);
49 _observer.observe(table, childList:true);
50 }
25 } 51 }
26 52
27 void scriptChanged(oldValue) { 53 void detached() {
54 if (_observer != null) {
55 _observer.disconnect();
56 _observer = null;
57 }
58 super.detached();
59 }
60
61 void currentPosChanged(oldValue) {
28 _updateLines(); 62 _updateLines();
29 } 63 }
30 64
31 void posChanged(oldValue) { 65 void startPosChanged(oldValue) {
32 _updateLines(); 66 _updateLines();
33 } 67 }
34 68
35 void endPosChanged(oldValue) { 69 void endPosChanged(oldValue) {
36 _updateLines(); 70 _updateLines();
37 } 71 }
38 72
39 static const hitStyleNone = 'min-width:32px;'; 73 void scriptChanged(oldValue) {
40 static const hitStyleExecuted = 'min-width:32px; background-color:green'; 74 _updateLines();
41 static const hitStyleNotExecuted = 'min-width:32px; background-color:red';
42
43 /// [hits] can be null which indicates that the line is not executable.
44 /// When [hits] is 0, the line is executable but hasn't been executed and
45 /// when [hits] is positive, the line is executable and has been executed.
46 String styleForHits(int hits) {
47 if (hits == null) {
48 return hitStyleNone;
49 } else if (hits == 0) {
50 return hitStyleNotExecuted;
51 }
52 assert(hits > 0);
53 return hitStyleExecuted;
54 } 75 }
55 76
56 var _updateFuture; 77 var _updateFuture;
57 78
58 void _updateLines() { 79 void _updateLines() {
59 if (_updateFuture != null) { 80 if (_updateFuture != null) {
60 // Already scheduled. 81 // Already scheduled.
61 return; 82 return;
62 } 83 }
84 if (script == null) {
85 // Wait for script to be assigned.
86 return;
87 }
63 if (!script.loaded) { 88 if (!script.loaded) {
64 _updateFuture = script.load().then((_) { 89 _updateFuture = script.load().then((_) {
65 if (script.loaded) { 90 if (script.loaded) {
66 _updateFuture = null; 91 _updateFuture = null;
67 _updateLines(); 92 _updateLines();
68 } 93 }
69 }); 94 });
70 return; 95 return;
71 } 96 }
72 startLine = 97 startLine = (startPos != null
73 (pos != null) ? script.tokenToLine(pos) - 1 : 0; 98 ? script.tokenToLine(startPos)
74 endLine = 99 : 1);
75 (endPos != null) ? script.tokenToLine(endPos) : startLine + 1; 100 currentLine = (currentPos != null
76 // Add line numbers. 101 ? script.tokenToLine(currentPos)
77 lineNumbers.clear(); 102 : null);
78 for (var i = startLine; i < endLine; i++) { 103 endLine = (endPos != null
79 lineNumbers.add(i); 104 ? script.tokenToLine(endPos)
105 : script.lines.length);
106 lines.clear();
107 for (int i = (startLine - 1); i <= (endLine - 1); i++) {
108 lines.add(script.lines[i]);
80 } 109 }
81 } 110 }
82 111
83 ScriptInsetElement.created() : super.created(); 112 ScriptInsetElement.created() : super.created();
84 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698