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 part of $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
6 | 6 |
7 $if DART2JS | 7 $if DART2JS |
8 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { | 8 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { |
9 $else | 9 $else |
10 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 10 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 throw new UnsupportedError('setImmediate is not supported'); | 224 throw new UnsupportedError('setImmediate is not supported'); |
225 } | 225 } |
226 $endif | 226 $endif |
227 | 227 |
228 /** | 228 /** |
229 * Access a sandboxed file system of the specified `size`. If `persistent` is | 229 * Access a sandboxed file system of the specified `size`. If `persistent` is |
230 * true, the application will request permission from the user to create | 230 * true, the application will request permission from the user to create |
231 * lasting storage. This storage cannot be freed without the user's | 231 * lasting storage. This storage cannot be freed without the user's |
232 * permission. Returns a [Future] whose value stores a reference to the | 232 * permission. Returns a [Future] whose value stores a reference to the |
233 * sandboxed file system for use. Because the file system is sandboxed, | 233 * sandboxed file system for use. Because the file system is sandboxed, |
234 * applications cannot access file systems created in other web pages. | 234 * applications cannot access file systems created in other web pages. |
235 */ | 235 */ |
236 Future<FileSystem> requestFileSystem(int size, {bool persistent: false}) { | 236 Future<FileSystem> requestFileSystem(int size, {bool persistent: false}) { |
237 return _requestFileSystem(persistent? 1 : 0, size); | 237 return _requestFileSystem(persistent? 1 : 0, size); |
238 } | 238 } |
239 $!MEMBERS | 239 $!MEMBERS |
| 240 |
| 241 @DomName('DOMWindow.beforeunloadEvent') |
| 242 @DocsEditable |
| 243 static const EventStreamProvider<BeforeUnloadEvent> beforeUnloadEvent = |
| 244 const _BeforeUnloadEventStreamProvider('beforeunload'); |
| 245 |
| 246 @DomName('DOMWindow.onbeforeunload') |
| 247 @DocsEditable |
| 248 Stream<Event> get onBeforeUnload => beforeUnloadEvent.forTarget(this); |
240 } | 249 } |
| 250 |
| 251 /** |
| 252 * Event object that is fired before the window is closed. |
| 253 * |
| 254 * The standard window close behavior can be prevented by setting the |
| 255 * [returnValue]. This will display a dialog to the user confirming that they |
| 256 * want to close the page. |
| 257 */ |
| 258 abstract class BeforeUnloadEvent implements Event { |
| 259 /** |
| 260 * If set to a non-null value, a dialog will be presented to the user |
| 261 * confirming that they want to close the page. |
| 262 */ |
| 263 String returnValue; |
| 264 } |
| 265 |
| 266 class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent { |
| 267 String _returnValue; |
| 268 |
| 269 _BeforeUnloadEvent(Event base): super(base); |
| 270 |
| 271 String get returnValue => _returnValue; |
| 272 |
| 273 void set returnValue(String value) { |
| 274 _returnValue = value; |
| 275 $if DART2JS |
| 276 // FF and IE use the value as the return value, Chrome will return this from |
| 277 // the event callback function. |
| 278 if (JS('bool', '("returnValue" in #)', _base)) { |
| 279 JS('void', '#.returnValue = #', _base, value); |
| 280 } |
| 281 $endif |
| 282 } |
| 283 } |
| 284 |
| 285 class _BeforeUnloadEventStreamProvider implements |
| 286 EventStreamProvider<BeforeUnloadEvent> { |
| 287 final String _eventType; |
| 288 |
| 289 const _BeforeUnloadEventStreamProvider(this._eventType); |
| 290 |
| 291 Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) { |
| 292 var controller = new StreamController.broadcast(); |
| 293 var stream = new _EventStream(e, _eventType, useCapture); |
| 294 stream.listen((event) { |
| 295 var wrapped = new _BeforeUnloadEvent(event); |
| 296 controller.add(wrapped); |
| 297 return wrapped.returnValue; |
| 298 }); |
| 299 |
| 300 return controller.stream; |
| 301 } |
| 302 |
| 303 String getEventType(EventTarget target) { |
| 304 return _eventType; |
| 305 } |
| 306 } |
OLD | NEW |