| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'node.dart'; | 5 import 'node.dart'; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 | 7 |
| 8 // ABSTRACT LAYOUT | 8 // ABSTRACT LAYOUT |
| 9 | 9 |
| 10 class ParentData { | 10 class ParentData { |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return clamp(min: minHeight, max: maxHeight, value: height); | 445 return clamp(min: minHeight, max: maxHeight, value: height); |
| 446 } | 446 } |
| 447 | 447 |
| 448 sky.Size constrain(sky.Size size) { | 448 sky.Size constrain(sky.Size size) { |
| 449 return new sky.Size(constrainWidth(size.width), constrainHeight(size.height)
); | 449 return new sky.Size(constrainWidth(size.width), constrainHeight(size.height)
); |
| 450 } | 450 } |
| 451 | 451 |
| 452 bool get isInfinite => maxWidth >= double.INFINITY || maxHeight >= double.INFI
NITY; | 452 bool get isInfinite => maxWidth >= double.INFINITY || maxHeight >= double.INFI
NITY; |
| 453 } | 453 } |
| 454 | 454 |
| 455 // TODO(abarth): Replace with sky.Size. | |
| 456 class BoxDimensions { | |
| 457 const BoxDimensions({ this.width: 0.0, this.height: 0.0 }); | |
| 458 | |
| 459 BoxDimensions.withConstraints( | |
| 460 BoxConstraints constraints, | |
| 461 { double width: 0.0, double height: 0.0 } | |
| 462 ) : width = constraints.constrainWidth(width), | |
| 463 height = constraints.constrainHeight(height); | |
| 464 | |
| 465 final double width; | |
| 466 final double height; | |
| 467 } | |
| 468 | |
| 469 class BoxParentData extends ParentData { | 455 class BoxParentData extends ParentData { |
| 470 sky.Point position = new sky.Point(0.0, 0.0); | 456 sky.Point position = new sky.Point(0.0, 0.0); |
| 471 } | 457 } |
| 472 | 458 |
| 473 abstract class RenderBox extends RenderNode { | 459 abstract class RenderBox extends RenderNode { |
| 474 | 460 |
| 475 void setParentData(RenderNode child) { | 461 void setParentData(RenderNode child) { |
| 476 if (child.parentData is! BoxParentData) | 462 if (child.parentData is! BoxParentData) |
| 477 child.parentData = new BoxParentData(); | 463 child.parentData = new BoxParentData(); |
| 478 } | 464 } |
| 479 | 465 |
| 480 // override this to report what dimensions you would have if you | 466 // override this to report what dimensions you would have if you |
| 481 // were laid out with the given constraints this can walk the tree | 467 // were laid out with the given constraints this can walk the tree |
| 482 // if it must, but it should be as cheap as possible; just get the | 468 // if it must, but it should be as cheap as possible; just get the |
| 483 // dimensions and nothing else (e.g. don't calculate hypothetical | 469 // dimensions and nothing else (e.g. don't calculate hypothetical |
| 484 // child positions if they're not needed to determine dimensions) | 470 // child positions if they're not needed to determine dimensions) |
| 485 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 471 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 486 return new BoxDimensions.withConstraints(constraints); | 472 return constraints.constrain(new sky.Size(0.0, 0.0)); |
| 487 } | 473 } |
| 488 | 474 |
| 489 BoxConstraints get constraints => super.constraints as BoxConstraints; | 475 BoxConstraints get constraints => super.constraints as BoxConstraints; |
| 490 void performResize() { | 476 void performResize() { |
| 491 // default behaviour for subclasses that have sizedByParent = true | 477 // default behaviour for subclasses that have sizedByParent = true |
| 492 size = constraints.constrain(new sky.Size(0.0, 0.0)); | 478 size = constraints.constrain(new sky.Size(0.0, 0.0)); |
| 493 assert(size.height < double.INFINITY); | 479 assert(size.height < double.INFINITY); |
| 494 assert(size.width < double.INFINITY); | 480 assert(size.width < double.INFINITY); |
| 495 } | 481 } |
| 496 void performLayout() { | 482 void performLayout() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 508 void hitTestChildren(HitTestResult result, { sky.Point position }) { } | 494 void hitTestChildren(HitTestResult result, { sky.Point position }) { } |
| 509 | 495 |
| 510 sky.Size size = new sky.Size(0.0, 0.0); | 496 sky.Size size = new sky.Size(0.0, 0.0); |
| 511 } | 497 } |
| 512 | 498 |
| 513 abstract class RenderProxyBox extends RenderBox with RenderNodeWithChildMixin<Re
nderBox> { | 499 abstract class RenderProxyBox extends RenderBox with RenderNodeWithChildMixin<Re
nderBox> { |
| 514 RenderProxyBox(RenderBox child) { | 500 RenderProxyBox(RenderBox child) { |
| 515 this.child = child; | 501 this.child = child; |
| 516 } | 502 } |
| 517 | 503 |
| 518 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 504 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 519 return child.getIntrinsicDimensions(constraints); | 505 return child.getIntrinsicDimensions(constraints); |
| 520 } | 506 } |
| 521 | 507 |
| 522 void performLayout() { | 508 void performLayout() { |
| 523 child.layout(constraints, parentUsesSize: true); | 509 child.layout(constraints, parentUsesSize: true); |
| 524 size = child.size; | 510 size = child.size; |
| 525 } | 511 } |
| 526 | 512 |
| 527 void hitTestChildren(HitTestResult result, { sky.Point position }) { | 513 void hitTestChildren(HitTestResult result, { sky.Point position }) { |
| 528 child.hitTest(result, position: position); | 514 child.hitTest(result, position: position); |
| 529 } | 515 } |
| 530 | 516 |
| 531 void paint(RenderNodeDisplayList canvas) { | 517 void paint(RenderNodeDisplayList canvas) { |
| 532 child.paint(canvas); | 518 child.paint(canvas); |
| 533 } | 519 } |
| 534 } | 520 } |
| 535 | 521 |
| 536 class RenderSizedBox extends RenderProxyBox { | 522 class RenderSizedBox extends RenderProxyBox { |
| 537 final sky.Size desiredSize; | 523 final sky.Size desiredSize; |
| 538 | 524 |
| 539 RenderSizedBox(RenderBox child, [this.desiredSize = const sky.Size.infinite()]
) | 525 RenderSizedBox(RenderBox child, [this.desiredSize = const sky.Size.infinite()]
) |
| 540 : super(child); | 526 : super(child); |
| 541 | 527 |
| 542 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 528 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 543 return new BoxDimensions.withConstraints(constraints, | 529 return constraints.constrain(desiredSize); |
| 544 width: desiredSize.width, | |
| 545 height: desiredSize.height); | |
| 546 } | 530 } |
| 547 | 531 |
| 548 void performLayout() { | 532 void performLayout() { |
| 549 size = constraints.constrain(desiredSize); | 533 size = constraints.constrain(desiredSize); |
| 550 child.layout(new BoxConstraints.tight(size)); | 534 child.layout(new BoxConstraints.tight(size)); |
| 551 } | 535 } |
| 552 } | 536 } |
| 553 | 537 |
| 554 class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { | 538 class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { |
| 555 | 539 |
| 556 RenderPadding(EdgeDims padding, RenderBox child) { | 540 RenderPadding(EdgeDims padding, RenderBox child) { |
| 557 assert(padding != null); | 541 assert(padding != null); |
| 558 this.padding = padding; | 542 this.padding = padding; |
| 559 this.child = child; | 543 this.child = child; |
| 560 } | 544 } |
| 561 | 545 |
| 562 EdgeDims _padding; | 546 EdgeDims _padding; |
| 563 EdgeDims get padding => _padding; | 547 EdgeDims get padding => _padding; |
| 564 void set padding (EdgeDims value) { | 548 void set padding (EdgeDims value) { |
| 565 assert(value != null); | 549 assert(value != null); |
| 566 if (_padding != value) { | 550 if (_padding != value) { |
| 567 _padding = value; | 551 _padding = value; |
| 568 markNeedsLayout(); | 552 markNeedsLayout(); |
| 569 } | 553 } |
| 570 } | 554 } |
| 571 | 555 |
| 572 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 556 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 573 assert(padding != null); | 557 assert(padding != null); |
| 574 constraints = constraints.deflate(padding); | 558 constraints = constraints.deflate(padding); |
| 575 if (child == null) | 559 if (child == null) |
| 576 return super.getIntrinsicDimensions(constraints); | 560 return super.getIntrinsicDimensions(constraints); |
| 577 return child.getIntrinsicDimensions(constraints); | 561 return child.getIntrinsicDimensions(constraints); |
| 578 } | 562 } |
| 579 | 563 |
| 580 void performLayout() { | 564 void performLayout() { |
| 581 assert(padding != null); | 565 assert(padding != null); |
| 582 BoxConstraints innerConstraints = constraints.deflate(padding); | 566 BoxConstraints innerConstraints = constraints.deflate(padding); |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 void setParentData(RenderBox child) { | 782 void setParentData(RenderBox child) { |
| 799 if (child.parentData is! BlockParentData) | 783 if (child.parentData is! BlockParentData) |
| 800 child.parentData = new BlockParentData(); | 784 child.parentData = new BlockParentData(); |
| 801 } | 785 } |
| 802 | 786 |
| 803 // override this to report what dimensions you would have if you | 787 // override this to report what dimensions you would have if you |
| 804 // were laid out with the given constraints this can walk the tree | 788 // were laid out with the given constraints this can walk the tree |
| 805 // if it must, but it should be as cheap as possible; just get the | 789 // if it must, but it should be as cheap as possible; just get the |
| 806 // dimensions and nothing else (e.g. don't calculate hypothetical | 790 // dimensions and nothing else (e.g. don't calculate hypothetical |
| 807 // child positions if they're not needed to determine dimensions) | 791 // child positions if they're not needed to determine dimensions) |
| 808 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { | 792 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 809 double outerHeight = 0.0; | 793 double height = 0.0; |
| 810 double outerWidth = constraints.constrainWidth(constraints.maxWidth); | 794 double width = constraints.constrainWidth(constraints.maxWidth); |
| 811 assert(outerWidth < double.INFINITY); | 795 assert(width < double.INFINITY); |
| 812 double innerWidth = outerWidth; | |
| 813 RenderBox child = firstChild; | 796 RenderBox child = firstChild; |
| 814 BoxConstraints innerConstraints = new BoxConstraints(minWidth: innerWidth, | 797 BoxConstraints innerConstraints = new BoxConstraints(minWidth: width, |
| 815 maxWidth: innerWidth); | 798 maxWidth: width); |
| 816 while (child != null) { | 799 while (child != null) { |
| 817 outerHeight += child.getIntrinsicDimensions(innerConstraints).height; | 800 height += child.getIntrinsicDimensions(innerConstraints).height; |
| 818 assert(child.parentData is BlockParentData); | 801 assert(child.parentData is BlockParentData); |
| 819 child = child.parentData.nextSibling; | 802 child = child.parentData.nextSibling; |
| 820 } | 803 } |
| 821 | 804 |
| 822 return new BoxDimensions(width: outerWidth, | 805 return new sky.Size(width, constraints.constrainHeight(height)); |
| 823 height: constraints.constrainHeight(outerHeight)); | |
| 824 } | 806 } |
| 825 | 807 |
| 826 void performLayout() { | 808 void performLayout() { |
| 827 assert(constraints is BoxConstraints); | 809 assert(constraints is BoxConstraints); |
| 828 double width = constraints.constrainWidth(constraints.maxWidth); | 810 double width = constraints.constrainWidth(constraints.maxWidth); |
| 829 double y = 0.0; | 811 double y = 0.0; |
| 830 RenderBox child = firstChild; | 812 RenderBox child = firstChild; |
| 831 while (child != null) { | 813 while (child != null) { |
| 832 child.layout(new BoxConstraints(minWidth: width, maxWidth: width), parentU
sesSize: true); | 814 child.layout(new BoxConstraints(minWidth: width, maxWidth: width), parentU
sesSize: true); |
| 833 assert(child.parentData is BlockParentData); | 815 assert(child.parentData is BlockParentData); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 972 |
| 991 void hitTestChildren(HitTestResult result, { double x, double y }) { | 973 void hitTestChildren(HitTestResult result, { double x, double y }) { |
| 992 // defaultHitTestChildren(result, x: x, y: y); | 974 // defaultHitTestChildren(result, x: x, y: y); |
| 993 } | 975 } |
| 994 | 976 |
| 995 void paint(RenderNodeDisplayList canvas) { | 977 void paint(RenderNodeDisplayList canvas) { |
| 996 super.paint(canvas); | 978 super.paint(canvas); |
| 997 _layoutRoot.paint(canvas); | 979 _layoutRoot.paint(canvas); |
| 998 } | 980 } |
| 999 } | 981 } |
| OLD | NEW |