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 'dart:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 | 7 |
8 import 'package:vector_math/vector_math.dart'; | 8 import 'package:vector_math/vector_math.dart'; |
9 | 9 |
10 import '../base/debug.dart'; | 10 import '../base/debug.dart'; |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 double delta = baseline - child.getDistanceToBaseline(baselineType); | 1007 double delta = baseline - child.getDistanceToBaseline(baselineType); |
1008 child.parentData.position = new Point(0.0, delta); | 1008 child.parentData.position = new Point(0.0, delta); |
1009 } else { | 1009 } else { |
1010 performResize(); | 1010 performResize(); |
1011 } | 1011 } |
1012 } | 1012 } |
1013 | 1013 |
1014 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}baseline: ${baseline}\nbaselineType: ${baselineType}'; | 1014 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}baseline: ${baseline}\nbaselineType: ${baselineType}'; |
1015 } | 1015 } |
1016 | 1016 |
1017 enum ViewportScrollDirection { horizontal, vertical, both } | |
1018 | |
1019 class RenderViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox > { | |
1020 | |
1021 RenderViewport({ | |
1022 RenderBox child, | |
1023 Offset scrollOffset, | |
1024 ViewportScrollDirection direction: ViewportScrollDirection.vertical | |
1025 }) : _scrollOffset = scrollOffset, | |
1026 _scrollDirection = direction { | |
1027 this.child = child; | |
1028 } | |
1029 | |
1030 Offset _scrollOffset; | |
1031 Offset get scrollOffset => _scrollOffset; | |
1032 void set scrollOffset(Offset value) { | |
1033 if (value == _scrollOffset) | |
1034 return; | |
1035 _scrollOffset = value; | |
abarth-chromium
2015/07/09 23:39:34
Probably should assert that _scrollOffset respects
| |
1036 markNeedsPaint(); | |
1037 } | |
1038 | |
1039 ViewportScrollDirection _scrollDirection; | |
1040 ViewportScrollDirection get scrollDirection => _scrollDirection; | |
1041 void set scrollDirection(ViewportScrollDirection value) { | |
1042 if (value == _scrollDirection) | |
1043 return; | |
1044 _scrollDirection = value; | |
1045 markNeedsLayout(); | |
1046 } | |
1047 | |
1048 double getMinIntrinsicWidth(BoxConstraints constraints) { | |
1049 if (child != null && scrollDirection != ViewportScrollDirection.vertical) | |
1050 return child.getMinIntrinsicWidth(constraints); | |
1051 return constraints.constrainWidth(); | |
1052 } | |
1053 | |
1054 double getMaxIntrinsicWidth(BoxConstraints constraints) { | |
1055 if (child != null && scrollDirection != ViewportScrollDirection.vertical) | |
1056 return child.getMaxIntrinsicWidth(constraints); | |
1057 return constraints.constrainWidth(); | |
1058 } | |
1059 | |
1060 double getMinIntrinsicHeight(BoxConstraints constraints) { | |
1061 if (child != null && scrollDirection != ViewportScrollDirection.horizontal) | |
1062 return child.getMinIntrinsicHeight(constraints); | |
1063 return constraints.constrainHeight(); | |
1064 } | |
1065 | |
1066 double getMaxIntrinsicHeight(BoxConstraints constraints) { | |
1067 if (child != null && scrollDirection != ViewportScrollDirection.horizontal) | |
1068 return child.getMaxIntrinsicHeight(constraints); | |
1069 return constraints.constrainHeight(); | |
1070 } | |
1071 | |
1072 // We don't override computeDistanceToActualBaseline(), because we | |
1073 // want the default behaviour (returning null). Otherwise, as you | |
1074 // scroll the RenderBlockViewport, it would shift in its parent if | |
1075 // the parent was baseline-aligned, which makes no sense. | |
1076 | |
1077 void performLayout() { | |
1078 if (child != null) { | |
1079 BoxConstraints innerConstraints; | |
1080 switch (scrollDirection) { | |
1081 case ViewportScrollDirection.both: | |
1082 innerConstraints = new BoxConstraints(); break; | |
abarth-chromium
2015/07/09 23:39:35
One statement per line please.
| |
1083 case ViewportScrollDirection.horizontal: | |
1084 innerConstraints = constraints.heightConstraints(); break; | |
1085 case ViewportScrollDirection.vertical: | |
1086 innerConstraints = constraints.widthConstraints(); break; | |
1087 } | |
1088 child.layout(innerConstraints, parentUsesSize: true); | |
1089 size = constraints.constrain(child.size); | |
1090 assert(child.parentData is BoxParentData); | |
1091 child.parentData.position = Point.origin; | |
1092 } | |
1093 } | |
abarth-chromium
2015/07/09 23:39:35
Don't we need to size ourselves to something even
| |
1094 | |
1095 void paint(PaintingCanvas canvas, Offset offset) { | |
1096 canvas.save(); | |
1097 canvas.clipRect(offset & size); | |
abarth-chromium
2015/07/09 23:39:35
We should only clip if the child is actually bigge
| |
1098 if (child != null) | |
1099 canvas.paintChild(child, (offset - scrollOffset).toPoint()); | |
1100 canvas.restore(); | |
1101 } | |
1102 | |
1103 void hitTestChildren(HitTestResult result, { Point position }) { | |
1104 if (child != null) { | |
1105 assert(child.parentData is BoxParentData); | |
1106 Rect childBounds = child.parentData.position & child.size; | |
1107 if (childBounds.contains(position + -scrollOffset)) | |
1108 child.hitTest(result, position: position + scrollOffset); | |
1109 } | |
1110 } | |
1111 | |
1112 } | |
1113 | |
1017 class RenderImage extends RenderBox { | 1114 class RenderImage extends RenderBox { |
1018 | 1115 |
1019 RenderImage(sky.Image image, Size requestedSize) | 1116 RenderImage(sky.Image image, Size requestedSize) |
1020 : _image = image, _requestedSize = requestedSize; | 1117 : _image = image, _requestedSize = requestedSize; |
1021 | 1118 |
1022 sky.Image _image; | 1119 sky.Image _image; |
1023 sky.Image get image => _image; | 1120 sky.Image get image => _image; |
1024 void set image (sky.Image value) { | 1121 void set image (sky.Image value) { |
1025 if (value == _image) | 1122 if (value == _image) |
1026 return; | 1123 return; |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1438 | 1535 |
1439 void defaultPaint(PaintingCanvas canvas, Offset offset) { | 1536 void defaultPaint(PaintingCanvas canvas, Offset offset) { |
1440 RenderBox child = firstChild; | 1537 RenderBox child = firstChild; |
1441 while (child != null) { | 1538 while (child != null) { |
1442 assert(child.parentData is ParentDataType); | 1539 assert(child.parentData is ParentDataType); |
1443 canvas.paintChild(child, child.parentData.position + offset); | 1540 canvas.paintChild(child, child.parentData.position + offset); |
1444 child = child.parentData.nextSibling; | 1541 child = child.parentData.nextSibling; |
1445 } | 1542 } |
1446 } | 1543 } |
1447 } | 1544 } |
OLD | NEW |