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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 12218111: Allowing Window.onBeforeUnload event to work properly. (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:
Download patch
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 34dd2e072eb6c4645d735393b3e13b1e722324c6..3abaae93eb6b27e21cf8e18f9fc0d90bc37598b6 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -684,10 +684,6 @@ class Blob native "*Blob" {
@DomName('HTMLBodyElement')
class BodyElement extends Element native "*HTMLBodyElement" {
- @DomName('HTMLBodyElement.beforeunloadEvent')
- @DocsEditable
- static const EventStreamProvider<Event> beforeUnloadEvent = const EventStreamProvider<Event>('beforeunload');
-
@DomName('HTMLBodyElement.blurEvent')
@DocsEditable
static const EventStreamProvider<Event> blurEvent = const EventStreamProvider<Event>('blur');
@@ -740,10 +736,6 @@ class BodyElement extends Element native "*HTMLBodyElement" {
@DocsEditable
factory BodyElement() => document.$dom_createElement("body");
- @DomName('HTMLBodyElement.onbeforeunload')
- @DocsEditable
- Stream<Event> get onBeforeUnload => beforeUnloadEvent.forTarget(this);
-
@DomName('HTMLBodyElement.onblur')
@DocsEditable
Stream<Event> get onBlur => blurEvent.forTarget(this);
@@ -10415,10 +10407,6 @@ class Event native "*Event" {
@DocsEditable
final int eventPhase;
- @DomName('Event.returnValue')
- @DocsEditable
- bool returnValue;
-
EventTarget get target => _convertNativeToDart_EventTarget(this._get_target);
@JSName('target')
@DomName('Event.target')
@@ -25076,7 +25064,7 @@ class Window extends EventTarget implements WindowBase native "@*DOMWindow" {
* lasting storage. This storage cannot be freed without the user's
* permission. Returns a [Future] whose value stores a reference to the
* sandboxed file system for use. Because the file system is sandboxed,
- * applications cannot access file systems created in other web pages.
+ * applications cannot access file systems created in other web pages.
*/
Future<FileSystem> requestFileSystem(int size, {bool persistent: false}) {
return _requestFileSystem(persistent? 1 : 0, size);
@@ -25086,10 +25074,6 @@ class Window extends EventTarget implements WindowBase native "@*DOMWindow" {
@DocsEditable
static const EventStreamProvider<Event> contentLoadedEvent = const EventStreamProvider<Event>('DOMContentLoaded');
- @DomName('DOMWindow.beforeunloadEvent')
- @DocsEditable
- static const EventStreamProvider<Event> beforeUnloadEvent = const EventStreamProvider<Event>('beforeunload');
-
@DomName('DOMWindow.devicemotionEvent')
@DocsEditable
static const EventStreamProvider<DeviceMotionEvent> deviceMotionEvent = const EventStreamProvider<DeviceMotionEvent>('devicemotion');
@@ -25586,10 +25570,6 @@ class Window extends EventTarget implements WindowBase native "@*DOMWindow" {
@DocsEditable
Stream<Event> get onAbort => Element.abortEvent.forTarget(this);
- @DomName('DOMWindow.onbeforeunload')
- @DocsEditable
- Stream<Event> get onBeforeUnload => beforeUnloadEvent.forTarget(this);
-
@DomName('DOMWindow.onblur')
@DocsEditable
Stream<Event> get onBlur => Element.blurEvent.forTarget(this);
@@ -25794,6 +25774,70 @@ class Window extends EventTarget implements WindowBase native "@*DOMWindow" {
@DocsEditable
Stream<TransitionEvent> get onTransitionEnd => Element.transitionEndEvent.forTarget(this);
+
+ @DomName('DOMWindow.beforeunloadEvent')
+ @DocsEditable
+ static const EventStreamProvider<BeforeUnloadEvent> beforeUnloadEvent =
+ const _BeforeUnloadEventStreamProvider('beforeunload');
+
+ @DomName('DOMWindow.onbeforeunload')
+ @DocsEditable
+ Stream<Event> get onBeforeUnload => beforeUnloadEvent.forTarget(this);
+}
+
+/**
+ * Event object that is fired before the window is closed.
+ *
+ * The standard window close behavior can be prevented by setting the
+ * [returnValue]. This will display a dialog to the user confirming that they
+ * want to close the page.
+ */
+abstract class BeforeUnloadEvent implements Event {
+ /**
+ * If set to a non-null value, a dialog will be presented to the user
+ * confirming that they want to close the page.
+ */
+ String returnValue;
+}
+
+class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent {
+ String _returnValue;
+
+ _BeforeUnloadEvent(Event base): super(base);
+
+ String get returnValue => _returnValue;
+
+ void set returnValue(String value) {
+ _returnValue = value;
+ // FF and IE use the value as the return value, Chrome will return this from
+ // the event callback function.
+ if (JS('bool', '("returnValue" in #)', _base)) {
+ JS('void', '#.returnValue = #', _base, value);
+ }
+ }
+}
+
+class _BeforeUnloadEventStreamProvider implements
+ EventStreamProvider<BeforeUnloadEvent> {
+ final String _eventType;
+
+ const _BeforeUnloadEventStreamProvider(this._eventType);
+
+ Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) {
+ var controller = new StreamController.broadcast();
+ var stream = new _EventStream(e, _eventType, useCapture);
+ stream.listen((event) {
+ var wrapped = new _BeforeUnloadEvent(event);
+ controller.add(wrapped);
+ return wrapped.returnValue;
+ });
+
+ return controller.stream;
+ }
+
+ String getEventType(EventTarget target) {
+ return _eventType;
+ }
}
// 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
@@ -29285,7 +29329,7 @@ abstract class CssClassSet implements Set<String> {
// BSD-style license that can be found in the LICENSE file.
-typedef void EventListener(Event event);
+typedef EventListener(Event event);
// 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.
@@ -31586,6 +31630,59 @@ abstract class _Deserializer {
/**
+ * Helper class to implement custom events which wrap DOM events.
+ */
+class _WrappedEvent implements Event {
+ final Event wrapped;
+ _WrappedEvent(this.wrapped);
+
+ bool get bubbles => wrapped.bubbles;
+
+ bool get cancelBubble => wrapped.bubbles;
+ void set cancelBubble(bool value) {
+ wrapped.cancelBubble = value;
+ }
+
+ bool get cancelable => wrapped.cancelable;
+
+ DataTransfer get clipboardData => wrapped.clipboardData;
+
+ EventTarget get currentTarget => wrapped.currentTarget;
+
+ bool get defaultPrevented => wrapped.defaultPrevented;
+
+ int get eventPhase => wrapped.eventPhase;
+
+ EventTarget get target => wrapped.target;
+
+ int get timeStamp => wrapped.timeStamp;
+
+ String get type => wrapped.type;
+
+ void $dom_initEvent(String eventTypeArg, bool canBubbleArg,
+ bool cancelableArg) {
+ throw new UnsupportedError(
+ 'Cannot initialize this Event.');
+ }
+
+ void preventDefault() {
+ wrapped.preventDefault();
+ }
+
+ void stopImmediatePropagation() {
+ wrapped.stopImmediatePropagation();
+ }
+
+ void stopPropagation() {
+ wrapped.stopPropagation();
+ }
+}
+// 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.
+
+
+/**
* A list which just wraps another list, for either intercepting list calls or
* retyping the list (for example, from List<A> to List<B> where B extends A).
*/
@@ -31976,7 +32073,7 @@ class _HistoryCrossFrame implements HistoryBase {
* on how we can make this class work with as many international keyboards as
* possible. Bugs welcome!
*/
-class KeyEvent implements KeyboardEvent {
+class KeyEvent extends _WrappedEvent implements KeyboardEvent {
/** The parent KeyboardEvent that this KeyEvent is wrapping and "fixing". */
KeyboardEvent _parent;
@@ -32011,7 +32108,7 @@ class KeyEvent implements KeyboardEvent {
bool get _realAltKey => JS('int', '#.altKey', _parent);
/** Construct a KeyEvent with [parent] as the event we're emulating. */
- KeyEvent(KeyboardEvent parent) {
+ KeyEvent(KeyboardEvent parent): super(parent) {
_parent = parent;
_shadowAltKey = _realAltKey;
_shadowCharCode = _realCharCode;
@@ -32032,22 +32129,11 @@ class KeyEvent implements KeyboardEvent {
/** True if the altGraphKey is pressed during this event. */
bool get altGraphKey => _parent.altGraphKey;
- bool get bubbles => _parent.bubbles;
- /** True if this event can be cancelled. */
- bool get cancelable => _parent.cancelable;
- bool get cancelBubble => _parent.cancelBubble;
- void set cancelBubble(bool cancel) {
- _parent.cancelBubble = cancel;
- }
/** Accessor to the clipboardData available for this event. */
DataTransfer get clipboardData => _parent.clipboardData;
/** True if the ctrl key is pressed during this event. */
bool get ctrlKey => _parent.ctrlKey;
- /** Accessor to the target this event is listening to for changes. */
- EventTarget get currentTarget => _parent.currentTarget;
- bool get defaultPrevented => _parent.defaultPrevented;
int get detail => _parent.detail;
- int get eventPhase => _parent.eventPhase;
/**
* Accessor to the part of the keyboard that the key was pressed from (one of
* KeyLocation.STANDARD, KeyLocation.RIGHT, KeyLocation.LEFT,
@@ -32058,35 +32144,17 @@ class KeyEvent implements KeyboardEvent {
/** True if the Meta (or Mac command) key is pressed during this event. */
bool get metaKey => _parent.metaKey;
Point get page => _parent.page;
- bool get returnValue => _parent.returnValue;
- void set returnValue(bool value) {
- _parent.returnValue = value;
- }
/** True if the shift key was pressed during this event. */
bool get shiftKey => _parent.shiftKey;
- int get timeStamp => _parent.timeStamp;
- /**
- * The type of key event that occurred. One of "keydown", "keyup", or
- * "keypress".
- */
- String get type => _parent.type;
Window get view => _parent.view;
- void preventDefault() => _parent.preventDefault();
- void stopImmediatePropagation() => _parent.stopImmediatePropagation();
- void stopPropagation() => _parent.stopPropagation();
void $dom_initUIEvent(String type, bool canBubble, bool cancelable,
Window view, int detail) {
throw new UnsupportedError("Cannot initialize a UI Event from a KeyEvent.");
}
- void $dom_initEvent(String eventTypeArg, bool canBubbleArg,
- bool cancelableArg) {
- throw new UnsupportedError("Cannot initialize an Event from a KeyEvent.");
- }
String get _shadowKeyIdentifier => JS('String', '#.keyIdentifier', _parent);
int get $dom_charCode => charCode;
int get $dom_keyCode => keyCode;
- EventTarget get target => _parent.target;
String get $dom_keyIdentifier {
throw new UnsupportedError("keyIdentifier is unsupported.");
}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/lib/native_helper.dart ('k') | sdk/lib/html/dartium/html_dartium.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698