| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 trydart.interaction_manager; | 5 library trydart.interaction_manager; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 | 8 |
| 9 import 'dart:convert' show | 9 import 'dart:convert' show |
| 10 JSON; | 10 JSON; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 import 'mock.dart' as mock; | 69 import 'mock.dart' as mock; |
| 70 | 70 |
| 71 import 'settings.dart' as settings; | 71 import 'settings.dart' as settings; |
| 72 | 72 |
| 73 import 'shadow_root.dart' show | 73 import 'shadow_root.dart' show |
| 74 getShadowRoot, | 74 getShadowRoot, |
| 75 getText, | 75 getText, |
| 76 removeShadowRootPolyfill, | 76 removeShadowRootPolyfill, |
| 77 setShadowRoot; | 77 setShadowRoot; |
| 78 | 78 |
| 79 import 'iframe_error_handler.dart' show |
| 80 ErrorMessage; |
| 81 |
| 79 const String TRY_DART_NEW_DEFECT = | 82 const String TRY_DART_NEW_DEFECT = |
| 80 'https://code.google.com/p/dart/issues/entry' | 83 'https://code.google.com/p/dart/issues/entry' |
| 81 '?template=Try+Dart+Internal+Error'; | 84 '?template=Try+Dart+Internal+Error'; |
| 82 | 85 |
| 83 /// How frequently [InteractionManager.onHeartbeat] is called. | 86 /// How frequently [InteractionManager.onHeartbeat] is called. |
| 84 const Duration HEARTBEAT_INTERVAL = const Duration(milliseconds: 50); | 87 const Duration HEARTBEAT_INTERVAL = const Duration(milliseconds: 50); |
| 85 | 88 |
| 86 /// Determines how frequently "project" files are saved. The time is measured | 89 /// Determines how frequently "project" files are saved. The time is measured |
| 87 /// from the time of last modification. | 90 /// from the time of last modification. |
| 88 const Duration SAVE_INTERVAL = const Duration(seconds: 5); | 91 const Duration SAVE_INTERVAL = const Duration(seconds: 5); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 156 |
| 154 void onCompilationDone(); | 157 void onCompilationDone(); |
| 155 | 158 |
| 156 /// Called when a compilation is starting, but just before sending the | 159 /// Called when a compilation is starting, but just before sending the |
| 157 /// initiating message to the compiler isolate. | 160 /// initiating message to the compiler isolate. |
| 158 void compilationStarting(); | 161 void compilationStarting(); |
| 159 | 162 |
| 160 // TODO(ahe): Remove this from InteractionManager, but not from InitialState. | 163 // TODO(ahe): Remove this from InteractionManager, but not from InitialState. |
| 161 void consolePrintLine(line); | 164 void consolePrintLine(line); |
| 162 | 165 |
| 166 /// Called just before running a freshly compiled program. |
| 167 void aboutToRun(); |
| 168 |
| 169 /// Called when an error occurs when running user code in an iframe. |
| 170 void onIframeError(ErrorMessage message); |
| 171 |
| 163 void verboseCompilerMessage(String message); | 172 void verboseCompilerMessage(String message); |
| 164 } | 173 } |
| 165 | 174 |
| 166 /** | 175 /** |
| 167 * State machine for UI interactions. | 176 * State machine for UI interactions. |
| 168 */ | 177 */ |
| 169 class InteractionContext extends InteractionManager { | 178 class InteractionContext extends InteractionManager { |
| 170 InteractionState state; | 179 InteractionState state; |
| 171 | 180 |
| 172 final Map<String, CompilationUnit> projectFiles = <String, CompilationUnit>{}; | 181 final Map<String, CompilationUnit> projectFiles = <String, CompilationUnit>{}; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void onWindowMessage(MessageEvent event) => state.onWindowMessage(event); | 270 void onWindowMessage(MessageEvent event) => state.onWindowMessage(event); |
| 262 | 271 |
| 263 void onCompilationFailed() => state.onCompilationFailed(); | 272 void onCompilationFailed() => state.onCompilationFailed(); |
| 264 | 273 |
| 265 void onCompilationDone() => state.onCompilationDone(); | 274 void onCompilationDone() => state.onCompilationDone(); |
| 266 | 275 |
| 267 void compilationStarting() => state.compilationStarting(); | 276 void compilationStarting() => state.compilationStarting(); |
| 268 | 277 |
| 269 void consolePrintLine(line) => state.consolePrintLine(line); | 278 void consolePrintLine(line) => state.consolePrintLine(line); |
| 270 | 279 |
| 280 void aboutToRun() => state.aboutToRun(); |
| 281 |
| 282 void onIframeError(ErrorMessage message) => state.onIframeError(message); |
| 283 |
| 271 void verboseCompilerMessage(String message) { | 284 void verboseCompilerMessage(String message) { |
| 272 return state.verboseCompilerMessage(message); | 285 return state.verboseCompilerMessage(message); |
| 273 } | 286 } |
| 274 } | 287 } |
| 275 | 288 |
| 276 abstract class InteractionState implements InteractionManager { | 289 abstract class InteractionState implements InteractionManager { |
| 277 InteractionContext get context; | 290 InteractionContext get context; |
| 278 | 291 |
| 279 // TODO(ahe): Remove this. | 292 // TODO(ahe): Remove this. |
| 280 Set<AnchorElement> get oldDiagnostics { | 293 Set<AnchorElement> get oldDiagnostics { |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 } | 611 } |
| 599 | 612 |
| 600 void onWindowMessage(MessageEvent event) { | 613 void onWindowMessage(MessageEvent event) { |
| 601 if (event.source is! WindowBase || event.source == window) { | 614 if (event.source is! WindowBase || event.source == window) { |
| 602 return onBadMessage(event); | 615 return onBadMessage(event); |
| 603 } | 616 } |
| 604 if (event.data is List) { | 617 if (event.data is List) { |
| 605 List message = event.data; | 618 List message = event.data; |
| 606 if (message.length > 0) { | 619 if (message.length > 0) { |
| 607 switch (message[0]) { | 620 switch (message[0]) { |
| 608 case 'error': | |
| 609 return onErrorMessage(message[1]['url'], message[1]['message']); | |
| 610 case 'scrollHeight': | 621 case 'scrollHeight': |
| 611 return onScrollHeightMessage(message[1]); | 622 return onScrollHeightMessage(message[1]); |
| 612 } | 623 } |
| 613 } | 624 } |
| 614 return onBadMessage(event); | 625 return onBadMessage(event); |
| 615 } else { | 626 } else { |
| 616 return consolePrintLine(event.data); | 627 return consolePrintLine(event.data); |
| 617 } | 628 } |
| 618 } | 629 } |
| 619 | 630 |
| 620 /// Called when an exception occurs in an iframe. | 631 /// Called when an exception occurs in an iframe. |
| 621 void onErrorMessage(String url, String message) { | 632 void onErrorMessage(ErrorMessage message) { |
| 622 outputDiv.appendText('$message\n'); | 633 outputDiv.appendText('$message\n'); |
| 623 } | 634 } |
| 624 | 635 |
| 625 /// Called when an iframe is modified. | 636 /// Called when an iframe is modified. |
| 626 void onScrollHeightMessage(int scrollHeight) { | 637 void onScrollHeightMessage(int scrollHeight) { |
| 627 window.console.log('scrollHeight = $scrollHeight'); | 638 window.console.log('scrollHeight = $scrollHeight'); |
| 628 if (scrollHeight > 8) { | 639 if (scrollHeight > 8) { |
| 629 outputFrame.style | 640 outputFrame.style |
| 630 ..height = '${scrollHeight}px' | 641 ..height = '${scrollHeight}px' |
| 631 ..visibility = '' | 642 ..visibility = '' |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 ..start() | 707 ..start() |
| 697 ..reset(); | 708 ..reset(); |
| 698 if (context.isFirstCompile) { | 709 if (context.isFirstCompile) { |
| 699 outputDiv.append(context.compilerConsole); | 710 outputDiv.append(context.compilerConsole); |
| 700 } | 711 } |
| 701 context.oldDiagnostics | 712 context.oldDiagnostics |
| 702 ..clear() | 713 ..clear() |
| 703 ..addAll(mainEditorPane.querySelectorAll('a.diagnostic')); | 714 ..addAll(mainEditorPane.querySelectorAll('a.diagnostic')); |
| 704 } | 715 } |
| 705 | 716 |
| 717 void aboutToRun() { |
| 718 context.shouldClearConsole = true; |
| 719 } |
| 720 |
| 721 void onIframeError(ErrorMessage message) { |
| 722 // TODO(ahe): Consider replacing object URLs with something like <a |
| 723 // href='...'>out.js</a>. |
| 724 // TODO(ahe): Use source maps to translate stack traces. |
| 725 consolePrintLine(message); |
| 726 } |
| 727 |
| 706 void verboseCompilerMessage(String message) { | 728 void verboseCompilerMessage(String message) { |
| 707 if (settings.verboseCompiler) { | 729 if (settings.verboseCompiler) { |
| 708 context.compilerConsole.appendText('$message\n'); | 730 context.compilerConsole.appendText('$message\n'); |
| 709 } else { | 731 } else { |
| 710 if (isCompilerStageMarker(message)) { | 732 if (isCompilerStageMarker(message)) { |
| 711 Element progress = context.compilerConsole.firstChild; | 733 Element progress = context.compilerConsole.firstChild; |
| 712 progress.appendText('.'); | 734 progress.appendText('.'); |
| 713 } | 735 } |
| 714 } | 736 } |
| 715 } | 737 } |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 bool isCompilerStageMarker(String message) { | 1188 bool isCompilerStageMarker(String message) { |
| 1167 return | 1189 return |
| 1168 message.startsWith('Package root is ') || | 1190 message.startsWith('Package root is ') || |
| 1169 message.startsWith('Compiling ') || | 1191 message.startsWith('Compiling ') || |
| 1170 message == "Resolving..." || | 1192 message == "Resolving..." || |
| 1171 message.startsWith('Resolved ') || | 1193 message.startsWith('Resolved ') || |
| 1172 message == "Inferring types..." || | 1194 message == "Inferring types..." || |
| 1173 message == "Compiling..." || | 1195 message == "Compiling..." || |
| 1174 message.startsWith('Compiled '); | 1196 message.startsWith('Compiled '); |
| 1175 } | 1197 } |
| OLD | NEW |