| 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:sky/base/debug.dart'; | 8 import 'package:sky/base/debug.dart'; |
| 9 import 'package:sky/painting/box_painter.dart'; | 9 import 'package:sky/painting/box_painter.dart'; |
| 10 import 'package:sky/rendering/object.dart'; | 10 import 'package:sky/rendering/object.dart'; |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 child.layout(_additionalConstraints.apply(constraints), parentUsesSize: tr
ue); | 584 child.layout(_additionalConstraints.apply(constraints), parentUsesSize: tr
ue); |
| 585 size = child.size; | 585 size = child.size; |
| 586 } else { | 586 } else { |
| 587 size = _additionalConstraints.apply(constraints).constrain(Size.zero); | 587 size = _additionalConstraints.apply(constraints).constrain(Size.zero); |
| 588 } | 588 } |
| 589 } | 589 } |
| 590 | 590 |
| 591 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n'; | 591 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}additionalConstraints: ${additionalConstraints}\n'; |
| 592 } | 592 } |
| 593 | 593 |
| 594 class RenderAspectRatio extends RenderProxyBox { |
| 595 RenderAspectRatio({ |
| 596 RenderBox child, |
| 597 double aspectRatio |
| 598 }) : super(child), _aspectRatio = aspectRatio { |
| 599 assert(_aspectRatio != null); |
| 600 } |
| 601 |
| 602 double _aspectRatio; |
| 603 double get aspectRatio => _aspectRatio; |
| 604 void set aspectRatio (double value) { |
| 605 assert(value != null); |
| 606 if (_aspectRatio == value) |
| 607 return; |
| 608 _aspectRatio = value; |
| 609 markNeedsLayout(); |
| 610 } |
| 611 |
| 612 double getMinIntrinsicHeight(BoxConstraints constraints) { |
| 613 return _applyAspectRatio(constraints).height; |
| 614 } |
| 615 |
| 616 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 617 return _applyAspectRatio(constraints).height; |
| 618 } |
| 619 |
| 620 Size _applyAspectRatio(BoxConstraints constraints) { |
| 621 double width = constraints.constrainWidth(); |
| 622 double height = constraints.constrainHeight(width / _aspectRatio); |
| 623 return new Size(width, height); |
| 624 } |
| 625 |
| 626 bool get sizedByParent => true; |
| 627 |
| 628 void performResize() { |
| 629 size = _applyAspectRatio(constraints); |
| 630 } |
| 631 |
| 632 void performLayout() { |
| 633 if (child != null) |
| 634 child.layout(new BoxConstraints.tight(size)); |
| 635 } |
| 636 |
| 637 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}aspectRatio: ${aspectRatio}\n'; |
| 638 } |
| 639 |
| 594 class RenderShrinkWrapWidth extends RenderProxyBox { | 640 class RenderShrinkWrapWidth extends RenderProxyBox { |
| 595 | 641 |
| 596 // This class will attempt to size its child to the child's maximum | 642 // This class will attempt to size its child to the child's maximum |
| 597 // intrinsic width, snapped to a multiple of the stepWidth, if one | 643 // intrinsic width, snapped to a multiple of the stepWidth, if one |
| 598 // is provided, and given the provided constraints; and will then | 644 // is provided, and given the provided constraints; and will then |
| 599 // adopt the child's resulting dimensions. | 645 // adopt the child's resulting dimensions. |
| 600 | 646 |
| 601 // Note: laying out this class is relatively expensive. Avoid using | 647 // Note: laying out this class is relatively expensive. Avoid using |
| 602 // it where possible. | 648 // it where possible. |
| 603 | 649 |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 | 1668 |
| 1623 void defaultPaint(PaintingCanvas canvas, Offset offset) { | 1669 void defaultPaint(PaintingCanvas canvas, Offset offset) { |
| 1624 RenderBox child = firstChild; | 1670 RenderBox child = firstChild; |
| 1625 while (child != null) { | 1671 while (child != null) { |
| 1626 assert(child.parentData is ParentDataType); | 1672 assert(child.parentData is ParentDataType); |
| 1627 canvas.paintChild(child, child.parentData.position + offset); | 1673 canvas.paintChild(child, child.parentData.position + offset); |
| 1628 child = child.parentData.nextSibling; | 1674 child = child.parentData.nextSibling; |
| 1629 } | 1675 } |
| 1630 } | 1676 } |
| 1631 } | 1677 } |
| OLD | NEW |