| 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 '../app/scheduler.dart' as scheduler; | 9 import '../base/hit_test.dart'; |
| 10 import '../framework/node.dart'; | 10 import '../base/node.dart'; |
| 11 import '../base/scheduler.dart' as scheduler; |
| 11 | 12 |
| 12 export 'dart:sky' show Point, Size, Rect, Color, Paint, Path; | 13 export 'dart:sky' show Point, Size, Rect, Color, Paint, Path; |
| 14 export '../base/hit_test.dart' show HitTestTarget, HitTestEntry, HitTestResult; |
| 15 |
| 13 | 16 |
| 14 class ParentData { | 17 class ParentData { |
| 15 void detach() { | 18 void detach() { |
| 16 detachSiblings(); | 19 detachSiblings(); |
| 17 } | 20 } |
| 18 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart | 21 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart |
| 19 void merge(ParentData other) { | 22 void merge(ParentData other) { |
| 20 // override this in subclasses to merge in data from other into this | 23 // override this in subclasses to merge in data from other into this |
| 21 assert(other.runtimeType == this.runtimeType); | 24 assert(other.runtimeType == this.runtimeType); |
| 22 } | 25 } |
| 23 String toString() => '<none>'; | 26 String toString() => '<none>'; |
| 24 } | 27 } |
| 25 | 28 |
| 26 const kLayoutDirections = 4; | 29 const kLayoutDirections = 4; |
| 27 | 30 |
| 28 class RenderObjectDisplayList extends sky.PictureRecorder { | 31 class RenderObjectDisplayList extends sky.PictureRecorder { |
| 29 RenderObjectDisplayList(double width, double height) : super(width, height); | 32 RenderObjectDisplayList(double width, double height) : super(width, height); |
| 30 void paintChild(RenderObject child, Point position) { | 33 void paintChild(RenderObject child, Point position) { |
| 31 translate(position.x, position.y); | 34 translate(position.x, position.y); |
| 32 child.paint(this); | 35 child.paint(this); |
| 33 translate(-position.x, -position.y); | 36 translate(-position.x, -position.y); |
| 34 } | 37 } |
| 35 } | 38 } |
| 36 | 39 |
| 37 abstract class RenderObject extends AbstractNode { | 40 abstract class RenderObject extends AbstractNode implements HitTestTarget { |
| 38 | 41 |
| 39 // LAYOUT | 42 // LAYOUT |
| 40 | 43 |
| 41 // parentData is only for use by the RenderObject that actually lays this | 44 // parentData is only for use by the RenderObject that actually lays this |
| 42 // node out, and any other nodes who happen to know exactly what | 45 // node out, and any other nodes who happen to know exactly what |
| 43 // kind of node that is. | 46 // kind of node that is. |
| 44 dynamic parentData; // TODO(ianh): change the type of this back to ParentData
once the analyzer is cleverer | 47 dynamic parentData; // TODO(ianh): change the type of this back to ParentData
once the analyzer is cleverer |
| 45 void setParentData(RenderObject child) { | 48 void setParentData(RenderObject child) { |
| 46 // override this to setup .parentData correctly for your class | 49 // override this to setup .parentData correctly for your class |
| 47 assert(!debugDoingLayout); | 50 assert(!debugDoingLayout); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 if (!attached) | 256 if (!attached) |
| 254 header += ' DETACHED'; | 257 header += ' DETACHED'; |
| 255 prefix += ' '; | 258 prefix += ' '; |
| 256 return '${header}\n${debugDescribeSettings(prefix)}${debugDescribeChildren(p
refix)}'; | 259 return '${header}\n${debugDescribeSettings(prefix)}${debugDescribeChildren(p
refix)}'; |
| 257 } | 260 } |
| 258 String debugDescribeSettings(String prefix) => '${prefix}parentData: ${parentD
ata}\n${prefix}constraints: ${constraints}\n'; | 261 String debugDescribeSettings(String prefix) => '${prefix}parentData: ${parentD
ata}\n${prefix}constraints: ${constraints}\n'; |
| 259 String debugDescribeChildren(String prefix) => ''; | 262 String debugDescribeChildren(String prefix) => ''; |
| 260 | 263 |
| 261 } | 264 } |
| 262 | 265 |
| 263 class HitTestEntry { | |
| 264 const HitTestEntry(this.target); | |
| 265 | |
| 266 final RenderObject target; | |
| 267 } | |
| 268 | |
| 269 class HitTestResult { | |
| 270 final List<HitTestEntry> path = new List<HitTestEntry>(); | |
| 271 | |
| 272 void add(HitTestEntry data) { | |
| 273 path.add(data); | |
| 274 } | |
| 275 } | |
| 276 | |
| 277 double clamp({ double min: 0.0, double value: 0.0, double max: double.INFINITY }
) { | 266 double clamp({ double min: 0.0, double value: 0.0, double max: double.INFINITY }
) { |
| 278 assert(min != null); | 267 assert(min != null); |
| 279 assert(value != null); | 268 assert(value != null); |
| 280 assert(max != null); | 269 assert(max != null); |
| 281 return math.max(min, math.min(max, value)); | 270 return math.max(min, math.min(max, value)); |
| 282 } | 271 } |
| 283 | 272 |
| 284 | 273 |
| 285 // GENERIC MIXIN FOR RENDER NODES WITH ONE CHILD | 274 // GENERIC MIXIN FOR RENDER NODES WITH ONE CHILD |
| 286 | 275 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 int count = 1; | 463 int count = 1; |
| 475 ChildType child = _firstChild; | 464 ChildType child = _firstChild; |
| 476 while (child != null) { | 465 while (child != null) { |
| 477 result += '${prefix}child ${count}: ${child.toString(prefix)}'; | 466 result += '${prefix}child ${count}: ${child.toString(prefix)}'; |
| 478 count += 1; | 467 count += 1; |
| 479 child = child.parentData.nextSibling; | 468 child = child.parentData.nextSibling; |
| 480 } | 469 } |
| 481 return result; | 470 return result; |
| 482 } | 471 } |
| 483 } | 472 } |
| OLD | NEW |