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 | 7 |
8 import 'package:vector_math/vector_math.dart'; | 8 import 'package:vector_math/vector_math.dart'; |
9 | 9 |
10 import '../base/debug.dart'; | 10 import '../base/debug.dart'; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 class BoxParentData extends ParentData { | 218 class BoxParentData extends ParentData { |
219 Point _position = Point.origin; | 219 Point _position = Point.origin; |
220 Point get position => _position; | 220 Point get position => _position; |
221 void set position(Point value) { | 221 void set position(Point value) { |
222 assert(RenderObject.debugDoingLayout); | 222 assert(RenderObject.debugDoingLayout); |
223 _position = value; | 223 _position = value; |
224 } | 224 } |
225 String toString() => 'position=$position'; | 225 String toString() => 'position=$position'; |
226 } | 226 } |
227 | 227 |
| 228 enum TextBaseline { alphabetic, ideographic } |
| 229 |
228 abstract class RenderBox extends RenderObject { | 230 abstract class RenderBox extends RenderObject { |
229 | 231 |
230 void setParentData(RenderObject child) { | 232 void setParentData(RenderObject child) { |
231 if (child.parentData is! BoxParentData) | 233 if (child.parentData is! BoxParentData) |
232 child.parentData = new BoxParentData(); | 234 child.parentData = new BoxParentData(); |
233 } | 235 } |
234 | 236 |
235 // getMinIntrinsicWidth() should return the minimum width that this box could | 237 // getMinIntrinsicWidth() should return the minimum width that this box could |
236 // be without failing to render its contents within itself. | 238 // be without failing to render its contents within itself. |
237 double getMinIntrinsicWidth(BoxConstraints constraints) { | 239 double getMinIntrinsicWidth(BoxConstraints constraints) { |
(...skipping 14 matching lines...) Expand all Loading... |
252 | 254 |
253 // getMaxIntrinsicHeight should return the smallest height beyond which | 255 // getMaxIntrinsicHeight should return the smallest height beyond which |
254 // increasing the height never decreases the width. | 256 // increasing the height never decreases the width. |
255 // If the layout algorithm used is width-in-height-out, i.e. the height | 257 // If the layout algorithm used is width-in-height-out, i.e. the height |
256 // depends on the width and not vice versa, then this will return the same | 258 // depends on the width and not vice versa, then this will return the same |
257 // as getMinIntrinsicHeight(). | 259 // as getMinIntrinsicHeight(). |
258 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 260 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
259 return constraints.constrainHeight(0.0); | 261 return constraints.constrainHeight(0.0); |
260 } | 262 } |
261 | 263 |
| 264 // getDistanceToBaseline() should return the distance from the |
| 265 // y-coordinate of the position of the box to the y-coordinate of |
| 266 // the first given baseline in the box's contents. This is used by |
| 267 // certain layout models to align adjacent boxes on a common |
| 268 // baseline, regardless of padding, font size differences, etc. If |
| 269 // there is no baseline, then it should return the distance from the |
| 270 // y-coordinate of the position of the box to the y-coordinate of |
| 271 // the bottom of the box, i.e., the height of the box. |
| 272 // Only call this after layout has been performed. |
| 273 double getDistanceToBaseline(TextBaseline baseline) { |
| 274 assert(!needsLayout); |
| 275 double result = getDistanceToActualBaseline(baseline); |
| 276 if (result == null) |
| 277 return size.height; |
| 278 return result; |
| 279 } |
| 280 // getDistanceToActualBaseline() should return the distance from the |
| 281 // y-coordinate of the position of the box to the y-coordinate of |
| 282 // the first given baseline in the box's contents, if any, or null |
| 283 // otherwise. |
| 284 double getDistanceToActualBaseline(TextBaseline baseline) { |
| 285 assert(!needsLayout); |
| 286 return null; |
| 287 } |
| 288 |
262 // This whole block should only be here in debug builds | 289 // This whole block should only be here in debug builds |
263 bool _debugDoingThisLayout = false; | 290 bool _debugDoingThisLayout = false; |
264 bool _debugCanParentUseSize; | 291 bool _debugCanParentUseSize; |
265 void layoutWithoutResize() { | 292 void layoutWithoutResize() { |
266 _debugDoingThisLayout = true; | 293 _debugDoingThisLayout = true; |
267 _debugCanParentUseSize = false; | 294 _debugCanParentUseSize = false; |
268 super.layoutWithoutResize(); | 295 super.layoutWithoutResize(); |
269 _debugCanParentUseSize = null; | 296 _debugCanParentUseSize = null; |
270 _debugDoingThisLayout = false; | 297 _debugDoingThisLayout = false; |
271 } | 298 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 return child.getMinIntrinsicHeight(constraints); | 368 return child.getMinIntrinsicHeight(constraints); |
342 return super.getMinIntrinsicHeight(constraints); | 369 return super.getMinIntrinsicHeight(constraints); |
343 } | 370 } |
344 | 371 |
345 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 372 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
346 if (child != null) | 373 if (child != null) |
347 return child.getMaxIntrinsicHeight(constraints); | 374 return child.getMaxIntrinsicHeight(constraints); |
348 return super.getMaxIntrinsicHeight(constraints); | 375 return super.getMaxIntrinsicHeight(constraints); |
349 } | 376 } |
350 | 377 |
| 378 double getDistanceToActualBaseline(TextBaseline baseline) { |
| 379 if (child != null) |
| 380 return child.getDistanceToActualBaseline(baseline); |
| 381 return super.getDistanceToActualBaseline(baseline); |
| 382 } |
| 383 |
351 void performLayout() { | 384 void performLayout() { |
352 if (child != null) { | 385 if (child != null) { |
353 child.layout(constraints, parentUsesSize: true); | 386 child.layout(constraints, parentUsesSize: true); |
354 size = child.size; | 387 size = child.size; |
355 } else { | 388 } else { |
356 performResize(); | 389 performResize(); |
357 } | 390 } |
358 } | 391 } |
359 | 392 |
360 void hitTestChildren(HitTestResult result, { Point position }) { | 393 void hitTestChildren(HitTestResult result, { Point position }) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 611 |
579 RenderShiftedBox(RenderBox child) { | 612 RenderShiftedBox(RenderBox child) { |
580 this.child = child; | 613 this.child = child; |
581 } | 614 } |
582 | 615 |
583 void paint(RenderCanvas canvas) { | 616 void paint(RenderCanvas canvas) { |
584 if (child != null) | 617 if (child != null) |
585 canvas.paintChild(child, child.parentData.position); | 618 canvas.paintChild(child, child.parentData.position); |
586 } | 619 } |
587 | 620 |
| 621 double getDistanceToActualBaseline(TextBaseline baseline) { |
| 622 double result; |
| 623 if (child != null) { |
| 624 assert(!needsLayout); |
| 625 result = child.getDistanceToActualBaseline(baseline); |
| 626 assert(child.parentData is BoxParentData); |
| 627 if (result != null) |
| 628 result += child.parentData.position.y; |
| 629 } else { |
| 630 result = super.getDistanceToActualBaseline(baseline); |
| 631 } |
| 632 return result; |
| 633 } |
| 634 |
588 void hitTestChildren(HitTestResult result, { Point position }) { | 635 void hitTestChildren(HitTestResult result, { Point position }) { |
589 if (child != null) { | 636 if (child != null) { |
590 assert(child.parentData is BoxParentData); | 637 assert(child.parentData is BoxParentData); |
591 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); | 638 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); |
592 if (childBounds.contains(position)) { | 639 if (childBounds.contains(position)) { |
593 child.hitTest(result, position: new Point(position.x - child.parentData.
position.x, | 640 child.hitTest(result, position: new Point(position.x - child.parentData.
position.x, |
594 position.y - child.parentD
ata.position.y)); | 641 position.y - child.parentD
ata.position.y)); |
595 } | 642 } |
596 } | 643 } |
597 } | 644 } |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 RenderObject.debugDoingPaint = false; | 1129 RenderObject.debugDoingPaint = false; |
1083 sky.tracing.end('RenderView.paintFrame'); | 1130 sky.tracing.end('RenderView.paintFrame'); |
1084 } | 1131 } |
1085 } | 1132 } |
1086 | 1133 |
1087 } | 1134 } |
1088 | 1135 |
1089 // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS | 1136 // DEFAULT BEHAVIORS FOR RENDERBOX CONTAINERS |
1090 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare
ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend
erObjectMixin<ChildType, ParentDataType> { | 1137 abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare
ntDataType extends ContainerParentDataMixin<ChildType>> implements ContainerRend
erObjectMixin<ChildType, ParentDataType> { |
1091 | 1138 |
| 1139 double defaultGetDistanceToFirstActualBaseline(TextBaseline baseline) { |
| 1140 assert(!needsLayout); |
| 1141 RenderBox child = firstChild; |
| 1142 while (child != null) { |
| 1143 assert(child.parentData is ParentDataType); |
| 1144 double result = child.getDistanceToActualBaseline(baseline); |
| 1145 if (result != null) |
| 1146 return result + child.parentData.position.y; |
| 1147 child = child.parentData.nextSibling; |
| 1148 } |
| 1149 return null; |
| 1150 } |
| 1151 |
| 1152 double defaultGetDistanceToHighestActualBaseline(TextBaseline baseline) { |
| 1153 assert(!needsLayout); |
| 1154 double result; |
| 1155 RenderBox child = firstChild; |
| 1156 while (child != null) { |
| 1157 assert(child.parentData is ParentDataType); |
| 1158 double candidate = child.getDistanceToActualBaseline(baseline); |
| 1159 if (candidate != null) { |
| 1160 candidate += child.parentData.position.x; |
| 1161 if (result != null) |
| 1162 result = math.min(result, candidate); |
| 1163 else |
| 1164 result = candidate; |
| 1165 } |
| 1166 child = child.parentData.nextSibling; |
| 1167 } |
| 1168 return result; |
| 1169 } |
| 1170 |
1092 void defaultHitTestChildren(HitTestResult result, { Point position }) { | 1171 void defaultHitTestChildren(HitTestResult result, { Point position }) { |
1093 // the x, y parameters have the top left of the node's box as the origin | 1172 // the x, y parameters have the top left of the node's box as the origin |
1094 ChildType child = lastChild; | 1173 ChildType child = lastChild; |
1095 while (child != null) { | 1174 while (child != null) { |
1096 assert(child.parentData is ParentDataType); | 1175 assert(child.parentData is ParentDataType); |
1097 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); | 1176 Rect childBounds = new Rect.fromPointAndSize(child.parentData.position, ch
ild.size); |
1098 if (childBounds.contains(position)) { | 1177 if (childBounds.contains(position)) { |
1099 if (child.hitTest(result, position: new Point(position.x - child.parentD
ata.position.x, | 1178 if (child.hitTest(result, position: new Point(position.x - child.parentD
ata.position.x, |
1100 position.y - child.par
entData.position.y))) | 1179 position.y - child.par
entData.position.y))) |
1101 break; | 1180 break; |
1102 } | 1181 } |
1103 child = child.parentData.previousSibling; | 1182 child = child.parentData.previousSibling; |
1104 } | 1183 } |
1105 } | 1184 } |
1106 | 1185 |
1107 void defaultPaint(RenderCanvas canvas) { | 1186 void defaultPaint(RenderCanvas canvas) { |
1108 RenderBox child = firstChild; | 1187 RenderBox child = firstChild; |
1109 while (child != null) { | 1188 while (child != null) { |
1110 assert(child.parentData is ParentDataType); | 1189 assert(child.parentData is ParentDataType); |
1111 canvas.paintChild(child, child.parentData.position); | 1190 canvas.paintChild(child, child.parentData.position); |
1112 child = child.parentData.nextSibling; | 1191 child = child.parentData.nextSibling; |
1113 } | 1192 } |
1114 } | 1193 } |
1115 } | 1194 } |
OLD | NEW |