Index: sky/sdk/lib/framework/fn2.dart |
diff --git a/sky/sdk/lib/framework/fn2.dart b/sky/sdk/lib/framework/fn2.dart |
index 4c0b3e6d36680637a0d3681c110d84cd419726cd..7bda517d00195ba777cd952fac1d92ad10d03340 100644 |
--- a/sky/sdk/lib/framework/fn2.dart |
+++ b/sky/sdk/lib/framework/fn2.dart |
@@ -157,10 +157,11 @@ abstract class UINode { |
// Component nodes with annotations, such as event listeners, |
// stylistic information, etc. |
abstract class TagNode extends UINode { |
- UINode content; |
TagNode(UINode content, { Object key }) : this.content = content, super(key: key); |
+ UINode content; |
+ |
void _sync(UINode old, dynamic slot) { |
UINode oldContent = old == null ? null : (old as TagNode).content; |
content = syncChild(content, oldContent, slot); |
@@ -173,12 +174,12 @@ abstract class TagNode extends UINode { |
removeChild(content); |
super.remove(); |
} |
+ |
} |
class ParentDataNode extends TagNode { |
- final ParentData parentData; |
- |
ParentDataNode(UINode content, this.parentData, { Object key }): super(content, key: key); |
+ final ParentData parentData; |
} |
typedef void GestureEventListener(sky.GestureEvent e); |
@@ -186,6 +187,36 @@ typedef void PointerEventListener(sky.PointerEvent e); |
typedef void EventListener(sky.Event e); |
class EventListenerNode extends TagNode { |
+ |
+ EventListenerNode(UINode content, { |
+ EventListener onWheel, |
+ GestureEventListener onGestureFlingCancel, |
+ GestureEventListener onGestureFlingStart, |
+ GestureEventListener onGestureScrollStart, |
+ GestureEventListener onGestureScrollUpdate, |
+ GestureEventListener onGestureTap, |
+ GestureEventListener onGestureTapDown, |
+ PointerEventListener onPointerCancel, |
+ PointerEventListener onPointerDown, |
+ PointerEventListener onPointerMove, |
+ PointerEventListener onPointerUp, |
+ Map<String, sky.EventListener> custom |
+ }) : listeners = _createListeners( |
+ onWheel: onWheel, |
+ onGestureFlingCancel: onGestureFlingCancel, |
+ onGestureFlingStart: onGestureFlingStart, |
+ onGestureScrollUpdate: onGestureScrollUpdate, |
+ onGestureScrollStart: onGestureScrollStart, |
+ onGestureTap: onGestureTap, |
+ onGestureTapDown: onGestureTapDown, |
+ onPointerCancel: onPointerCancel, |
+ onPointerDown: onPointerDown, |
+ onPointerMove: onPointerMove, |
+ onPointerUp: onPointerUp, |
+ custom: custom |
+ ), |
+ super(content); |
+ |
final Map<String, sky.EventListener> listeners; |
static Map<String, sky.EventListener> _createListeners({ |
@@ -232,41 +263,13 @@ class EventListenerNode extends TagNode { |
return listeners; |
} |
- EventListenerNode(UINode content, { |
- EventListener onWheel, |
- GestureEventListener onGestureFlingCancel, |
- GestureEventListener onGestureFlingStart, |
- GestureEventListener onGestureScrollStart, |
- GestureEventListener onGestureScrollUpdate, |
- GestureEventListener onGestureTap, |
- GestureEventListener onGestureTapDown, |
- PointerEventListener onPointerCancel, |
- PointerEventListener onPointerDown, |
- PointerEventListener onPointerMove, |
- PointerEventListener onPointerUp, |
- Map<String, sky.EventListener> custom |
- }) : listeners = _createListeners( |
- onWheel: onWheel, |
- onGestureFlingCancel: onGestureFlingCancel, |
- onGestureFlingStart: onGestureFlingStart, |
- onGestureScrollUpdate: onGestureScrollUpdate, |
- onGestureScrollStart: onGestureScrollStart, |
- onGestureTap: onGestureTap, |
- onGestureTapDown: onGestureTapDown, |
- onPointerCancel: onPointerCancel, |
- onPointerDown: onPointerDown, |
- onPointerMove: onPointerMove, |
- onPointerUp: onPointerUp, |
- custom: custom |
- ), |
- super(content); |
- |
void _handleEvent(sky.Event e) { |
sky.EventListener listener = listeners[e.type]; |
if (listener != null) { |
listener(e); |
} |
} |
+ |
} |
/* |
@@ -278,11 +281,6 @@ class EventListenerNode extends TagNode { |
*/ |
abstract class RenderObjectWrapper extends UINode { |
- static final Map<RenderObject, RenderObjectWrapper> _nodeMap = |
- new HashMap<RenderObject, RenderObjectWrapper>(); |
- |
- static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node]; |
- |
RenderObjectWrapper({ |
Object key |
}) : super(key: key); |
@@ -291,6 +289,11 @@ abstract class RenderObjectWrapper extends UINode { |
void insert(RenderObjectWrapper child, dynamic slot); |
+ static final Map<RenderObject, RenderObjectWrapper> _nodeMap = |
+ new HashMap<RenderObject, RenderObjectWrapper>(); |
+ |
+ static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node]; |
+ |
void _sync(UINode old, dynamic slot) { |
assert(parent != null); |
if (old == null) { |
@@ -336,11 +339,12 @@ abstract class RenderObjectWrapper extends UINode { |
} |
abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { |
- UINode _child; |
- UINode get child => _child; |
OneChildRenderObjectWrapper({ UINode child, Object key }) : _child = child, super(key: key); |
+ UINode _child; |
+ UINode get child => _child; |
+ |
void syncRenderObject(RenderObjectWrapper old) { |
super.syncRenderObject(old); |
UINode oldChild = old == null ? null : (old as OneChildRenderObjectWrapper).child; |
@@ -368,50 +372,54 @@ abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { |
removeChild(child); |
super.remove(); |
} |
+ |
} |
class Clip extends OneChildRenderObjectWrapper { |
- RenderClip root; |
Clip({ UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderClip root; |
RenderClip createNode() => new RenderClip(); |
+ |
} |
class Padding extends OneChildRenderObjectWrapper { |
- RenderPadding root; |
- final EdgeDims padding; |
Padding({ this.padding, UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderPadding root; |
+ final EdgeDims padding; |
+ |
RenderPadding createNode() => new RenderPadding(padding: padding); |
void syncRenderObject(Padding old) { |
super.syncRenderObject(old); |
root.padding = padding; |
} |
+ |
} |
class DecoratedBox extends OneChildRenderObjectWrapper { |
- RenderDecoratedBox root; |
- final BoxDecoration decoration; |
DecoratedBox({ this.decoration, UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderDecoratedBox root; |
+ final BoxDecoration decoration; |
+ |
RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decoration); |
void syncRenderObject(DecoratedBox old) { |
super.syncRenderObject(old); |
root.decoration = decoration; |
} |
+ |
} |
class SizedBox extends OneChildRenderObjectWrapper { |
- RenderSizedBox root; |
- final Size desiredSize; |
SizedBox({ |
double width: double.INFINITY, |
@@ -420,59 +428,70 @@ class SizedBox extends OneChildRenderObjectWrapper { |
Object key |
}) : desiredSize = new Size(width, height), super(child: child, key: key); |
+ RenderSizedBox root; |
+ final Size desiredSize; |
+ |
RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize); |
void syncRenderObject(SizedBox old) { |
super.syncRenderObject(old); |
root.desiredSize = desiredSize; |
} |
+ |
} |
class ConstrainedBox extends OneChildRenderObjectWrapper { |
- RenderConstrainedBox root; |
- final BoxConstraints constraints; |
ConstrainedBox({ this.constraints, UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderConstrainedBox root; |
+ final BoxConstraints constraints; |
+ |
RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstraints: constraints); |
void syncRenderObject(ConstrainedBox old) { |
super.syncRenderObject(old); |
root.additionalConstraints = constraints; |
} |
+ |
} |
class ShrinkWrapWidth extends OneChildRenderObjectWrapper { |
- RenderShrinkWrapWidth root; |
ShrinkWrapWidth({ UINode child, Object key }) : super(child: child, key: key); |
+ RenderShrinkWrapWidth root; |
+ |
RenderShrinkWrapWidth createNode() => new RenderShrinkWrapWidth(); |
+ |
} |
class Transform extends OneChildRenderObjectWrapper { |
- RenderTransform root; |
- final Matrix4 transform; |
Transform({ this.transform, UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderTransform root; |
+ final Matrix4 transform; |
+ |
RenderTransform createNode() => new RenderTransform(transform: transform); |
void syncRenderObject(Transform old) { |
super.syncRenderObject(old); |
root.transform = transform; |
} |
+ |
} |
class SizeObserver extends OneChildRenderObjectWrapper { |
- RenderSizeObserver root; |
- final SizeChangedCallback callback; |
SizeObserver({ this.callback, UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderSizeObserver root; |
+ final SizeChangedCallback callback; |
+ |
RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback); |
void syncRenderObject(SizeObserver old) { |
@@ -484,16 +503,18 @@ class SizeObserver extends OneChildRenderObjectWrapper { |
root.callback = null; |
super.remove(); |
} |
+ |
} |
// TODO(jackson) need a mechanism for marking the RenderCustomPaint as needing paint |
class CustomPaint extends OneChildRenderObjectWrapper { |
- RenderCustomPaint root; |
- final CustomPaintCallback callback; |
CustomPaint({ this.callback, UINode child, Object key }) |
: super(child: child, key: key); |
+ RenderCustomPaint root; |
+ final CustomPaintCallback callback; |
+ |
RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback); |
void syncRenderObject(CustomPaint old) { |
@@ -505,6 +526,7 @@ class CustomPaint extends OneChildRenderObjectWrapper { |
root.callback = null; |
super.remove(); |
} |
+ |
} |
final List<UINode> _emptyList = new List<UINode>(); |
@@ -514,8 +536,6 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { |
// In MultiChildRenderObjectWrapper subclasses, slots are RenderObject nodes |
// to use as the "insert before" sibling in ContainerRenderObjectMixin.add() calls |
- final List<UINode> children; |
- |
MultiChildRenderObjectWrapper({ |
Object key, |
List<UINode> children |
@@ -526,6 +546,8 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { |
assert(!_debugHasDuplicateIds()); |
} |
+ final List<UINode> children; |
+ |
void insert(RenderObjectWrapper child, dynamic slot) { |
final root = this.root; // TODO(ianh): Remove this once the analyzer is cleverer |
assert(slot == null || slot is RenderObject); |
@@ -693,22 +715,27 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { |
assert(root == this.root); // TODO(ianh): Remove this once the analyzer is cleverer |
} |
+ |
} |
class BlockContainer extends MultiChildRenderObjectWrapper { |
- RenderBlock root; |
- RenderBlock createNode() => new RenderBlock(); |
BlockContainer({ Object key, List<UINode> children }) |
: super(key: key, children: children); |
+ |
+ RenderBlock root; |
+ RenderBlock createNode() => new RenderBlock(); |
+ |
} |
class StackContainer extends MultiChildRenderObjectWrapper { |
- RenderStack root; |
- RenderStack createNode() => new RenderStack(); |
StackContainer({ Object key, List<UINode> children }) |
: super(key: key, children: children); |
+ |
+ RenderStack root; |
+ RenderStack createNode() => new RenderStack(); |
+ |
} |
class StackPositionedChild extends ParentDataNode { |
@@ -721,13 +748,14 @@ class StackPositionedChild extends ParentDataNode { |
} |
class Paragraph extends RenderObjectWrapper { |
+ |
+ Paragraph({ Object key, this.text }) : super(key: key); |
+ |
RenderParagraph root; |
RenderParagraph createNode() => new RenderParagraph(text: text); |
final String text; |
- Paragraph({ Object key, this.text }) : super(key: key); |
- |
void syncRenderObject(UINode old) { |
super.syncRenderObject(old); |
root.text = text; |
@@ -737,14 +765,10 @@ class Paragraph extends RenderObjectWrapper { |
assert(false); |
// Paragraph does not support having children currently |
} |
+ |
} |
class FlexContainer extends MultiChildRenderObjectWrapper { |
- RenderFlex root; |
- RenderFlex createNode() => new RenderFlex(direction: this.direction); |
- |
- final FlexDirection direction; |
- final FlexJustifyContent justifyContent; |
FlexContainer({ |
Object key, |
@@ -753,11 +777,18 @@ class FlexContainer extends MultiChildRenderObjectWrapper { |
this.justifyContent: FlexJustifyContent.flexStart |
}) : super(key: key, children: children); |
+ RenderFlex root; |
+ RenderFlex createNode() => new RenderFlex(direction: this.direction); |
+ |
+ final FlexDirection direction; |
+ final FlexJustifyContent justifyContent; |
+ |
void syncRenderObject(UINode old) { |
super.syncRenderObject(old); |
root.direction = direction; |
root.justifyContent = justifyContent; |
} |
+ |
} |
class FlexExpandingChild extends ParentDataNode { |
@@ -766,11 +797,6 @@ class FlexExpandingChild extends ParentDataNode { |
} |
class Image extends RenderObjectWrapper { |
- RenderImage root; |
- RenderImage createNode() => new RenderImage(this.src, this.size); |
- |
- final String src; |
- final Size size; |
Image({ |
Object key, |
@@ -778,6 +804,12 @@ class Image extends RenderObjectWrapper { |
this.size |
}) : super(key: key); |
+ RenderImage root; |
+ RenderImage createNode() => new RenderImage(this.src, this.size); |
+ |
+ final String src; |
+ final Size size; |
+ |
void syncRenderObject(UINode old) { |
super.syncRenderObject(old); |
root.src = src; |
@@ -788,6 +820,7 @@ class Image extends RenderObjectWrapper { |
assert(false); |
// Image does not support having children currently |
} |
+ |
} |
Set<Component> _dirtyComponents = new Set<Component>(); |
@@ -837,19 +870,24 @@ void _scheduleComponentForRender(Component c) { |
} |
abstract class Component extends UINode { |
+ |
+ Component({ Object key, bool stateful }) |
+ : _stateful = stateful != null ? stateful : false, |
+ _order = _currentOrder + 1, |
+ super(key: key); |
+ |
+ Component.fromArgs(Object key, bool stateful) |
+ : this(key: key, stateful: stateful); |
+ |
+ static Component _currentlyBuilding; |
bool get _isBuilding => _currentlyBuilding == this; |
- bool _dirty = true; |
+ bool _stateful; |
+ bool _dirty = true; |
bool _disqualifiedFromEverAppearingAgain = false; |
- UINode _built; |
- final int _order; |
- static int _currentOrder = 0; |
- bool _stateful; |
- static Component _currentlyBuilding; |
List<Function> _mountCallbacks; |
List<Function> _unmountCallbacks; |
- dynamic _slot; // cached slot from the last time we were synced |
void onDidMount(Function fn) { |
if (_mountCallbacks == null) |
@@ -865,14 +903,6 @@ abstract class Component extends UINode { |
_unmountCallbacks.add(fn); |
} |
- Component({ Object key, bool stateful }) |
- : _stateful = stateful != null ? stateful : false, |
- _order = _currentOrder + 1, |
- super(key: key); |
- |
- Component.fromArgs(Object key, bool stateful) |
- : this(key: key, stateful: stateful); |
- |
void _didMount() { |
assert(!_disqualifiedFromEverAppearingAgain); |
super._didMount(); |
@@ -916,6 +946,9 @@ abstract class Component extends UINode { |
return true; |
} |
+ final int _order; |
+ static int _currentOrder = 0; |
+ |
/* There are three cases here: |
* 1) Building for the first time: |
* assert(_built == null && old == null) |
@@ -980,17 +1013,10 @@ abstract class Component extends UINode { |
} |
UINode build(); |
+ |
} |
class Container extends Component { |
- final UINode child; |
- final BoxConstraints constraints; |
- final BoxDecoration decoration; |
- final EdgeDims margin; |
- final EdgeDims padding; |
- final Matrix4 transform; |
- final double width; |
- final double height; |
Container({ |
Object key, |
@@ -1004,6 +1030,15 @@ class Container extends Component { |
this.transform |
}) : super(key: key); |
+ final UINode child; |
+ final BoxConstraints constraints; |
+ final BoxDecoration decoration; |
+ final EdgeDims margin; |
+ final EdgeDims padding; |
+ final Matrix4 transform; |
+ final double width; |
+ final double height; |
+ |
UINode build() { |
UINode current = child; |
@@ -1034,6 +1069,7 @@ class Container extends Component { |
return current; |
} |
+ |
} |
class _AppView extends AppView { |
@@ -1072,6 +1108,7 @@ abstract class App extends Component { |
_appView.root = root; |
assert(root.parent is RenderView); |
} |
+ |
} |
class Text extends Component { |