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 'node.dart'; | 5 import 'node.dart'; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 | 7 |
8 // ABSTRACT LAYOUT | 8 // ABSTRACT LAYOUT |
9 | 9 |
10 class ParentData { | 10 class ParentData { |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 (left == other.left); | 409 (left == other.left); |
410 } | 410 } |
411 | 411 |
412 class BoxConstraints { | 412 class BoxConstraints { |
413 const BoxConstraints({ | 413 const BoxConstraints({ |
414 this.minWidth: 0.0, | 414 this.minWidth: 0.0, |
415 this.maxWidth: double.INFINITY, | 415 this.maxWidth: double.INFINITY, |
416 this.minHeight: 0.0, | 416 this.minHeight: 0.0, |
417 this.maxHeight: double.INFINITY}); | 417 this.maxHeight: double.INFINITY}); |
418 | 418 |
419 const BoxConstraints.tight({ double width: 0.0, double height: 0.0 }) | 419 BoxConstraints.tight(sky.Size size) |
420 : minWidth = width, | 420 : minWidth = size.width, |
421 maxWidth = width, | 421 maxWidth = size.width, |
422 minHeight = height, | 422 minHeight = size.height, |
423 maxHeight = height; | 423 maxHeight = size.height; |
424 | 424 |
425 BoxConstraints deflate(EdgeDims edges) { | 425 BoxConstraints deflate(EdgeDims edges) { |
426 assert(edges != null); | 426 assert(edges != null); |
427 return new BoxConstraints( | 427 return new BoxConstraints( |
428 minWidth: minWidth, | 428 minWidth: minWidth, |
429 maxWidth: maxWidth - (edges.left + edges.right), | 429 maxWidth: maxWidth - (edges.left + edges.right), |
430 minHeight: minHeight, | 430 minHeight: minHeight, |
431 maxHeight: maxHeight - (edges.top + edges.bottom) | 431 maxHeight: maxHeight - (edges.top + edges.bottom) |
432 ); | 432 ); |
433 } | 433 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 bool hitTest(HitTestResult result, { sky.Point position }) { | 503 bool hitTest(HitTestResult result, { sky.Point position }) { |
504 hitTestChildren(result, position: position); | 504 hitTestChildren(result, position: position); |
505 result.add(this); | 505 result.add(this); |
506 return true; | 506 return true; |
507 } | 507 } |
508 void hitTestChildren(HitTestResult result, { sky.Point position }) { } | 508 void hitTestChildren(HitTestResult result, { sky.Point position }) { } |
509 | 509 |
510 sky.Size size = new sky.Size(0.0, 0.0); | 510 sky.Size size = new sky.Size(0.0, 0.0); |
511 } | 511 } |
512 | 512 |
| 513 abstract class RenderProxyBox extends RenderBox with RenderNodeWithChildMixin<Re
nderBox> { |
| 514 RenderProxyBox(RenderBox child) { |
| 515 this.child = child; |
| 516 } |
| 517 |
| 518 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
| 519 return child.getIntrinsicDimensions(constraints); |
| 520 } |
| 521 |
| 522 void performLayout() { |
| 523 child.layout(constraints, parentUsesSize: true); |
| 524 size = child.size; |
| 525 } |
| 526 |
| 527 void hitTestChildren(HitTestResult result, { sky.Point position }) { |
| 528 child.hitTest(result, position: position); |
| 529 } |
| 530 |
| 531 void paint(RenderNodeDisplayList canvas) { |
| 532 child.paint(canvas); |
| 533 } |
| 534 } |
| 535 |
| 536 class RenderSizedBox extends RenderProxyBox { |
| 537 final sky.Size desiredSize; |
| 538 |
| 539 RenderSizedBox(RenderBox child, [this.desiredSize = const sky.Size.infinite()]
) |
| 540 : super(child); |
| 541 |
| 542 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { |
| 543 return new BoxDimensions.withConstraints(constraints, |
| 544 width: desiredSize.width, |
| 545 height: desiredSize.height); |
| 546 } |
| 547 |
| 548 void performLayout() { |
| 549 size = constraints.constrain(desiredSize); |
| 550 child.layout(new BoxConstraints.tight(size)); |
| 551 } |
| 552 } |
| 553 |
513 class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { | 554 class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { |
514 | 555 |
515 RenderPadding(EdgeDims padding, RenderBox child) { | 556 RenderPadding(EdgeDims padding, RenderBox child) { |
516 assert(padding != null); | 557 assert(padding != null); |
517 this.padding = padding; | 558 this.padding = padding; |
518 this.child = child; | 559 this.child = child; |
519 } | 560 } |
520 | 561 |
521 EdgeDims _padding; | 562 EdgeDims _padding; |
522 EdgeDims get padding => _padding; | 563 EdgeDims get padding => _padding; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 | 625 |
585 BoxDecoration _decoration; | 626 BoxDecoration _decoration; |
586 BoxDecoration get decoration => _decoration; | 627 BoxDecoration get decoration => _decoration; |
587 void set decoration (BoxDecoration value) { | 628 void set decoration (BoxDecoration value) { |
588 if (value == _decoration) | 629 if (value == _decoration) |
589 return; | 630 return; |
590 _decoration = value; | 631 _decoration = value; |
591 markNeedsPaint(); | 632 markNeedsPaint(); |
592 } | 633 } |
593 | 634 |
| 635 void performLayout() { |
| 636 size = constraints.constrain(new sky.Size.infinite()); |
| 637 } |
| 638 |
594 void paint(RenderNodeDisplayList canvas) { | 639 void paint(RenderNodeDisplayList canvas) { |
595 assert(size.width != null); | 640 assert(size.width != null); |
596 assert(size.height != null); | 641 assert(size.height != null); |
597 | 642 |
598 if (_decoration == null) | 643 if (_decoration == null) |
599 return; | 644 return; |
600 | 645 |
601 if (_decoration.backgroundColor != null) { | 646 if (_decoration.backgroundColor != null) { |
602 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; | 647 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
603 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height),
paint); | 648 canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height),
paint); |
604 } | 649 } |
605 } | 650 } |
606 | |
607 } | 651 } |
608 | 652 |
609 class RenderDecoratedCircle extends RenderDecoratedBox with RenderNodeWithChildM
ixin<RenderBox> { | 653 class RenderDecoratedCircle extends RenderDecoratedBox with RenderNodeWithChildM
ixin<RenderBox> { |
610 RenderDecoratedCircle({ | 654 RenderDecoratedCircle({ |
611 BoxDecoration decoration, | 655 BoxDecoration decoration, |
612 RenderBox child | 656 RenderBox child |
613 }) : super(decoration) { | 657 }) : super(decoration) { |
614 this.child = child; | 658 this.child = child; |
615 } | 659 } |
616 | 660 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 if (_orientation != null && child != null) | 711 if (_orientation != null && child != null) |
668 child.rotate(oldAngle: _orientation, newAngle: constraints.orientation,
time: timeForRotation); | 712 child.rotate(oldAngle: _orientation, newAngle: constraints.orientation,
time: timeForRotation); |
669 _orientation = constraints.orientation; | 713 _orientation = constraints.orientation; |
670 } | 714 } |
671 _size = new sky.Size(constraints.width, constraints.height); | 715 _size = new sky.Size(constraints.width, constraints.height); |
672 assert(_size.height < double.INFINITY); | 716 assert(_size.height < double.INFINITY); |
673 assert(_size.width < double.INFINITY); | 717 assert(_size.width < double.INFINITY); |
674 } | 718 } |
675 void performLayout() { | 719 void performLayout() { |
676 if (child != null) { | 720 if (child != null) { |
677 child.layout(new BoxConstraints.tight(width: width, height: height)); | 721 child.layout(new BoxConstraints.tight(_size)); |
678 assert(child.size.width == width); | 722 assert(child.size.width == width); |
679 assert(child.size.height == height); | 723 assert(child.size.height == height); |
680 } | 724 } |
681 } | 725 } |
682 | 726 |
683 void rotate({ int oldAngle, int newAngle, Duration time }) { | 727 void rotate({ int oldAngle, int newAngle, Duration time }) { |
684 assert(false); // nobody tells the screen to rotate, the whole rotate() danc
e is started from our performResize() | 728 assert(false); // nobody tells the screen to rotate, the whole rotate() danc
e is started from our performResize() |
685 } | 729 } |
686 | 730 |
687 bool hitTest(HitTestResult result, { sky.Point position }) { | 731 bool hitTest(HitTestResult result, { sky.Point position }) { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 | 990 |
947 void hitTestChildren(HitTestResult result, { double x, double y }) { | 991 void hitTestChildren(HitTestResult result, { double x, double y }) { |
948 // defaultHitTestChildren(result, x: x, y: y); | 992 // defaultHitTestChildren(result, x: x, y: y); |
949 } | 993 } |
950 | 994 |
951 void paint(RenderNodeDisplayList canvas) { | 995 void paint(RenderNodeDisplayList canvas) { |
952 super.paint(canvas); | 996 super.paint(canvas); |
953 _layoutRoot.paint(canvas); | 997 _layoutRoot.paint(canvas); |
954 } | 998 } |
955 } | 999 } |
OLD | NEW |