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:mirrors'; | 9 import 'dart:mirrors'; |
10 import 'dart:sky' as sky; | 10 import 'dart:sky' as sky; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 super.removeChild(node); | 320 super.removeChild(node); |
321 } | 321 } |
322 | 322 |
323 void _remove() { | 323 void _remove() { |
324 assert(root != null); | 324 assert(root != null); |
325 _nodeMap.remove(root); | 325 _nodeMap.remove(root); |
326 super._remove(); | 326 super._remove(); |
327 } | 327 } |
328 } | 328 } |
329 | 329 |
330 abstract class OneChildRenderNodeWrapper extends RenderNodeWrapper { | |
331 final UINode child; | |
332 | |
333 OneChildRenderNodeWrapper({ this.child, Object key }) : super(key: key); | |
334 | |
335 void insert(RenderNodeWrapper child, dynamic slot) { | |
336 assert(slot == null); | |
337 root.child = child.root; | |
338 } | |
339 | |
340 void syncRenderNode(RenderNodeWrapper old) { | |
341 super.syncRenderNode(old); | |
342 UINode oldChild = old == null ? null : (old as OneChildRenderNodeWrapper).ch ild; | |
343 syncChild(child, oldChild, null); | |
344 } | |
345 | |
346 void _remove() { | |
347 assert(child != null); | |
348 removeChild(child); | |
349 super._remove(); | |
350 } | |
351 } | |
352 | |
353 class Padding extends OneChildRenderNodeWrapper { | |
354 RenderPadding root; | |
355 final EdgeDims padding; | |
356 | |
357 Padding({ this.padding, UINode child, Object key }) | |
358 : super(child: child, key: key); | |
359 | |
360 RenderPadding createNode() => new RenderPadding(padding: padding); | |
361 | |
362 void syncRenderNode(Padding old) { | |
363 super.syncRenderNode(old); | |
364 root.padding = padding; | |
365 } | |
366 } | |
367 | |
368 class DecoratedBox extends OneChildRenderNodeWrapper { | |
369 RenderDecoratedBox root; | |
370 final BoxDecoration decoration; | |
371 | |
372 DecoratedBox({ this.decoration, UINode child, Object key }) | |
373 : super(child: child, key: key); | |
374 | |
375 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati on); | |
376 | |
377 void syncRenderNode(DecoratedBox old) { | |
378 super.syncRenderNode(old); | |
379 root.decoration = decoration; | |
380 } | |
381 } | |
382 | |
383 class SizedBox extends OneChildRenderNodeWrapper { | |
384 RenderSizedBox root; | |
385 final sky.Size desiredSize; | |
386 | |
387 SizedBox({ this.desiredSize, UINode child, Object key }) | |
388 : super(child: child, key: key); | |
389 | |
390 RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize); | |
391 | |
392 void syncRenderNode(DecoratedBox old) { | |
393 super.syncRenderNode(old); | |
394 root.desiredSize = desiredSize; | |
395 } | |
396 } | |
397 | |
Hixie
2015/06/02 21:52:21
Man, this could really benefit from macros.
| |
330 final List<UINode> _emptyList = new List<UINode>(); | 398 final List<UINode> _emptyList = new List<UINode>(); |
331 | 399 |
332 abstract class OneChildListRenderNodeWrapper extends RenderNodeWrapper { | 400 abstract class OneChildListRenderNodeWrapper extends RenderNodeWrapper { |
333 | 401 |
334 // In OneChildListRenderNodeWrapper subclasses, slots are RenderNode nodes | 402 // In OneChildListRenderNodeWrapper subclasses, slots are RenderNode nodes |
335 // to use as the "insert before" sibling in ContainerRenderNodeMixin.add() cal ls | 403 // to use as the "insert before" sibling in ContainerRenderNodeMixin.add() cal ls |
336 | 404 |
337 final List<UINode> children; | 405 final List<UINode> children; |
338 | 406 |
339 OneChildListRenderNodeWrapper({ | 407 OneChildListRenderNodeWrapper({ |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 if (_isBuilding || _dirty || _defunct) | 841 if (_isBuilding || _dirty || _defunct) |
774 return; | 842 return; |
775 | 843 |
776 _dirty = true; | 844 _dirty = true; |
777 _scheduleComponentForRender(this); | 845 _scheduleComponentForRender(this); |
778 } | 846 } |
779 | 847 |
780 UINode build(); | 848 UINode build(); |
781 } | 849 } |
782 | 850 |
851 class Container extends Component { | |
852 final UINode child; | |
853 final EdgeDims margin; | |
854 final BoxDecoration decoration; | |
855 final sky.Size desiredSize; | |
856 final EdgeDims padding; | |
857 | |
858 Container({ | |
859 Object key, | |
860 this.child, | |
861 this.margin, | |
862 this.decoration, | |
863 this.desiredSize, | |
864 this.padding | |
865 }) : super(key: key); | |
866 | |
867 UINode build() { | |
868 UINode current = child; | |
869 | |
870 if (padding != null) | |
871 current = new Padding(padding: padding, child: current); | |
872 | |
873 if (decoration != null) | |
874 current = new DecoratedBox(decoration: decoration, child: current); | |
875 | |
876 if (desiredSize != null) | |
877 current = new SizedBox(desiredSize: desiredSize, child: current); | |
878 | |
879 if (margin != null) | |
880 current = new Padding(padding: margin, child: current); | |
881 | |
882 return current; | |
883 } | |
884 } | |
885 | |
783 class _AppView extends AppView { | 886 class _AppView extends AppView { |
784 _AppView() : super(null); | 887 _AppView() : super(null); |
785 | 888 |
786 void dispatchPointerEvent(sky.PointerEvent event, HitTestResult result) { | 889 void dispatchPointerEvent(sky.PointerEvent event, HitTestResult result) { |
787 super.dispatchPointerEvent(event, result); | 890 super.dispatchPointerEvent(event, result); |
788 | 891 |
789 UINode target = RenderNodeWrapper._getMounted(result.path.first); | 892 UINode target = RenderNodeWrapper._getMounted(result.path.first); |
790 | 893 |
791 // TODO(rafaelw): StopPropagation? | 894 // TODO(rafaelw): StopPropagation? |
792 while (target != null) { | 895 while (target != null) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
853 | 956 |
854 class Rectangle extends RenderNodeWrapper { | 957 class Rectangle extends RenderNodeWrapper { |
855 RenderSolidColor root; | 958 RenderSolidColor root; |
856 RenderSolidColor createNode() => | 959 RenderSolidColor createNode() => |
857 new RenderSolidColor(color, desiredSize: new sky.Size(40.0, 130.0)); | 960 new RenderSolidColor(color, desiredSize: new sky.Size(40.0, 130.0)); |
858 | 961 |
859 final int color; | 962 final int color; |
860 | 963 |
861 Rectangle(this.color, { Object key }) : super(key: key); | 964 Rectangle(this.color, { Object key }) : super(key: key); |
862 } | 965 } |
OLD | NEW |