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 '../node.dart'; | 9 import '../node.dart'; |
10 import '../scheduler.dart' as scheduler; | 10 import '../scheduler.dart' as scheduler; |
11 | 11 |
12 export 'dart:sky' show Point, Size, Rect, Color, Paint, Path; | 12 export 'dart:sky' show Point, Size, Rect, Color, Paint, Path; |
13 | 13 |
14 class ParentData { | 14 class ParentData { |
15 void detach() { | 15 void detach() { |
16 detachSiblings(); | 16 detachSiblings(); |
17 } | 17 } |
18 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart | 18 void detachSiblings() { } // workaround for lack of inter-class mixins in Dart |
19 void merge(ParentData other) { | 19 void merge(ParentData other) { |
20 // override this in subclasses to merge in data from other into this | 20 // override this in subclasses to merge in data from other into this |
21 assert(other.runtimeType == this.runtimeType); | 21 assert(other.runtimeType == this.runtimeType); |
22 } | 22 } |
23 String toString() => '<none>'; | 23 String toString() => '<none>'; |
24 } | 24 } |
25 | 25 |
26 const kLayoutDirections = 4; | 26 const kLayoutDirections = 4; |
27 | 27 |
28 class RenderObjectDisplayList extends sky.PictureRecorder { | |
29 RenderObjectDisplayList(double width, double height) : super(width, height); | |
30 void paintChild(RenderObject child, Point position) { | |
31 translate(position.x, position.y); | |
32 child.paint(this); | |
33 translate(-position.x, -position.y); | |
34 } | |
35 } | |
36 | |
37 abstract class RenderObject extends AbstractNode { | 28 abstract class RenderObject extends AbstractNode { |
38 | 29 |
39 // LAYOUT | 30 // LAYOUT |
40 | 31 |
41 // parentData is only for use by the RenderObject that actually lays this | 32 // 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 | 33 // node out, and any other nodes who happen to know exactly what |
43 // kind of node that is. | 34 // kind of node that is. |
44 dynamic parentData; // TODO(ianh): change the type of this back to ParentData once the analyzer is cleverer | 35 dynamic parentData; // TODO(ianh): change the type of this back to ParentData once the analyzer is cleverer |
45 void setParentData(RenderObject child) { | 36 void setParentData(RenderObject child) { |
46 // override this to setup .parentData correctly for your class | 37 // override this to setup .parentData correctly for your class |
47 assert(!debugDoingLayout); | 38 assert(!debugDoingLayout); |
48 assert(!debugDoingPaint); | 39 assert(!debugDoingPaint); |
49 if (child.parentData is! ParentData) | 40 if (child.parentData is! ParentData) |
50 child.parentData = new ParentData(); | 41 child.parentData = new ParentData(); |
51 } | 42 } |
52 | 43 |
44 void paintChild(sky.Canvas canvas, RenderObject child, Point position) { | |
45 canvas.translate(position.x, position.y); | |
46 child.paint(canvas); | |
47 canvas.translate(-position.x, -position.y); | |
48 } | |
49 | |
Hixie
2015/06/18 00:07:09
I really don't like this change. It is going to en
iansf
2015/06/20 00:02:38
Let me know what you think of the new version.
| |
53 void adoptChild(RenderObject child) { // only for use by subclasses | 50 void adoptChild(RenderObject child) { // only for use by subclasses |
54 // call this whenever you decide a node is a child | 51 // call this whenever you decide a node is a child |
55 assert(!debugDoingLayout); | 52 assert(!debugDoingLayout); |
56 assert(!debugDoingPaint); | 53 assert(!debugDoingPaint); |
57 assert(child != null); | 54 assert(child != null); |
58 setParentData(child); | 55 setParentData(child); |
59 super.adoptChild(child); | 56 super.adoptChild(child); |
60 markNeedsLayout(); | 57 markNeedsLayout(); |
61 } | 58 } |
62 void dropChild(RenderObject child) { // only for use by subclasses | 59 void dropChild(RenderObject child) { // only for use by subclasses |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 }) { } | 191 }) { } |
195 | 192 |
196 | 193 |
197 // PAINTING | 194 // PAINTING |
198 | 195 |
199 static bool debugDoingPaint = false; | 196 static bool debugDoingPaint = false; |
200 void markNeedsPaint() { | 197 void markNeedsPaint() { |
201 assert(!debugDoingPaint); | 198 assert(!debugDoingPaint); |
202 scheduler.ensureVisualUpdate(); | 199 scheduler.ensureVisualUpdate(); |
203 } | 200 } |
204 void paint(RenderObjectDisplayList canvas) { } | 201 void paint(sky.Canvas canvas) { } |
205 | 202 |
206 | 203 |
207 // EVENTS | 204 // EVENTS |
208 | 205 |
209 void handleEvent(sky.Event event, HitTestEntry entry) { | 206 void handleEvent(sky.Event event, HitTestEntry entry) { |
210 // override this if you have a client, to hand it to the client | 207 // override this if you have a client, to hand it to the client |
211 // override this if you want to do anything with the event | 208 // override this if you want to do anything with the event |
212 } | 209 } |
213 | 210 |
214 | 211 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 int count = 1; | 454 int count = 1; |
458 ChildType child = _firstChild; | 455 ChildType child = _firstChild; |
459 while (child != null) { | 456 while (child != null) { |
460 result += '${prefix}child ${count}: ${child.toString(prefix)}'; | 457 result += '${prefix}child ${count}: ${child.toString(prefix)}'; |
461 count += 1; | 458 count += 1; |
462 child = child.parentData.nextSibling; | 459 child = child.parentData.nextSibling; |
463 } | 460 } |
464 return result; | 461 return result; |
465 } | 462 } |
466 } | 463 } |
OLD | NEW |