Chromium Code Reviews| Index: sky/sdk/lib/framework/layout2.dart |
| diff --git a/sky/sdk/lib/framework/layout2.dart b/sky/sdk/lib/framework/layout2.dart |
| index e7e0b6d9a17a0523c52429a29db24b62d12629d2..aa24db1657c162e96bc6f295363c66501d3aa049 100644 |
| --- a/sky/sdk/lib/framework/layout2.dart |
| +++ b/sky/sdk/lib/framework/layout2.dart |
| @@ -34,9 +34,9 @@ double clamp({double min: 0.0, double value: 0.0, double max: double.INFINITY}) |
| class RenderNodeDisplayList extends sky.PictureRecorder { |
| RenderNodeDisplayList(double width, double height) : super(width, height); |
| - void paintChild(RenderNode child, double x, double y) { |
| + void paintChild(RenderNode child, sky.Point position) { |
| save(); |
| - translate(x, y); |
| + translate(position.x, position.y); |
|
Hixie
2015/05/28 18:45:22
translate() should take a Point. :-)
|
| child.paint(this); |
| restore(); |
| } |
| @@ -239,7 +239,7 @@ abstract class RenderNode extends AbstractNode { |
| // RenderNode subclasses are expected to have a method like the |
| // following (with the signature being whatever passes for coordinates |
| // for this particular class): |
| - // bool hitTest(HitTestResult result, { double x, double y }) { |
| + // bool hitTest(HitTestResult result, { sky.Point position }) { |
| // // If (x,y) is not inside this node, then return false. (You |
| // // can assume that the given coordinate is inside your |
| // // dimensions. You only need to check this if you're an |
| @@ -486,9 +486,14 @@ class BoxConstraints { |
| return clamp(min: minHeight, max: maxHeight, value: height); |
| } |
| + sky.Size constrain(sky.Size size) { |
| + return new sky.Size(constrainWidth(size.width), constrainHeight(size.height)); |
| + } |
| + |
| bool get isInfinite => maxWidth >= double.INFINITY || maxHeight >= double.INFINITY; |
| } |
| +// TODO(abarth): Replace with sky.Size. |
| class BoxDimensions { |
| const BoxDimensions({ this.width: 0.0, this.height: 0.0 }); |
| @@ -503,8 +508,7 @@ class BoxDimensions { |
| } |
| class BoxParentData extends ParentData { |
| - double x = 0.0; |
| - double y = 0.0; |
| + sky.Point position = new sky.Point(); |
|
Hixie
2015/05/28 18:45:22
It's tempting to suggest that BoxParentData should
|
| } |
| abstract class RenderBox extends RenderNode { |
| @@ -524,20 +528,18 @@ abstract class RenderBox extends RenderNode { |
| } |
| void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { |
| - width = constraints.constrainWidth(0.0); |
| - height = constraints.constrainHeight(0.0); |
| + size = constraints.constrain(new sky.Size()); |
| layoutDone(); |
| } |
| - bool hitTest(HitTestResult result, { double x, double y }) { |
| - hitTestChildren(result, x: x, y: y); |
| + bool hitTest(HitTestResult result, { sky.Point position }) { |
| + hitTestChildren(result, position: position); |
| result.add(this); |
| return true; |
| } |
| - void hitTestChildren(HitTestResult result, { double x, double y }) { } |
| + void hitTestChildren(HitTestResult result, { sky.Point position }) { } |
| - double width; |
| - double height; |
| + sky.Size size = new sky.Size(); |
| } |
| class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { |
| @@ -570,8 +572,8 @@ class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { |
| assert(padding != null); |
| constraints = constraints.deflate(padding); |
| if (child == null) { |
| - width = constraints.constrainWidth(padding.left + padding.right); |
| - height = constraints.constrainHeight(padding.top + padding.bottom); |
| + size = constraints.constrain(new sky.Size(padding.left + padding.right, |
| + padding.top + padding.bottom)); |
| return; |
| } |
| if (relayoutSubtreeRoot != null) |
| @@ -580,23 +582,24 @@ class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { |
| relayoutSubtreeRoot = this; |
| child.layout(constraints, relayoutSubtreeRoot: relayoutSubtreeRoot); |
| assert(child.parentData is BoxParentData); |
| - child.parentData.x = padding.left; |
| - child.parentData.y = padding.top; |
| - width = constraints.constrainWidth(padding.left + child.width + padding.right); |
| - height = constraints.constrainHeight(padding.top + child.height + padding.bottom); |
| + child.parentData.position = new sky.Point(padding.left, padding.top); |
| + size = constraints.constrain(new sky.Size(padding.left + child.size.width + padding.right, |
| + padding.top + child.size.height + padding.bottom)); |
| } |
| void paint(RenderNodeDisplayList canvas) { |
| if (child != null) |
| - canvas.paintChild(child, child.parentData.x, child.parentData.y); |
| + canvas.paintChild(child, child.parentData.position); |
| } |
| - void hitTestChildren(HitTestResult result, { double x, double y }) { |
| + void hitTestChildren(HitTestResult result, { sky.Point position }) { |
| if (child != null) { |
| assert(child.parentData is BoxParentData); |
| - if ((x >= child.parentData.x) && (x < child.parentData.x + child.width) && |
| - (y >= child.parentData.y) && (y < child.parentData.y + child.height)) |
| - child.hitTest(result, x: x+child.parentData.x, y: y+child.parentData.y); |
| + sky.Rect childRect = new sky.Rect.fromPointAndSize(child.parentData.position, child.size); |
| + if (childRect.contains(position)) { |
| + child.hitTest(result, position: new sky.Point(position.x - child.parentData.position.x, |
| + position.y - child.parentData.position.y)); |
| + } |
| } |
| } |
| @@ -625,15 +628,15 @@ class RenderDecoratedBox extends RenderBox { |
| } |
| void paint(RenderNodeDisplayList canvas) { |
| - assert(width != null); |
| - assert(height != null); |
| + assert(size.width != null); |
| + assert(size.height != null); |
| if (_decoration == null) |
| return; |
| if (_decoration.backgroundColor != null) { |
| sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
| - canvas.drawRect(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint); |
| + canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint); |
| } |
| } |
| @@ -648,15 +651,15 @@ class RenderDecoratedCircle extends RenderDecoratedBox with RenderNodeWithChildM |
| } |
| void paint(RenderNodeDisplayList canvas) { |
| - assert(width != null); |
| - assert(height != null); |
| + assert(size.width != null); |
| + assert(size.height != null); |
| if (_decoration == null) |
| return; |
| if (_decoration.backgroundColor != null) { |
| sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
| - canvas.drawCircle(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint); |
| + canvas.drawCircle(0.0, 0.0, (size.width + size.height) / 2, paint); |
| } |
| } |
| } |
| @@ -673,10 +676,9 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> { |
| this.child = child; |
| } |
| - double _width; |
| - double get width => _width; |
| - double _height; |
| - double get height => _height; |
| + sky.Size _size = new sky.Size(); |
| + double get width => _size.width; |
| + double get height => _size.height; |
| int _orientation; // 0..3 |
| int get orientation => _orientation; |
| @@ -693,8 +695,7 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> { |
| _orientation = newOrientation; |
| } |
| if ((newWidth != width) || (newHeight != height)) { |
| - _width = newWidth; |
| - _height = newHeight; |
| + _size = new sky.Size(newWidth, newHeight); |
| relayout(); |
| } else { |
| layoutDone(); |
| @@ -704,8 +705,8 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> { |
| void relayout() { |
| if (child != null) { |
| child.layout(new BoxConstraints.tight(width: width, height: height)); |
| - assert(child.width == width); |
| - assert(child.height == height); |
| + assert(child.size.width == width); |
| + assert(child.size.height == height); |
| } |
| layoutDone(); |
| } |
| @@ -714,16 +715,19 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> { |
| assert(false); // nobody tells the screen to rotate, the whole rotate() dance is started from our layout() |
| } |
| - bool hitTest(HitTestResult result, { double x, double y }) { |
| - if (child != null && x >= 0.0 && x < child.width && y >= 0.0 && y < child.height) |
| - child.hitTest(result, x: x, y: y); |
| + bool hitTest(HitTestResult result, { sky.Point position }) { |
| + if (child != null) { |
| + sky.Rect childRect = new sky.Rect.fromPointAndSize(new sky.Point(), child.size); |
| + if (childRect.contains(position)) |
| + child.hitTest(result, position: position); |
| + } |
| result.add(this); |
| return true; |
| } |
| void paint(RenderNodeDisplayList canvas) { |
| if (child != null) |
| - canvas.paintChild(child, 0.0, 0.0); |
| + canvas.paintChild(child, new sky.Point()); |
| } |
| void paintFrame() { |
| @@ -739,14 +743,15 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> { |
| // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS |
| abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, ParentDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRenderNodeMixin<ChildType, ParentDataType> { |
| - void defaultHitTestChildren(HitTestResult result, { double x, double y }) { |
| + void defaultHitTestChildren(HitTestResult result, { sky.Point position }) { |
| // the x, y parameters have the top left of the node's box as the origin |
| ChildType child = lastChild; |
| while (child != null) { |
| assert(child.parentData is BoxParentData); |
| - if ((x >= child.parentData.x) && (x < child.parentData.x + child.width) && |
| - (y >= child.parentData.y) && (y < child.parentData.y + child.height)) { |
| - if (child.hitTest(result, x: x-child.parentData.x, y: y-child.parentData.y)) |
| + sky.Rect childRect = new sky.Rect.fromPointAndSize(child.parentData.position, child.size); |
| + if (childRect.contains(position)) { |
| + if (child.hitTest(result, position: new sky.Point(position.x - child.parentData.position.x, |
| + position.y - child.parentData.position.y))) |
| break; |
| } |
| child = child.parentData.previousSibling; |
| @@ -757,7 +762,7 @@ abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare |
| RenderBox child = firstChild; |
| while (child != null) { |
| assert(child.parentData is BoxParentData); |
| - canvas.paintChild(child, child.parentData.x, child.parentData.y); |
| + canvas.paintChild(child, child.parentData.position); |
| child = child.parentData.nextSibling; |
| } |
| } |
| @@ -811,8 +816,8 @@ class RenderBlock extends RenderDecoratedBox with ContainerRenderNodeMixin<Rende |
| saveRelayoutSubtreeRoot(relayoutSubtreeRoot); |
| else |
| relayoutSubtreeRoot = this; |
| - width = constraints.constrainWidth(constraints.maxWidth); |
| - assert(width < double.INFINITY); |
| + size.width = constraints.constrainWidth(constraints.maxWidth); |
| + assert(size.width < double.INFINITY); |
| _constraints = constraints; |
| internalLayout(relayoutSubtreeRoot); |
| } |
| @@ -824,23 +829,22 @@ class RenderBlock extends RenderDecoratedBox with ContainerRenderNodeMixin<Rende |
| void internalLayout(RenderNode relayoutSubtreeRoot) { |
| assert(_constraints != null); |
| double y = 0.0; |
| - double innerWidth = width; |
| + double innerWidth = size.width; |
| RenderBox child = firstChild; |
| while (child != null) { |
| child.layout(new BoxConstraints(minWidth: innerWidth, maxWidth: innerWidth), |
| relayoutSubtreeRoot: relayoutSubtreeRoot); |
| assert(child.parentData is BlockParentData); |
| - child.parentData.x = 0.0; |
| - child.parentData.y = y; |
| - y += child.height; |
| + child.parentData.position = new sky.Point(0.0, y); |
| + y += child.size.height; |
| child = child.parentData.nextSibling; |
| } |
| - height = _constraints.constrainHeight(y); |
| + size.height = _constraints.constrainHeight(y); |
| layoutDone(); |
| } |
| - void hitTestChildren(HitTestResult result, { double x, double y }) { |
| - defaultHitTestChildren(result, x: x, y: y); |
| + void hitTestChildren(HitTestResult result, { sky.Point position }) { |
| + defaultHitTestChildren(result, position: position); |
| } |
| void paint(RenderNodeDisplayList canvas) { |
| @@ -893,10 +897,9 @@ class RenderFlex extends RenderDecoratedBox with ContainerRenderNodeMixin<Render |
| else |
| relayoutSubtreeRoot = this; |
| _constraints = constraints; |
| - width = _constraints.constrainWidth(_constraints.maxWidth); |
| - height = _constraints.constrainHeight(_constraints.maxHeight); |
| - assert(height < double.INFINITY); |
| - assert(width < double.INFINITY); |
| + size = _constraints.constrain(new sky.Size(_constraints.maxWidth, _constraints.maxHeight)); |
| + assert(size.width < double.INFINITY); |
| + assert(size.height < double.INFINITY); |
| internalLayout(relayoutSubtreeRoot); |
| } |
| @@ -925,7 +928,7 @@ class RenderFlex extends RenderDecoratedBox with ContainerRenderNodeMixin<Render |
| maxWidth: _constraints.maxWidth); |
| child.layout(constraints, |
| relayoutSubtreeRoot: relayoutSubtreeRoot); |
| - freeSpace -= (_direction == FlexDirection.Horizontal) ? child.width : child.height; |
| + freeSpace -= (_direction == FlexDirection.Horizontal) ? child.size.width : child.size.height; |
| } |
| child = child.parentData.nextSibling; |
| } |
| @@ -957,14 +960,12 @@ class RenderFlex extends RenderDecoratedBox with ContainerRenderNodeMixin<Render |
| // For now, center the flex items in the cross direction |
| switch (_direction) { |
| case FlexDirection.Horizontal: |
| - child.parentData.x = usedSpace; |
| - usedSpace += child.width; |
| - child.parentData.y = height / 2 - child.height / 2; |
| + child.parentData.position = new sky.Point(usedSpace, size.height / 2 - child.size.height / 2); |
| + usedSpace += child.size.width; |
| break; |
| case FlexDirection.Vertical: |
| - child.parentData.y = usedSpace; |
| - usedSpace += child.height; |
| - child.parentData.x = width / 2 - child.width / 2; |
| + child.parentData.position = new sky.Point(size.width / 2 - child.size.width / 2, usedSpace); |
| + usedSpace += child.size.height; |
| break; |
| } |
| child = child.parentData.nextSibling; |
| @@ -972,8 +973,8 @@ class RenderFlex extends RenderDecoratedBox with ContainerRenderNodeMixin<Render |
| layoutDone(); |
| } |
| - void hitTestChildren(HitTestResult result, { double x, double y }) { |
| - defaultHitTestChildren(result, x: x, y: y); |
| + void hitTestChildren(HitTestResult result, { sky.Point position }) { |
| + defaultHitTestChildren(result, position: position); |
| } |
| void paint(RenderNodeDisplayList canvas) { |