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

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

Issue 408783002: Enable Try Dart to run on IE11. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: removed dynamic, marked one test as Fail on IE11 Created 6 years, 4 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) 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.shadow_root; 5 library trydart.shadow_root;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 8
9 import 'selection.dart' show 9 import 'selection.dart' show
10 TrySelection; 10 TrySelection;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 String getText(Element node) { 44 String getText(Element node) {
45 if (ShadowRoot.supported) return node.text; 45 if (ShadowRoot.supported) return node.text;
46 StringBuffer buffer = new StringBuffer(); 46 StringBuffer buffer = new StringBuffer();
47 htmlToText( 47 htmlToText(
48 node, buffer, new TrySelection.empty(node), treatRootAsInline: true); 48 node, buffer, new TrySelection.empty(node), treatRootAsInline: true);
49 return '$buffer'; 49 return '$buffer';
50 } 50 }
51 51
52 /// Element.contains(n) doesn't work when n is node(Text) in IE,
53 /// so this is a brute-force implementation of contains.
54 bool containsNode(parent, child) {
55 var p = child;
56 while (p != null && p != parent) {
57 p = p.parentNode;
58 }
59 return p != null;
60 }
61
52 /// Position [walker] at the last predecessor (that is, child of child of 62 /// Position [walker] at the last predecessor (that is, child of child of
53 /// child...) of [node]. The next call to walker.nextNode will return the first 63 /// child...) of [node]. The next call to walker.nextNode will return the first
54 /// node after [node]. 64 /// node after [node].
55 void skip(Node node, TreeWalker walker) { 65 void skip(Node node, TreeWalker walker) {
56 if (walker.nextSibling() != null) { 66 if (walker.nextSibling() != null) {
57 walker.previousNode(); 67 walker.previousNode();
58 return; 68 return;
59 } 69 }
60 for (Node current = walker.nextNode(); 70 for (Node current = walker.nextNode();
61 current != null; 71 current != null;
62 current = walker.nextNode()) { 72 current = walker.nextNode()) {
63 if (!node.contains(current)) { 73 if (!containsNode(node, current)) {
64 walker.previousNode(); 74 walker.previousNode();
65 return; 75 return;
66 } 76 }
67 } 77 }
68 } 78 }
69 79
70 /// Call [f] on each node in [root] in same order as [TreeWalker]. Skip any 80 /// Call [f] on each node in [root] in same order as [TreeWalker]. Skip any
71 /// nodes used to implement shadow root polyfill. 81 /// nodes used to implement shadow root polyfill.
72 void walkNodes(Node root, int f(Node node)) { 82 void walkNodes(Node root, int f(Node node)) {
73 TreeWalker walker = new TreeWalker(root, NodeFilter.SHOW_ALL); 83 TreeWalker walker = new TreeWalker(root, NodeFilter.SHOW_ALL);
74 84
75 for (Node node = root; node != null; node = walker.nextNode()) { 85 for (Node node = root; node != null; node = walker.nextNode()) {
76 if (!ShadowRoot.supported && 86 if (!ShadowRoot.supported &&
77 node is Element && 87 node is Element &&
78 node.getAttribute('try-dart-shadow-root') != null) { 88 node.getAttribute('try-dart-shadow-root') != null) {
79 skip(node, walker); 89 skip(node, walker);
80 } 90 } else {
81 int action = f(node); 91 int action = f(node);
82 switch (action) { 92 switch (action) {
83 case WALKER_RETURN: 93 case WALKER_RETURN:
84 return; 94 return;
85 case WALKER_SKIP_NODE: 95 case WALKER_SKIP_NODE:
86 skip(node, walker); 96 skip(node, walker);
87 break; 97 break;
88 case WALKER_NEXT: 98 case WALKER_NEXT:
89 break; 99 break;
90 default: 100 default:
91 throw 'Unexpected action returned from [f]: $action'; 101 throw 'Unexpected action returned from [f]: $action';
102 }
92 } 103 }
93 } 104 }
94 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698