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 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
8 import 'object.dart'; | 8 import 'object.dart'; |
9 import '../painting/shadows.dart'; | 9 import '../painting/shadows.dart'; |
10 import 'package:vector_math/vector_math.dart'; | 10 import 'package:vector_math/vector_math.dart'; |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 | 549 |
550 Size _requestedSize; | 550 Size _requestedSize; |
551 Size get requestedSize => _requestedSize; | 551 Size get requestedSize => _requestedSize; |
552 void set requestedSize (Size value) { | 552 void set requestedSize (Size value) { |
553 if (value == _requestedSize) | 553 if (value == _requestedSize) |
554 return; | 554 return; |
555 _requestedSize = value; | 555 _requestedSize = value; |
556 markNeedsLayout(); | 556 markNeedsLayout(); |
557 } | 557 } |
558 | 558 |
559 void performLayout() { | 559 Size _sizeForConstraints(BoxConstraints innerConstraints) { |
560 // If there's no image, we can't size ourselves automatically | 560 // If there's no image, we can't size ourselves automatically |
561 if (_image == null) { | 561 if (_image == null) { |
562 double width = requestedSize.width == null ? 0.0 : requestedSize.width; | 562 double width = requestedSize.width == null ? 0.0 : requestedSize.width; |
563 double height = requestedSize.height == null ? 0.0 : requestedSize.height; | 563 double height = requestedSize.height == null ? 0.0 : requestedSize.height; |
564 size = constraints.constrain(new Size(width, height)); | 564 return constraints.constrain(new Size(width, height)); |
565 return; | |
566 } | 565 } |
567 | 566 |
568 // If neither height nor width are specified, use inherent image dimensions | 567 // If neither height nor width are specified, use inherent image dimensions |
569 // If only one dimension is specified, adjust the other dimension to | 568 // If only one dimension is specified, adjust the other dimension to |
570 // maintain the aspect ratio | 569 // maintain the aspect ratio |
571 if (requestedSize.width == null) { | 570 if (requestedSize.width == null) { |
572 if (requestedSize.height == null) { | 571 if (requestedSize.height == null) { |
573 size = constraints.constrain(new Size(_image.width.toDouble(), _image.he ight.toDouble())); | 572 return constraints.constrain(new Size(_image.width.toDouble(), _image.he ight.toDouble())); |
574 } else { | 573 } else { |
575 double width = requestedSize.height * _image.width / _image.height; | 574 double width = requestedSize.height * _image.width / _image.height; |
576 size = constraints.constrain(new Size(width, requestedSize.height)); | 575 return constraints.constrain(new Size(width, requestedSize.height)); |
577 } | 576 } |
578 } else if (requestedSize.height == null) { | 577 } else if (requestedSize.height == null) { |
579 double height = requestedSize.width * _image.height / _image.width; | 578 double height = requestedSize.width * _image.height / _image.width; |
580 size = constraints.constrain(new Size(requestedSize.width, height)); | 579 return constraints.constrain(new Size(requestedSize.width, height)); |
581 } else { | 580 } else { |
582 size = constraints.constrain(requestedSize); | 581 return constraints.constrain(requestedSize); |
583 } | 582 } |
584 } | 583 } |
585 | 584 |
585 double getMinIntrinsicWidth(BoxConstraints constraints) { | |
586 if (requestedSize.width == null && requestedSize.height == null) | |
587 return constraints.constrainWidth(0.0); | |
588 return _sizeForConstraints(constraints).width; | |
589 } | |
590 | |
591 double getMaxIntrinsicWidth(BoxConstraints constraints) { | |
592 return _sizeForConstraints(constraints).width; | |
593 } | |
594 | |
595 double getMinIntrinsicHeight(BoxConstraints constraints) { | |
596 if (requestedSize.width == null && requestedSize.height == null) | |
597 return constraints.constrainHeight(0.0); | |
598 return _sizeForConstraints(constraints).width; | |
abarth-chromium
2015/06/10 04:23:19
.height
jackson
2015/06/10 04:44:46
Acknowledged.
| |
599 } | |
600 | |
601 double getMaxIntrinsicHeight(BoxConstraints constraints) { | |
602 return _sizeForConstraints(constraints).height; | |
603 } | |
604 | |
605 void performLayout() { | |
606 size = _sizeForConstraints(constraints); | |
607 } | |
608 | |
586 void paint(RenderObjectDisplayList canvas) { | 609 void paint(RenderObjectDisplayList canvas) { |
587 if (_image == null) return; | 610 if (_image == null) return; |
588 bool needsScale = size.width != _image.width || size.height != _image.height ; | 611 bool needsScale = size.width != _image.width || size.height != _image.height ; |
589 if (needsScale) { | 612 if (needsScale) { |
590 double widthScale = size.width / _image.width; | 613 double widthScale = size.width / _image.width; |
591 double heightScale = size.height / _image.height; | 614 double heightScale = size.height / _image.height; |
592 canvas.save(); | 615 canvas.save(); |
593 canvas.scale(widthScale, heightScale); | 616 canvas.scale(widthScale, heightScale); |
594 } | 617 } |
595 Paint paint = new Paint(); | 618 Paint paint = new Paint(); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1031 | 1054 |
1032 void defaultPaint(RenderObjectDisplayList canvas) { | 1055 void defaultPaint(RenderObjectDisplayList canvas) { |
1033 RenderBox child = firstChild; | 1056 RenderBox child = firstChild; |
1034 while (child != null) { | 1057 while (child != null) { |
1035 assert(child.parentData is ParentDataType); | 1058 assert(child.parentData is ParentDataType); |
1036 canvas.paintChild(child, child.parentData.position); | 1059 canvas.paintChild(child, child.parentData.position); |
1037 child = child.parentData.nextSibling; | 1060 child = child.parentData.nextSibling; |
1038 } | 1061 } |
1039 } | 1062 } |
1040 } | 1063 } |
OLD | NEW |