Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(607)

Side by Side Diff: sky/examples/raw/simple_render_tree.dart

Issue 1143343004: Rationalise hit testing in the new RenderNode world (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
6 import 'dart:sky'; 5 import 'dart:sky';
6 import 'package:sky/framework/app.dart';
7 import 'package:sky/framework/layout2.dart'; 7 import 'package:sky/framework/layout2.dart';
8 8
9 class RenderSolidColor extends RenderDecoratedBox { 9 class RenderSolidColor extends RenderDecoratedBox {
10 final double desiredHeight; 10 final double desiredHeight;
11 final double desiredWidth; 11 final double desiredWidth;
12 final int backgroundColor; 12 final int backgroundColor;
13 13
14 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY, 14 RenderSolidColor(int backgroundColor, { this.desiredHeight: double.INFINITY,
15 this.desiredWidth: double.INFINITY }) 15 this.desiredWidth: double.INFINITY })
16 : backgroundColor = backgroundColor, 16 : backgroundColor = backgroundColor,
17 super(new BoxDecoration(backgroundColor: backgroundColor)); 17 super(new BoxDecoration(backgroundColor: backgroundColor));
18 18
19 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { 19 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
20 return new BoxDimensions.withConstraints(constraints, 20 return new BoxDimensions.withConstraints(constraints,
21 height: desiredHeight, 21 height: desiredHeight,
22 width: desiredWidth); 22 width: desiredWidth);
23 } 23 }
24 24
25 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { 25 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) {
26 width = constraints.constrainWidth(desiredWidth); 26 width = constraints.constrainWidth(desiredWidth);
27 height = constraints.constrainHeight(desiredHeight); 27 height = constraints.constrainHeight(desiredHeight);
28 layoutDone(); 28 layoutDone();
29 } 29 }
30 30
31 bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) { 31 void handlePointer(PointerEvent event) {
32 if (event.type == 'pointerdown') { 32 if (event.type == 'pointerdown')
33 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000)); 33 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000));
34 return true; 34 else if (event.type == 'pointerup')
35 }
36
37 if (event.type == 'pointerup') {
38 setBoxDecoration(new BoxDecoration(backgroundColor: backgroundColor)); 35 setBoxDecoration(new BoxDecoration(backgroundColor: backgroundColor));
39 return true;
40 }
41
42 return false;
43 } 36 }
44 } 37 }
45 38
46 RenderView renderView; 39 AppView app;
47
48 void beginFrame(double timeStamp) {
49 RenderNode.flushLayout();
50
51 renderView.paintFrame();
52 }
53
54 bool handleEvent(Event event) {
55 if (event is! PointerEvent)
56 return false;
57 return renderView.handlePointer(event, x: event.x, y: event.y);
58 }
59 40
60 void main() { 41 void main() {
61 view.setEventCallback(handleEvent);
62 view.setBeginFrameCallback(beginFrame);
63
64 var root = new RenderFlex( 42 var root = new RenderFlex(
65 direction: FlexDirection.Vertical, 43 direction: FlexDirection.Vertical,
66 decoration: new BoxDecoration(backgroundColor: 0xFF000000)); 44 decoration: new BoxDecoration(backgroundColor: 0xFF000000));
67 45
68 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) { 46 void addFlexChild(RenderFlex parent, int backgroundColor, { int flex: 0 }) {
69 RenderNode child = new RenderSolidColor(backgroundColor); 47 RenderNode child = new RenderSolidColor(backgroundColor);
70 parent.add(child); 48 parent.add(child);
71 child.parentData.flex = flex; 49 child.parentData.flex = flex;
72 } 50 }
73 51
(...skipping 17 matching lines...) Expand all
91 direction: FlexDirection.Horizontal, 69 direction: FlexDirection.Horizontal,
92 decoration: new BoxDecoration(backgroundColor: 0xFF333333)); 70 decoration: new BoxDecoration(backgroundColor: 0xFF333333));
93 71
94 // Purple and blue cells 72 // Purple and blue cells
95 addFlexChild(row, 0x77FF00FF, flex: 1); 73 addFlexChild(row, 0x77FF00FF, flex: 1);
96 addFlexChild(row, 0xFF0000FF, flex: 2); 74 addFlexChild(row, 0xFF0000FF, flex: 2);
97 75
98 root.add(row); 76 root.add(row);
99 row.parentData.flex = 3; 77 row.parentData.flex = 3;
100 78
101 renderView = new RenderView(root: root); 79 app = new AppView(root);
102 renderView.layout(newWidth: view.width, newHeight: view.height);
103 80
104 view.scheduleFrame();
105 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698