Chromium Code Reviews| 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, Function> _callbacks; | |
|
vsm
2013/03/07 23:53:04
Might as well s/Function/RequestAnimationFrameCall
gram
2013/03/08 00:26:42
Done.
| |
| 23 | |
| 24 Window._internal() : _callbacks = new Map(); | |
|
vsm
2013/03/07 23:53:04
nit: new lines between methods.
gram
2013/03/08 00:26:42
Done.
| |
| 25 int requestAnimationFrame(RequestAnimationFrameCallback callback) { | |
| 26 _callbacks[_nextId++] = callback; | |
| 27 } | |
| 28 void cancelAnimationFrame(id) { | |
| 29 if (_callbacks.containsKey(id)) { | |
| 30 _callbacks.remove(id); | |
| 31 } | |
| 32 } | |
| 33 get animationFrame { | |
| 34 // TODO(gram) | |
| 35 return null; | |
| 36 } | |
| 37 | |
| 38 void _dispatch() { | |
| 39 var when = (new DateTime.now()).millisecondsSinceEpoch; | |
| 40 // We clear out the callbacks map before calling any callbacks, | |
| 41 // as they may schedule new callbacks. | |
| 42 var oldcallbacks = _callbacks; | |
| 43 _callbacks = new Map(); | |
| 44 for (var c in oldcallbacks.values) { | |
| 45 c(when); | |
| 46 } | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 Window window = new Window._internal(); | |
| 51 | |
| 16 // The OpenGLUI "equivalent" of HtmlDocument. | 52 // The OpenGLUI "equivalent" of HtmlDocument. |
| 17 class Document { | 53 class Document { |
| 18 BodyElement _body; | 54 BodyElement _body; |
| 19 get body => _body; | 55 get body => _body; |
| 20 Document._internal() : _body = new BodyElement(); | 56 Document._internal() : _body = new BodyElement(); |
| 21 } | 57 } |
| 22 | 58 |
| 23 Document document = new Document._internal(); | 59 Document document = new Document._internal(); |
| 24 | 60 |
| 61 update_() { | |
|
vsm
2013/03/07 23:53:04
TODO to make private? I assume this is only calle
gram
2013/03/08 00:26:42
Done.
| |
| 62 window._dispatch(); | |
| 63 } | |
| 64 | |
| 25 // Event handling. This is very kludgy for now, especially the | 65 // Event handling. This is very kludgy for now, especially the |
| 26 // bare-bones Stream stuff! | 66 // bare-bones Stream stuff! |
| 27 | 67 |
| 28 class Event { | 68 class Event { |
| 29 final String type; | 69 final String type; |
| 30 Event(String type) : this.type = type; | 70 Event(String type) : this.type = type; |
| 31 } | 71 } |
| 32 | 72 |
| 33 class KeyEvent extends Event { | 73 class KeyEvent extends Event { |
| 34 final bool altKey; | 74 final bool altKey; |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 953 num dirtyWidth, num dirtyHeight]) { | 993 num dirtyWidth, num dirtyHeight]) { |
| 954 throw new Exception('Unimplemented webkitGetImageDataHD'); | 994 throw new Exception('Unimplemented webkitGetImageDataHD'); |
| 955 } | 995 } |
| 956 | 996 |
| 957 // TODO(vsm): Kill. | 997 // TODO(vsm): Kill. |
| 958 noSuchMethod(invocation) { | 998 noSuchMethod(invocation) { |
| 959 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); | 999 throw new Exception('Unimplemented/unknown ${invocation.memberName}'); |
| 960 } | 1000 } |
| 961 } | 1001 } |
| 962 | 1002 |
| OLD | NEW |