提交 cf4733f2 编写于 作者: H Hixie

[Effen] Add a "parent" pointer to Node.

Per discussion about https://codereview.chromium.org/1093633002 it
appears that we don't have a way around having a parent pointer after
all, so this exposes it.

It also renames setAsChild() to adoptChild() for better readability.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1134593007
上级 b8b22315
......@@ -78,11 +78,11 @@ abstract class RenderNode extends Node {
child.parentData = new ParentData();
}
void setAsChild(RenderNode child) { // only for use by subclasses
void adoptChild(RenderNode child) { // only for use by subclasses
// call this whenever you decide a node is a child
assert(child != null);
setupPos(child);
super.setAsChild(child);
super.adoptChild(child);
}
void dropChild(RenderNode child) { // only for use by subclasses
assert(child != null);
......@@ -149,7 +149,7 @@ abstract class ContainerRenderNodeMixin<ChildType extends RenderNode, ParentData
assert(child != before);
assert(child != _firstChild);
assert(child != _lastChild);
setAsChild(child);
adoptChild(child);
assert(child.parentData is ParentDataType);
assert(child.parentData.nextSibling == null);
assert(child.parentData.previousSibling == null);
......
......@@ -44,15 +44,21 @@ class Node {
}
detachChildren() { } // workaround for lack of inter-class mixins in Dart
void setAsChild(Node child) { // only for use by subclasses
Node _parent;
Node get parent => _parent;
void adoptChild(Node child) { // only for use by subclasses
assert(child != null);
assert(child._parent == null);
child._parent = this;
if (attached)
child.attach();
redepthChild(child);
}
void dropChild(Node child) { // only for use by subclasses
assert(child != null);
assert(child._parent == this);
assert(child.attached == attached);
child._parent = null;
if (attached)
child.detach();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册