| 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 '../node.dart'; | 5 import '../node.dart'; |
| 6 import '../scheduler.dart' as scheduler; | 6 import '../scheduler.dart' as scheduler; |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 import 'dart:sky' as sky; | 8 import 'dart:sky' as sky; |
| 9 import 'dart:sky' show Point, Size, Rect, Color, Paint, Path; | 9 import 'dart:sky' show Point, Size, Rect, Color, Paint, Path; |
| 10 export 'dart:sky' show Point, Size, Rect, Color, Paint, Path; | 10 export 'dart:sky' show Point, Size, Rect, Color, Paint, Path; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 abstract class RenderObject extends AbstractNode { | 42 abstract class RenderObject extends AbstractNode { |
| 43 | 43 |
| 44 // LAYOUT | 44 // LAYOUT |
| 45 | 45 |
| 46 // parentData is only for use by the RenderObject that actually lays this | 46 // parentData is only for use by the RenderObject that actually lays this |
| 47 // node out, and any other nodes who happen to know exactly what | 47 // node out, and any other nodes who happen to know exactly what |
| 48 // kind of node that is. | 48 // kind of node that is. |
| 49 dynamic parentData; // TODO(ianh): change the type of this back to ParentData
once the analyzer is cleverer | 49 dynamic parentData; // TODO(ianh): change the type of this back to ParentData
once the analyzer is cleverer |
| 50 void setParentData(RenderObject child) { | 50 void setParentData(RenderObject child) { |
| 51 // override this to setup .parentData correctly for your class | 51 // override this to setup .parentData correctly for your class |
| 52 assert(!_debugDoingLayout); | 52 assert(!debugDoingLayout); |
| 53 assert(!debugDoingPaint); | 53 assert(!debugDoingPaint); |
| 54 if (child.parentData is! ParentData) | 54 if (child.parentData is! ParentData) |
| 55 child.parentData = new ParentData(); | 55 child.parentData = new ParentData(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void adoptChild(RenderObject child) { // only for use by subclasses | 58 void adoptChild(RenderObject child) { // only for use by subclasses |
| 59 // call this whenever you decide a node is a child | 59 // call this whenever you decide a node is a child |
| 60 assert(!_debugDoingLayout); | 60 assert(!debugDoingLayout); |
| 61 assert(!debugDoingPaint); | 61 assert(!debugDoingPaint); |
| 62 assert(child != null); | 62 assert(child != null); |
| 63 setParentData(child); | 63 setParentData(child); |
| 64 super.adoptChild(child); | 64 super.adoptChild(child); |
| 65 markNeedsLayout(); | 65 markNeedsLayout(); |
| 66 } | 66 } |
| 67 void dropChild(RenderObject child) { // only for use by subclasses | 67 void dropChild(RenderObject child) { // only for use by subclasses |
| 68 assert(!_debugDoingLayout); | 68 assert(!debugDoingLayout); |
| 69 assert(!debugDoingPaint); | 69 assert(!debugDoingPaint); |
| 70 assert(child != null); | 70 assert(child != null); |
| 71 assert(child.parentData != null); | 71 assert(child.parentData != null); |
| 72 child.parentData.detach(); | 72 child.parentData.detach(); |
| 73 if (child._relayoutSubtreeRoot != child) { | 73 if (child._relayoutSubtreeRoot != child) { |
| 74 child._relayoutSubtreeRoot = null; | 74 child._relayoutSubtreeRoot = null; |
| 75 child._needsLayout = true; | 75 child._needsLayout = true; |
| 76 } | 76 } |
| 77 super.dropChild(child); | 77 super.dropChild(child); |
| 78 markNeedsLayout(); | 78 markNeedsLayout(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 static List<RenderObject> _nodesNeedingLayout = new List<RenderObject>(); | 81 static List<RenderObject> _nodesNeedingLayout = new List<RenderObject>(); |
| 82 static bool _debugDoingLayout = false; | 82 static bool _debugDoingLayout = false; |
| 83 static bool get debugDoingLayout => _debugDoingLayout; |
| 83 bool _needsLayout = true; | 84 bool _needsLayout = true; |
| 84 bool get needsLayout => _needsLayout; | 85 bool get needsLayout => _needsLayout; |
| 85 RenderObject _relayoutSubtreeRoot; | 86 RenderObject _relayoutSubtreeRoot; |
| 86 dynamic _constraints; | 87 dynamic _constraints; |
| 87 dynamic get constraints => _constraints; | 88 dynamic get constraints => _constraints; |
| 88 bool debugAncestorsAlreadyMarkedNeedsLayout() { | 89 bool debugAncestorsAlreadyMarkedNeedsLayout() { |
| 89 if (_relayoutSubtreeRoot == null) | 90 if (_relayoutSubtreeRoot == null) |
| 90 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 |
| 91 RenderObject node = this; | 92 RenderObject node = this; |
| 92 while (node != _relayoutSubtreeRoot) { | 93 while (node != _relayoutSubtreeRoot) { |
| 93 assert(node._relayoutSubtreeRoot == _relayoutSubtreeRoot); | 94 assert(node._relayoutSubtreeRoot == _relayoutSubtreeRoot); |
| 94 assert(node.parent != null); | 95 assert(node.parent != null); |
| 95 node = node.parent as RenderObject; | 96 node = node.parent as RenderObject; |
| 96 if (!node._needsLayout) | 97 if (!node._needsLayout) |
| 97 return false; | 98 return false; |
| 98 } | 99 } |
| 99 assert(node._relayoutSubtreeRoot == node); | 100 assert(node._relayoutSubtreeRoot == node); |
| 100 return true; | 101 return true; |
| 101 } | 102 } |
| 102 void markNeedsLayout() { | 103 void markNeedsLayout() { |
| 103 assert(!_debugDoingLayout); | 104 assert(!debugDoingLayout); |
| 104 assert(!debugDoingPaint); | 105 assert(!debugDoingPaint); |
| 105 if (_needsLayout) { | 106 if (_needsLayout) { |
| 106 assert(debugAncestorsAlreadyMarkedNeedsLayout()); | 107 assert(debugAncestorsAlreadyMarkedNeedsLayout()); |
| 107 return; | 108 return; |
| 108 } | 109 } |
| 109 _needsLayout = true; | 110 _needsLayout = true; |
| 110 assert(_relayoutSubtreeRoot != null); | 111 assert(_relayoutSubtreeRoot != null); |
| 111 if (_relayoutSubtreeRoot != this) { | 112 if (_relayoutSubtreeRoot != this) { |
| 112 final parent = this.parent; // TODO(ianh): Remove this once the analyzer i
s cleverer | 113 final parent = this.parent; // TODO(ianh): Remove this once the analyzer i
s cleverer |
| 113 assert(parent is RenderObject); | 114 assert(parent is RenderObject); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 int count = 1; | 443 int count = 1; |
| 443 ChildType child = _firstChild; | 444 ChildType child = _firstChild; |
| 444 while (child != null) { | 445 while (child != null) { |
| 445 result += '${prefix}child ${count}: ${child.toString(prefix)}'; | 446 result += '${prefix}child ${count}: ${child.toString(prefix)}'; |
| 446 count += 1; | 447 count += 1; |
| 447 child = child.parentData.nextSibling; | 448 child = child.parentData.nextSibling; |
| 448 } | 449 } |
| 449 return result; | 450 return result; |
| 450 } | 451 } |
| 451 } | 452 } |
| OLD | NEW |