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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 double constrainHeight([double height = double.INFINITY]) { | 198 double constrainHeight([double height = double.INFINITY]) { |
199 return clamp(min: minHeight, max: maxHeight, value: height); | 199 return clamp(min: minHeight, max: maxHeight, value: height); |
200 } | 200 } |
201 | 201 |
202 Size constrain(Size size) { | 202 Size constrain(Size size) { |
203 Size result = new Size(constrainWidth(size.width), constrainHeight(size.heig
ht)); | 203 Size result = new Size(constrainWidth(size.width), constrainHeight(size.heig
ht)); |
204 if (size is _DebugSize) | 204 if (size is _DebugSize) |
205 result = new _DebugSize(result, size._owner, size._canBeUsedByParent); | 205 result = new _DebugSize(result, size._owner, size._canBeUsedByParent); |
206 return result; | 206 return result; |
207 } | 207 } |
| 208 Size get biggest => new Size(constrainWidth(), constrainHeight()); |
| 209 Size get smallest => new Size(constrainWidth(0.0), constrainHeight(0.0)); |
208 | 210 |
209 bool get isInfinite => maxWidth >= double.INFINITY && maxHeight >= double.INFI
NITY; | 211 bool get isInfinite => maxWidth >= double.INFINITY && maxHeight >= double.INFI
NITY; |
210 | 212 |
211 bool get hasTightWidth => minWidth >= maxWidth; | 213 bool get hasTightWidth => minWidth >= maxWidth; |
212 bool get hasTightHeight => minHeight >= maxHeight; | 214 bool get hasTightHeight => minHeight >= maxHeight; |
213 bool get isTight => hasTightWidth && hasTightHeight; | 215 bool get isTight => hasTightWidth && hasTightHeight; |
214 | 216 |
215 bool contains(Size size) { | 217 bool contains(Size size) { |
216 return (minWidth <= size.width) && (size.width <= math.max(minWidth, maxWidt
h)) && | 218 return (minWidth <= size.width) && (size.width <= math.max(minWidth, maxWidt
h)) && |
217 (minHeight <= size.height) && (size.height <= math.max(minHeight, max
Height)); | 219 (minHeight <= size.height) && (size.height <= math.max(minHeight, max
Height)); |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 if (child != null) | 834 if (child != null) |
833 return child.getMaxIntrinsicHeight(constraints); | 835 return child.getMaxIntrinsicHeight(constraints); |
834 return super.getMaxIntrinsicHeight(constraints); | 836 return super.getMaxIntrinsicHeight(constraints); |
835 } | 837 } |
836 | 838 |
837 void performLayout() { | 839 void performLayout() { |
838 if (child != null) { | 840 if (child != null) { |
839 child.layout(constraints.loosen(), parentUsesSize: true); | 841 child.layout(constraints.loosen(), parentUsesSize: true); |
840 size = constraints.constrain(child.size); | 842 size = constraints.constrain(child.size); |
841 assert(child.parentData is BoxParentData); | 843 assert(child.parentData is BoxParentData); |
842 Size delta = size - child.size; | 844 Offset delta = size - child.size; |
843 child.parentData.position = new Point(delta.width * horizontal, delta.heig
ht * vertical); | 845 child.parentData.position = (delta.scale(horizontal, vertical)).toPoint(); |
844 } else { | 846 } else { |
845 performResize(); | 847 performResize(); |
846 } | 848 } |
847 } | 849 } |
848 | 850 |
849 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}horizontal: ${horizontal}\n${prefix}vertical: ${vertical}\n'; | 851 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}horizontal: ${horizontal}\n${prefix}vertical: ${vertical}\n'; |
850 } | 852 } |
851 | 853 |
852 class RenderImage extends RenderBox { | 854 class RenderImage extends RenderBox { |
853 | 855 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 void paint(RenderCanvas canvas) { | 937 void paint(RenderCanvas canvas) { |
936 if (_image == null) return; | 938 if (_image == null) return; |
937 bool needsScale = size.width != _image.width || size.height != _image.height
; | 939 bool needsScale = size.width != _image.width || size.height != _image.height
; |
938 if (needsScale) { | 940 if (needsScale) { |
939 double widthScale = size.width / _image.width; | 941 double widthScale = size.width / _image.width; |
940 double heightScale = size.height / _image.height; | 942 double heightScale = size.height / _image.height; |
941 canvas.save(); | 943 canvas.save(); |
942 canvas.scale(widthScale, heightScale); | 944 canvas.scale(widthScale, heightScale); |
943 } | 945 } |
944 Paint paint = new Paint(); | 946 Paint paint = new Paint(); |
945 canvas.drawImage(_image, 0.0, 0.0, paint); | 947 canvas.drawImage(_image, Point.origin, paint); |
946 if (needsScale) | 948 if (needsScale) |
947 canvas.restore(); | 949 canvas.restore(); |
948 } | 950 } |
949 | 951 |
950 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}url: ${src}\n${prefix}dimensions: ${requestedSize}\n'; | 952 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}url: ${src}\n${prefix}dimensions: ${requestedSize}\n'; |
951 } | 953 } |
952 | 954 |
953 class RenderDecoratedBox extends RenderProxyBox { | 955 class RenderDecoratedBox extends RenderProxyBox { |
954 | 956 |
955 RenderDecoratedBox({ | 957 RenderDecoratedBox({ |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 void paint(RenderCanvas canvas) { | 1104 void paint(RenderCanvas canvas) { |
1103 assert(_callback != null); | 1105 assert(_callback != null); |
1104 _callback(canvas, size); | 1106 _callback(canvas, size); |
1105 super.paint(canvas); | 1107 super.paint(canvas); |
1106 } | 1108 } |
1107 } | 1109 } |
1108 | 1110 |
1109 // RENDER VIEW LAYOUT MANAGER | 1111 // RENDER VIEW LAYOUT MANAGER |
1110 | 1112 |
1111 class ViewConstraints { | 1113 class ViewConstraints { |
1112 | |
1113 const ViewConstraints({ | 1114 const ViewConstraints({ |
1114 this.width: 0.0, this.height: 0.0, this.orientation: null | 1115 this.size: Size.zero, |
| 1116 this.orientation |
1115 }); | 1117 }); |
1116 | 1118 final Size size; |
1117 final double width; | |
1118 final double height; | |
1119 final int orientation; | 1119 final int orientation; |
1120 | |
1121 } | 1120 } |
1122 | 1121 |
1123 class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
{ | 1122 class RenderView extends RenderObject with RenderObjectWithChildMixin<RenderBox>
{ |
1124 | 1123 |
1125 RenderView({ | 1124 RenderView({ |
1126 RenderBox child, | 1125 RenderBox child, |
1127 this.timeForRotation: const Duration(microseconds: 83333) | 1126 this.timeForRotation: const Duration(microseconds: 83333) |
1128 }) { | 1127 }) { |
1129 this.child = child; | 1128 this.child = child; |
1130 } | 1129 } |
1131 | 1130 |
1132 Size _size = Size.zero; | 1131 Size _size = Size.zero; |
1133 double get width => _size.width; | 1132 Size get size => _size; |
1134 double get height => _size.height; | |
1135 | 1133 |
1136 int _orientation; // 0..3 | 1134 int _orientation; // 0..3 |
1137 int get orientation => _orientation; | 1135 int get orientation => _orientation; |
1138 Duration timeForRotation; | 1136 Duration timeForRotation; |
1139 | 1137 |
1140 ViewConstraints _rootConstraints; | 1138 ViewConstraints _rootConstraints; |
1141 ViewConstraints get rootConstraints => _rootConstraints; | 1139 ViewConstraints get rootConstraints => _rootConstraints; |
1142 void set rootConstraints(ViewConstraints value) { | 1140 void set rootConstraints(ViewConstraints value) { |
1143 if (_rootConstraints == value) | 1141 if (_rootConstraints == value) |
1144 return; | 1142 return; |
1145 _rootConstraints = value; | 1143 _rootConstraints = value; |
1146 markNeedsLayout(); | 1144 markNeedsLayout(); |
1147 } | 1145 } |
1148 | 1146 |
1149 void performResize() { | 1147 void performResize() { |
1150 assert(false); | 1148 assert(false); |
1151 } | 1149 } |
1152 | 1150 |
1153 void performLayout() { | 1151 void performLayout() { |
1154 if (_rootConstraints.orientation != _orientation) { | 1152 if (_rootConstraints.orientation != _orientation) { |
1155 if (_orientation != null && child != null) | 1153 if (_orientation != null && child != null) |
1156 child.rotate(oldAngle: _orientation, newAngle: _rootConstraints.orientat
ion, time: timeForRotation); | 1154 child.rotate(oldAngle: _orientation, newAngle: _rootConstraints.orientat
ion, time: timeForRotation); |
1157 _orientation = _rootConstraints.orientation; | 1155 _orientation = _rootConstraints.orientation; |
1158 } | 1156 } |
1159 _size = new Size(_rootConstraints.width, _rootConstraints.height); | 1157 _size = _rootConstraints.size; |
1160 assert(!_size.isInfinite); | 1158 assert(!_size.isInfinite); |
1161 | 1159 |
1162 if (child != null) | 1160 if (child != null) |
1163 child.layout(new BoxConstraints.tight(_size)); | 1161 child.layout(new BoxConstraints.tight(_size)); |
1164 } | 1162 } |
1165 | 1163 |
1166 void rotate({ int oldAngle, int newAngle, Duration time }) { | 1164 void rotate({ int oldAngle, int newAngle, Duration time }) { |
1167 assert(false); // nobody tells the screen to rotate, the whole rotate() danc
e is started from our performResize() | 1165 assert(false); // nobody tells the screen to rotate, the whole rotate() danc
e is started from our performResize() |
1168 } | 1166 } |
1169 | 1167 |
(...skipping 10 matching lines...) Expand all Loading... |
1180 void paint(RenderCanvas canvas) { | 1178 void paint(RenderCanvas canvas) { |
1181 if (child != null) | 1179 if (child != null) |
1182 canvas.paintChild(child, Point.origin); | 1180 canvas.paintChild(child, Point.origin); |
1183 } | 1181 } |
1184 | 1182 |
1185 void paintFrame() { | 1183 void paintFrame() { |
1186 sky.tracing.begin('RenderView.paintFrame'); | 1184 sky.tracing.begin('RenderView.paintFrame'); |
1187 RenderObject.debugDoingPaint = true; | 1185 RenderObject.debugDoingPaint = true; |
1188 try { | 1186 try { |
1189 sky.PictureRecorder recorder = new sky.PictureRecorder(); | 1187 sky.PictureRecorder recorder = new sky.PictureRecorder(); |
1190 RenderCanvas canvas = new RenderCanvas(recorder, width, height); | 1188 RenderCanvas canvas = new RenderCanvas(recorder, _size); |
1191 paint(canvas); | 1189 paint(canvas); |
1192 sky.view.picture = recorder.endRecording(); | 1190 sky.view.picture = recorder.endRecording(); |
1193 } finally { | 1191 } finally { |
1194 RenderObject.debugDoingPaint = false; | 1192 RenderObject.debugDoingPaint = false; |
1195 sky.tracing.end('RenderView.paintFrame'); | 1193 sky.tracing.end('RenderView.paintFrame'); |
1196 } | 1194 } |
1197 } | 1195 } |
1198 | 1196 |
1199 } | 1197 } |
1200 | 1198 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 | 1251 |
1254 void defaultPaint(RenderCanvas canvas) { | 1252 void defaultPaint(RenderCanvas canvas) { |
1255 RenderBox child = firstChild; | 1253 RenderBox child = firstChild; |
1256 while (child != null) { | 1254 while (child != null) { |
1257 assert(child.parentData is ParentDataType); | 1255 assert(child.parentData is ParentDataType); |
1258 canvas.paintChild(child, child.parentData.position); | 1256 canvas.paintChild(child, child.parentData.position); |
1259 child = child.parentData.nextSibling; | 1257 child = child.parentData.nextSibling; |
1260 } | 1258 } |
1261 } | 1259 } |
1262 } | 1260 } |
OLD | NEW |