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

Unified Diff: tools/dom/templates/html/impl/impl_ScriptProcessorNode.darttemplate

Issue 11510013: Making ScriptProcessorNode not an EventTarget. (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/dom/templates/html/dart2js/web_audio_dart2js.darttemplate ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/dom/templates/html/impl/impl_ScriptProcessorNode.darttemplate
diff --git a/tools/dom/templates/html/impl/impl_ScriptProcessorNode.darttemplate b/tools/dom/templates/html/impl/impl_ScriptProcessorNode.darttemplate
new file mode 100644
index 0000000000000000000000000000000000000000..231000db047456df6c9baa83971b3c02f857db0b
--- /dev/null
+++ b/tools/dom/templates/html/impl/impl_ScriptProcessorNode.darttemplate
@@ -0,0 +1,143 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+part of $LIBRARY;
+
+$(ANNOTATIONS)class $CLASSNAME$EXTENDS$NATIVESPEC {
+ Stream<AudioProcessingEvent> _eventStream;
Anton Muhin 2013/03/14 08:27:39 please, no: we agreed that we're going to implemen
Anton Muhin 2013/03/14 09:30:52 My bad, please, disregard.
Emily Fortuna 2013/03/14 18:11:50 I made this change because Pavel asked for it agai
+
+ /**
+ * Get a Stream that fires events when AudioProcessingEvents occur.
+ * This particular stream is special in that it only allows one listener to a
+ * given stream. Subsequent calls to [listen] after the first call will throw
+ */
+ Stream<AudioProcessingEvent> get onAudioProcess {
+ if (_eventStream == null) {
+ _eventStream = new _AudioEventStream(this);
+ }
+ return _eventStream;
+ }
+$!MEMBERS
+}
+
+class _AudioEventStreamSubscription<AudioProcessingEvent> extends
Anton Muhin 2013/03/14 09:30:52 why this generic argument? looks like a typo.
Emily Fortuna 2013/03/14 18:11:50 removed. it was left over from the general EventSt
+ StreamSubscription<AudioProcessingEvent> {
+ EventListener _callback;
Anton Muhin 2013/03/14 09:30:52 if we prohibit null _callback, is it true _callbac
Emily Fortuna 2013/03/14 18:11:50 True. Fixed up. I had the paused variable to disti
+ ScriptProcessorNode _target;
+ bool _paused;
+
+ _AudioEventStreamSubscription(this._target, this._callback) {
+ _paused = false;
Anton Muhin 2013/03/14 09:30:52 maybe move into field declaration?
Emily Fortuna 2013/03/14 18:11:50 Done.
+ _tryResume();
+ }
+
+ void cancel() {
Anton Muhin 2013/03/14 09:30:52 shouldn't it also clear _AudioEventStream._streamS
Anton Muhin 2013/03/14 09:32:22 cannot we have: void cancel() { pause(); } ?
Emily Fortuna 2013/03/14 18:11:50 Done.
Emily Fortuna 2013/03/14 18:11:50 No, a StreamSubscription can only be associated wi
+ if (_callback != null) {
+ throw new StateError("Subscription has already been canceled.");
+ }
+ _unlisten();
+ }
+
+ void onData(void callback(AudioProcessingEvent)) {
+ if (_callback != null) {
+ throw new StateError("Subscription has been canceled.");
+ }
+ _setCallback(callback);
+ }
+
+ /// Has no effect.
+ void onError(void handleError(AsyncError error)) {}
+
+ /// Has no effect.
+ void onDone(void handleDone()) {}
+
+ void pause([Future resumeSignal]) {
+ if (_callback != null) {
+ throw new StateError("Subscription has been canceled.");
+ }
+ _unlisten();
+ _paused = true;
+
+ if (resumeSignal != null) {
+ resumeSignal.whenComplete(() { _paused = false; resume(); });
+ }
+ }
+
+ void resume() {
+ if (_callback != null) {
Anton Muhin 2013/03/14 09:30:52 if (_callback == null) ? and has been resumed?
Emily Fortuna 2013/03/14 18:11:50 Done.
+ throw new StateError("Subscription has been canceled.");
+ }
+ if (!_paused) {
+ throw new StateError("Subscription is not paused.");
+ }
+ _tryResume();
+ }
+
+ void _tryResume() {
+ if (_callback != null) {
+ _setCallback(_callback);
+ _callback = null;
+ }
+ }
+
+ void _unlisten() {
+ if (_callback == null) {
+ var noop = (event) {};
Anton Muhin 2013/03/14 09:30:52 why not null?
Emily Fortuna 2013/03/14 18:11:50 Done.
+$if DART2JS
Anton Muhin 2013/03/14 09:30:52 Why have conditional code here? Why not have _onA
Emily Fortuna 2013/03/14 18:11:50 Because in this version we're returning a custom S
+ _callback = JS('Function', '#.onaudioprocess', _target);
+$else
+ // TODO(podivilov): Implement on Dartium.
+$endif
+ _setCallback(noop);
+ }
+ }
+
+ void _setCallback(callbackFunc) {
+$if DART2JS
+ JS('void', '#.onaudioprocess = #', _target,
+ convertDartClosureToJS(_callback, 1));
+$else
+ // TODO(podivilov): Implement on Dartium.
+$endif
+ }
+}
+
+/**
+ * Adapter for exposing DOM events as Dart streams.
+ */
+class _AudioEventStream<AudioProcessingEvent>
Anton Muhin 2013/03/14 09:30:52 why generic argument here?
Emily Fortuna 2013/03/14 18:11:50 removed
+ extends Stream<AudioProcessingEvent> {
+ static Set _createdTargets = new Set();
Anton Muhin 2013/03/14 09:30:52 nit: do not we name static _CREATED_TARGETS? And
Emily Fortuna 2013/03/14 18:11:50 I thought all caps were for constants. This isn't
+ ScriptProcessorNode _target;
+ StreamSubscription _streamSubscription;
+
+ _AudioEventStream(target) {
+ if (_createdTargets.contains(target)) {
Anton Muhin 2013/03/14 09:30:52 why we need this check? Note as well, that you ne
Emily Fortuna 2013/03/14 18:11:50 This was to enforce the "one listener per ScriptPr
+ throw new ArgumentError('This ScriptProcessorNode already has an event '
Anton Muhin 2013/03/14 09:30:52 nit: there is a mix of " and ' for string literals
Emily Fortuna 2013/03/14 18:11:50 Done.
+ 'stream associated with it. There can be only one listener per '
+ 'ScriptProcessorNode');
+ } else {
Anton Muhin 2013/03/14 09:30:52 do we need else clause as then class always throws
Emily Fortuna 2013/03/14 18:11:50 removed else clause
+ _target = target;
+ _createdTargets.add(_target);
+ }
+ }
+
+ bool get isBroadcast => true;
+
+ StreamSubscription<AudioProcessingEvent> listen(
+ void onData(AudioProcessingEvent event),
Anton Muhin 2013/03/14 09:30:52 is onData null allowed?
Emily Fortuna 2013/03/14 18:11:50 no longer. I could have it convert to the no-op fu
+ { void onError(AsyncError error),
Anton Muhin 2013/03/14 09:30:52 nit: no space after {
Emily Fortuna 2013/03/14 18:11:50 Done.
+ void onDone(),
+ bool unsubscribeOnError}) {
+ if (_streamSubscription != null) {
+ throw new StateError('Only one listener is allowed for this particular '
+ 'stream.');
+ }
+ _streamSubscription =
+ new _AudioEventStreamSubscription<AudioProcessingEvent>(
+ this._target, onData);
+ return _streamSubscription;
+ }
+}
+
« no previous file with comments | « tools/dom/templates/html/dart2js/web_audio_dart2js.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698