Chromium Code Reviews| Index: sky/framework/node.dart |
| diff --git a/sky/framework/node.dart b/sky/framework/node.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4deefb0f9ae45b695f3d34522f683a56d429500f |
| --- /dev/null |
| +++ b/sky/framework/node.dart |
| @@ -0,0 +1,52 @@ |
| +library node; |
| + |
| +class Node { |
| + |
| + // nodes always have an order greater than their ancestors'. |
| + // there's no guarantee regarding order between siblings |
| + |
| + int _order = 0; |
|
ojan
2015/04/23 20:28:32
bikeshed: I might call this _treeDepth. It took me
Hixie
2015/04/23 20:45:13
Makes sense. It's not quite the depth (e.g. if you
ojan
2015/04/23 21:12:36
Hmmm...then I think I don't understand what this d
|
| + int get order => _order; |
| + void reorderChild(Node child) { // internal, do not call |
| + assert(child._attached == _attached); |
| + if (child._order <= _order) { |
| + child._order = _order + 1; |
| + child.reorderChildren(); |
| + } |
| + } |
| + void reorderChildren() { // internal, do not call |
| + // override this in subclasses with child nodes |
| + // simply call reorderChild(child) for each child |
| + } |
| + |
| + bool _attached = false; |
| + bool get attached => _attached; |
| + void attach() { |
| + // override this in subclasses with child nodes |
| + // simply call attach() for each child then call your superclass |
| + _attached = true; |
| + attachChildren(); |
| + } |
| + attachChildren() { } // workaround for lack of inter-class mixins in Dart |
| + void detach() { |
| + // override this in subclasses with child nodes |
| + // simply call detach() for each child then call your superclass |
| + _attached = false; |
| + detachChildren(); |
| + } |
| + detachChildren() { } // workaround for lack of inter-class mixins in Dart |
| + |
| + void setAsChild(RenderNode child) { // only for use by subclasses |
| + assert(child != null); |
| + if (attached) |
| + child.attach(); |
| + reorderChild(child); |
| + } |
| + void dropChild(RenderNode child) { // only for use by subclasses |
| + assert(child != null); |
| + assert(child.attached == attached); |
| + if (attached) |
| + child.detach(); |
| + } |
| + |
| +} |