OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, 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 class _NodeImpl extends _EventTargetImpl implements Node { |
| 6 _NodeListImpl get nodes() { |
| 7 final list = _childNodes; |
| 8 list._parent = this; |
| 9 return list; |
| 10 } |
| 11 |
| 12 void set nodes(Collection<Node> value) { |
| 13 // Copy list first since we don't want liveness during iteration. |
| 14 // TODO(jacobr): there is a better way to do this. |
| 15 List copy = new List.from(value); |
| 16 nodes.clear(); |
| 17 nodes.addAll(copy); |
| 18 } |
| 19 |
| 20 // TODO(jacobr): should we throw an exception if parent is already null? |
| 21 _NodeImpl remove() { |
| 22 if (this.parent != null) { |
| 23 this.parent._removeChild(this); |
| 24 } |
| 25 return this; |
| 26 } |
| 27 |
| 28 _NodeImpl replaceWith(Node otherNode) { |
| 29 try { |
| 30 this.parent._replaceChild(otherNode, this); |
| 31 } catch(var e) { |
| 32 |
| 33 }; |
| 34 return this; |
| 35 } |
| 36 |
| 37 _NodeImpl._wrap(ptr) : super._wrap(ptr); |
| 38 |
| 39 NamedNodeMap get _attributes() => _wrap(_ptr.attributes); |
| 40 |
| 41 NodeList get _childNodes() => _wrap(_ptr.childNodes); |
| 42 |
| 43 Node get nextNode() => _wrap(_ptr.nextSibling); |
| 44 |
| 45 Document get document() => _FixHtmlDocumentReference(_wrap(_ptr.ownerDocument)
); |
| 46 |
| 47 Node get parent() => _wrap(_ptr.parentNode); |
| 48 |
| 49 Node get previousNode() => _wrap(_ptr.previousSibling); |
| 50 |
| 51 String get text() => _wrap(_ptr.textContent); |
| 52 |
| 53 void set text(String value) { _ptr.textContent = _unwrap(value); } |
| 54 |
| 55 Node _appendChild(Node newChild) { |
| 56 return _wrap(_ptr.appendChild(_unwrap(newChild))); |
| 57 } |
| 58 |
| 59 Node clone(bool deep) { |
| 60 return _wrap(_ptr.cloneNode(_unwrap(deep))); |
| 61 } |
| 62 |
| 63 bool contains(Node other) { |
| 64 return _wrap(_ptr.contains(_unwrap(other))); |
| 65 } |
| 66 |
| 67 bool hasChildNodes() { |
| 68 return _wrap(_ptr.hasChildNodes()); |
| 69 } |
| 70 |
| 71 Node insertBefore(Node newChild, Node refChild) { |
| 72 return _wrap(_ptr.insertBefore(_unwrap(newChild), _unwrap(refChild))); |
| 73 } |
| 74 |
| 75 Node _removeChild(Node oldChild) { |
| 76 return _wrap(_ptr.removeChild(_unwrap(oldChild))); |
| 77 } |
| 78 |
| 79 Node _replaceChild(Node newChild, Node oldChild) { |
| 80 return _wrap(_ptr.replaceChild(_unwrap(newChild), _unwrap(oldChild))); |
| 81 } |
| 82 |
| 83 } |
OLD | NEW |