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

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

Issue 1226103003: Factor RenderBlock out into a base class and a subclass. (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
« 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 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 bool _hasVisualOverflow = false; 18 bool _hasVisualOverflow = false;
19 19
20 RenderBlock({ 20 RenderBlockBase({
21 List<RenderBox> children 21 List<RenderBox> children
22 }) { 22 }) {
23 addAll(children); 23 addAll(children);
24 } 24 }
25 25
26 void setupParentData(RenderBox child) { 26 void setupParentData(RenderBox child) {
27 if (child.parentData is! BlockParentData) 27 if (child.parentData is! BlockParentData)
28 child.parentData = new BlockParentData(); 28 child.parentData = new BlockParentData();
29 } 29 }
30 30
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 76 }
77 77
78 double getMaxIntrinsicHeight(BoxConstraints constraints) { 78 double getMaxIntrinsicHeight(BoxConstraints constraints) {
79 return _getIntrinsicHeight(constraints); 79 return _getIntrinsicHeight(constraints);
80 } 80 }
81 81
82 double computeDistanceToActualBaseline(TextBaseline baseline) { 82 double computeDistanceToActualBaseline(TextBaseline baseline) {
83 return defaultComputeDistanceToFirstActualBaseline(baseline); 83 return defaultComputeDistanceToFirstActualBaseline(baseline);
84 } 84 }
85 85
86 double _childrenHeight;
87 double get childrenHeight => _childrenHeight;
88
89 void markNeedsLayout() {
90 _childrenHeight = null;
91 super.markNeedsLayout();
92 }
93
86 void performLayout() { 94 void performLayout() {
87 assert(constraints is BoxConstraints); 95 assert(constraints is BoxConstraints);
88 double width = constraints.constrainWidth(constraints.maxWidth); 96 double width = constraints.constrainWidth(constraints.maxWidth);
89 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width); 97 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width);
90 double y = 0.0; 98 double y = 0.0;
91 RenderBox child = firstChild; 99 RenderBox child = firstChild;
92 while (child != null) { 100 while (child != null) {
93 child.layout(innerConstraints, parentUsesSize: true); 101 child.layout(innerConstraints, parentUsesSize: true);
94 assert(child.parentData is BlockParentData); 102 assert(child.parentData is BlockParentData);
95 child.parentData.position = new Point(0.0, y); 103 child.parentData.position = new Point(0.0, y);
96 y += child.size.height; 104 y += child.size.height;
97 child = child.parentData.nextSibling; 105 child = child.parentData.nextSibling;
98 } 106 }
99 // FIXME(eseidel): Block lays out its children with unconstrained height 107 _childrenHeight = y;
100 // yet itself remains constrained. Remember that our children wanted to
101 // be taller than we are so we know to clip them (and not cause confusing
102 // mismatch of painting vs. hittesting).
103 size = new Size(width, constraints.constrainHeight(y));
104 _hasVisualOverflow = y > size.height;
105 assert(!size.isInfinite);
106 } 108 }
107 109
108 void hitTestChildren(HitTestResult result, { Point position }) { 110 void hitTestChildren(HitTestResult result, { Point position }) {
109 defaultHitTestChildren(result, position: position); 111 defaultHitTestChildren(result, position: position);
110 } 112 }
111 113
112 void paint(PaintingCanvas canvas, Offset offset) { 114 void paint(PaintingCanvas canvas, Offset offset) {
115 defaultPaint(canvas, offset);
116 }
117
118 }
119
120 class RenderBlock extends RenderBlockBase {
121
122 // sizes itself to the height of its child stack
123
124 RenderBlock({ List<RenderBox> children }) : super(children: children);
125
126 void performLayout() {
127 super.performLayout();
128 // FIXME(eseidel): Block lays out its children with unconstrained height
129 // yet itself remains constrained. Remember that our children wanted to
130 // be taller than we are so we know to clip them (and not cause confusing
131 // mismatch of painting vs. hittesting).
132 _hasVisualOverflow = childrenHeight > size.height;
133 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight)) ;
134 assert(!size.isInfinite);
135 }
136
137 void paint(PaintingCanvas canvas, Offset offset) {
113 if (_hasVisualOverflow) { 138 if (_hasVisualOverflow) {
114 canvas.save(); 139 canvas.save();
115 canvas.clipRect(offset & size); 140 canvas.clipRect(offset & size);
116 } 141 }
117 defaultPaint(canvas, offset); 142 super.paint(canvas, offset);
118 if (_hasVisualOverflow) { 143 if (_hasVisualOverflow) {
119 canvas.restore(); 144 canvas.restore();
120 } 145 }
121 } 146 }
122 147
123 } 148 }
124 149
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