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

Side by Side Diff: runtime/embedders/openglui/common/gl.dart

Issue 12390045: Added a rudimentary DOM, to assist with event dispatch. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library android_extension; 5 library android_extension;
6 6
7 class CanvasElement { 7 // A VERY simplified DOM.
8
9 class BodyElement {
10 List _nodes;
11 get nodes => _nodes;
12 BodyElement() : _nodes = new List();
13 }
14
15 class HtmlDocument {
vsm 2013/03/04 17:34:55 I'd rather make this "Document" ... but body is de
gram 2013/03/04 23:53:14 Changed to OpenGLUIDocument. As the user just uses
16 BodyElement _body;
17 get body => _body;
18 HtmlDocument() : _body = new BodyElement();
vsm 2013/03/04 17:34:55 Can we make these constructors (this and below) pr
gram 2013/03/04 23:53:14 I'm familiar with doing this in Cxx/Java when impl
vsm 2013/03/05 00:23:58 The usual pattern is: HtmlDocument._internal()
gram 2013/03/05 01:06:49 Done.
19 }
20
21 HtmlDocument document = new HtmlDocument();
22
23 // Event handling. This is very kludgy for now, especially the
24 // bare-bones Stream stuff!
25
26 class Event {
27 final String type;
28 Event(String type) : this.type = type;
29 }
30
31 class KeyEvent extends Event {
32 final bool altKey;
33 final bool ctrlKey;
34 final bool shiftKey;
35 final int keyCode;
36
37 KeyEvent(String type, int keycode, bool alt, bool ctrl, bool shift)
38 : super(type),
39 keyCode = keycode,
40 altKey = alt,
41 ctrlKey = ctrl,
42 shiftKey = shift {
43 }
44 }
45
46 class MouseEvent extends Event {
47 final double screenX, screenY;
48 final double clientX, clientY;
vsm 2013/03/04 17:34:55 These are ints, not doubles in dart:html.
gram 2013/03/04 23:53:14 Done.
49
50 MouseEvent(String type, double x, double y)
51 : super(type),
52 screenX = x,
53 screenY = y,
54 clientX = x,
55 clientY = y {
56 }
57 }
58
59 class StreamSubscription {
60 Stream _stream;
61 int _id;
62
63 StreamSubscription(this._stream, this._id);
64 void onData(handler) => _stream.onData(_id, handler);
vsm 2013/03/04 17:34:55 Probably should declare: typedef void EventListene
gram 2013/03/04 23:53:14 Done.
65 }
66
67 class Stream {
vsm 2013/03/04 17:34:55 These will conflict with the names in dart:async.
gram 2013/03/04 23:53:14 Modified the code to work with async library.
68 int _nextListenerId;
69 Map _listeners;
70
71 Stream() : _nextListenerId = 0, _listeners = new Map();
72
73 void onData(id, handler) {
vsm 2013/03/04 17:34:55 types for args
gram 2013/03/04 23:53:14 Done.
74 _listeners[id] = handler;
75 }
76
77 listen(callback) {
vsm 2013/03/04 17:34:55 types for args
gram 2013/03/04 23:53:14 Done.
78 var sub = new StreamSubscription(this, _nextListenerId++);
79 sub.onData(callback);
80 return sub;
81 }
82
83 post(Event e) {
84 for (var listener in _listeners.values) {
85 listener(e);
86 }
87 }
88 }
89
90 class Node {
91 Map<String,Stream> _events;
92
93 get onMouseDown => _events['mousedown'];
94 get onMouseMove => _events['mousemove'];
95 get onMouseUp => _events['mouseup'];
96 get onKeyDown => _events['keydown'];
97 get onKeyUp => _events['keyup'];
98
99 get events => _events;
100
101 Node() : _events = new Map() {
102 _events['mousedown'] = new Stream();
103 _events['mousemove'] = new Stream();
104 _events['mouseup'] = new Stream();
105 _events['keydown'] = new Stream();
106 _events['keyup'] = new Stream();
107 }
108 }
109
110 _dispatchEvent(String type, Event e) {
111 for (var n in document.body.nodes) {
112 var handler = n.events[type];
113 if (handler != null) {
114 handler.post(e);
115 }
116 }
117 }
118
119 _dispatchKeyEvent(String type, int keyCode, bool alt, bool ctrl, bool shift) =>
120 _dispatchEvent(type, new KeyEvent(type, keyCode, alt, ctrl, shift));
121
122 _dispatchMouseEvent(String type, double x, double y) =>
123 _dispatchEvent(type, new MouseEvent(type, x, y));
124
125 onKeyDown(int when, int keyCode, bool alt, bool ctrl, bool shift, int repeat)
vsm 2013/03/04 17:34:55 Do you really want these to be globally visible?
gram 2013/03/04 23:53:14 They have to be callable from vmglue.cc. Would the
vsm 2013/03/05 00:23:58 I'm pretty sure it will work fine. Dartium does i
gram 2013/03/05 01:06:49 I tried, but it didn't work: Invoke _onMouseDown
126 => _dispatchKeyEvent('keydown', keyCode, alt, ctrl, shift);
127
128 onKeyUp(int when, int keyCode, bool alt, bool ctrl, bool shift, int repeat) =>
129 _dispatchKeyEvent('keyup', keyCode, alt, ctrl, shift);
130
131 onMouseDown(int when, double x, double y) =>
132 _dispatchMouseEvent('mousedown', x, y);
133
134 onMouseMove(int when, double x, double y) =>
135 _dispatchMouseEvent('mousemove', x, y);
136
137 onMouseUp(int when, double x, double y) =>
138 _dispatchMouseEvent('mouseup', x, y);
139
140 class CanvasElement extends Node {
8 int _height; 141 int _height;
9 int _width; 142 int _width;
10 143
11 get height => _height; 144 get height => _height;
12 get width => _width; 145 get width => _width;
13 146
14 CanvasRenderingContext2D _context2d; 147 CanvasRenderingContext2D _context2d;
15 WebGLRenderingContext _context3d; 148 WebGLRenderingContext _context3d;
16 149
17 // For use with drawImage, we want to support a src property 150 // For use with drawImage, we want to support a src property
18 // like ImageElement, which maps to the context handle in native 151 // like ImageElement, which maps to the context handle in native
19 // code. 152 // code.
20 get src => "context2d://${_context2d.handle}"; 153 get src => "context2d://${_context2d.handle}";
21 154
22 CanvasElement({int width, int height}) { 155 CanvasElement({int width, int height})
vsm 2013/03/04 17:34:55 Can we have more than one Canvas right now?
gram 2013/03/04 23:53:14 Yes. Currently we can have just one canvas that is
156 : super() {
23 _width = (width == null) ? getDeviceScreenWidth() : width; 157 _width = (width == null) ? getDeviceScreenWidth() : width;
24 _height = (height == null) ? getDeviceScreenHeight() : height; 158 _height = (height == null) ? getDeviceScreenHeight() : height;
25 } 159 }
26 160
27 CanvasRenderingContext getContext(String contextId) { 161 CanvasRenderingContext getContext(String contextId) {
28 if (contextId == "2d") { 162 if (contextId == "2d") {
29 if (_context2d == null) { 163 if (_context2d == null) {
30 _context2d = new CanvasRenderingContext2D(this, _width, _height); 164 _context2d = new CanvasRenderingContext2D(this, _width, _height);
31 } 165 }
32 return _context2d; 166 return _context2d;
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 num dirtyWidth, num dirtyHeight]) { 870 num dirtyWidth, num dirtyHeight]) {
737 throw new Exception('Unimplemented webkitGetImageDataHD'); 871 throw new Exception('Unimplemented webkitGetImageDataHD');
738 } 872 }
739 873
740 // TODO(vsm): Kill. 874 // TODO(vsm): Kill.
741 noSuchMethod(invocation) { 875 noSuchMethod(invocation) {
742 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); 876 throw new Exception('Unimplemented/unknown ${invocation.memberName}');
743 } 877 }
744 } 878 }
745 879
OLDNEW
« no previous file with comments | « runtime/embedders/openglui/android/eventloop.cc ('k') | runtime/embedders/openglui/common/input_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698