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

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

Issue 1215023002: Fix theme changing: turns out we were not reparenting stateful surviving nodes when their parents c… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « sky/sdk/lib/painting/box_painter.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '../base/hit_test.dart'; 10 import '../base/hit_test.dart';
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 Widget get parent => _parent; 43 Widget get parent => _parent;
44 44
45 bool _mounted = false; 45 bool _mounted = false;
46 bool _wasMounted = false; 46 bool _wasMounted = false;
47 bool get mounted => _mounted; 47 bool get mounted => _mounted;
48 static bool _notifyingMountStatus = false; 48 static bool _notifyingMountStatus = false;
49 static List<Widget> _mountedChanged = new List<Widget>(); 49 static List<Widget> _mountedChanged = new List<Widget>();
50 50
51 void setParent(Widget newParent) { 51 void setParent(Widget newParent) {
52 assert(!_notifyingMountStatus); 52 assert(!_notifyingMountStatus);
53 if (_parent == newParent)
54 return;
53 _parent = newParent; 55 _parent = newParent;
54 if (newParent == null) { 56 if (newParent == null) {
55 if (_mounted) { 57 if (_mounted) {
56 _mounted = false; 58 _mounted = false;
57 _mountedChanged.add(this); 59 _mountedChanged.add(this);
58 } 60 }
59 } else { 61 } else {
60 assert(newParent._mounted); 62 assert(newParent._mounted);
61 if (_parent._mounted != _mounted) { 63 if (_parent._mounted != _mounted) {
62 _mounted = _parent._mounted; 64 _mounted = _parent._mounted;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 removeChild(oldNode); 141 removeChild(oldNode);
140 assert(!oldNode.mounted); 142 assert(!oldNode.mounted);
141 return null; 143 return null;
142 } 144 }
143 145
144 if (oldNode != null) { 146 if (oldNode != null) {
145 if (oldNode.runtimeType == node.runtimeType && oldNode.key == node.key) { 147 if (oldNode.runtimeType == node.runtimeType && oldNode.key == node.key) {
146 if (node._retainStatefulNodeIfPossible(oldNode)) { 148 if (node._retainStatefulNodeIfPossible(oldNode)) {
147 assert(oldNode.mounted); 149 assert(oldNode.mounted);
148 assert(!node.mounted); 150 assert(!node.mounted);
151 oldNode.setParent(this);
149 oldNode._sync(node, slot); 152 oldNode._sync(node, slot);
150 assert(oldNode.root is RenderObject); 153 assert(oldNode.root is RenderObject);
151 return oldNode; 154 return oldNode;
152 } 155 }
153 } else { 156 } else {
154 assert(oldNode.mounted); 157 assert(oldNode.mounted);
155 oldNode.detachRoot(); 158 oldNode.detachRoot();
156 removeChild(oldNode); 159 removeChild(oldNode);
157 oldNode = null; 160 oldNode = null;
158 } 161 }
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 } 953 }
951 954
952 class AppContainer extends AbstractWidgetRoot { 955 class AppContainer extends AbstractWidgetRoot {
953 AppContainer(this.app) { 956 AppContainer(this.app) {
954 assert(SkyBinding.instance is WidgetSkyBinding); 957 assert(SkyBinding.instance is WidgetSkyBinding);
955 } 958 }
956 final App app; 959 final App app;
957 Widget build() => new RenderViewWrapper(child: app); 960 Widget build() => new RenderViewWrapper(child: app);
958 } 961 }
959 962
960 void runApp(App app, { RenderView renderViewOverride }) { 963 void runApp(App app, { RenderView renderViewOverride, bool enableProfilingLoop: false }) {
961 WidgetSkyBinding.initWidgetSkyBinding(renderViewOverride: renderViewOverride); 964 WidgetSkyBinding.initWidgetSkyBinding(renderViewOverride: renderViewOverride);
962 new AppContainer(app); 965 new AppContainer(app);
966 if (enableProfilingLoop) {
967 new Timer.periodic(const Duration(milliseconds: 20), (_) {
968 app.scheduleBuild();
969 });
970 }
963 } 971 }
964 972
965 typedef Widget Builder(); 973 typedef Widget Builder();
966 974
967 class RenderBoxToWidgetAdapter extends AbstractWidgetRoot { 975 class RenderBoxToWidgetAdapter extends AbstractWidgetRoot {
968 976
969 RenderBoxToWidgetAdapter( 977 RenderBoxToWidgetAdapter(
970 RenderObjectWithChildMixin<RenderBox> container, 978 RenderObjectWithChildMixin<RenderBox> container,
971 this.builder 979 this.builder
972 ) : _container = container, super() { 980 ) : _container = container, super() {
(...skipping 24 matching lines...) Expand all
997 if (root.parent == null) { 1005 if (root.parent == null) {
998 // we haven't attached it yet 1006 // we haven't attached it yet
999 assert(_container.child == null); 1007 assert(_container.child == null);
1000 _container.child = root; 1008 _container.child = root;
1001 } 1009 }
1002 assert(root.parent == _container); 1010 assert(root.parent == _container);
1003 } 1011 }
1004 1012
1005 Widget build() => builder(); 1013 Widget build() => builder();
1006 } 1014 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/painting/box_painter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698