| OLD | NEW |
| 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 import 'dart:async'; | 6 import 'dart:async'; |
| 7 | 7 |
| 8 // A VERY simplified DOM. | 8 // A VERY simplified DOM. |
| 9 | 9 |
| 10 class BodyElement { | 10 class BodyElement { |
| 11 List _nodes; | 11 List _nodes; |
| 12 get nodes => _nodes; | 12 get nodes => _nodes; |
| 13 BodyElement() : _nodes = new List(); | 13 BodyElement() : _nodes = new List(); |
| 14 } | 14 } |
| 15 | 15 |
| 16 // The OpenGLUI "equivalent" of Window. |
| 17 |
| 18 typedef void RequestAnimationFrameCallback(num highResTime); |
| 19 |
| 20 class Window { |
| 21 static int _nextId = 0; |
| 22 Map<int, RequestAnimationFrameCallback> _callbacks; |
| 23 |
| 24 Window._internal() : _callbacks = new Map(); |
| 25 |
| 26 int requestAnimationFrame(RequestAnimationFrameCallback callback) { |
| 27 _callbacks[_nextId++] = callback; |
| 28 } |
| 29 void cancelAnimationFrame(id) { |
| 30 if (_callbacks.containsKey(id)) { |
| 31 _callbacks.remove(id); |
| 32 } |
| 33 } |
| 34 get animationFrame { |
| 35 // TODO(gram) |
| 36 return null; |
| 37 } |
| 38 |
| 39 void _dispatch() { |
| 40 var when = (new DateTime.now()).millisecondsSinceEpoch; |
| 41 // We clear out the callbacks map before calling any callbacks, |
| 42 // as they may schedule new callbacks. |
| 43 var oldcallbacks = _callbacks; |
| 44 _callbacks = new Map(); |
| 45 for (var c in oldcallbacks.values) { |
| 46 c(when); |
| 47 } |
| 48 } |
| 49 } |
| 50 |
| 51 Window window = new Window._internal(); |
| 52 |
| 16 // The OpenGLUI "equivalent" of HtmlDocument. | 53 // The OpenGLUI "equivalent" of HtmlDocument. |
| 17 class Document { | 54 class Document { |
| 18 BodyElement _body; | 55 BodyElement _body; |
| 19 get body => _body; | 56 get body => _body; |
| 20 Document._internal() : _body = new BodyElement(); | 57 Document._internal() : _body = new BodyElement(); |
| 21 } | 58 } |
| 22 | 59 |
| 23 Document document = new Document._internal(); | 60 Document document = new Document._internal(); |
| 24 | 61 |
| 62 // TODO(gram): make private and call from within library context. |
| 63 update_() { |
| 64 window._dispatch(); |
| 65 } |
| 66 |
| 25 // Event handling. This is very kludgy for now, especially the | 67 // Event handling. This is very kludgy for now, especially the |
| 26 // bare-bones Stream stuff! | 68 // bare-bones Stream stuff! |
| 27 | 69 |
| 28 class Event { | 70 class Event { |
| 29 final String type; | 71 final String type; |
| 30 Event(String type) : this.type = type; | 72 Event(String type) : this.type = type; |
| 31 } | 73 } |
| 32 | 74 |
| 33 class KeyEvent extends Event { | 75 class KeyEvent extends Event { |
| 34 final bool altKey; | 76 final bool altKey; |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 num dirtyWidth, num dirtyHeight]) { | 995 num dirtyWidth, num dirtyHeight]) { |
| 954 throw new Exception('Unimplemented webkitGetImageDataHD'); | 996 throw new Exception('Unimplemented webkitGetImageDataHD'); |
| 955 } | 997 } |
| 956 | 998 |
| 957 // TODO(vsm): Kill. | 999 // TODO(vsm): Kill. |
| 958 noSuchMethod(invocation) { | 1000 noSuchMethod(invocation) { |
| 959 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); | 1001 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); |
| 960 } | 1002 } |
| 961 } | 1003 } |
| 962 | 1004 |
| OLD | NEW |