Chromium Code Reviews| Index: runtime/embedders/openglui/common/gl.dart |
| =================================================================== |
| --- runtime/embedders/openglui/common/gl.dart (revision 19252) |
| +++ runtime/embedders/openglui/common/gl.dart (working copy) |
| @@ -4,7 +4,140 @@ |
| library android_extension; |
| -class CanvasElement { |
| +// A VERY simplified DOM. |
| + |
| +class BodyElement { |
| + List _nodes; |
| + get nodes => _nodes; |
| + BodyElement() : _nodes = new List(); |
| +} |
| + |
| +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
|
| + BodyElement _body; |
| + get body => _body; |
| + 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.
|
| +} |
| + |
| +HtmlDocument document = new HtmlDocument(); |
| + |
| +// Event handling. This is very kludgy for now, especially the |
| +// bare-bones Stream stuff! |
| + |
| +class Event { |
| + final String type; |
| + Event(String type) : this.type = type; |
| +} |
| + |
| +class KeyEvent extends Event { |
| + final bool altKey; |
| + final bool ctrlKey; |
| + final bool shiftKey; |
| + final int keyCode; |
| + |
| + KeyEvent(String type, int keycode, bool alt, bool ctrl, bool shift) |
| + : super(type), |
| + keyCode = keycode, |
| + altKey = alt, |
| + ctrlKey = ctrl, |
| + shiftKey = shift { |
| + } |
| +} |
| + |
| +class MouseEvent extends Event { |
| + final double screenX, screenY; |
| + 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.
|
| + |
| + MouseEvent(String type, double x, double y) |
| + : super(type), |
| + screenX = x, |
| + screenY = y, |
| + clientX = x, |
| + clientY = y { |
| + } |
| +} |
| + |
| +class StreamSubscription { |
| + Stream _stream; |
| + int _id; |
| + |
| + StreamSubscription(this._stream, this._id); |
| + 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.
|
| +} |
| + |
| +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.
|
| + int _nextListenerId; |
| + Map _listeners; |
| + |
| + Stream() : _nextListenerId = 0, _listeners = new Map(); |
| + |
| + void onData(id, handler) { |
|
vsm
2013/03/04 17:34:55
types for args
gram
2013/03/04 23:53:14
Done.
|
| + _listeners[id] = handler; |
| + } |
| + |
| + listen(callback) { |
|
vsm
2013/03/04 17:34:55
types for args
gram
2013/03/04 23:53:14
Done.
|
| + var sub = new StreamSubscription(this, _nextListenerId++); |
| + sub.onData(callback); |
| + return sub; |
| + } |
| + |
| + post(Event e) { |
| + for (var listener in _listeners.values) { |
| + listener(e); |
| + } |
| + } |
| +} |
| + |
| +class Node { |
| + Map<String,Stream> _events; |
| + |
| + get onMouseDown => _events['mousedown']; |
| + get onMouseMove => _events['mousemove']; |
| + get onMouseUp => _events['mouseup']; |
| + get onKeyDown => _events['keydown']; |
| + get onKeyUp => _events['keyup']; |
| + |
| + get events => _events; |
| + |
| + Node() : _events = new Map() { |
| + _events['mousedown'] = new Stream(); |
| + _events['mousemove'] = new Stream(); |
| + _events['mouseup'] = new Stream(); |
| + _events['keydown'] = new Stream(); |
| + _events['keyup'] = new Stream(); |
| + } |
| +} |
| + |
| +_dispatchEvent(String type, Event e) { |
| + for (var n in document.body.nodes) { |
| + var handler = n.events[type]; |
| + if (handler != null) { |
| + handler.post(e); |
| + } |
| + } |
| +} |
| + |
| +_dispatchKeyEvent(String type, int keyCode, bool alt, bool ctrl, bool shift) => |
| + _dispatchEvent(type, new KeyEvent(type, keyCode, alt, ctrl, shift)); |
| + |
| +_dispatchMouseEvent(String type, double x, double y) => |
| + _dispatchEvent(type, new MouseEvent(type, x, y)); |
| + |
| +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
|
| + => _dispatchKeyEvent('keydown', keyCode, alt, ctrl, shift); |
| + |
| +onKeyUp(int when, int keyCode, bool alt, bool ctrl, bool shift, int repeat) => |
| + _dispatchKeyEvent('keyup', keyCode, alt, ctrl, shift); |
| + |
| +onMouseDown(int when, double x, double y) => |
| + _dispatchMouseEvent('mousedown', x, y); |
| + |
| +onMouseMove(int when, double x, double y) => |
| + _dispatchMouseEvent('mousemove', x, y); |
| + |
| +onMouseUp(int when, double x, double y) => |
| + _dispatchMouseEvent('mouseup', x, y); |
| + |
| +class CanvasElement extends Node { |
| int _height; |
| int _width; |
| @@ -19,7 +152,8 @@ |
| // code. |
| get src => "context2d://${_context2d.handle}"; |
| - CanvasElement({int width, int height}) { |
| + 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
|
| + : super() { |
| _width = (width == null) ? getDeviceScreenWidth() : width; |
| _height = (height == null) ? getDeviceScreenHeight() : height; |
| } |