Chromium Code Reviews| 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.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 Loading... | |
| 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 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); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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'; |
| 92 } | 102 } |
| 93 } | 103 } |
| 94 } | 104 } |
| 105 | |
|
ahe
2014/07/21 08:16:00
Extra line.
aam-me
2014/07/21 12:20:38
Done.
| |
| OLD | NEW |