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 library layout; | 5 library layout; |
6 | 6 |
7 // This version of layout.dart is an update to the other one, this one using new
APIs. | 7 // This version of layout.dart is an update to the other one, this one using new
APIs. |
8 // It will not work in a stock Sky setup currently. | 8 // It will not work in a stock Sky setup currently. |
9 | 9 |
10 import 'node.dart'; | 10 import 'node.dart'; |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 while (child != null) { | 709 while (child != null) { |
710 outerHeight += child.getIntrinsicDimensions(innerConstraints).height; | 710 outerHeight += child.getIntrinsicDimensions(innerConstraints).height; |
711 assert(child.parentData is BlockParentData); | 711 assert(child.parentData is BlockParentData); |
712 child = child.parentData.nextSibling; | 712 child = child.parentData.nextSibling; |
713 } | 713 } |
714 | 714 |
715 return new BoxDimensions(width: outerWidth, | 715 return new BoxDimensions(width: outerWidth, |
716 height: constraints.constrainHeight(outerHeight)); | 716 height: constraints.constrainHeight(outerHeight)); |
717 } | 717 } |
718 | 718 |
719 double _minHeight; // value cached from parent for relayout call | 719 BoxConstraints _constraints; // value cached from parent for relayout call |
720 double _maxHeight; // value cached from parent for relayout call | |
721 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { | 720 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { |
722 if (relayoutSubtreeRoot != null) | 721 if (relayoutSubtreeRoot != null) |
723 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); | 722 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); |
724 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; | 723 else |
| 724 relayoutSubtreeRoot = this; |
725 width = constraints.constrainWidth(constraints.maxWidth); | 725 width = constraints.constrainWidth(constraints.maxWidth); |
726 assert(width < double.INFINITY); | 726 assert(width < double.INFINITY); |
727 _minHeight = constraints.minHeight; | 727 _constraints = constraints; |
728 _maxHeight = constraints.maxHeight; | |
729 internalLayout(relayoutSubtreeRoot); | 728 internalLayout(relayoutSubtreeRoot); |
730 } | 729 } |
731 | 730 |
732 void relayout() { | 731 void relayout() { |
733 internalLayout(this); | 732 internalLayout(this); |
734 } | 733 } |
735 | 734 |
736 void internalLayout(RenderNode relayoutSubtreeRoot) { | 735 void internalLayout(RenderNode relayoutSubtreeRoot) { |
737 assert(_minHeight != null); | 736 assert(_constraints != null); |
738 assert(_maxHeight != null); | |
739 double y = _padding.top; | 737 double y = _padding.top; |
740 double innerWidth = width - (_padding.left + _padding.right); | 738 double innerWidth = width - (_padding.left + _padding.right); |
741 RenderBox child = firstChild; | 739 RenderBox child = firstChild; |
742 while (child != null) { | 740 while (child != null) { |
743 child.layout(new BoxConstraints(minWidth: innerWidth, maxWidth: innerWidth
), | 741 child.layout(new BoxConstraints(minWidth: innerWidth, maxWidth: innerWidth
), |
744 relayoutSubtreeRoot: relayoutSubtreeRoot); | 742 relayoutSubtreeRoot: relayoutSubtreeRoot); |
745 assert(child.parentData is BlockParentData); | 743 assert(child.parentData is BlockParentData); |
746 child.parentData.x = _padding.left; | 744 child.parentData.x = _padding.left; |
747 child.parentData.y = y; | 745 child.parentData.y = y; |
748 y += child.height; | 746 y += child.height; |
749 child = child.parentData.nextSibling; | 747 child = child.parentData.nextSibling; |
750 } | 748 } |
751 height = clamp(min: _minHeight, value: y + _padding.bottom, max: _maxHeight)
; | 749 height = _constraints.constrainHeight(y + _padding.bottom); |
752 layoutDone(); | 750 layoutDone(); |
753 } | 751 } |
754 | 752 |
755 void hitTestChildren(HitTestResult result, { double x, double y }) { | 753 void hitTestChildren(HitTestResult result, { double x, double y }) { |
756 defaultHitTestChildren(result, x: x, y: y); | 754 defaultHitTestChildren(result, x: x, y: y); |
757 } | 755 } |
758 | 756 |
759 void paint(RenderNodeDisplayList canvas) { | 757 void paint(RenderNodeDisplayList canvas) { |
760 super.paint(canvas); | 758 super.paint(canvas); |
761 defaultPaint(canvas); | 759 defaultPaint(canvas); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 | 794 |
797 void setParentData(RenderBox child) { | 795 void setParentData(RenderBox child) { |
798 if (child.parentData is! FlexBoxParentData) | 796 if (child.parentData is! FlexBoxParentData) |
799 child.parentData = new FlexBoxParentData(); | 797 child.parentData = new FlexBoxParentData(); |
800 } | 798 } |
801 | 799 |
802 BoxConstraints _constraints; // value cached from parent for relayout call | 800 BoxConstraints _constraints; // value cached from parent for relayout call |
803 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { | 801 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { |
804 if (relayoutSubtreeRoot != null) | 802 if (relayoutSubtreeRoot != null) |
805 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); | 803 saveRelayoutSubtreeRoot(relayoutSubtreeRoot); |
806 relayoutSubtreeRoot = relayoutSubtreeRoot == null ? this : relayoutSubtreeRo
ot; | 804 else |
| 805 relayoutSubtreeRoot = this; |
807 _constraints = constraints; | 806 _constraints = constraints; |
808 width = _constraints.constrainWidth(_constraints.maxWidth); | 807 width = _constraints.constrainWidth(_constraints.maxWidth); |
809 height = _constraints.constrainHeight(_constraints.maxHeight); | 808 height = _constraints.constrainHeight(_constraints.maxHeight); |
810 assert(height < double.INFINITY); | 809 assert(height < double.INFINITY); |
811 assert(width < double.INFINITY); | 810 assert(width < double.INFINITY); |
812 internalLayout(relayoutSubtreeRoot); | 811 internalLayout(relayoutSubtreeRoot); |
813 } | 812 } |
814 | 813 |
815 void relayout() { | 814 void relayout() { |
816 internalLayout(this); | 815 internalLayout(this); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parentDa
ta as BoxParentData).y); | 955 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parentDa
ta as BoxParentData).y); |
957 if (statusbar != null) | 956 if (statusbar != null) |
958 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s
tatusbar.parentData as BoxParentData).y); | 957 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s
tatusbar.parentData as BoxParentData).y); |
959 if (toolbar != null) | 958 if (toolbar != null) |
960 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb
ar.parentData as BoxParentData).y); | 959 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb
ar.parentData as BoxParentData).y); |
961 if (drawer != null) | 960 if (drawer != null) |
962 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer.
parentData as BoxParentData).y); | 961 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer.
parentData as BoxParentData).y); |
963 } | 962 } |
964 | 963 |
965 } | 964 } |
OLD | NEW |