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

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

Issue 837723004: Build Observatory as part of runtime (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library script_inset_element;
6
7 import 'dart:html';
8 import 'observatory_element.dart';
9 import 'package:observatory/service.dart';
10 import 'package:polymer/polymer.dart';
11
12 /// Box with script source code in it.
13 @CustomTag('script-inset')
14 class ScriptInsetElement extends ObservatoryElement {
15 @published Script script;
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;
23 @published int endPos;
24
25 @observable int currentLine;
26 @observable int startLine;
27 @observable int endLine;
28 @observable bool linesReady = false;
29
30 @observable List<ScriptLine> lines = toObservable([]);
31
32 String makeLineId(int line) {
33 return 'line-$line';
34 }
35
36 MutationObserver _observer;
37
38 void _scrollToCurrentPos() {
39 var line = shadowRoot.querySelector('#line-$currentLine');
40 if (line != null) {
41 line.scrollIntoView();
42 }
43 }
44
45 void _onMutation(mutations, observer) {
46 _scrollToCurrentPos();
47 }
48
49 void attached() {
50 super.attached();
51 var table = shadowRoot.querySelector('.sourceTable');
52 if (table != null) {
53 _observer = new MutationObserver(_onMutation);
54 _observer.observe(table, childList:true);
55 }
56 }
57
58 void detached() {
59 if (_observer != null) {
60 _observer.disconnect();
61 _observer = null;
62 }
63 super.detached();
64 }
65
66 void currentPosChanged(oldValue) {
67 _updateLines();
68 _scrollToCurrentPos();
69 }
70
71 void startPosChanged(oldValue) {
72 _updateLines();
73 }
74
75 void endPosChanged(oldValue) {
76 _updateLines();
77 }
78
79 void scriptChanged(oldValue) {
80 _updateLines();
81 }
82
83 var _updateFuture;
84
85 void _updateLines() {
86 linesReady = false;
87 if (_updateFuture != null) {
88 // Already scheduled.
89 return;
90 }
91 if (script == null) {
92 // Wait for script to be assigned.
93 return;
94 }
95 if (!script.loaded) {
96 _updateFuture = script.load().then((_) {
97 if (script.loaded) {
98 _updateFuture = null;
99 _updateLines();
100 }
101 });
102 return;
103 }
104 startLine = (startPos != null
105 ? script.tokenToLine(startPos)
106 : 1);
107 currentLine = (currentPos != null
108 ? script.tokenToLine(currentPos)
109 : null);
110 endLine = (endPos != null
111 ? script.tokenToLine(endPos)
112 : script.lines.length);
113
114 lines.clear();
115 for (int i = (startLine - 1); i <= (endLine - 1); i++) {
116 lines.add(script.lines[i]);
117 }
118 linesReady = true;
119 }
120
121 ScriptInsetElement.created() : super.created();
122 }
123
124 @CustomTag('breakpoint-toggle')
125 class BreakpointToggleElement extends ObservatoryElement {
126 @published ScriptLine line;
127 @observable bool busy = false;
128
129 void toggleBreakpoint(var a, var b, var c) {
130 if (busy) {
131 return;
132 }
133 busy = true;
134 if (line.bpt == null) {
135 // No breakpoint. Set it.
136 line.script.isolate.setBreakpoint(line.script, line.line).then((_) {
137 busy = false;
138 });
139 } else {
140 // Existing breakpoint. Remove it.
141 line.script.isolate.clearBreakpoint(line.bpt).then((_) {
142 busy = false;
143 });
144 }
145 }
146
147 BreakpointToggleElement.created() : super.created();
148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698