| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 result = new _DebugSize(result, size._owner, size._canBeUsedByParent); | 186 result = new _DebugSize(result, size._owner, size._canBeUsedByParent); |
| 187 return result; | 187 return result; |
| 188 } | 188 } |
| 189 | 189 |
| 190 bool get isInfinite => maxWidth >= double.INFINITY && maxHeight >= double.INFI
NITY; | 190 bool get isInfinite => maxWidth >= double.INFINITY && maxHeight >= double.INFI
NITY; |
| 191 | 191 |
| 192 bool get hasTightWidth => minWidth >= maxWidth; | 192 bool get hasTightWidth => minWidth >= maxWidth; |
| 193 bool get hasTightHeight => minHeight >= maxHeight; | 193 bool get hasTightHeight => minHeight >= maxHeight; |
| 194 bool get isTight => hasTightWidth && hasTightHeight; | 194 bool get isTight => hasTightWidth && hasTightHeight; |
| 195 | 195 |
| 196 bool contains(Size size) { |
| 197 return (minWidth <= size.width) && (size.width <= math.max(minWidth, maxWidt
h)) && |
| 198 (minHeight <= size.height) && (size.height <= math.max(minHeight, max
Height)); |
| 199 } |
| 200 |
| 196 bool operator ==(other) { | 201 bool operator ==(other) { |
| 197 if (identical(this, other)) | 202 if (identical(this, other)) |
| 198 return true; | 203 return true; |
| 199 return other is BoxConstraints && | 204 return other is BoxConstraints && |
| 200 minWidth == other.minWidth && | 205 minWidth == other.minWidth && |
| 201 maxWidth == other.maxWidth && | 206 maxWidth == other.maxWidth && |
| 202 minHeight == other.minHeight && | 207 minHeight == other.minHeight && |
| 203 maxHeight == other.maxHeight; | 208 maxHeight == other.maxHeight; |
| 204 } | 209 } |
| 205 int get hashCode { | 210 int get hashCode { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 } | 288 } |
| 284 // getDistanceToActualBaseline() should return the distance from the | 289 // getDistanceToActualBaseline() should return the distance from the |
| 285 // y-coordinate of the position of the box to the y-coordinate of | 290 // y-coordinate of the position of the box to the y-coordinate of |
| 286 // the first given baseline in the box's contents, if any, or null | 291 // the first given baseline in the box's contents, if any, or null |
| 287 // otherwise. | 292 // otherwise. |
| 288 double getDistanceToActualBaseline(TextBaseline baseline) { | 293 double getDistanceToActualBaseline(TextBaseline baseline) { |
| 289 assert(!needsLayout); | 294 assert(!needsLayout); |
| 290 return null; | 295 return null; |
| 291 } | 296 } |
| 292 | 297 |
| 293 // This whole block should only be here in debug builds | 298 BoxConstraints get constraints => super.constraints; |
| 294 bool _debugDoingThisLayout = false; | 299 bool debugDoesMeetConstraints() { |
| 295 bool _debugCanParentUseSize; | 300 assert(constraints != null); |
| 296 void layoutWithoutResize() { | 301 assert(_size != null); |
| 297 _debugDoingThisLayout = true; | 302 assert(!_size.isInfinite); |
| 298 _debugCanParentUseSize = false; | 303 return constraints.contains(_size); |
| 299 super.layoutWithoutResize(); | |
| 300 _debugCanParentUseSize = null; | |
| 301 _debugDoingThisLayout = false; | |
| 302 } | 304 } |
| 303 void layout(dynamic constraints, { bool parentUsesSize: false }) { | |
| 304 _debugDoingThisLayout = true; | |
| 305 _debugCanParentUseSize = parentUsesSize; | |
| 306 super.layout(constraints, parentUsesSize: parentUsesSize); | |
| 307 _debugCanParentUseSize = null; | |
| 308 _debugDoingThisLayout = false; | |
| 309 } | |
| 310 | |
| 311 BoxConstraints get constraints => super.constraints; | |
| 312 void performResize() { | 305 void performResize() { |
| 313 // default behaviour for subclasses that have sizedByParent = true | 306 // default behaviour for subclasses that have sizedByParent = true |
| 314 size = constraints.constrain(Size.zero); | 307 size = constraints.constrain(Size.zero); |
| 315 assert(size.height < double.INFINITY); | 308 assert(size.height < double.INFINITY); |
| 316 assert(size.width < double.INFINITY); | 309 assert(size.width < double.INFINITY); |
| 317 } | 310 } |
| 318 void performLayout() { | 311 void performLayout() { |
| 319 // descendants have to either override performLayout() to set both | 312 // descendants have to either override performLayout() to set both |
| 320 // width and height and lay out children, or, set sizedByParent to | 313 // width and height and lay out children, or, set sizedByParent to |
| 321 // true so that performResize()'s logic above does its thing. | 314 // true so that performResize()'s logic above does its thing. |
| 322 assert(sizedByParent); | 315 assert(sizedByParent); |
| 323 } | 316 } |
| 324 | 317 |
| 325 bool hitTest(HitTestResult result, { Point position }) { | 318 bool hitTest(HitTestResult result, { Point position }) { |
| 326 hitTestChildren(result, position: position); | 319 hitTestChildren(result, position: position); |
| 327 result.add(new BoxHitTestEntry(this, position)); | 320 result.add(new BoxHitTestEntry(this, position)); |
| 328 return true; | 321 return true; |
| 329 } | 322 } |
| 330 void hitTestChildren(HitTestResult result, { Point position }) { } | 323 void hitTestChildren(HitTestResult result, { Point position }) { } |
| 331 | 324 |
| 325 // TODO(ianh): move size up to before constraints |
| 332 // TODO(ianh): In non-debug builds, this should all just be: | 326 // TODO(ianh): In non-debug builds, this should all just be: |
| 333 // Size size = Size.zero; | 327 // Size size = Size.zero; |
| 334 // In debug builds, however: | 328 // In debug builds, however: |
| 335 Size _size = Size.zero; | 329 Size _size = Size.zero; |
| 336 Size get size => _size; | 330 Size get size { |
| 331 if (_size is _DebugSize) { |
| 332 final _DebugSize _size = this._size; // TODO(ianh): Remove this once the a
nalyzer is cleverer |
| 333 assert(_size._owner == this); |
| 334 if (RenderObject.debugActiveLayout != null) { |
| 335 // we are always allowed to access our own size (for print debugging and
asserts if nothing else) |
| 336 // other than us, the only object that's allowed to read our size is our
parent, if they're said they will |
| 337 assert(debugDoingThisResize || debugDoingThisLayout || |
| 338 (RenderObject.debugActiveLayout == parent && _size._canBeUsedByPa
rent)); |
| 339 } |
| 340 assert(_size == this._size); // TODO(ianh): Remove this once the analyzer
is cleverer |
| 341 } |
| 342 return _size; |
| 343 } |
| 337 void set size(Size value) { | 344 void set size(Size value) { |
| 338 assert(RenderObject.debugDoingLayout); | 345 assert(RenderObject.debugDoingLayout); |
| 339 assert(_debugDoingThisLayout); | 346 assert((sizedByParent && debugDoingThisResize) || |
| 347 (!sizedByParent && debugDoingThisLayout)); |
| 340 if (value is _DebugSize) { | 348 if (value is _DebugSize) { |
| 341 assert(value._canBeUsedByParent); | 349 assert(value._canBeUsedByParent); |
| 342 assert(value._owner.parent == this); | 350 assert(value._owner.parent == this); |
| 343 } | 351 } |
| 344 _size = inDebugBuild ? new _DebugSize(value, this, _debugCanParentUseSize) :
value; | 352 _size = inDebugBuild ? new _DebugSize(value, this, debugCanParentUseSize) :
value; |
| 345 } | 353 } |
| 346 | 354 |
| 347 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}size: ${size}\n'; | 355 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}size: ${size}\n'; |
| 348 } | 356 } |
| 349 | 357 |
| 350 class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox
> { | 358 class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox
> { |
| 351 | 359 |
| 352 // ProxyBox assumes the child will be at 0,0 and will have the same size | 360 // ProxyBox assumes the child will be at 0,0 and will have the same size |
| 353 | 361 |
| 354 RenderProxyBox([RenderBox child = null]) { | 362 RenderProxyBox([RenderBox child = null]) { |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 void performLayout() { | 1135 void performLayout() { |
| 1128 if (_rootConstraints.orientation != _orientation) { | 1136 if (_rootConstraints.orientation != _orientation) { |
| 1129 if (_orientation != null && child != null) | 1137 if (_orientation != null && child != null) |
| 1130 child.rotate(oldAngle: _orientation, newAngle: _rootConstraints.orientat
ion, time: timeForRotation); | 1138 child.rotate(oldAngle: _orientation, newAngle: _rootConstraints.orientat
ion, time: timeForRotation); |
| 1131 _orientation = _rootConstraints.orientation; | 1139 _orientation = _rootConstraints.orientation; |
| 1132 } | 1140 } |
| 1133 _size = new Size(_rootConstraints.width, _rootConstraints.height); | 1141 _size = new Size(_rootConstraints.width, _rootConstraints.height); |
| 1134 assert(_size.height < double.INFINITY); | 1142 assert(_size.height < double.INFINITY); |
| 1135 assert(_size.width < double.INFINITY); | 1143 assert(_size.width < double.INFINITY); |
| 1136 | 1144 |
| 1137 if (child != null) { | 1145 if (child != null) |
| 1138 child.layout(new BoxConstraints.tight(_size)); | 1146 child.layout(new BoxConstraints.tight(_size)); |
| 1139 assert(child.size.width == width); | |
| 1140 assert(child.size.height == height); | |
| 1141 } | |
| 1142 } | 1147 } |
| 1143 | 1148 |
| 1144 void rotate({ int oldAngle, int newAngle, Duration time }) { | 1149 void rotate({ int oldAngle, int newAngle, Duration time }) { |
| 1145 assert(false); // nobody tells the screen to rotate, the whole rotate() danc
e is started from our performResize() | 1150 assert(false); // nobody tells the screen to rotate, the whole rotate() danc
e is started from our performResize() |
| 1146 } | 1151 } |
| 1147 | 1152 |
| 1148 bool hitTest(HitTestResult result, { Point position }) { | 1153 bool hitTest(HitTestResult result, { Point position }) { |
| 1149 if (child != null) { | 1154 if (child != null) { |
| 1150 Rect childBounds = new Rect.fromSize(child.size); | 1155 Rect childBounds = new Rect.fromSize(child.size); |
| 1151 if (childBounds.contains(position)) | 1156 if (childBounds.contains(position)) |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 | 1236 |
| 1232 void defaultPaint(RenderCanvas canvas) { | 1237 void defaultPaint(RenderCanvas canvas) { |
| 1233 RenderBox child = firstChild; | 1238 RenderBox child = firstChild; |
| 1234 while (child != null) { | 1239 while (child != null) { |
| 1235 assert(child.parentData is ParentDataType); | 1240 assert(child.parentData is ParentDataType); |
| 1236 canvas.paintChild(child, child.parentData.position); | 1241 canvas.paintChild(child, child.parentData.position); |
| 1237 child = child.parentData.nextSibling; | 1242 child = child.parentData.nextSibling; |
| 1238 } | 1243 } |
| 1239 } | 1244 } |
| 1240 } | 1245 } |
| OLD | NEW |