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

Side by Side Diff: sky/sdk/lib/rendering/block.dart

Issue 1222913013: Introduce BlockViewport. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
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 'dart:math' as math; 5 import 'dart:math' as math;
6 6
7 import 'box.dart'; 7 import 'box.dart';
8 import 'object.dart'; 8 import 'object.dart';
9 9
10 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { } 10 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { }
11 11
12 class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B lockParentData>, 12 abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin <RenderBox, BlockParentData>,
13 RenderBoxContainerDefaultsMixin<RenderB ox, BlockParentData> { 13 RenderBoxContainerDefaults Mixin<RenderBox, BlockParentData> {
14
14 // lays out RenderBox children in a vertical stack 15 // lays out RenderBox children in a vertical stack
15 // uses the maximum width provided by the parent 16 // uses the maximum width provided by the parent
16 // sizes itself to the height of its child stack
17 17
18 RenderBlock({ 18 RenderBlockBase({
19 List<RenderBox> children 19 List<RenderBox> children
20 }) { 20 }) {
21 addAll(children); 21 addAll(children);
22 } 22 }
23 23
24 void setupParentData(RenderBox child) { 24 void setupParentData(RenderBox child) {
25 if (child.parentData is! BlockParentData) 25 if (child.parentData is! BlockParentData)
26 child.parentData = new BlockParentData(); 26 child.parentData = new BlockParentData();
27 } 27 }
28 28
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 double getMaxIntrinsicHeight(BoxConstraints constraints) { 76 double getMaxIntrinsicHeight(BoxConstraints constraints) {
77 return _getIntrinsicHeight(constraints); 77 return _getIntrinsicHeight(constraints);
78 } 78 }
79 79
80 double computeDistanceToActualBaseline(TextBaseline baseline) { 80 double computeDistanceToActualBaseline(TextBaseline baseline) {
81 return defaultComputeDistanceToFirstActualBaseline(baseline); 81 return defaultComputeDistanceToFirstActualBaseline(baseline);
82 } 82 }
83 83
84 double _childrenHeight;
85 double get childrenHeight => _childrenHeight;
86
87 void markNeedsLayout() {
88 _childrenHeight = null;
89 super.markNeedsLayout();
90 }
91
84 void performLayout() { 92 void performLayout() {
85 assert(constraints is BoxConstraints); 93 assert(constraints is BoxConstraints);
86 double width = constraints.constrainWidth(constraints.maxWidth); 94 double width = constraints.constrainWidth(constraints.maxWidth);
87 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width); 95 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width);
88 double y = 0.0; 96 double y = 0.0;
89 RenderBox child = firstChild; 97 RenderBox child = firstChild;
90 while (child != null) { 98 while (child != null) {
91 child.layout(innerConstraints, parentUsesSize: true); 99 child.layout(innerConstraints, parentUsesSize: true);
92 assert(child.parentData is BlockParentData); 100 assert(child.parentData is BlockParentData);
93 child.parentData.position = new Point(0.0, y); 101 child.parentData.position = new Point(0.0, y);
94 y += child.size.height; 102 y += child.size.height;
95 child = child.parentData.nextSibling; 103 child = child.parentData.nextSibling;
96 } 104 }
97 size = new Size(width, constraints.constrainHeight(y)); 105 _childrenHeight = y;
98 assert(!size.isInfinite);
99 } 106 }
100 107
101 void hitTestChildren(HitTestResult result, { Point position }) { 108 void hitTestChildren(HitTestResult result, { Point position }) {
102 defaultHitTestChildren(result, position: position); 109 defaultHitTestChildren(result, position: position);
103 } 110 }
104 111
105 void paint(PaintingCanvas canvas, Offset offset) { 112 void paint(PaintingCanvas canvas, Offset offset) {
106 defaultPaint(canvas, offset); 113 defaultPaint(canvas, offset);
107 } 114 }
108 115
109 } 116 }
110 117
118 class RenderBlock extends RenderBlockBase {
119
120 // sizes itself to the height of its child stack
121
122 RenderBlock({ List<RenderBox> children }) : super(children: children);
123
124 void performLayout() {
125 super.performLayout();
126 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight)) ;
127 assert(!size.isInfinite);
128 }
129
130 }
131
132 class RenderBlockViewport extends RenderBlockBase {
133
134 // sizes itself to the given constraints
135 // at the start of layout, calls callback
136
137 RenderBlockViewport({
138 LayoutCallback callback,
139 List<RenderBox> children,
140 double startOffset: 0.0
141 }) : _callback = callback, _startOffset = startOffset, super(children: childre n);
142
143 bool _inCallback = false;
144
145 LayoutCallback _callback;
146 LayoutCallback get callback => _callback;
147 void set callback(LayoutCallback value) {
148 assert(!_inCallback);
149 if (value == _callback)
150 return;
151 _callback = value;
152 markNeedsLayout();
153 }
154
155 // you can set this from within the callback if necessary
156 double _startOffset;
157 double get startOffset => _startOffset;
158 void set startOffset(double value) {
159 if (value == _startOffset)
160 return;
161 _startOffset = value;
162 if (!_inCallback)
163 markNeedsLayout();
164 }
165
166 bool get sizedByParent => true;
167
168 void performResize() {
169 size = constraints.biggest;
170 assert(!size.isInfinite);
171 }
172
173 bool get debugDoesLayoutWithCallback => true;
174 void performLayout() {
175 if (_callback != null) {
176 try {
177 _inCallback = true;
178 invokeLayoutCallback(_callback);
179 } finally {
180 _inCallback = false;
181 }
182 }
183 super.performLayout();
184 }
185
186 void paint(PaintingCanvas canvas, Offset offset) {
187 canvas.save();
188 canvas.clipRect(offset & size);
189 super.paint(canvas, offset.translate(0.0, _startOffset));
190 canvas.restore();
191 }
192
193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698