Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: sky/sdk/lib/framework/layout2.dart

Issue 1156013003: Introduce RenderNodeWithChildMixin (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/framework/fn2.dart ('k') | sky/tests/raw/render_box.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 class HitTestResult { 255 class HitTestResult {
256 final List<RenderNode> path = new List<RenderNode>(); 256 final List<RenderNode> path = new List<RenderNode>();
257 257
258 RenderNode get result => path.first; 258 RenderNode get result => path.first;
259 259
260 void add(RenderNode node) { 260 void add(RenderNode node) {
261 path.add(node); 261 path.add(node);
262 } 262 }
263 } 263 }
264 264
265 abstract class RenderNodeWithChildMixin<ChildType extends RenderNode> {
266 ChildType _child;
267 ChildType get child => _child;
268 void set child (ChildType value) {
269 if (_child != null)
270 dropChild(_child);
271 _child = value;
272 if (_child != null)
273 adoptChild(_child);
274 markNeedsLayout();
275 }
276 }
277
265 // GENERIC MIXIN FOR RENDER NODES THAT TAKE A LIST OF CHILDREN 278 // GENERIC MIXIN FOR RENDER NODES THAT TAKE A LIST OF CHILDREN
266 279
267 abstract class ContainerParentDataMixin<ChildType extends RenderNode> { 280 abstract class ContainerParentDataMixin<ChildType extends RenderNode> {
268 ChildType previousSibling; 281 ChildType previousSibling;
269 ChildType nextSibling; 282 ChildType nextSibling;
270 void detachSiblings() { 283 void detachSiblings() {
271 if (previousSibling != null) { 284 if (previousSibling != null) {
272 assert(previousSibling.parentData is ContainerParentDataMixin<ChildType>); 285 assert(previousSibling.parentData is ContainerParentDataMixin<ChildType>);
273 assert(previousSibling != this); 286 assert(previousSibling != this);
274 assert(previousSibling.parentData.nextSibling == this); 287 assert(previousSibling.parentData.nextSibling == this);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 return; 542 return;
530 543
531 if (_decoration.backgroundColor != null) { 544 if (_decoration.backgroundColor != null) {
532 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor; 545 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor;
533 canvas.drawRect(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint); 546 canvas.drawRect(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint);
534 } 547 }
535 } 548 }
536 549
537 } 550 }
538 551
552 class RenderDecoratedCircle extends RenderDecoratedBox with RenderNodeWithChildM ixin<RenderBox> {
553 RenderDecoratedCircle({
554 BoxDecoration decoration,
555 RenderBox child
556 }) : super(decoration) {
557 this.child = child;
558 }
559
560 void paint(RenderNodeDisplayList canvas) {
561 assert(width != null);
562 assert(height != null);
563
564 if (_decoration == null)
565 return;
566
567 if (_decoration.backgroundColor != null) {
568 sky.Paint paint = new sky.Paint()..color = _decoration.backgroundColor;
569 canvas.drawCircle(new sky.Rect()..setLTRB(0.0, 0.0, width, height), paint) ;
570 }
571 }
572 }
573
539 574
540 // RENDER VIEW LAYOUT MANAGER 575 // RENDER VIEW LAYOUT MANAGER
541 576
542 class RenderView extends RenderNode { 577 class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> {
543 578
544 RenderView({ 579 RenderView({
545 RenderBox root, 580 RenderBox child,
546 this.timeForRotation: const Duration(microseconds: 83333) 581 this.timeForRotation: const Duration(microseconds: 83333)
547 }) { 582 }) {
548 this.root = root; 583 this.child = child;
549 } 584 }
550 585
551 double _width; 586 double _width;
552 double get width => _width; 587 double get width => _width;
553 double _height; 588 double _height;
554 double get height => _height; 589 double get height => _height;
555 590
556 int _orientation; // 0..3 591 int _orientation; // 0..3
557 int get orientation => _orientation; 592 int get orientation => _orientation;
558 Duration timeForRotation; 593 Duration timeForRotation;
559 594
560 RenderBox _root;
561 RenderBox get root => _root;
562 void set root (RenderBox value) {
563 if (_root != null)
564 dropChild(_root);
565 _root = value;
566 if (_root != null)
567 adoptChild(_root);
568 markNeedsLayout();
569 }
570
571 void layout({ 595 void layout({
572 double newWidth, 596 double newWidth,
573 double newHeight, 597 double newHeight,
574 int newOrientation 598 int newOrientation
575 }) { 599 }) {
576 if (newOrientation != orientation) { 600 if (newOrientation != orientation) {
577 if (orientation != null && root != null) 601 if (orientation != null && child != null)
578 root.rotate(oldAngle: orientation, newAngle: newOrientation, time: timeF orRotation); 602 child.rotate(oldAngle: orientation, newAngle: newOrientation, time: time ForRotation);
579 _orientation = newOrientation; 603 _orientation = newOrientation;
580 } 604 }
581 if ((newWidth != width) || (newHeight != height)) { 605 if ((newWidth != width) || (newHeight != height)) {
582 _width = newWidth; 606 _width = newWidth;
583 _height = newHeight; 607 _height = newHeight;
584 relayout(); 608 relayout();
585 } else { 609 } else {
586 layoutDone(); 610 layoutDone();
587 } 611 }
588 } 612 }
589 613
590 void relayout() { 614 void relayout() {
591 if (root != null) { 615 if (child != null) {
592 root.layout(new BoxConstraints( 616 child.layout(new BoxConstraints(
593 minWidth: width, 617 minWidth: width,
594 maxWidth: width, 618 maxWidth: width,
595 minHeight: height, 619 minHeight: height,
596 maxHeight: height 620 maxHeight: height
597 )); 621 ));
598 assert(root.width == width); 622 assert(child.width == width);
599 assert(root.height == height); 623 assert(child.height == height);
600 } 624 }
601 layoutDone(); 625 layoutDone();
602 } 626 }
603 627
604 void rotate({ int oldAngle, int newAngle, Duration time }) { 628 void rotate({ int oldAngle, int newAngle, Duration time }) {
605 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our layout() 629 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our layout()
606 } 630 }
607 631
608 bool hitTest(HitTestResult result, { double x, double y }) { 632 bool hitTest(HitTestResult result, { double x, double y }) {
609 if (x < 0.0 || x >= width || y < 0.0 || y >= height) 633 if (x < 0.0 || x >= width || y < 0.0 || y >= height)
610 return false; 634 return false;
611 if (root != null) { 635 if (child != null) {
612 if (x >= 0.0 && x < root.width && y >= 0.0 && y < root.height) 636 if (x >= 0.0 && x < child.width && y >= 0.0 && y < child.height)
613 root.hitTest(result, x: x, y: y); 637 child.hitTest(result, x: x, y: y);
614 } 638 }
615 result.add(this); 639 result.add(this);
616 return true; 640 return true;
617 } 641 }
618 642
619 void paint(RenderNodeDisplayList canvas) { 643 void paint(RenderNodeDisplayList canvas) {
620 if (root != null) 644 if (child != null)
621 canvas.paintChild(root, 0.0, 0.0); 645 canvas.paintChild(child, 0.0, 0.0);
622 } 646 }
623 647
624 void paintFrame() { 648 void paintFrame() {
625 RenderNode._debugDoingPaint = true; 649 RenderNode._debugDoingPaint = true;
626 var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height); 650 var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height);
627 paint(canvas); 651 paint(canvas);
628 sky.view.picture = canvas.endRecording(); 652 sky.view.picture = canvas.endRecording();
629 RenderNode._debugDoingPaint = false; 653 RenderNode._debugDoingPaint = false;
630 } 654 }
631 655
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 917
894 void hitTestChildren(HitTestResult result, { double x, double y }) { 918 void hitTestChildren(HitTestResult result, { double x, double y }) {
895 defaultHitTestChildren(result, x: x, y: y); 919 defaultHitTestChildren(result, x: x, y: y);
896 } 920 }
897 921
898 void paint(RenderNodeDisplayList canvas) { 922 void paint(RenderNodeDisplayList canvas) {
899 super.paint(canvas); 923 super.paint(canvas);
900 defaultPaint(canvas); 924 defaultPaint(canvas);
901 } 925 }
902 } 926 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/fn2.dart ('k') | sky/tests/raw/render_box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698