| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library fn; | 5 library fn; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:sky' as sky; | 9 import 'dart:sky' as sky; |
| 10 import 'reflect.dart' as reflect; | 10 import 'reflect.dart' as reflect; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 StyleNode(UINode content, this.style): super(content); | 150 StyleNode(UINode content, this.style): super(content); |
| 151 } | 151 } |
| 152 | 152 |
| 153 class ParentDataNode extends ContentNode { | 153 class ParentDataNode extends ContentNode { |
| 154 final ParentData parentData; | 154 final ParentData parentData; |
| 155 | 155 |
| 156 ParentDataNode(UINode content, this.parentData): super(content); | 156 ParentDataNode(UINode content, this.parentData): super(content); |
| 157 } | 157 } |
| 158 | 158 |
| 159 /* | |
| 160 * RenderNodeWrappers correspond to a desired state of a RenderCSS. | |
| 161 * They are fully immutable, with one exception: A UINode which is a | |
| 162 * Component which lives within an OneChildListRenderNodeWrapper's | |
| 163 * children list, may be replaced with the "old" instance if it has | |
| 164 * become stateful. | |
| 165 */ | |
| 166 abstract class RenderNodeWrapper extends UINode { | |
| 167 | |
| 168 static final Map<RenderCSS, RenderNodeWrapper> _nodeMap = | |
| 169 new HashMap<RenderCSS, RenderNodeWrapper>(); | |
| 170 | |
| 171 static RenderNodeWrapper _getMounted(RenderCSS node) => _nodeMap[node]; | |
| 172 | |
| 173 RenderNodeWrapper({ Object key }) : super(key: key); | |
| 174 | |
| 175 RenderNodeWrapper get _emptyNode; | |
| 176 | |
| 177 RenderCSS _createNode(); | |
| 178 | |
| 179 void _sync(UINode old, RenderCSSContainer host, RenderCSS insertBefore) { | |
| 180 if (old == null) { | |
| 181 _root = _createNode(); | |
| 182 assert(_root != null); | |
| 183 host.add(_root, before: insertBefore); | |
| 184 old = _emptyNode; | |
| 185 } else { | |
| 186 _root = old._root; | |
| 187 assert(_root != null); | |
| 188 } | |
| 189 | |
| 190 _nodeMap[_root] = this; | |
| 191 _syncNode(old); | |
| 192 } | |
| 193 | |
| 194 void _syncNode(RenderNodeWrapper old); | |
| 195 | |
| 196 void _removeChild(UINode node) { | |
| 197 assert(_root is RenderCSSContainer); | |
| 198 _root.remove(node._root); | |
| 199 super._removeChild(node); | |
| 200 } | |
| 201 | |
| 202 void _remove() { | |
| 203 assert(_root != null); | |
| 204 _nodeMap.remove(_root); | |
| 205 super._remove(); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 typedef GestureEventListener(sky.GestureEvent e); | 159 typedef GestureEventListener(sky.GestureEvent e); |
| 210 typedef PointerEventListener(sky.PointerEvent e); | 160 typedef PointerEventListener(sky.PointerEvent e); |
| 211 typedef EventListener(sky.Event e); | 161 typedef EventListener(sky.Event e); |
| 212 | 162 |
| 213 class EventListenerNode extends ContentNode { | 163 class EventListenerNode extends ContentNode { |
| 214 final Map<String, sky.EventListener> listeners; | 164 final Map<String, sky.EventListener> listeners; |
| 215 | 165 |
| 216 static final Set<String> _registeredEvents = new HashSet<String>(); | 166 static final Set<String> _registeredEvents = new HashSet<String>(); |
| 217 | 167 |
| 218 static Map<String, sky.EventListener> _createListeners({ | 168 static Map<String, sky.EventListener> _createListeners({ |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 266 |
| 317 void _sync(UINode old, RenderCSSContainer host, RenderCSS insertBefore) { | 267 void _sync(UINode old, RenderCSSContainer host, RenderCSS insertBefore) { |
| 318 for (var type in listeners.keys) { | 268 for (var type in listeners.keys) { |
| 319 _ensureDocumentListener(type); | 269 _ensureDocumentListener(type); |
| 320 } | 270 } |
| 321 | 271 |
| 322 super._sync(old, host, insertBefore); | 272 super._sync(old, host, insertBefore); |
| 323 } | 273 } |
| 324 } | 274 } |
| 325 | 275 |
| 276 /* |
| 277 * RenderNodeWrappers correspond to a desired state of a RenderCSS. |
| 278 * They are fully immutable, with one exception: A UINode which is a |
| 279 * Component which lives within an OneChildListRenderNodeWrapper's |
| 280 * children list, may be replaced with the "old" instance if it has |
| 281 * become stateful. |
| 282 */ |
| 283 abstract class RenderNodeWrapper extends UINode { |
| 284 |
| 285 static final Map<RenderCSS, RenderNodeWrapper> _nodeMap = |
| 286 new HashMap<RenderCSS, RenderNodeWrapper>(); |
| 287 |
| 288 static RenderNodeWrapper _getMounted(RenderCSS node) => _nodeMap[node]; |
| 289 |
| 290 RenderNodeWrapper({ Object key }) : super(key: key); |
| 291 |
| 292 RenderNodeWrapper get _emptyNode; |
| 293 |
| 294 RenderCSS _createNode(); |
| 295 |
| 296 void _sync(UINode old, RenderCSSContainer host, RenderCSS insertBefore) { |
| 297 if (old == null) { |
| 298 _root = _createNode(); |
| 299 assert(_root != null); |
| 300 host.add(_root, before: insertBefore); |
| 301 old = _emptyNode; |
| 302 } else { |
| 303 _root = old._root; |
| 304 assert(_root != null); |
| 305 } |
| 306 |
| 307 _nodeMap[_root] = this; |
| 308 _syncNode(old); |
| 309 } |
| 310 |
| 311 void _syncNode(RenderNodeWrapper old); |
| 312 |
| 313 void _removeChild(UINode node) { |
| 314 assert(_root is RenderCSSContainer); |
| 315 _root.remove(node._root); |
| 316 super._removeChild(node); |
| 317 } |
| 318 |
| 319 void _remove() { |
| 320 assert(_root != null); |
| 321 _nodeMap.remove(_root); |
| 322 super._remove(); |
| 323 } |
| 324 } |
| 325 |
| 326 final List<UINode> _emptyList = new List<UINode>(); | 326 final List<UINode> _emptyList = new List<UINode>(); |
| 327 | 327 |
| 328 abstract class OneChildListRenderNodeWrapper extends RenderNodeWrapper { | 328 abstract class OneChildListRenderNodeWrapper extends RenderNodeWrapper { |
| 329 | 329 |
| 330 final List<UINode> children; | 330 final List<UINode> children; |
| 331 final Style style; | 331 final Style style; |
| 332 final String inlineStyle; | 332 final String inlineStyle; |
| 333 | 333 |
| 334 OneChildListRenderNodeWrapper({ | 334 OneChildListRenderNodeWrapper({ |
| 335 Object key, | 335 Object key, |
| (...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 _sync(null, _host, _root); | 916 _sync(null, _host, _root); |
| 917 } | 917 } |
| 918 } | 918 } |
| 919 | 919 |
| 920 class Text extends Component { | 920 class Text extends Component { |
| 921 Text(this.data) : super(key: '*text*'); | 921 Text(this.data) : super(key: '*text*'); |
| 922 final String data; | 922 final String data; |
| 923 bool get interchangeable => true; | 923 bool get interchangeable => true; |
| 924 UINode build() => new Paragraph(children: [new TextFragment(data)]); | 924 UINode build() => new Paragraph(children: [new TextFragment(data)]); |
| 925 } | 925 } |
| OLD | NEW |