Commit 2a5fad93 authored by Hixie's avatar Hixie

fn3: Minor cleanup

- Remove the unique objects used as slots since we decided 'null' was
  fine after all
- Rename 'slot' to 'newSlot' when it's used as an argument to change the
  _slot field, to clarify which variable has the newer value
- Remove the RenderObject registry since we'll do listeners a different
  way. This also removes handleEvent for the same reason.
- Remove the TODOs for mount/unmount becoming didMount/didUnmount since
  the methods do in fact do the mounting/unmounting.
parent 555138e6
...@@ -12,7 +12,7 @@ class WidgetFlutterBinding extends SkyBinding { ...@@ -12,7 +12,7 @@ class WidgetFlutterBinding extends SkyBinding {
WidgetFlutterBinding() { WidgetFlutterBinding() {
BuildableElement.scheduleBuildFor = scheduleBuildFor; BuildableElement.scheduleBuildFor = scheduleBuildFor;
_renderViewElement = new RenderObjectToWidgetElement<RenderBox>(describeApp(null)); _renderViewElement = new RenderObjectToWidgetElement<RenderBox>(describeApp(null));
_renderViewElement.mount(null, this); _renderViewElement.mount(null, null);
} }
/// Ensures that there is a SkyBinding object instantiated. /// Ensures that there is a SkyBinding object instantiated.
...@@ -36,19 +36,6 @@ class WidgetFlutterBinding extends SkyBinding { ...@@ -36,19 +36,6 @@ class WidgetFlutterBinding extends SkyBinding {
); );
} }
void handleEvent(sky.Event event, BindingHitTestEntry entry) {
for (HitTestEntry entry in entry.result.path) {
if (entry.target is! RenderObject)
continue;
for (Widget target in RenderObjectElement.getElementsForRenderObject(entry.target)) {
// TODO(ianh): implement event handling
// if (target is ListenerElement)
// target.handleEvent(event);
}
}
super.handleEvent(event, entry);
}
void beginFrame(double timeStamp) { void beginFrame(double timeStamp) {
buildDirtyElements(); buildDirtyElements();
super.beginFrame(timeStamp); super.beginFrame(timeStamp);
...@@ -150,9 +137,9 @@ class RenderObjectToWidgetElement<T extends RenderObject> extends RenderObjectEl ...@@ -150,9 +137,9 @@ class RenderObjectToWidgetElement<T extends RenderObject> extends RenderObjectEl
visitor(_child); visitor(_child);
} }
void mount(Element parent, dynamic slot) { void mount(Element parent, dynamic newSlot) {
assert(parent == null); assert(parent == null);
super.mount(parent, slot); super.mount(parent, newSlot);
_child = updateChild(_child, widget.child, _rootChild); _child = updateChild(_child, widget.child, _rootChild);
} }
......
...@@ -392,8 +392,6 @@ enum _ElementLifecycle { ...@@ -392,8 +392,6 @@ enum _ElementLifecycle {
typedef void ElementVisitor(Element element); typedef void ElementVisitor(Element element);
const Object _uniqueChild = const Object();
abstract class BuildContext { abstract class BuildContext {
InheritedWidget inheritedWidgetOfType(Type targetType); InheritedWidget inheritedWidgetOfType(Type targetType);
} }
...@@ -412,7 +410,7 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -412,7 +410,7 @@ abstract class Element<T extends Widget> implements BuildContext {
/// Information set by parent to define where this child fits in its parent's /// Information set by parent to define where this child fits in its parent's
/// child list. /// child list.
/// ///
/// Subclasses of Element that only have one child should use _uniqueChild for /// Subclasses of Element that only have one child should use null for
/// the slot for that child. /// the slot for that child.
dynamic _slot; dynamic _slot;
...@@ -475,7 +473,7 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -475,7 +473,7 @@ abstract class Element<T extends Widget> implements BuildContext {
/// The updateChild() method returns the new child, if it had to create one, /// The updateChild() method returns the new child, if it had to create one,
/// or the child that was passed in, if it just had to update the child, or /// or the child that was passed in, if it just had to update the child, or
/// null, if it removed the child and did not replace it. /// null, if it removed the child and did not replace it.
Element updateChild(Element child, Widget newWidget, dynamic slot) { Element updateChild(Element child, Widget newWidget, dynamic newSlot) {
if (newWidget == null) { if (newWidget == null) {
if (child != null) if (child != null)
_detachChild(child); _detachChild(child);
...@@ -483,13 +481,13 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -483,13 +481,13 @@ abstract class Element<T extends Widget> implements BuildContext {
} }
if (child != null) { if (child != null) {
if (child.widget == newWidget) { if (child.widget == newWidget) {
if (child._slot != slot) if (child._slot != newSlot)
updateSlotForChild(child, slot); updateSlotForChild(child, newSlot);
return child; return child;
} }
if (_canUpdate(child.widget, newWidget)) { if (_canUpdate(child.widget, newWidget)) {
if (child._slot != slot) if (child._slot != newSlot)
updateSlotForChild(child, slot); updateSlotForChild(child, newSlot);
child.update(newWidget); child.update(newWidget);
assert(child.widget == newWidget); assert(child.widget == newWidget);
return child; return child;
...@@ -498,15 +496,14 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -498,15 +496,14 @@ abstract class Element<T extends Widget> implements BuildContext {
assert(child._parent == null); assert(child._parent == null);
} }
child = newWidget.createElement(); child = newWidget.createElement();
child.mount(this, slot); child.mount(this, newSlot);
assert(child._debugLifecycleState == _ElementLifecycle.mounted); assert(child._debugLifecycleState == _ElementLifecycle.mounted);
return child; return child;
} }
/// Called when an Element is given a new parent shortly after having been /// Called when an Element is given a new parent shortly after having been
/// created. /// created.
// TODO(ianh): rename to didMount void mount(Element parent, dynamic newSlot) {
void mount(Element parent, dynamic slot) {
assert(_debugLifecycleState == _ElementLifecycle.initial); assert(_debugLifecycleState == _ElementLifecycle.initial);
assert(widget != null); assert(widget != null);
assert(_parent == null); assert(_parent == null);
...@@ -514,7 +511,7 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -514,7 +511,7 @@ abstract class Element<T extends Widget> implements BuildContext {
assert(_slot == null); assert(_slot == null);
assert(depth == null); assert(depth == null);
_parent = parent; _parent = parent;
_slot = slot; _slot = newSlot;
_depth = _parent != null ? _parent.depth + 1 : 1; _depth = _parent != null ? _parent.depth + 1 : 1;
assert(() { _debugLifecycleState = _ElementLifecycle.mounted; return true; }); assert(() { _debugLifecycleState = _ElementLifecycle.mounted; return true; });
} }
...@@ -532,25 +529,25 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -532,25 +529,25 @@ abstract class Element<T extends Widget> implements BuildContext {
/// Called by MultiChildRenderObjectElement, and other RenderObjectElement /// Called by MultiChildRenderObjectElement, and other RenderObjectElement
/// subclasses that have multiple children, to update the slot of a particular /// subclasses that have multiple children, to update the slot of a particular
/// child when the child is moved in its child list. /// child when the child is moved in its child list.
void updateSlotForChild(Element child, dynamic slot) { void updateSlotForChild(Element child, dynamic newSlot) {
assert(_debugLifecycleState == _ElementLifecycle.mounted); assert(_debugLifecycleState == _ElementLifecycle.mounted);
assert(child != null); assert(child != null);
assert(child._parent == this); assert(child._parent == this);
void visit(Element element) { void visit(Element element) {
element._updateSlot(slot); element._updateSlot(newSlot);
if (element is! RenderObjectElement) if (element is! RenderObjectElement)
element.visitChildren(visit); element.visitChildren(visit);
} }
visit(child); visit(child);
} }
void _updateSlot(dynamic slot) { void _updateSlot(dynamic newSlot) {
assert(_debugLifecycleState == _ElementLifecycle.mounted); assert(_debugLifecycleState == _ElementLifecycle.mounted);
assert(widget != null); assert(widget != null);
assert(_parent != null); assert(_parent != null);
assert(_parent._debugLifecycleState == _ElementLifecycle.mounted); assert(_parent._debugLifecycleState == _ElementLifecycle.mounted);
assert(depth != null); assert(depth != null);
_slot = slot; _slot = newSlot;
} }
void _detachChild(Element child) { void _detachChild(Element child) {
...@@ -577,7 +574,6 @@ abstract class Element<T extends Widget> implements BuildContext { ...@@ -577,7 +574,6 @@ abstract class Element<T extends Widget> implements BuildContext {
/// Called when an Element is removed from the tree. /// Called when an Element is removed from the tree.
/// Currently, an Element removed from the tree never returns. /// Currently, an Element removed from the tree never returns.
// TODO(ianh): rename to didUnmount
void unmount() { void unmount() {
assert(_debugLifecycleState == _ElementLifecycle.mounted); assert(_debugLifecycleState == _ElementLifecycle.mounted);
assert(widget != null); assert(widget != null);
...@@ -616,8 +612,8 @@ abstract class BuildableElement<T extends Widget> extends Element<T> { ...@@ -616,8 +612,8 @@ abstract class BuildableElement<T extends Widget> extends Element<T> {
bool get dirty => _dirty; bool get dirty => _dirty;
bool _dirty = true; bool _dirty = true;
void mount(Element parent, dynamic slot) { void mount(Element parent, dynamic newSlot) {
super.mount(parent, slot); super.mount(parent, newSlot);
assert(_child == null); assert(_child == null);
rebuild(); rebuild();
assert(_child != null); assert(_child != null);
...@@ -794,23 +790,11 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element ...@@ -794,23 +790,11 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element
return null; return null;
} }
static Map<RenderObject, RenderObjectElement> _registry = new Map<RenderObject, RenderObjectElement>(); void mount(Element parent, dynamic newSlot) {
static Iterable<RenderObjectElement> getElementsForRenderObject(RenderObject renderObject) sync* { super.mount(parent, newSlot);
Element target = _registry[renderObject];
while (target != null) {
yield target;
target = target._parent;
if (target is RenderObjectElement)
break;
}
}
void mount(Element parent, dynamic slot) {
super.mount(parent, slot);
_registry[renderObject] = this;
assert(_ancestorRenderObjectElement == null); assert(_ancestorRenderObjectElement == null);
_ancestorRenderObjectElement = _findAncestorRenderObjectElement(); _ancestorRenderObjectElement = _findAncestorRenderObjectElement();
_ancestorRenderObjectElement?.insertChildRenderObject(renderObject, slot); _ancestorRenderObjectElement?.insertChildRenderObject(renderObject, newSlot);
ParentDataElement parentDataElement = _findAncestorParentDataElement(); ParentDataElement parentDataElement = _findAncestorParentDataElement();
if (parentDataElement != null) if (parentDataElement != null)
updateParentData(parentDataElement.widget); updateParentData(parentDataElement.widget);
...@@ -826,7 +810,6 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element ...@@ -826,7 +810,6 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element
void unmount() { void unmount() {
super.unmount(); super.unmount();
widget.didUnmountRenderObject(renderObject); widget.didUnmountRenderObject(renderObject);
_registry.remove(renderObject);
} }
void updateParentData(ParentDataWidget parentData) { void updateParentData(ParentDataWidget parentData) {
...@@ -837,10 +820,10 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element ...@@ -837,10 +820,10 @@ abstract class RenderObjectElement<T extends RenderObjectWidget> extends Element
parentData.applyParentData(renderObject); parentData.applyParentData(renderObject);
} }
void _updateSlot(dynamic slot) { void _updateSlot(dynamic newSlot) {
assert(_slot != slot); assert(_slot != newSlot);
super._updateSlot(slot); super._updateSlot(newSlot);
assert(_slot == slot); assert(_slot == newSlot);
_ancestorRenderObjectElement.moveChildRenderObject(renderObject, _slot); _ancestorRenderObjectElement.moveChildRenderObject(renderObject, _slot);
} }
...@@ -884,21 +867,21 @@ class OneChildRenderObjectElement<T extends OneChildRenderObjectWidget> extends ...@@ -884,21 +867,21 @@ class OneChildRenderObjectElement<T extends OneChildRenderObjectWidget> extends
visitor(_child); visitor(_child);
} }
void mount(Element parent, dynamic slot) { void mount(Element parent, dynamic newSlot) {
super.mount(parent, slot); super.mount(parent, newSlot);
_child = updateChild(_child, widget.child, _uniqueChild); _child = updateChild(_child, widget.child, null);
} }
void update(T newWidget) { void update(T newWidget) {
super.update(newWidget); super.update(newWidget);
assert(widget == newWidget); assert(widget == newWidget);
_child = updateChild(_child, widget.child, _uniqueChild); _child = updateChild(_child, widget.child, null);
} }
void insertChildRenderObject(RenderObject child, dynamic slot) { void insertChildRenderObject(RenderObject child, dynamic slot) {
final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer
assert(renderObject is RenderObjectWithChildMixin); assert(renderObject is RenderObjectWithChildMixin);
assert(slot == _uniqueChild); assert(slot == null);
renderObject.child = child; renderObject.child = child;
assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer assert(renderObject == this.renderObject); // TODO(ianh): Remove this once the analyzer is cleverer
} }
...@@ -967,8 +950,8 @@ class MultiChildRenderObjectElement<T extends MultiChildRenderObjectWidget> exte ...@@ -967,8 +950,8 @@ class MultiChildRenderObjectElement<T extends MultiChildRenderObjectWidget> exte
visitor(child); visitor(child);
} }
void mount(Element parent, dynamic slot) { void mount(Element parent, dynamic newSlot) {
super.mount(parent, slot); super.mount(parent, newSlot);
_children = new List<Element>(widget.children.length); _children = new List<Element>(widget.children.length);
Element previousChild; Element previousChild;
for (int i = _children.length - 1; i >= 0; --i) { for (int i = _children.length - 1; i >= 0; --i) {
......
...@@ -18,8 +18,6 @@ class RootComponentState extends ComponentState<RootComponent> { ...@@ -18,8 +18,6 @@ class RootComponentState extends ComponentState<RootComponent> {
Widget build(BuildContext context) => child; Widget build(BuildContext context) => child;
} }
const Object _rootSlot = const Object();
class WidgetTester { class WidgetTester {
void walkElements(ElementVisitor visitor) { void walkElements(ElementVisitor visitor) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment