OLD | NEW |
---|---|
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 import 'dart:math' as math; | |
7 | 8 |
8 // GENERIC BOX RENDERING | 9 // GENERIC BOX RENDERING |
9 // Anything that has a concept of x, y, width, height is going to derive from th is | 10 // Anything that has a concept of x, y, width, height is going to derive from th is |
10 | 11 |
11 class EdgeDims { | 12 class EdgeDims { |
12 // used for e.g. padding | 13 // used for e.g. padding |
13 const EdgeDims(this.top, this.right, this.bottom, this.left); | 14 const EdgeDims(this.top, this.right, this.bottom, this.left); |
14 const EdgeDims.all(double value) | 15 const EdgeDims.all(double value) |
15 : top = value, right = value, bottom = value, left = value; | 16 : top = value, right = value, bottom = value, left = value; |
16 | 17 |
(...skipping 16 matching lines...) Expand all Loading... | |
33 this.maxHeight: double.INFINITY}); | 34 this.maxHeight: double.INFINITY}); |
34 | 35 |
35 BoxConstraints.tight(sky.Size size) | 36 BoxConstraints.tight(sky.Size size) |
36 : minWidth = size.width, | 37 : minWidth = size.width, |
37 maxWidth = size.width, | 38 maxWidth = size.width, |
38 minHeight = size.height, | 39 minHeight = size.height, |
39 maxHeight = size.height; | 40 maxHeight = size.height; |
40 | 41 |
41 BoxConstraints deflate(EdgeDims edges) { | 42 BoxConstraints deflate(EdgeDims edges) { |
42 assert(edges != null); | 43 assert(edges != null); |
44 var horizontal = edges.left + edges.right; | |
45 var vertical = edges.top + edges.bottom; | |
abarth-chromium
2015/06/03 17:22:33
s/var/double/
| |
43 return new BoxConstraints( | 46 return new BoxConstraints( |
44 minWidth: minWidth, | 47 minWidth: math.min(0.0, minWidth - horizontal), |
45 maxWidth: maxWidth - (edges.left + edges.right), | 48 maxWidth: maxWidth - horizontal, |
46 minHeight: minHeight, | 49 minHeight: math.min(0.0, minHeight - vertical), |
47 maxHeight: maxHeight - (edges.top + edges.bottom) | 50 maxHeight: maxHeight - vertical |
48 ); | 51 ); |
49 } | 52 } |
50 | 53 |
51 final double minWidth; | 54 final double minWidth; |
52 final double maxWidth; | 55 final double maxWidth; |
53 final double minHeight; | 56 final double minHeight; |
54 final double maxHeight; | 57 final double maxHeight; |
55 | 58 |
56 double constrainWidth(double width) { | 59 double constrainWidth(double width) { |
57 return clamp(min: minWidth, max: maxWidth, value: width); | 60 return clamp(min: minWidth, max: maxWidth, value: width); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 _desiredSize = value; | 167 _desiredSize = value; |
165 markNeedsLayout(); | 168 markNeedsLayout(); |
166 } | 169 } |
167 | 170 |
168 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 171 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
169 return constraints.constrain(_desiredSize); | 172 return constraints.constrain(_desiredSize); |
170 } | 173 } |
171 | 174 |
172 void performLayout() { | 175 void performLayout() { |
173 size = constraints.constrain(_desiredSize); | 176 size = constraints.constrain(_desiredSize); |
174 child.layout(new BoxConstraints.tight(size)); | 177 if (child != null) |
178 child.layout(new BoxConstraints.tight(size)); | |
175 } | 179 } |
176 } | 180 } |
177 | 181 |
178 class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { | 182 class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> { |
179 | 183 |
180 RenderPadding({ EdgeDims padding, RenderBox child }) { | 184 RenderPadding({ EdgeDims padding, RenderBox child }) { |
181 assert(padding != null); | 185 assert(padding != null); |
182 this.padding = padding; | 186 this.padding = padding; |
183 this.child = child; | 187 this.child = child; |
184 } | 188 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 | 382 |
379 void defaultPaint(RenderNodeDisplayList canvas) { | 383 void defaultPaint(RenderNodeDisplayList canvas) { |
380 RenderBox child = firstChild; | 384 RenderBox child = firstChild; |
381 while (child != null) { | 385 while (child != null) { |
382 assert(child.parentData is ParentDataType); | 386 assert(child.parentData is ParentDataType); |
383 canvas.paintChild(child, child.parentData.position); | 387 canvas.paintChild(child, child.parentData.position); |
384 child = child.parentData.nextSibling; | 388 child = child.parentData.nextSibling; |
385 } | 389 } |
386 } | 390 } |
387 } | 391 } |
OLD | NEW |