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

Unified Diff: sky/sdk/lib/framework/layout2.dart

Issue 1162033002: Introduce RenderProxyBox and RenderSizedBox (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Now with test 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/lib/framework/components2/scaffold.dart ('k') | sky/tests/raw/render_box.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/framework/layout2.dart
diff --git a/sky/sdk/lib/framework/layout2.dart b/sky/sdk/lib/framework/layout2.dart
index 37eaff8ee78c69d1b01bea97b1ab34f41f8a45ba..ee76408115da6b7fbc8ccdd1e91d4b68fba5ab7d 100644
--- a/sky/sdk/lib/framework/layout2.dart
+++ b/sky/sdk/lib/framework/layout2.dart
@@ -416,11 +416,11 @@ class BoxConstraints {
this.minHeight: 0.0,
this.maxHeight: double.INFINITY});
- const BoxConstraints.tight({ double width: 0.0, double height: 0.0 })
- : minWidth = width,
- maxWidth = width,
- minHeight = height,
- maxHeight = height;
+ BoxConstraints.tight(sky.Size size)
+ : minWidth = size.width,
+ maxWidth = size.width,
+ minHeight = size.height,
+ maxHeight = size.height;
BoxConstraints deflate(EdgeDims edges) {
assert(edges != null);
@@ -510,6 +510,47 @@ abstract class RenderBox extends RenderNode {
sky.Size size = new sky.Size(0.0, 0.0);
}
+abstract class RenderProxyBox extends RenderBox with RenderNodeWithChildMixin<RenderBox> {
+ RenderProxyBox(RenderBox child) {
+ this.child = child;
+ }
+
+ BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
+ return child.getIntrinsicDimensions(constraints);
+ }
+
+ void performLayout() {
+ child.layout(constraints, parentUsesSize: true);
+ size = child.size;
+ }
+
+ void hitTestChildren(HitTestResult result, { sky.Point position }) {
+ child.hitTest(result, position: position);
+ }
+
+ void paint(RenderNodeDisplayList canvas) {
+ child.paint(canvas);
+ }
+}
+
+class RenderSizedBox extends RenderProxyBox {
+ final sky.Size desiredSize;
+
+ RenderSizedBox(RenderBox child, [this.desiredSize = const sky.Size.infinite()])
+ : super(child);
+
+ BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
+ return new BoxDimensions.withConstraints(constraints,
+ width: desiredSize.width,
+ height: desiredSize.height);
+ }
+
+ void performLayout() {
+ size = constraints.constrain(desiredSize);
+ child.layout(new BoxConstraints.tight(size));
+ }
+}
+
class RenderPadding extends RenderBox with RenderNodeWithChildMixin<RenderBox> {
RenderPadding(EdgeDims padding, RenderBox child) {
@@ -591,6 +632,10 @@ class RenderDecoratedBox extends RenderBox {
markNeedsPaint();
}
+ void performLayout() {
+ size = constraints.constrain(new sky.Size.infinite());
+ }
+
void paint(RenderNodeDisplayList canvas) {
assert(size.width != null);
assert(size.height != null);
@@ -603,7 +648,6 @@ class RenderDecoratedBox extends RenderBox {
canvas.drawRect(new sky.Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint);
}
}
-
}
class RenderDecoratedCircle extends RenderDecoratedBox with RenderNodeWithChildMixin<RenderBox> {
@@ -674,7 +718,7 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin<RenderBox> {
}
void performLayout() {
if (child != null) {
- child.layout(new BoxConstraints.tight(width: width, height: height));
+ child.layout(new BoxConstraints.tight(_size));
assert(child.size.width == width);
assert(child.size.height == height);
}
« no previous file with comments | « sky/sdk/lib/framework/components2/scaffold.dart ('k') | sky/tests/raw/render_box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698