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

Side by Side Diff: dart/site/try/src/editor.dart

Issue 261413002: Use ShadowRoot to hide non-user content (for example, diagnostics). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address Kasper's comments. Created 6 years, 7 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
« no previous file with comments | « dart/site/try/src/decoration.dart ('k') | dart/site/try/src/html_to_text.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 trydart.editor; 5 library trydart.editor;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 8
9 import 'package:compiler/implementation/scanner/scannerlib.dart' show 9 import 'package:compiler/implementation/scanner/scannerlib.dart' show
10 EOF_TOKEN, 10 EOF_TOKEN,
(...skipping 12 matching lines...) Expand all
23 CodeCompletionDecoration, 23 CodeCompletionDecoration,
24 Decoration, 24 Decoration,
25 DiagnosticDecoration, 25 DiagnosticDecoration,
26 error, 26 error,
27 info, 27 info,
28 warning; 28 warning;
29 29
30 import 'selection.dart' show 30 import 'selection.dart' show
31 isCollapsed; 31 isCollapsed;
32 32
33 import 'shadow_root.dart' show
34 getShadowRoot;
35
33 const String INDENT = '\u{a0}\u{a0}'; 36 const String INDENT = '\u{a0}\u{a0}';
34 37
35 Set<String> seenIdentifiers; 38 Set<String> seenIdentifiers;
36 39
37 Element moveActive(int distance) { 40 Element moveActive(int distance, Node ui) {
38 List<Element> entries = document.querySelectorAll('.dart-static>.dart-entry'); 41 var /* ShadowRoot or Element */ root = getShadowRoot(ui);
42 List<Element> entries = root.querySelectorAll('.dart-static>.dart-entry');
39 int activeIndex = -1; 43 int activeIndex = -1;
40 for (var i = 0; i < entries.length; i++) { 44 for (var i = 0; i < entries.length; i++) {
41 if (entries[i].classes.contains('activeEntry')) { 45 if (entries[i].classes.contains('activeEntry')) {
42 activeIndex = i; 46 activeIndex = i;
43 break; 47 break;
44 } 48 }
45 } 49 }
46 int newIndex = activeIndex + distance; 50 int newIndex = activeIndex + distance;
47 Element currentEntry; 51 Element currentEntry;
48 if (0 <= newIndex && newIndex < entries.length) { 52 if (0 <= newIndex && newIndex < entries.length) {
49 currentEntry = entries[newIndex]; 53 currentEntry = entries[newIndex];
50 } 54 }
51 if (currentEntry == null) return null; 55 if (currentEntry == null) return null;
52 if (0 <= newIndex && activeIndex != -1) { 56 if (0 <= newIndex && activeIndex != -1) {
53 entries[activeIndex].classes.remove('activeEntry'); 57 entries[activeIndex].classes.remove('activeEntry');
54 } 58 }
55 Element staticNode = document.querySelector('.dart-static'); 59 Element staticNode = root.querySelector('.dart-static');
56 String visibility = computeVisibility(currentEntry, staticNode); 60 String visibility = computeVisibility(currentEntry, staticNode);
57 print(visibility); 61 print(visibility);
58 var serverResults = document.querySelectorAll('.dart-server>.dart-entry'); 62 var serverResults = root.querySelectorAll('.dart-server>.dart-entry');
59 var serverResultCount = serverResults.length; 63 var serverResultCount = serverResults.length;
60 if (serverResultCount > 0) { 64 if (serverResultCount > 0) {
61 switch (visibility) { 65 switch (visibility) {
62 case obscured: 66 case obscured:
63 case hidden: { 67 case hidden: {
64 Rectangle cr = currentEntry.getBoundingClientRect(); 68 Rectangle cr = currentEntry.getBoundingClientRect();
65 Rectangle sr = staticNode.getBoundingClientRect(); 69 Rectangle sr = staticNode.getBoundingClientRect();
66 Element entry = serverResults[0]; 70 Element entry = serverResults[0];
67 entry.remove(); 71 entry.remove();
68 currentEntry.parentNode.insertBefore(entry, currentEntry); 72 currentEntry.parentNode.insertBefore(entry, currentEntry);
69 currentEntry = entry; 73 currentEntry = entry;
70 serverResultCount--; 74 serverResultCount--;
71 75
72 staticNode.style.maxHeight = '${sr.boundingBox(cr).height}px'; 76 staticNode.style.maxHeight = '${sr.boundingBox(cr).height}px';
73 } 77 }
74 } 78 }
75 } else { 79 } else {
76 currentEntry.scrollIntoView(ScrollAlignment.BOTTOM); 80 currentEntry.scrollIntoView(ScrollAlignment.BOTTOM);
77 } 81 }
78 if (serverResultCount == 0) { 82 if (serverResultCount == 0) {
79 document.querySelector('.dart-server').style.display = 'none'; 83 root.querySelector('.dart-server').style.display = 'none';
80 } 84 }
81 if (currentEntry != null) { 85 if (currentEntry != null) {
82 currentEntry.classes.add('activeEntry'); 86 currentEntry.classes.add('activeEntry');
83 } 87 }
84 // Discard mutations. 88 // Discard mutations.
85 observer.takeRecords(); 89 observer.takeRecords();
86 return currentEntry; 90 return currentEntry;
87 } 91 }
88 92
89 const visible = 'visible'; 93 const visible = 'visible';
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 229
226 diagnostic(text, tip) { 230 diagnostic(text, tip) {
227 if (text is String) { 231 if (text is String) {
228 text = new Text(text); 232 text = new Text(text);
229 } 233 }
230 return new AnchorElement() 234 return new AnchorElement()
231 ..classes.add('diagnostic') 235 ..classes.add('diagnostic')
232 ..append(text) 236 ..append(text)
233 ..append(tip); 237 ..append(tip);
234 } 238 }
OLDNEW
« no previous file with comments | « dart/site/try/src/decoration.dart ('k') | dart/site/try/src/html_to_text.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698