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

Side by Side Diff: sky/sdk/lib/framework/rendering/stack.dart

Issue 1166363002: Position the popup menu in stocks2 correctly (Closed) Base URL: git@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 | « sky/sdk/lib/framework/rendering/flex.dart ('k') | 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 'box.dart'; 5 import 'box.dart';
6 import 'object.dart'; 6 import 'object.dart';
7 7
8 class StackParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { } 8 class StackParentData extends BoxParentData with ContainerParentDataMixin<Render Box> {
9 double top;
10 double right;
11 double bottom;
12 double left;
13
14 void merge(StackParentData other) {
15 if (other.top != null)
16 top = other.top;
17 if (other.right != null)
18 right = other.right;
19 if (other.bottom != null)
20 bottom = other.bottom;
21 if (other.left != null)
22 left = other.left;
23 super.merge(other);
24 }
25
26 String toString() => '${super.toString()}; top=$top; right=$right; bottom=$bot tom, left=$left';
27 }
9 28
10 class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S tackParentData>, 29 class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S tackParentData>,
11 RenderBoxContainerDefaultsMixin<RenderB ox, StackParentData> { 30 RenderBoxContainerDefaultsMixin<RenderB ox, StackParentData> {
12 RenderStack({ 31 RenderStack({
13 List<RenderBox> children 32 List<RenderBox> children
14 }) { 33 }) {
15 if (children != null) 34 if (children != null)
16 children.forEach((child) { add(child); }); 35 children.forEach((child) { add(child); });
17 } 36 }
18 37
(...skipping 19 matching lines...) Expand all
38 } 57 }
39 58
40 void performLayout() { 59 void performLayout() {
41 size = constraints.constrain(Size.infinite); 60 size = constraints.constrain(Size.infinite);
42 assert(size.width < double.INFINITY); 61 assert(size.width < double.INFINITY);
43 assert(size.height < double.INFINITY); 62 assert(size.height < double.INFINITY);
44 BoxConstraints innerConstraints = new BoxConstraints.loose(size); 63 BoxConstraints innerConstraints = new BoxConstraints.loose(size);
45 64
46 RenderBox child = firstChild; 65 RenderBox child = firstChild;
47 while (child != null) { 66 while (child != null) {
48 child.layout(innerConstraints);
49 assert(child.parentData is StackParentData); 67 assert(child.parentData is StackParentData);
50 child.parentData.position = Point.origin; 68 StackParentData parentData = child.parentData;
69
70 BoxConstraints childConstraints = innerConstraints;
71
72 if (parentData.left != null && parentData.right != null)
73 childConstraints = childConstraints.applyWidth(parentData.right - parent Data.left);
74 else if (parentData.left != null)
75 childConstraints = childConstraints.applyMaxWidth(size.width - parentDat a.left);
76 else if (parentData.right != null)
77 childConstraints = childConstraints.applyMaxWidth(size.width - parentDat a.right);
78
79 if (parentData.top != null && parentData.bottom != null)
80 childConstraints = childConstraints.applyHeight(parentData.bottom - pare ntData.top);
81 else if (parentData.top != null)
82 childConstraints = childConstraints.applyMaxHeight(size.height - parentD ata.top);
83 else if (parentData.bottom != null)
84 childConstraints = childConstraints.applyMaxHeight(size.width - parentDa ta.bottom);
85
86 child.layout(childConstraints);
87
88 double x = 0.0;
89 if (parentData.left != null)
90 x = parentData.left;
91 else if (parentData.right != null)
92 x = size.width - parentData.right - child.size.width;
93 assert(x >= 0.0 && x + child.size.width <= size.width);
94
95 double y = 0.0;
96 if (parentData.top != null)
97 y = parentData.top;
98 else if (parentData.bottom != null)
99 y = size.height - parentData.bottom - child.size.height;
100 assert(y >= 0.0 && y + child.size.height <= size.height);
101
102 parentData.position = new Point(x, y);
103
51 child = child.parentData.nextSibling; 104 child = child.parentData.nextSibling;
52 } 105 }
53 } 106 }
54 107
55 void hitTestChildren(HitTestResult result, { Point position }) { 108 void hitTestChildren(HitTestResult result, { Point position }) {
56 defaultHitTestChildren(result, position: position); 109 defaultHitTestChildren(result, position: position);
57 } 110 }
58 111
59 void paint(RenderObjectDisplayList canvas) { 112 void paint(RenderObjectDisplayList canvas) {
60 defaultPaint(canvas); 113 defaultPaint(canvas);
61 } 114 }
62 } 115 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/rendering/flex.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698