Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(861)

Side by Side Diff: sky/sdk/lib/widgets/widget.dart

Issue 1184823006: Settings menu item in stock2 doesn't work (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:mirrors'; 7 import 'dart:mirrors';
8 import 'dart:sky' as sky; 8 import 'dart:sky' as sky;
9 9
10 import '../app/view.dart'; 10 import '../app/view.dart';
11 import '../rendering/box.dart'; 11 import '../rendering/box.dart';
12 import '../rendering/object.dart'; 12 import '../rendering/object.dart';
13 13
14 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde rSide, EdgeDims; 14 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde rSide, EdgeDims;
15 export '../rendering/flex.dart' show FlexDirection; 15 export '../rendering/flex.dart' show FlexDirection;
16 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path; 16 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path;
17 17
18 final bool _shouldLogRenderDuration = false; 18 final bool _shouldLogRenderDuration = false;
19 19
20 // All Effen nodes derive from Widget. All nodes have a _parent, a _key and 20 // All Effen nodes derive from Widget. All nodes have a _parent, a _key and
21 // can be sync'd. 21 // can be sync'd.
22 abstract class Widget { 22 abstract class Widget {
23 23
24 Widget({ String key }) { 24 Widget({ String key }) {
25 _key = key != null ? key : runtimeType.toString(); 25 _key = key != null ? key : runtimeType.toString();
26 assert(this is AbstractWidgetRoot || _inRenderDirtyComponents); // you shoul d not build the UI tree ahead of time, build it only during build() 26 assert(this is AbstractWidgetRoot || this is App || _inRenderDirtyComponents ); // you should not build the UI tree ahead of time, build it only during build ()
27 } 27 }
28 28
29 String _key; 29 String _key;
30 String get key => _key; 30 String get key => _key;
31 31
32 Widget _parent; 32 Widget _parent;
33 Widget get parent => _parent; 33 Widget get parent => _parent;
34 34
35 bool _mounted = false; 35 bool _mounted = false;
36 bool _wasMounted = false; 36 bool _wasMounted = false;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 RenderObject createNode(); 467 RenderObject createNode();
468 468
469 void insert(RenderObjectWrapper child, dynamic slot); 469 void insert(RenderObjectWrapper child, dynamic slot);
470 470
471 static final Map<RenderObject, RenderObjectWrapper> _nodeMap = 471 static final Map<RenderObject, RenderObjectWrapper> _nodeMap =
472 new HashMap<RenderObject, RenderObjectWrapper>(); 472 new HashMap<RenderObject, RenderObjectWrapper>();
473 473
474 static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node]; 474 static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node];
475 475
476 void _sync(Widget old, dynamic slot) { 476 void _sync(Widget old, dynamic slot) {
477 assert(parent != null); 477 assert(parent != null || this is RenderViewWrapper);
Hixie 2015/06/17 19:21:25 This should never be called for RenderViewWrapper.
478 if (old == null) { 478 if (old == null) {
479 _root = createNode(); 479 _root = createNode();
480 var ancestor = findAncestor(RenderObjectWrapper); 480 var ancestor = findAncestor(RenderObjectWrapper);
481 if (ancestor is RenderObjectWrapper) 481 if (ancestor is RenderObjectWrapper)
482 ancestor.insert(this, slot); 482 ancestor.insert(this, slot);
483 } else { 483 } else {
484 _root = old.root; 484 _root = old.root;
485 } 485 }
486 assert(_root == root); // in case a subclass reintroduces it 486 assert(_root == root); // in case a subclass reintroduces it
487 assert(root != null); 487 assert(root != null);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 while (target != null && target.root == targetRoot) { 760 while (target != null && target.root == targetRoot) {
761 if (target is Listener) 761 if (target is Listener)
762 target._handleEvent(event); 762 target._handleEvent(event);
763 target = target._parent; 763 target = target._parent;
764 } 764 }
765 } 765 }
766 } 766 }
767 767
768 } 768 }
769 769
770 abstract class App extends Component {
771 }
772
770 abstract class AbstractWidgetRoot extends Component { 773 abstract class AbstractWidgetRoot extends Component {
771 774
772 AbstractWidgetRoot({ RenderView renderViewOverride }) : super(stateful: true) { 775 AbstractWidgetRoot() : super(stateful: true) {
773 WidgetAppView.initWidgetAppView(renderViewOverride: renderViewOverride);
774 _mounted = true; 776 _mounted = true;
775 _scheduleComponentForRender(this); 777 _scheduleComponentForRender(this);
776 } 778 }
777 779
778 void syncFields(AbstractWidgetRoot source) { 780 void syncFields(AbstractWidgetRoot source) {
779 assert(false); 781 assert(false);
780 // if we get here, it implies that we have a parent 782 // if we get here, it implies that we have a parent
781 } 783 }
782 784
783 void _buildIfDirty() { 785 void _buildIfDirty() {
784 assert(_dirty); 786 assert(_dirty);
785 assert(_mounted); 787 assert(_mounted);
786 assert(parent == null); 788 assert(parent == null);
787 _sync(null, null); 789 _sync(null, null);
788 } 790 }
789 791
790 } 792 }
791 793
792 abstract class App extends AbstractWidgetRoot { 794 class RenderViewWrapper extends OneChildRenderObjectWrapper {
795 RenderViewWrapper({ String key, Widget child }) : super(key: key, child: child );
796 RenderView get root => super.root;
797 RenderView createNode() => WidgetAppView._appView.renderView;
798 }
793 799
794 App({ RenderView renderViewOverride }) : super(renderViewOverride: renderViewO verride); 800 class AppContainer extends AbstractWidgetRoot {
801 AppContainer(this.app);
802 final App app;
803 Widget build() => new RenderViewWrapper(child: app);
804 }
795 805
796 void _buildIfDirty() { 806 void runApp(App app, { RenderView renderViewOverride }) {
797 super._buildIfDirty(); 807 WidgetAppView.initWidgetAppView(renderViewOverride: renderViewOverride);
798 808 new AppContainer(app);
799 if (root.parent == null) {
800 // we haven't attached it yet
801 WidgetAppView._appView.root = root;
802 }
803 assert(root.parent is RenderView);
804 }
805
806 } 809 }
807 810
808 typedef Widget Builder(); 811 typedef Widget Builder();
809 812
810 class RenderBoxToWidgetAdapter extends AbstractWidgetRoot { 813 class RenderBoxToWidgetAdapter extends AbstractWidgetRoot {
811 814
812 RenderBoxToWidgetAdapter( 815 RenderBoxToWidgetAdapter(
813 RenderObjectWithChildMixin<RenderBox> container, 816 RenderObjectWithChildMixin<RenderBox> container,
814 this.builder 817 this.builder
815 ) : _container = container, super() { 818 ) : _container = container, super() {
(...skipping 24 matching lines...) Expand all
840 if (root.parent == null) { 843 if (root.parent == null) {
841 // we haven't attached it yet 844 // we haven't attached it yet
842 assert(_container.child == null); 845 assert(_container.child == null);
843 _container.child = root; 846 _container.child = root;
844 } 847 }
845 assert(root.parent == _container); 848 assert(root.parent == _container);
846 } 849 }
847 850
848 Widget build() => builder(); 851 Widget build() => builder();
849 } 852 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698