| OLD | NEW |
| (Empty) |
| 1 import 'dart:async'; | |
| 2 | |
| 3 void assertHasParentNode(Node n) { assert(n.parentNode != null); } | |
| 4 void assertHasParentNodes(List<Node> list) { | |
| 5 for (var n in list) { | |
| 6 assertHasParentNode(n); | |
| 7 } | |
| 8 } | |
| 9 | |
| 10 class Node { | |
| 11 | |
| 12 ParentNode parentNode; | |
| 13 Node nextSibling; | |
| 14 Node previousSibling; | |
| 15 Node(); | |
| 16 | |
| 17 void insertBefore(List<Node> nodes) { | |
| 18 int count = nodes.length; | |
| 19 while (count-- > 0) { | |
| 20 parentNode._insertBefore(nodes[count], this); | |
| 21 } | |
| 22 | |
| 23 assertHasParentNodes(nodes); | |
| 24 } | |
| 25 | |
| 26 remove() { | |
| 27 if (parentNode == null) { | |
| 28 return; | |
| 29 } | |
| 30 | |
| 31 if (nextSibling != null) { | |
| 32 nextSibling.previousSibling = previousSibling; | |
| 33 } else { | |
| 34 parentNode.lastChild = previousSibling; | |
| 35 } | |
| 36 | |
| 37 if (previousSibling != null) { | |
| 38 previousSibling.nextSibling = nextSibling; | |
| 39 } else { | |
| 40 parentNode.firstChild = nextSibling; | |
| 41 } | |
| 42 | |
| 43 parentNode = null; | |
| 44 nextSibling = null; | |
| 45 previousSibling = null; | |
| 46 } | |
| 47 } | |
| 48 | |
| 49 class Text extends Node { | |
| 50 String data; | |
| 51 Text(this.data) : super(); | |
| 52 } | |
| 53 | |
| 54 class ParentNode extends Node { | |
| 55 Node firstChild; | |
| 56 Node lastChild; | |
| 57 | |
| 58 ParentNode() : super(); | |
| 59 | |
| 60 Node setChild(Node node) { | |
| 61 firstChild = node; | |
| 62 lastChild = node; | |
| 63 node.parentNode = this; | |
| 64 assertHasParentNode(node); | |
| 65 return node; | |
| 66 } | |
| 67 | |
| 68 Node _insertBefore(Node node, Node ref) { | |
| 69 assert(ref == null || ref.parentNode == this); | |
| 70 | |
| 71 if (node.parentNode != null) { | |
| 72 node.remove(); | |
| 73 } | |
| 74 | |
| 75 node.parentNode = this; | |
| 76 | |
| 77 if (firstChild == null && lastChild == null) { | |
| 78 firstChild = node; | |
| 79 lastChild = node; | |
| 80 } else if (ref == null) { | |
| 81 node.previousSibling = lastChild; | |
| 82 lastChild.nextSibling = node; | |
| 83 lastChild = node; | |
| 84 } else { | |
| 85 if (ref == firstChild) { | |
| 86 assert(ref.previousSibling == null); | |
| 87 firstChild = node; | |
| 88 } | |
| 89 node.previousSibling = ref.previousSibling; | |
| 90 ref.previousSibling = node; | |
| 91 node.nextSibling = ref; | |
| 92 } | |
| 93 | |
| 94 assertHasParentNode(node); | |
| 95 return node; | |
| 96 } | |
| 97 | |
| 98 Node appendChild(Node node) { | |
| 99 return _insertBefore(node, null); | |
| 100 } | |
| 101 } | |
| 102 | |
| 103 class Element extends ParentNode { | |
| 104 void addEventListener(String type, EventListener listener, [bool useCapture =
false]) {} | |
| 105 void removeEventListener(String type, EventListener listener) {} | |
| 106 void setAttribute(String name, [String value]) {} | |
| 107 } | |
| 108 | |
| 109 class Document extends ParentNode { | |
| 110 Document(); | |
| 111 Element createElement(String tagName) { | |
| 112 switch (tagName) { | |
| 113 case 'img' : return new HTMLImageElement(); | |
| 114 default : return new Element(); | |
| 115 } | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 class HTMLImageElement extends Element { | |
| 120 HTMLImageElement(); | |
| 121 String src; | |
| 122 Object style = {}; | |
| 123 } | |
| 124 | |
| 125 class Event {} | |
| 126 | |
| 127 class PointerEvent extends Event {} | |
| 128 class GestureEvent extends Event {} | |
| 129 class WheelEvent extends Event {} | |
| 130 | |
| 131 typedef EventListener(Event event); | |
| 132 | |
| 133 void _callRAF(Function fn) { | |
| 134 fn(new DateTime.now().millisecondsSinceEpoch.toDouble()); | |
| 135 } | |
| 136 | |
| 137 class Window { | |
| 138 int requestAnimationFrame(Function fn) { | |
| 139 new Timer(const Duration(milliseconds: 16), () { | |
| 140 _callRAF(fn); | |
| 141 }); | |
| 142 return 1; | |
| 143 } | |
| 144 | |
| 145 void cancelAnimationFrame(int id) { | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 Document document = new Document(); | |
| 150 | |
| 151 Window window = new Window(); | |
| 152 | |
| 153 class ClientRect { | |
| 154 double top; | |
| 155 double right; | |
| 156 double bottomr; | |
| 157 double left; | |
| 158 double width; | |
| 159 double height; | |
| 160 } | |
| OLD | NEW |