15e086338d
Take-two of https://code.google.com/p/dart/source/detail?r=29022 The issue with the original was that addEventListener was changed to private, but this caused the IDB classes which override it to not override it any longer. This was breaking C++ multiple inheritance type casts. Fix is to make addEventListener public. BUG= R=efortuna@google.com Review URL: https://codereview.chromium.org//35013003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@29051 260f80e4-7a28-3924-810f-c04153c831b5
105 lines
3.2 KiB
Plaintext
105 lines
3.2 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);
|
|
}
|
|
}
|
|
|
|
class ElementEvents extends Events {
|
|
/* Raw event target. */
|
|
final Element _ptr;
|
|
static final webkitEvents = {
|
|
'animationend' : 'webkitAnimationEnd',
|
|
'animationiteration' : 'webkitAnimationIteration',
|
|
'animationstart' : 'webkitAnimationStart',
|
|
'fullscreenchange' : 'webkitfullscreenchange',
|
|
'fullscreenerror' : 'webkitfullscreenerror',
|
|
'keyadded' : 'webkitkeyadded',
|
|
'keyerror' : 'webkitkeyerror',
|
|
'keymessage' : 'webkitkeymessage',
|
|
'needkey' : 'webkitneedkey',
|
|
'pointerlockchange' : 'webkitpointerlockchange',
|
|
'pointerlockerror' : 'webkitpointerlockerror',
|
|
'resourcetimingbufferfull' : 'webkitresourcetimingbufferfull',
|
|
'transitionend': 'webkitTransitionEnd',
|
|
'speechchange' : 'webkitSpeechChange'
|
|
};
|
|
|
|
ElementEvents(Element ptr) : this._ptr = ptr, super(ptr);
|
|
|
|
Stream operator [](String type) {
|
|
if (webkitEvents.keys.contains(type.toLowerCase())) {
|
|
if (Device.isWebKit) {
|
|
return new _ElementEventStreamImpl(
|
|
_ptr, webkitEvents[type.toLowerCase()], false);
|
|
}
|
|
}
|
|
return new _ElementEventStreamImpl(_ptr, type, false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Base class for all browser objects that support events.
|
|
*
|
|
* Use the [on] property to add, and remove events
|
|
* for compile-time type checks and a more concise API.
|
|
*/
|
|
$(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
|
|
|
|
// Custom element created callback.
|
|
EventTarget._created();
|
|
|
|
/**
|
|
* 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
|
|
}
|