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

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

Issue 1213473003: Add asserts to catch potential misuses of the rendering framework. (Closed) Base URL: https://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
« no previous file with comments | « sky/sdk/lib/rendering/stack.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 '../rendering/box.dart'; 5 import '../rendering/box.dart';
6 import '../rendering/object.dart'; 6 import '../rendering/object.dart';
7 import '../theme/view_configuration.dart'; 7 import '../theme/view_configuration.dart';
8 import 'widget.dart'; 8 import 'widget.dart';
9 9
10 enum ScaffoldSlots { 10 enum ScaffoldSlots {
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 Map<ScaffoldSlots, RenderBox> _slots = new Map<ScaffoldSlots, RenderBox>(); 34 Map<ScaffoldSlots, RenderBox> _slots = new Map<ScaffoldSlots, RenderBox>();
35 RenderBox operator[] (ScaffoldSlots slot) => _slots[slot]; 35 RenderBox operator[] (ScaffoldSlots slot) => _slots[slot];
36 void operator[]= (ScaffoldSlots slot, RenderBox value) { 36 void operator[]= (ScaffoldSlots slot, RenderBox value) {
37 RenderBox old = _slots[slot]; 37 RenderBox old = _slots[slot];
38 if (old == value) 38 if (old == value)
39 return; 39 return;
40 if (old != null) 40 if (old != null)
41 dropChild(old); 41 dropChild(old);
42 _slots[slot] = value; 42 if (value == null) {
43 if (value != null) 43 _slots.remove(slot);
44 } else {
45 _slots[slot] = value;
44 adoptChild(value); 46 adoptChild(value);
47 }
45 markNeedsLayout(); 48 markNeedsLayout();
46 } 49 }
47 50
48 void attachChildren() { 51 void attachChildren() {
49 for (ScaffoldSlots slot in ScaffoldSlots.values) { 52 for (ScaffoldSlots slot in ScaffoldSlots.values) {
50 RenderBox box = _slots[slot]; 53 RenderBox box = _slots[slot];
51 if (box != null) 54 if (box != null)
52 box.attach(); 55 box.attach();
53 } 56 }
54 } 57 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 114 }
112 if (_slots[ScaffoldSlots.drawer] != null) { 115 if (_slots[ScaffoldSlots.drawer] != null) {
113 RenderBox drawer = _slots[ScaffoldSlots.drawer]; 116 RenderBox drawer = _slots[ScaffoldSlots.drawer];
114 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: size.width, minH eight: size.height, maxHeight: size.height)); 117 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: size.width, minH eight: size.height, maxHeight: size.height));
115 assert(drawer.parentData is BoxParentData); 118 assert(drawer.parentData is BoxParentData);
116 drawer.parentData.position = Point.origin; 119 drawer.parentData.position = Point.origin;
117 } 120 }
118 if (_slots[ScaffoldSlots.floatingActionButton] != null) { 121 if (_slots[ScaffoldSlots.floatingActionButton] != null) {
119 RenderBox floatingActionButton = _slots[ScaffoldSlots.floatingActionButton ]; 122 RenderBox floatingActionButton = _slots[ScaffoldSlots.floatingActionButton ];
120 Size area = new Size(size.width - kButtonX, size.height - kButtonY); 123 Size area = new Size(size.width - kButtonX, size.height - kButtonY);
121 floatingActionButton.layout(new BoxConstraints.loose(area)); 124 floatingActionButton.layout(new BoxConstraints.loose(area), parentUsesSize : true);
122 assert(floatingActionButton.parentData is BoxParentData); 125 assert(floatingActionButton.parentData is BoxParentData);
123 floatingActionButton.parentData.position = (area - floatingActionButton.si ze).toPoint(); 126 floatingActionButton.parentData.position = (area - floatingActionButton.si ze).toPoint();
124 } 127 }
125 } 128 }
126 129
127 void paint(RenderCanvas canvas) { 130 void paint(RenderCanvas canvas) {
128 for (ScaffoldSlots slot in [ScaffoldSlots.body, ScaffoldSlots.statusBar, Sca ffoldSlots.toolbar, ScaffoldSlots.floatingActionButton, ScaffoldSlots.drawer]) { 131 for (ScaffoldSlots slot in [ScaffoldSlots.body, ScaffoldSlots.statusBar, Sca ffoldSlots.toolbar, ScaffoldSlots.floatingActionButton, ScaffoldSlots.drawer]) {
129 RenderBox box = _slots[slot]; 132 RenderBox box = _slots[slot];
130 if (box != null) { 133 if (box != null) {
131 assert(box.parentData is BoxParentData); 134 assert(box.parentData is BoxParentData);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 void syncRenderObject(Widget old) { 217 void syncRenderObject(Widget old) {
215 super.syncRenderObject(old); 218 super.syncRenderObject(old);
216 _toolbar = syncChild(_toolbar, old is Scaffold ? old._toolbar : null, Scaffo ldSlots.toolbar); 219 _toolbar = syncChild(_toolbar, old is Scaffold ? old._toolbar : null, Scaffo ldSlots.toolbar);
217 _body = syncChild(_body, old is Scaffold ? old._body : null, ScaffoldSlots.b ody); 220 _body = syncChild(_body, old is Scaffold ? old._body : null, ScaffoldSlots.b ody);
218 _statusBar = syncChild(_statusBar, old is Scaffold ? old._statusBar : null, ScaffoldSlots.statusBar); 221 _statusBar = syncChild(_statusBar, old is Scaffold ? old._statusBar : null, ScaffoldSlots.statusBar);
219 _drawer = syncChild(_drawer, old is Scaffold ? old._drawer : null, ScaffoldS lots.drawer); 222 _drawer = syncChild(_drawer, old is Scaffold ? old._drawer : null, ScaffoldS lots.drawer);
220 _floatingActionButton = syncChild(_floatingActionButton, old is Scaffold ? o ld._floatingActionButton : null, ScaffoldSlots.floatingActionButton); 223 _floatingActionButton = syncChild(_floatingActionButton, old is Scaffold ? o ld._floatingActionButton : null, ScaffoldSlots.floatingActionButton);
221 } 224 }
222 225
223 } 226 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/rendering/stack.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698