Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 library layout; | 1 library layout; |
| 2 | 2 |
| 3 // This version of layout.dart is an update to the other one, this one using new APIs. | 3 // This version of layout.dart is an update to the other one, this one using new APIs. |
| 4 // It will not work in a stock Sky setup currently. | 4 // It will not work in a stock Sky setup currently. |
| 5 | 5 |
| 6 import 'node.dart'; | 6 import 'node.dart'; |
| 7 | 7 |
| 8 import 'dart:sky' as sky; | 8 import 'dart:sky' as sky; |
| 9 | 9 |
| 10 // ABSTRACT LAYOUT | 10 // ABSTRACT LAYOUT |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 | 211 |
| 212 void rotate({ | 212 void rotate({ |
| 213 int oldAngle, // 0..3 | 213 int oldAngle, // 0..3 |
| 214 int newAngle, // 0..3 | 214 int newAngle, // 0..3 |
| 215 Duration time | 215 Duration time |
| 216 }) { } | 216 }) { } |
| 217 | 217 |
| 218 | 218 |
| 219 // HIT TESTING | 219 // HIT TESTING |
| 220 | 220 |
| 221 void handlePointer(sky.PointerEvent event) { | 221 bool handlePointer(sky.PointerEvent event, { double x: 0.0, double y: 0.0 }) { |
|
Hixie
2015/05/21 19:31:42
Remove the x/y arguments here.
| |
| 222 // override this if you have children, to hand it to the appropriate child | 222 // override this if you have children, to hand it to the appropriate child |
| 223 // override this if you want to do anything with the pointer event | 223 // override this if you want to do anything with the pointer event |
| 224 } | 224 } |
|
Hixie
2015/05/21 19:31:42
Add the following (or something like it):
// The
| |
| 225 | 225 |
| 226 | 226 |
| 227 // PAINTING | 227 // PAINTING |
| 228 | 228 |
| 229 static bool _debugDoingPaint = false; | 229 static bool _debugDoingPaint = false; |
| 230 void markNeedsPaint() { | 230 void markNeedsPaint() { |
| 231 assert(!_debugDoingPaint); | 231 assert(!_debugDoingPaint); |
| 232 // TODO(abarth): It's very redunant to call this for every node in the | |
| 233 // render tree during layout. We should instead compute a summary bit and | |
| 234 // call it once at the end of layout. | |
| 235 sky.view.scheduleFrame(); | |
| 232 } | 236 } |
| 233 void paint(RenderNodeDisplayList canvas) { } | 237 void paint(RenderNodeDisplayList canvas) { } |
| 234 | 238 |
| 235 } | 239 } |
| 236 | 240 |
| 237 | 241 |
| 238 // GENERIC MIXIN FOR RENDER NODES THAT TAKE A LIST OF CHILDREN | 242 // GENERIC MIXIN FOR RENDER NODES THAT TAKE A LIST OF CHILDREN |
| 239 | 243 |
| 240 abstract class ContainerParentDataMixin<ChildType extends RenderNode> { | 244 abstract class ContainerParentDataMixin<ChildType extends RenderNode> { |
| 241 ChildType previousSibling; | 245 ChildType previousSibling; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 | 465 |
| 462 class BoxDecoration { | 466 class BoxDecoration { |
| 463 BoxDecoration({ | 467 BoxDecoration({ |
| 464 this.backgroundColor | 468 this.backgroundColor |
| 465 }); | 469 }); |
| 466 | 470 |
| 467 final int backgroundColor; | 471 final int backgroundColor; |
| 468 } | 472 } |
| 469 | 473 |
| 470 class RenderDecoratedBox extends RenderBox { | 474 class RenderDecoratedBox extends RenderBox { |
| 471 BoxDecoration decoration; | 475 BoxDecoration _decoration; |
| 472 | 476 |
| 473 RenderDecoratedBox(this.decoration); | 477 RenderDecoratedBox(BoxDecoration decoration) : _decoration = decoration; |
| 478 | |
| 479 void setBoxDecoration(BoxDecoration decoration) { | |
| 480 if (_decoration == decoration) | |
| 481 return; | |
| 482 _decoration = decoration; | |
| 483 markNeedsPaint(); | |
| 484 } | |
| 474 | 485 |
| 475 void paint(RenderNodeDisplayList canvas) { | 486 void paint(RenderNodeDisplayList canvas) { |
| 476 assert(width != null); | 487 assert(width != null); |
| 477 assert(height != null); | 488 assert(height != null); |
| 478 | 489 |
| 479 if (decoration == null) | 490 if (_decoration == null) |
| 480 return; | 491 return; |
| 481 | 492 |
| 482 if (decoration.backgroundColor != null) { | 493 if (_decoration.backgroundColor != null) { |
| 483 sky.Paint paint = new sky.Paint()..color = decoration.backgroundColor; | 494 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; |
| 484 canvas.drawRect(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint); | 495 canvas.drawRect(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint); |
| 485 } | 496 } |
| 486 } | 497 } |
| 487 } | 498 } |
| 488 | 499 |
| 489 | 500 |
| 490 // RENDER VIEW LAYOUT MANAGER | 501 // RENDER VIEW LAYOUT MANAGER |
| 491 | 502 |
| 492 class RenderView extends RenderNode { | 503 class RenderView extends RenderNode { |
| 493 | 504 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 root.layout(new BoxConstraints( | 551 root.layout(new BoxConstraints( |
| 541 minWidth: width, maxWidth: width, minHeight: height, maxHeight: height)) ; | 552 minWidth: width, maxWidth: width, minHeight: height, maxHeight: height)) ; |
| 542 assert(root.width == width); | 553 assert(root.width == width); |
| 543 assert(root.height == height); | 554 assert(root.height == height); |
| 544 } | 555 } |
| 545 | 556 |
| 546 void rotate({ int oldAngle, int newAngle, Duration time }) { | 557 void rotate({ int oldAngle, int newAngle, Duration time }) { |
| 547 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our layout() | 558 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our layout() |
| 548 } | 559 } |
| 549 | 560 |
| 561 bool handlePointer(sky.PointerEvent event, { double x: 0.0, double y: 0.0 }) { | |
| 562 if (x < 0.0 || x >= root.width || y < 0.0 || y >= root.height) | |
| 563 return false; | |
| 564 return root.handlePointer(event, x: x, y: y); | |
| 565 } | |
| 566 | |
| 550 void paint(RenderNodeDisplayList canvas) { | 567 void paint(RenderNodeDisplayList canvas) { |
| 551 canvas.paintChild(root, 0.0, 0.0); | 568 canvas.paintChild(root, 0.0, 0.0); |
| 552 } | 569 } |
| 553 | 570 |
| 554 void paintFrame() { | 571 void paintFrame() { |
| 555 RenderNode._debugDoingPaint = true; | 572 RenderNode._debugDoingPaint = true; |
| 556 var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height); | 573 var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height); |
| 557 paint(canvas); | 574 paint(canvas); |
| 558 sky.view.picture = canvas.endRecording(); | 575 sky.view.picture = canvas.endRecording(); |
| 559 sky.view.schedulePaint(); | |
| 560 RenderNode._debugDoingPaint = false; | 576 RenderNode._debugDoingPaint = false; |
| 561 } | 577 } |
| 562 | 578 |
| 563 } | 579 } |
| 564 | 580 |
| 565 | 581 |
| 566 // BLOCK LAYOUT MANAGER | 582 // BLOCK LAYOUT MANAGER |
| 567 | 583 |
| 568 class EdgeDims { | 584 class EdgeDims { |
| 569 // used for e.g. padding | 585 // used for e.g. padding |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 assert(child.parentData is BlockParentData); | 678 assert(child.parentData is BlockParentData); |
| 663 child.parentData.x = 0.0; // TODO(abarth): Shouldn't this be _padding.left ? | 679 child.parentData.x = 0.0; // TODO(abarth): Shouldn't this be _padding.left ? |
| 664 child.parentData.y = y; | 680 child.parentData.y = y; |
| 665 y += child.height; | 681 y += child.height; |
| 666 child = child.parentData.nextSibling; | 682 child = child.parentData.nextSibling; |
| 667 } | 683 } |
| 668 height = clamp(min: _minHeight, value: y + _padding.bottom, max: _maxHeight) ; | 684 height = clamp(min: _minHeight, value: y + _padding.bottom, max: _maxHeight) ; |
| 669 layoutDone(); | 685 layoutDone(); |
| 670 } | 686 } |
| 671 | 687 |
| 672 void handlePointer(sky.PointerEvent event, { double x: 0.0, double y: 0.0 }) { | 688 bool handlePointer(sky.PointerEvent event, { double x: 0.0, double y: 0.0 }) { |
| 673 // the x, y parameters have the top left of the node's box as the origin | 689 // the x, y parameters have the top left of the node's box as the origin |
| 674 RenderBox child = _lastChild; | 690 RenderBox child = _lastChild; |
| 675 while (child != null) { | 691 while (child != null) { |
| 676 assert(child.parentData is BlockParentData); | 692 assert(child.parentData is BlockParentData); |
| 677 if ((x >= child.parentData.x) && (x < child.parentData.x + child.width) && | 693 if ((x >= child.parentData.x) && (x < child.parentData.x + child.width) && |
| 678 (y >= child.parentData.y) && (y < child.parentData.y + child.height)) { | 694 (y >= child.parentData.y) && (y < child.parentData.y + child.height)) { |
| 679 child.handlePointer(event, x: x-child.parentData.x, y: y-child.parentDat a.y); | 695 if (child.handlePointer(event, x: x-child.parentData.x, y: y-child.paren tData.y)) |
| 696 return true; | |
| 680 break; | 697 break; |
| 681 } | 698 } |
| 682 child = child.parentData.previousSibling; | 699 child = child.parentData.previousSibling; |
| 683 } | 700 } |
| 684 super.handlePointer(event); | 701 return super.handlePointer(event, x: x, y: y); |
|
Hixie
2015/05/21 19:31:42
Render block should always return true, by definit
| |
| 685 } | 702 } |
| 686 | 703 |
| 687 void paint(RenderNodeDisplayList canvas) { | 704 void paint(RenderNodeDisplayList canvas) { |
| 688 super.paint(canvas); | 705 super.paint(canvas); |
| 689 RenderBox child = _firstChild; | 706 RenderBox child = _firstChild; |
| 690 while (child != null) { | 707 while (child != null) { |
| 691 assert(child.parentData is BlockParentData); | 708 assert(child.parentData is BlockParentData); |
| 692 canvas.paintChild(child, child.parentData.x, child.parentData.y); | 709 canvas.paintChild(child, child.parentData.x, child.parentData.y); |
| 693 child = child.parentData.nextSibling; | 710 child = child.parentData.nextSibling; |
| 694 } | 711 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 statusbar.parentData.x = 0.0; | 766 statusbar.parentData.x = 0.0; |
| 750 statusbar.parentData.y = height - kStatusbarHeight; | 767 statusbar.parentData.y = height - kStatusbarHeight; |
| 751 bodyHeight -= kStatusbarHeight; | 768 bodyHeight -= kStatusbarHeight; |
| 752 } | 769 } |
| 753 body.layout(new BoxConstraints(minWidth: width, maxWidth: width, minHeight: bodyHeight, maxHeight: bodyHeight)); | 770 body.layout(new BoxConstraints(minWidth: width, maxWidth: width, minHeight: bodyHeight, maxHeight: bodyHeight)); |
| 754 if (drawer != null) | 771 if (drawer != null) |
| 755 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: width, minHeight : height, maxHeight: height)); | 772 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: width, minHeight : height, maxHeight: height)); |
| 756 layoutDone(); | 773 layoutDone(); |
| 757 } | 774 } |
| 758 | 775 |
| 759 void handlePointer(sky.PointerEvent event, { double x: 0.0, double y: 0.0 }) { | 776 bool handlePointer(sky.PointerEvent event, { double x: 0.0, double y: 0.0 }) { |
| 760 if ((drawer != null) && (x < drawer.width)) { | 777 if ((drawer != null) && (x < drawer.width)) { |
| 761 drawer.handlePointer(event, x: x, y: y); | 778 if (drawer.handlePointer(event, x: x, y: y)) |
| 779 return true; | |
| 762 } else if ((toolbar != null) && (y < toolbar.height)) { | 780 } else if ((toolbar != null) && (y < toolbar.height)) { |
| 763 toolbar.handlePointer(event, x: x, y: y); | 781 if (toolbar.handlePointer(event, x: x, y: y)) |
| 782 return true; | |
| 764 } else if ((statusbar != null) && (y > (statusbar.parentData as BoxParentDat a).y)) { | 783 } else if ((statusbar != null) && (y > (statusbar.parentData as BoxParentDat a).y)) { |
| 765 statusbar.handlePointer(event, x: x, y: y-(statusbar.parentData as BoxPare ntData).y); | 784 if (statusbar.handlePointer(event, x: x, y: y-(statusbar.parentData as Box ParentData).y)) |
| 785 return true; | |
| 766 } else { | 786 } else { |
| 767 body.handlePointer(event, x: x, y: y-(body.parentData as BoxParentData).y) ; | 787 if (body.handlePointer(event, x: x, y: y-(body.parentData as BoxParentData ).y)) |
| 788 return true; | |
| 768 } | 789 } |
| 769 super.handlePointer(event, x: x, y: y); | 790 return super.handlePointer(event, x: x, y: y); |
|
Hixie
2015/05/21 19:31:42
I think ScaffoldBox.handlePointer should always re
| |
| 770 } | 791 } |
| 771 | 792 |
| 772 void paint(RenderNodeDisplayList canvas) { | 793 void paint(RenderNodeDisplayList canvas) { |
| 773 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parentDa ta as BoxParentData).y); | 794 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parentDa ta as BoxParentData).y); |
| 774 if (statusbar != null) | 795 if (statusbar != null) |
| 775 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s tatusbar.parentData as BoxParentData).y); | 796 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s tatusbar.parentData as BoxParentData).y); |
| 776 if (toolbar != null) | 797 if (toolbar != null) |
| 777 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb ar.parentData as BoxParentData).y); | 798 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb ar.parentData as BoxParentData).y); |
| 778 if (drawer != null) | 799 if (drawer != null) |
| 779 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer. parentData as BoxParentData).y); | 800 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer. parentData as BoxParentData).y); |
| 780 } | 801 } |
| 781 | 802 |
| 782 } | 803 } |
| OLD | NEW |