| 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 'object.dart'; | 7 import 'object.dart'; |
| 8 import '../painting/box_painter.dart'; | 8 import '../painting/box_painter.dart'; |
| 9 import 'package:vector_math/vector_math.dart'; | 9 import 'package:vector_math/vector_math.dart'; |
| 10 import 'package:sky/framework/net/image_cache.dart' as image_cache; | 10 import 'package:sky/framework/net/image_cache.dart' as image_cache; |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 | 282 |
| 283 void hitTestChildren(HitTestResult result, { Point position }) { | 283 void hitTestChildren(HitTestResult result, { Point position }) { |
| 284 if (child != null) | 284 if (child != null) |
| 285 child.hitTest(result, position: position); | 285 child.hitTest(result, position: position); |
| 286 else | 286 else |
| 287 super.hitTestChildren(result, position: position); | 287 super.hitTestChildren(result, position: position); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void paint(RenderObjectDisplayList canvas) { | 290 void paint(sky.Canvas canvas) { |
| 291 if (child != null) | 291 if (child != null) |
| 292 child.paint(canvas); | 292 child.paint(canvas); |
| 293 } | 293 } |
| 294 | 294 |
| 295 } | 295 } |
| 296 | 296 |
| 297 class RenderSizedBox extends RenderProxyBox { | 297 class RenderSizedBox extends RenderProxyBox { |
| 298 | 298 |
| 299 RenderSizedBox({ | 299 RenderSizedBox({ |
| 300 RenderBox child, | 300 RenderBox child, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 double get opacity => _opacity; | 445 double get opacity => _opacity; |
| 446 void set opacity (double value) { | 446 void set opacity (double value) { |
| 447 assert(value != null); | 447 assert(value != null); |
| 448 assert(value >= 0.0 && value <= 1.0); | 448 assert(value >= 0.0 && value <= 1.0); |
| 449 if (_opacity == value) | 449 if (_opacity == value) |
| 450 return; | 450 return; |
| 451 _opacity = value; | 451 _opacity = value; |
| 452 markNeedsPaint(); | 452 markNeedsPaint(); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void paint(RenderObjectDisplayList canvas) { | 455 void paint(sky.Canvas canvas) { |
| 456 if (child != null) { | 456 if (child != null) { |
| 457 int a = (_opacity * 255).round(); | 457 int a = (_opacity * 255).round(); |
| 458 | 458 |
| 459 if (a == 0) | 459 if (a == 0) |
| 460 return; | 460 return; |
| 461 | 461 |
| 462 if (a == 255) { | 462 if (a == 255) { |
| 463 child.paint(canvas); | 463 child.paint(canvas); |
| 464 return; | 464 return; |
| 465 } | 465 } |
| 466 | 466 |
| 467 Paint paint = new Paint() | 467 Paint paint = new Paint() |
| 468 ..color = new Color.fromARGB(a, 0, 0, 0) | 468 ..color = new Color.fromARGB(a, 0, 0, 0) |
| 469 ..setTransferMode(sky.TransferMode.srcOverMode); | 469 ..setTransferMode(sky.TransferMode.srcOverMode); |
| 470 canvas.saveLayer(null, paint); | 470 canvas.saveLayer(null, paint); |
| 471 child.paint(canvas); | 471 child.paint(canvas); |
| 472 canvas.restore(); | 472 canvas.restore(); |
| 473 } | 473 } |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 class RenderClipRect extends RenderProxyBox { | 477 class RenderClipRect extends RenderProxyBox { |
| 478 RenderClipRect({ RenderBox child }) : super(child); | 478 RenderClipRect({ RenderBox child }) : super(child); |
| 479 | 479 |
| 480 void paint(RenderObjectDisplayList canvas) { | 480 void paint(sky.Canvas canvas) { |
| 481 if (child != null) { | 481 if (child != null) { |
| 482 canvas.save(); | 482 canvas.save(); |
| 483 canvas.clipRect(new Rect.fromSize(size)); | 483 canvas.clipRect(new Rect.fromSize(size)); |
| 484 child.paint(canvas); | 484 child.paint(canvas); |
| 485 canvas.restore(); | 485 canvas.restore(); |
| 486 } | 486 } |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 | 489 |
| 490 class RenderClipOval extends RenderProxyBox { | 490 class RenderClipOval extends RenderProxyBox { |
| 491 RenderClipOval({ RenderBox child }) : super(child); | 491 RenderClipOval({ RenderBox child }) : super(child); |
| 492 | 492 |
| 493 void paint(RenderObjectDisplayList canvas) { | 493 void paint(sky.Canvas canvas) { |
| 494 if (child != null) { | 494 if (child != null) { |
| 495 Rect rect = new Rect.fromSize(size); | 495 Rect rect = new Rect.fromSize(size); |
| 496 canvas.saveLayer(rect, new Paint()); | 496 canvas.saveLayer(rect, new Paint()); |
| 497 Path path = new Path(); | 497 Path path = new Path(); |
| 498 path.addOval(rect); | 498 path.addOval(rect); |
| 499 canvas.clipPath(path); | 499 canvas.clipPath(path); |
| 500 child.paint(canvas); | 500 child.paint(canvas); |
| 501 canvas.restore(); | 501 canvas.restore(); |
| 502 } | 502 } |
| 503 } | 503 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 new Size(padding.left + padding.right, padding.top + padding.bottom)); | 557 new Size(padding.left + padding.right, padding.top + padding.bottom)); |
| 558 return; | 558 return; |
| 559 } | 559 } |
| 560 child.layout(innerConstraints, parentUsesSize: true); | 560 child.layout(innerConstraints, parentUsesSize: true); |
| 561 assert(child.parentData is BoxParentData); | 561 assert(child.parentData is BoxParentData); |
| 562 child.parentData.position = new Point(padding.left, padding.top); | 562 child.parentData.position = new Point(padding.left, padding.top); |
| 563 size = constraints.constrain(new Size(padding.left + child.size.width + padd
ing.right, | 563 size = constraints.constrain(new Size(padding.left + child.size.width + padd
ing.right, |
| 564 padding.top + child.size.height +
padding.bottom)); | 564 padding.top + child.size.height +
padding.bottom)); |
| 565 } | 565 } |
| 566 | 566 |
| 567 void paint(RenderObjectDisplayList canvas) { | 567 void paint(sky.Canvas canvas) { |
| 568 if (child != null) | 568 if (child != null) |
| 569 canvas.paintChild(child, child.parentData.position); | 569 paintChild(canvas, child, child.parentData.position); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void hitTestChildren(HitTestResult result, { Point position }) { | 572 void hitTestChildren(HitTestResult result, { Point position }) { |
| 573 if (child != null) { | 573 if (child != null) { |
| 574 assert(child.parentData is BoxParentData); | 574 assert(child.parentData is BoxParentData); |
| 575 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); | 575 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); |
| 576 if (childBounds.contains(position)) { | 576 if (childBounds.contains(position)) { |
| 577 child.hitTest(result, position: new Point(position.x - child.parentData.
position.x, | 577 child.hitTest(result, position: new Point(position.x - child.parentData.
position.x, |
| 578 position.y - child.parentD
ata.position.y)); | 578 position.y - child.parentD
ata.position.y)); |
| 579 } | 579 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 } | 657 } |
| 658 | 658 |
| 659 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 659 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 660 return _sizeForConstraints(constraints).height; | 660 return _sizeForConstraints(constraints).height; |
| 661 } | 661 } |
| 662 | 662 |
| 663 void performLayout() { | 663 void performLayout() { |
| 664 size = _sizeForConstraints(constraints); | 664 size = _sizeForConstraints(constraints); |
| 665 } | 665 } |
| 666 | 666 |
| 667 void paint(RenderObjectDisplayList canvas) { | 667 void paint(sky.Canvas canvas) { |
| 668 if (_image == null) return; | 668 if (_image == null) return; |
| 669 bool needsScale = size.width != _image.width || size.height != _image.height
; | 669 bool needsScale = size.width != _image.width || size.height != _image.height
; |
| 670 if (needsScale) { | 670 if (needsScale) { |
| 671 double widthScale = size.width / _image.width; | 671 double widthScale = size.width / _image.width; |
| 672 double heightScale = size.height / _image.height; | 672 double heightScale = size.height / _image.height; |
| 673 canvas.save(); | 673 canvas.save(); |
| 674 canvas.scale(widthScale, heightScale); | 674 canvas.scale(widthScale, heightScale); |
| 675 } | 675 } |
| 676 Paint paint = new Paint(); | 676 Paint paint = new Paint(); |
| 677 canvas.drawImage(_image, 0.0, 0.0, paint); | 677 canvas.drawImage(_image, 0.0, 0.0, paint); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 692 BoxPainter _painter; | 692 BoxPainter _painter; |
| 693 BoxDecoration get decoration => _painter.decoration; | 693 BoxDecoration get decoration => _painter.decoration; |
| 694 void set decoration (BoxDecoration value) { | 694 void set decoration (BoxDecoration value) { |
| 695 assert(value != null); | 695 assert(value != null); |
| 696 if (value == _painter.decoration) | 696 if (value == _painter.decoration) |
| 697 return; | 697 return; |
| 698 _painter.decoration = value; | 698 _painter.decoration = value; |
| 699 markNeedsPaint(); | 699 markNeedsPaint(); |
| 700 } | 700 } |
| 701 | 701 |
| 702 void paint(RenderObjectDisplayList canvas) { | 702 void paint(sky.Canvas canvas) { |
| 703 assert(size.width != null); | 703 assert(size.width != null); |
| 704 assert(size.height != null); | 704 assert(size.height != null); |
| 705 _painter.paint(canvas, new Rect.fromSize(size)); | 705 _painter.paint(canvas, new Rect.fromSize(size)); |
| 706 super.paint(canvas); | 706 super.paint(canvas); |
| 707 } | 707 } |
| 708 | 708 |
| 709 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n'; | 709 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(
prefix)}${prefix}decoration:\n${_painter.decoration.toString(prefix + " ")}\n'; |
| 710 } | 710 } |
| 711 | 711 |
| 712 class RenderTransform extends RenderProxyBox { | 712 class RenderTransform extends RenderProxyBox { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 Matrix4 inverse = new Matrix4.zero(); | 762 Matrix4 inverse = new Matrix4.zero(); |
| 763 double det = inverse.copyInverse(_transform); | 763 double det = inverse.copyInverse(_transform); |
| 764 // TODO(abarth): Check the determinant for degeneracy. | 764 // TODO(abarth): Check the determinant for degeneracy. |
| 765 | 765 |
| 766 Vector3 position3 = new Vector3(position.x, position.y, 0.0); | 766 Vector3 position3 = new Vector3(position.x, position.y, 0.0); |
| 767 Vector3 transformed3 = inverse.transform3(position3); | 767 Vector3 transformed3 = inverse.transform3(position3); |
| 768 Point transformed = new Point(transformed3.x, transformed3.y); | 768 Point transformed = new Point(transformed3.x, transformed3.y); |
| 769 super.hitTestChildren(result, position: transformed); | 769 super.hitTestChildren(result, position: transformed); |
| 770 } | 770 } |
| 771 | 771 |
| 772 void paint(RenderObjectDisplayList canvas) { | 772 void paint(sky.Canvas canvas) { |
| 773 canvas.save(); | 773 canvas.save(); |
| 774 canvas.concat(_transform.storage); | 774 canvas.concat(_transform.storage); |
| 775 super.paint(canvas); | 775 super.paint(canvas); |
| 776 canvas.restore(); | 776 canvas.restore(); |
| 777 } | 777 } |
| 778 | 778 |
| 779 String debugDescribeSettings(String prefix) { | 779 String debugDescribeSettings(String prefix) { |
| 780 List<String> result = _transform.toString().split('\n').map((s) => '$prefix
$s\n').toList(); | 780 List<String> result = _transform.toString().split('\n').map((s) => '$prefix
$s\n').toList(); |
| 781 result.removeLast(); | 781 result.removeLast(); |
| 782 return '${super.debugDescribeSettings(prefix)}${prefix}transform matrix:\n${
result.join()}'; | 782 return '${super.debugDescribeSettings(prefix)}${prefix}transform matrix:\n${
result.join()}'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 return; | 824 return; |
| 825 _callback = value; | 825 _callback = value; |
| 826 markNeedsPaint(); | 826 markNeedsPaint(); |
| 827 } | 827 } |
| 828 | 828 |
| 829 void attach() { | 829 void attach() { |
| 830 assert(_callback != null); | 830 assert(_callback != null); |
| 831 super.attach(); | 831 super.attach(); |
| 832 } | 832 } |
| 833 | 833 |
| 834 void paint(RenderObjectDisplayList canvas) { | 834 void paint(sky.Canvas canvas) { |
| 835 assert(_callback != null); | 835 assert(_callback != null); |
| 836 _callback(canvas, size); | 836 _callback(canvas, size); |
| 837 super.paint(canvas); | 837 super.paint(canvas); |
| 838 } | 838 } |
| 839 } | 839 } |
| 840 | 840 |
| 841 // RENDER VIEW LAYOUT MANAGER | 841 // RENDER VIEW LAYOUT MANAGER |
| 842 | 842 |
| 843 class ViewConstraints { | 843 class ViewConstraints { |
| 844 | 844 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 bool hitTest(HitTestResult result, { Point position }) { | 902 bool hitTest(HitTestResult result, { Point position }) { |
| 903 if (child != null) { | 903 if (child != null) { |
| 904 Rect childBounds = new Rect.fromSize(child.size); | 904 Rect childBounds = new Rect.fromSize(child.size); |
| 905 if (childBounds.contains(position)) | 905 if (childBounds.contains(position)) |
| 906 child.hitTest(result, position: position); | 906 child.hitTest(result, position: position); |
| 907 } | 907 } |
| 908 result.add(new HitTestEntry(this)); | 908 result.add(new HitTestEntry(this)); |
| 909 return true; | 909 return true; |
| 910 } | 910 } |
| 911 | 911 |
| 912 void paint(RenderObjectDisplayList canvas) { | 912 void paint(sky.Canvas canvas) { |
| 913 if (child != null) | 913 if (child != null) |
| 914 canvas.paintChild(child, Point.origin); | 914 paintChild(canvas, child, Point.origin); |
| 915 } | 915 } |
| 916 | 916 |
| 917 void paintFrame() { | 917 void paintFrame() { |
| 918 RenderObject.debugDoingPaint = true; | 918 RenderObject.debugDoingPaint = true; |
| 919 RenderObjectDisplayList canvas = new RenderObjectDisplayList(sky.view.width,
sky.view.height); | 919 sky.PictureRecorder recorder = new sky.PictureRecorder(); |
| 920 sky.Canvas canvas = recorder.beginRecording(sky.view.width, sky.view.height)
; |
| 920 paint(canvas); | 921 paint(canvas); |
| 921 sky.view.picture = canvas.endRecording(); | 922 sky.view.picture = recorder.endRecording(); |
| 922 RenderObject.debugDoingPaint = false; | 923 RenderObject.debugDoingPaint = false; |
| 923 } | 924 } |
| 924 | 925 |
| 925 } | 926 } |
| 926 | 927 |
| 927 // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS | 928 // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS |
| 928 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare
ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend
erObjectMixin<ChildType, ParentDataType> { | 929 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare
ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend
erObjectMixin<ChildType, ParentDataType> { |
| 929 | 930 |
| 930 void defaultHitTestChildren(HitTestResult result, { Point position }) { | 931 void defaultHitTestChildren(HitTestResult result, { Point position }) { |
| 931 // the x, y parameters have the top left of the node's box as the origin | 932 // the x, y parameters have the top left of the node's box as the origin |
| 932 ChildType child = lastChild; | 933 ChildType child = lastChild; |
| 933 while (child != null) { | 934 while (child != null) { |
| 934 assert(child.parentData is ParentDataType); | 935 assert(child.parentData is ParentDataType); |
| 935 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); | 936 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); |
| 936 if (childBounds.contains(position)) { | 937 if (childBounds.contains(position)) { |
| 937 if (child.hitTest(result, position: new Point(position.x - child.parentD
ata.position.x, | 938 if (child.hitTest(result, position: new Point(position.x - child.parentD
ata.position.x, |
| 938 position.y - child.par
entData.position.y))) | 939 position.y - child.par
entData.position.y))) |
| 939 break; | 940 break; |
| 940 } | 941 } |
| 941 child = child.parentData.previousSibling; | 942 child = child.parentData.previousSibling; |
| 942 } | 943 } |
| 943 } | 944 } |
| 944 | 945 |
| 945 void defaultPaint(RenderObjectDisplayList canvas) { | 946 void defaultPaint(sky.Canvas canvas) { |
| 946 RenderBox child = firstChild; | 947 RenderBox child = firstChild; |
| 947 while (child != null) { | 948 while (child != null) { |
| 948 assert(child.parentData is ParentDataType); | 949 assert(child.parentData is ParentDataType); |
| 949 canvas.paintChild(child, child.parentData.position); | 950 paintChild(canvas, child, child.parentData.position); |
| 950 child = child.parentData.nextSibling; | 951 child = child.parentData.nextSibling; |
| 951 } | 952 } |
| 952 } | 953 } |
| 953 } | 954 } |
| OLD | NEW |