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 'dart:math' as math; | 5 import 'dart:math' as math; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
7 import 'dart:sky' show Point, Size, Rect, Color, Paint, Path; | 7 import 'dart:sky' show Point, Size, Rect, Color, Paint, Path; |
8 | 8 |
9 import '../base/hit_test.dart'; | 9 import '../base/hit_test.dart'; |
10 import '../base/node.dart'; | 10 import '../base/node.dart'; |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 class RenderObjectDisplayList extends sky.PictureRecorder { | 31 class RenderObjectDisplayList extends sky.PictureRecorder { |
32 RenderObjectDisplayList(double width, double height) : super(width, height); | 32 RenderObjectDisplayList(double width, double height) : super(width, height); |
33 void paintChild(RenderObject child, Point position) { | 33 void paintChild(RenderObject child, Point position) { |
34 translate(position.x, position.y); | 34 translate(position.x, position.y); |
35 child.paint(this); | 35 child.paint(this); |
36 translate(-position.x, -position.y); | 36 translate(-position.x, -position.y); |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
| 40 abstract class Constraints { |
| 41 const Constraints(); |
| 42 bool get isTight; |
| 43 } |
| 44 |
40 abstract class RenderObject extends AbstractNode implements HitTestTarget { | 45 abstract class RenderObject extends AbstractNode implements HitTestTarget { |
41 | 46 |
42 // LAYOUT | 47 // LAYOUT |
43 | 48 |
44 // parentData is only for use by the RenderObject that actually lays this | 49 // parentData is only for use by the RenderObject that actually lays this |
45 // node out, and any other nodes who happen to know exactly what | 50 // node out, and any other nodes who happen to know exactly what |
46 // kind of node that is. | 51 // kind of node that is. |
47 dynamic parentData; // TODO(ianh): change the type of this back to ParentData
once the analyzer is cleverer | 52 dynamic parentData; // TODO(ianh): change the type of this back to ParentData
once the analyzer is cleverer |
48 void setParentData(RenderObject child) { | 53 void setParentData(RenderObject child) { |
49 // override this to setup .parentData correctly for your class | 54 // override this to setup .parentData correctly for your class |
(...skipping 22 matching lines...) Expand all Loading... |
72 super.dropChild(child); | 77 super.dropChild(child); |
73 markNeedsLayout(); | 78 markNeedsLayout(); |
74 } | 79 } |
75 | 80 |
76 static List<RenderObject> _nodesNeedingLayout = new List<RenderObject>(); | 81 static List<RenderObject> _nodesNeedingLayout = new List<RenderObject>(); |
77 static bool _debugDoingLayout = false; | 82 static bool _debugDoingLayout = false; |
78 static bool get debugDoingLayout => _debugDoingLayout; | 83 static bool get debugDoingLayout => _debugDoingLayout; |
79 bool _needsLayout = true; | 84 bool _needsLayout = true; |
80 bool get needsLayout => _needsLayout; | 85 bool get needsLayout => _needsLayout; |
81 RenderObject _relayoutSubtreeRoot; | 86 RenderObject _relayoutSubtreeRoot; |
82 dynamic _constraints; | 87 Constraints _constraints; |
83 dynamic get constraints => _constraints; | 88 Constraints get constraints => _constraints; |
84 bool debugAncestorsAlreadyMarkedNeedsLayout() { | 89 bool debugAncestorsAlreadyMarkedNeedsLayout() { |
85 if (_relayoutSubtreeRoot == null) | 90 if (_relayoutSubtreeRoot == null) |
86 return true; // we haven't yet done layout even once, so there's nothing f
or us to do | 91 return true; // we haven't yet done layout even once, so there's nothing f
or us to do |
87 RenderObject node = this; | 92 RenderObject node = this; |
88 while (node != _relayoutSubtreeRoot) { | 93 while (node != _relayoutSubtreeRoot) { |
89 assert(node._relayoutSubtreeRoot == _relayoutSubtreeRoot); | 94 assert(node._relayoutSubtreeRoot == _relayoutSubtreeRoot); |
90 assert(node.parent != null); | 95 assert(node.parent != null); |
91 node = node.parent as RenderObject; | 96 node = node.parent as RenderObject; |
92 if (!node._needsLayout) | 97 if (!node._needsLayout) |
93 return false; | 98 return false; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 try { | 154 try { |
150 assert(_relayoutSubtreeRoot == this); | 155 assert(_relayoutSubtreeRoot == this); |
151 performLayout(); | 156 performLayout(); |
152 } catch (e, stack) { | 157 } catch (e, stack) { |
153 print('Exception raised during layout of ${this}: ${e}'); | 158 print('Exception raised during layout of ${this}: ${e}'); |
154 print(stack); | 159 print(stack); |
155 return; | 160 return; |
156 } | 161 } |
157 _needsLayout = false; | 162 _needsLayout = false; |
158 } | 163 } |
159 void layout(dynamic constraints, { bool parentUsesSize: false }) { | 164 void layout(Constraints constraints, { bool parentUsesSize: false }) { |
160 final parent = this.parent; // TODO(ianh): Remove this once the analyzer is
cleverer | 165 final parent = this.parent; // TODO(ianh): Remove this once the analyzer is
cleverer |
161 RenderObject relayoutSubtreeRoot; | 166 RenderObject relayoutSubtreeRoot; |
162 if (!parentUsesSize || sizedByParent || parent is! RenderObject) | 167 if (!parentUsesSize || sizedByParent || constraints.isTight || parent is! Re
nderObject) |
163 relayoutSubtreeRoot = this; | 168 relayoutSubtreeRoot = this; |
164 else | 169 else |
165 relayoutSubtreeRoot = parent._relayoutSubtreeRoot; | 170 relayoutSubtreeRoot = parent._relayoutSubtreeRoot; |
166 assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer
is cleverer | 171 assert(parent == this.parent); // TODO(ianh): Remove this once the analyzer
is cleverer |
167 if (!needsLayout && constraints == _constraints && relayoutSubtreeRoot == _r
elayoutSubtreeRoot) | 172 if (!needsLayout && constraints == _constraints && relayoutSubtreeRoot == _r
elayoutSubtreeRoot) |
168 return; | 173 return; |
169 _constraints = constraints; | 174 _constraints = constraints; |
170 _relayoutSubtreeRoot = relayoutSubtreeRoot; | 175 _relayoutSubtreeRoot = relayoutSubtreeRoot; |
171 if (sizedByParent) | 176 if (sizedByParent) |
172 performResize(); | 177 performResize(); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 int count = 1; | 490 int count = 1; |
486 ChildType child = _firstChild; | 491 ChildType child = _firstChild; |
487 while (child != null) { | 492 while (child != null) { |
488 result += '${prefix}child ${count}: ${child.toString(prefix)}'; | 493 result += '${prefix}child ${count}: ${child.toString(prefix)}'; |
489 count += 1; | 494 count += 1; |
490 child = child.parentData.nextSibling; | 495 child = child.parentData.nextSibling; |
491 } | 496 } |
492 return result; | 497 return result; |
493 } | 498 } |
494 } | 499 } |
OLD | NEW |