6735b55710
BUG= Review URL: https://codereview.chromium.org//12217124 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@18459 260f80e4-7a28-3924-810f-c04153c831b5
70 lines
2.1 KiB
Plaintext
70 lines
2.1 KiB
Plaintext
// Copyright (c) 2012, 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 $LIBRARYNAME;
|
|
|
|
/**
|
|
* Base class that supports listening for and dispatching browser events.
|
|
*
|
|
* Normally events are accessed via the Stream getter:
|
|
*
|
|
* element.onMouseOver.listen((e) => print('Mouse over!'));
|
|
*
|
|
* To access bubbling events which are declared on one element, but may bubble
|
|
* up to another element type (common for MediaElement events):
|
|
*
|
|
* MediaElement.pauseEvent.forTarget(document.body).listen(...);
|
|
*
|
|
* To useCapture on events:
|
|
*
|
|
* Element.keyDownEvent.forTarget(element, useCapture: true).listen(...);
|
|
*
|
|
* Custom events can be declared as:
|
|
*
|
|
* class DataGenerator {
|
|
* static EventStreamProvider<Event> dataEvent =
|
|
* new EventStreamProvider('data');
|
|
* }
|
|
*
|
|
* Then listeners should access the event with:
|
|
*
|
|
* DataGenerator.dataEvent.forTarget(element).listen(...);
|
|
*
|
|
* Custom events can also be accessed as:
|
|
*
|
|
* element.on['some_event'].listen(...);
|
|
*
|
|
* This approach is generally discouraged as it loses the event typing and
|
|
* some DOM events may have multiple platform-dependent event names under the
|
|
* covers. By using the standard Stream getters you will get the platform
|
|
* specific event name automatically.
|
|
*/
|
|
class Events {
|
|
/* Raw event target. */
|
|
final EventTarget _ptr;
|
|
|
|
Events(this._ptr);
|
|
|
|
Stream operator [](String type) {
|
|
return new _EventStream(_ptr, type, false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Base class for all browser objects that support events.
|
|
*
|
|
* Use the [on] property to add, and remove events (rather than
|
|
* [$dom_addEventListener] and [$dom_removeEventListener]
|
|
* for compile-time type checks and a more concise API.
|
|
*/
|
|
$(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
|
|
|
|
/**
|
|
* This is an ease-of-use accessor for event streams which should only be
|
|
* used when an explicit accessor is not available.
|
|
*/
|
|
Events get on => new Events(this);
|
|
$!MEMBERS
|
|
}
|