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

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

Issue 1157563007: Make RenderView support changing the root dynamically, including being null. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | no next file » | 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 library layout;
6
7 // This version of layout.dart is an update to the other one, this one using new APIs.
8 // It will not work in a stock Sky setup currently.
9
10 import 'node.dart'; 5 import 'node.dart';
11
12 import 'dart:sky' as sky; 6 import 'dart:sky' as sky;
13 7
14 // ABSTRACT LAYOUT 8 // ABSTRACT LAYOUT
15 9
16 class ParentData { 10 class ParentData {
17 void detach() { 11 void detach() {
18 detachSiblings(); 12 detachSiblings();
19 } 13 }
20 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart 14 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart
21 void merge(ParentData other) { 15 void merge(ParentData other) {
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 537
544 538
545 // RENDER VIEW LAYOUT MANAGER 539 // RENDER VIEW LAYOUT MANAGER
546 540
547 class RenderView extends RenderNode { 541 class RenderView extends RenderNode {
548 542
549 RenderView({ 543 RenderView({
550 RenderBox root, 544 RenderBox root,
551 this.timeForRotation: const Duration(microseconds: 83333) 545 this.timeForRotation: const Duration(microseconds: 83333)
552 }) { 546 }) {
553 assert(root != null);
554 this.root = root; 547 this.root = root;
555 } 548 }
556 549
557 double _width; 550 double _width;
558 double get width => _width; 551 double get width => _width;
559 double _height; 552 double _height;
560 double get height => _height; 553 double get height => _height;
561 554
562 int _orientation; // 0..3 555 int _orientation; // 0..3
563 int get orientation => _orientation; 556 int get orientation => _orientation;
564 Duration timeForRotation; 557 Duration timeForRotation;
565 558
566 RenderBox _root; 559 RenderBox _root;
567 RenderBox get root => _root; 560 RenderBox get root => _root;
568 void set root (RenderBox value) { 561 void set root (RenderBox value) {
569 assert(value != null); 562 if (_root != null)
563 dropChild(_root);
570 _root = value; 564 _root = value;
571 adoptChild(_root); 565 if (_root != null)
566 adoptChild(_root);
572 markNeedsLayout(); 567 markNeedsLayout();
573 } 568 }
574 569
575 void layout({ 570 void layout({
576 double newWidth, 571 double newWidth,
577 double newHeight, 572 double newHeight,
578 int newOrientation 573 int newOrientation
579 }) { 574 }) {
580 assert(root != null);
581 if (newOrientation != orientation) { 575 if (newOrientation != orientation) {
582 if (orientation != null) 576 if (orientation != null && root != null)
583 root.rotate(oldAngle: orientation, newAngle: newOrientation, time: timeF orRotation); 577 root.rotate(oldAngle: orientation, newAngle: newOrientation, time: timeF orRotation);
584 _orientation = newOrientation; 578 _orientation = newOrientation;
585 } 579 }
586 if ((newWidth != width) || (newHeight != height)) { 580 if ((newWidth != width) || (newHeight != height)) {
587 _width = newWidth; 581 _width = newWidth;
588 _height = newHeight; 582 _height = newHeight;
589 relayout(); 583 relayout();
590 } 584 }
591 } 585 }
592 586
593 void relayout() { 587 void relayout() {
594 assert(root != null); 588 if (root != null) {
595 root.layout(new BoxConstraints( 589 root.layout(new BoxConstraints(
596 minWidth: width, maxWidth: width, minHeight: height, maxHeight: height)) ; 590 minWidth: width,
597 assert(root.width == width); 591 maxWidth: width,
598 assert(root.height == height); 592 minHeight: height,
593 maxHeight: height
594 ));
595 assert(root.width == width);
596 assert(root.height == height);
597 }
599 } 598 }
600 599
601 void rotate({ int oldAngle, int newAngle, Duration time }) { 600 void rotate({ int oldAngle, int newAngle, Duration time }) {
602 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our layout() 601 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our layout()
603 } 602 }
604 603
605 bool hitTest(HitTestResult result, { double x, double y }) { 604 bool hitTest(HitTestResult result, { double x, double y }) {
606 assert(root != null);
607 if (x < 0.0 || x >= width || y < 0.0 || y >= height) 605 if (x < 0.0 || x >= width || y < 0.0 || y >= height)
608 return false; 606 return false;
609 if (x >= 0.0 && x < root.width && y >= 0.0 && y < root.height) 607 if (root != null) {
610 root.hitTest(result, x: x, y: y); 608 if (x >= 0.0 && x < root.width && y >= 0.0 && y < root.height)
609 root.hitTest(result, x: x, y: y);
610 }
611 result.add(this); 611 result.add(this);
612 return true; 612 return true;
613 } 613 }
614 614
615 void paint(RenderNodeDisplayList canvas) { 615 void paint(RenderNodeDisplayList canvas) {
616 canvas.paintChild(root, 0.0, 0.0); 616 if (root != null)
617 canvas.paintChild(root, 0.0, 0.0);
617 } 618 }
618 619
619 void paintFrame() { 620 void paintFrame() {
620 RenderNode._debugDoingPaint = true; 621 RenderNode._debugDoingPaint = true;
621 var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height); 622 var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height);
622 paint(canvas); 623 paint(canvas);
623 sky.view.picture = canvas.endRecording(); 624 sky.view.picture = canvas.endRecording();
624 RenderNode._debugDoingPaint = false; 625 RenderNode._debugDoingPaint = false;
625 } 626 }
626 627
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 890
890 void hitTestChildren(HitTestResult result, { double x, double y }) { 891 void hitTestChildren(HitTestResult result, { double x, double y }) {
891 defaultHitTestChildren(result, x: x, y: y); 892 defaultHitTestChildren(result, x: x, y: y);
892 } 893 }
893 894
894 void paint(RenderNodeDisplayList canvas) { 895 void paint(RenderNodeDisplayList canvas) {
895 super.paint(canvas); 896 super.paint(canvas);
896 defaultPaint(canvas); 897 defaultPaint(canvas);
897 } 898 }
898 } 899 }
899
900 // SCAFFOLD LAYOUT MANAGER
901
902 // a sample special-purpose layout manager
903
904 class ScaffoldBox extends RenderBox {
905
906 ScaffoldBox(this.toolbar, this.body, this.statusbar, this.drawer) {
907 assert(body != null);
908 }
909
910 final RenderBox toolbar;
911 final RenderBox body;
912 final RenderBox statusbar;
913 final RenderBox drawer;
914
915 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) {
916 width = constraints.constrainWidth(0.0);
917 height = constraints.constrainHeight(0.0);
918 relayout();
919 }
920
921 static const kToolbarHeight = 100.0;
922 static const kStatusbarHeight = 50.0;
923
924 void relayout() {
925 double bodyHeight = height;
926 if (toolbar != null) {
927 toolbar.layout(new BoxConstraints.tight(width: width, height: kToolbarHeig ht));
928 assert(toolbar.parentData is BoxParentData);
929 toolbar.parentData.x = 0.0;
930 toolbar.parentData.y = 0.0;
931 bodyHeight -= kToolbarHeight;
932 }
933 if (statusbar != null) {
934 statusbar.layout(new BoxConstraints.tight(width: width, height: kStatusbar Height));
935 assert(statusbar.parentData is BoxParentData);
936 statusbar.parentData.x = 0.0;
937 statusbar.parentData.y = height - kStatusbarHeight;
938 bodyHeight -= kStatusbarHeight;
939 }
940 body.layout(new BoxConstraints.tight(width: width, height: bodyHeight));
941 if (drawer != null)
942 drawer.layout(new BoxConstraints(minWidth: 0.0, maxWidth: width, minHeight : height, maxHeight: height));
943 layoutDone();
944 }
945
946 void hitTestChildren(HitTestResult result, { double x, double y }) {
947 if ((drawer != null) && (x < drawer.width)) {
948 drawer.hitTest(result, x: x, y: y);
949 } else if ((toolbar != null) && (y < toolbar.height)) {
950 toolbar.hitTest(result, x: x, y: y);
951 } else if ((statusbar != null) && (y > (statusbar.parentData as BoxParentDat a).y)) {
952 statusbar.hitTest(result, x: x, y: y-(statusbar.parentData as BoxParentDat a).y);
953 } else {
954 body.hitTest(result, x: x, y: y-(body.parentData as BoxParentData).y);
955 }
956 }
957
958 void paint(RenderNodeDisplayList canvas) {
959 canvas.paintChild(body, (body.parentData as BoxParentData).x, (body.parentDa ta as BoxParentData).y);
960 if (statusbar != null)
961 canvas.paintChild(statusbar, (statusbar.parentData as BoxParentData).x, (s tatusbar.parentData as BoxParentData).y);
962 if (toolbar != null)
963 canvas.paintChild(toolbar, (toolbar.parentData as BoxParentData).x, (toolb ar.parentData as BoxParentData).y);
964 if (drawer != null)
965 canvas.paintChild(drawer, (drawer.parentData as BoxParentData).x, (drawer. parentData as BoxParentData).y);
966 }
967
968 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698