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

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

Issue 1153543002: Make hit testing work in layout2.dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Add missing file Created 5 years, 7 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'; 5 import 'dart:math';
6 import 'dart:sky'; 6 import 'dart:sky';
7 import 'package:sky/framework/layout2.dart'; 7 import 'package:sky/framework/layout2.dart';
8 8
9 class SimpleBlock extends RenderDecoratedBox { 9 class SimpleBlock extends RenderDecoratedBox {
10 final int backgroundColor;
11
10 SimpleBlock(int backgroundColor) 12 SimpleBlock(int backgroundColor)
11 : super(new BoxDecoration(backgroundColor: backgroundColor)); 13 : super(new BoxDecoration(backgroundColor: backgroundColor)),
14 backgroundColor = backgroundColor;
12 15
13 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) { 16 BoxDimensions getIntrinsicDimensions(BoxConstraints constraints) {
14 return new BoxDimensions.withConstraints(constraints, height: 200.0); 17 return new BoxDimensions.withConstraints(constraints, height: 200.0);
15 } 18 }
16 19
17 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) { 20 void layout(BoxConstraints constraints, { RenderNode relayoutSubtreeRoot }) {
18 setWidth(constraints, constraints.maxWidth); 21 setWidth(constraints, constraints.maxWidth);
19 setHeight(constraints, 200.0); 22 setHeight(constraints, 200.0);
20 layoutDone(); 23 layoutDone();
21 } 24 }
25
26 bool handlePointer(PointerEvent event, { double x: 0.0, double y: 0.0 }) {
27 if (event.type == 'pointerdown') {
28 setBoxDecoration(new BoxDecoration(backgroundColor: 0xFFFF0000));
29 return true;
30 }
31
32 if (event.type == 'pointerup') {
33 setBoxDecoration(new BoxDecoration(backgroundColor: backgroundColor));
34 return true;
35 }
36
37 return false;
Hixie 2015/05/21 19:31:42 This is a rectangle with no holes, so it should al
38 }
39 }
40
41 RenderView renderView;
42
43 void beginFrame(double timeStamp) {
44 RenderNode.flushLayout();
45
46 renderView.paintFrame();
47 }
48
49 bool handleEvent(Event event) {
50 if (event is! PointerEvent)
51 return false;
52 return renderView.handlePointer(event, x: event.x, y: event.y);
22 } 53 }
23 54
24 void main() { 55 void main() {
56 view.setEventCallback(handleEvent);
57 view.setBeginFrameCallback(beginFrame);
58
25 var root = new RenderBlock( 59 var root = new RenderBlock(
26 decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF)); 60 decoration: new BoxDecoration(backgroundColor: 0xFF00FFFF));
27
28 root.add(new SimpleBlock(0xFF00FF00)); 61 root.add(new SimpleBlock(0xFF00FF00));
29 root.add(new SimpleBlock(0xFF0000FF)); 62 root.add(new SimpleBlock(0xFF0000FF));
30 63
31 RenderView renderView = new RenderView(root: root); 64 renderView = new RenderView(root: root);
32 renderView.layout(newWidth: view.width, newHeight: view.height); 65 renderView.layout(newWidth: view.width, newHeight: view.height);
33 renderView.paintFrame(); 66
67 view.scheduleFrame();
34 } 68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698