| 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 @DocsEditable() | 7 @DocsEditable() |
| 8 $if DART2JS | |
| 9 $(ANNOTATIONS)@Native("Window,DOMWindow") | 8 $(ANNOTATIONS)@Native("Window,DOMWindow") |
| 10 $(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS { | 9 $(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS { |
| 11 $else | |
| 12 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | |
| 13 $endif | |
| 14 | 10 |
| 15 /** | 11 /** |
| 16 * Returns a Future that completes just before the window is about to | 12 * Returns a Future that completes just before the window is about to |
| 17 * repaint so the user can draw an animation frame. | 13 * repaint so the user can draw an animation frame. |
| 18 * | 14 * |
| 19 * If you need to later cancel this animation, use [requestAnimationFrame] | 15 * If you need to later cancel this animation, use [requestAnimationFrame] |
| 20 * instead. | 16 * instead. |
| 21 * | 17 * |
| 22 * The [Future] completes to a timestamp that represents a floating | 18 * The [Future] completes to a timestamp that represents a floating |
| 23 * point value of the number of milliseconds that have elapsed since the page | 19 * point value of the number of milliseconds that have elapsed since the page |
| 24 * started to load (which is also the timestamp at this call to | 20 * started to load (which is also the timestamp at this call to |
| 25 * animationFrame). | 21 * animationFrame). |
| 26 * | 22 * |
| 27 * Note: The code that runs when the future completes should call | 23 * Note: The code that runs when the future completes should call |
| 28 * [animationFrame] again for the animation to continue. | 24 * [animationFrame] again for the animation to continue. |
| 29 */ | 25 */ |
| 30 Future<num> get animationFrame { | 26 Future<num> get animationFrame { |
| 31 var completer = new Completer<num>.sync(); | 27 var completer = new Completer<num>.sync(); |
| 32 requestAnimationFrame((time) { | 28 requestAnimationFrame((time) { |
| 33 completer.complete(time); | 29 completer.complete(time); |
| 34 }); | 30 }); |
| 35 return completer.future; | 31 return completer.future; |
| 36 } | 32 } |
| 37 | 33 |
| 38 $if DART2JS | |
| 39 /** | 34 /** |
| 40 * The newest document in this window. | 35 * The newest document in this window. |
| 41 * | 36 * |
| 42 * ## Other resources | 37 * ## Other resources |
| 43 * | 38 * |
| 44 * * [Loading web | 39 * * [Loading web |
| 45 * pages](https://html.spec.whatwg.org/multipage/browsers.html) | 40 * pages](https://html.spec.whatwg.org/multipage/browsers.html) |
| 46 * from WHATWG. | 41 * from WHATWG. |
| 47 */ | 42 */ |
| 48 Document get document => JS('Document', '#.document', this); | 43 Document get document => JS('Document', '#.document', this); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 @Experimental() | 170 @Experimental() |
| 176 IdbFactory get indexedDB => | 171 IdbFactory get indexedDB => |
| 177 JS('IdbFactory|Null', // If not supported, returns null. | 172 JS('IdbFactory|Null', // If not supported, returns null. |
| 178 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', | 173 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', |
| 179 this, this, this); | 174 this, this, this); |
| 180 | 175 |
| 181 /// The debugging console for this window. | 176 /// The debugging console for this window. |
| 182 @DomName('Window.console') | 177 @DomName('Window.console') |
| 183 Console get console => Console._safeConsole; | 178 Console get console => Console._safeConsole; |
| 184 | 179 |
| 185 $else | |
| 186 /** | |
| 187 * Called to draw an animation frame and then request the window to repaint | |
| 188 * after [callback] has finished (creating the animation). | |
| 189 * | |
| 190 * Use this method only if you need to later call [cancelAnimationFrame]. If | |
| 191 * not, the preferred Dart idiom is to set animation frames by calling | |
| 192 * [animationFrame], which returns a Future. | |
| 193 * | |
| 194 * Returns a non-zero valued integer to represent the request id for this | |
| 195 * request. This value only needs to be saved if you intend to call | |
| 196 * [cancelAnimationFrame] so you can specify the particular animation to | |
| 197 * cancel. | |
| 198 * | |
| 199 * Note: The supplied [callback] needs to call [requestAnimationFrame] again | |
| 200 * for the animation to continue. | |
| 201 */ | |
| 202 @DomName('Window.requestAnimationFrame') | |
| 203 int requestAnimationFrame(FrameRequestCallback callback) { | |
| 204 return _requestAnimationFrame(_wrapZone(callback)); | |
| 205 } | |
| 206 $endif | |
| 207 | 180 |
| 208 /** | 181 /** |
| 209 * Access a sandboxed file system of the specified `size`. If `persistent` is | 182 * Access a sandboxed file system of the specified `size`. If `persistent` is |
| 210 * true, the application will request permission from the user to create | 183 * true, the application will request permission from the user to create |
| 211 * lasting storage. This storage cannot be freed without the user's | 184 * lasting storage. This storage cannot be freed without the user's |
| 212 * permission. Returns a [Future] whose value stores a reference to the | 185 * permission. Returns a [Future] whose value stores a reference to the |
| 213 * sandboxed file system for use. Because the file system is sandboxed, | 186 * sandboxed file system for use. Because the file system is sandboxed, |
| 214 * applications cannot access file systems created in other web pages. | 187 * applications cannot access file systems created in other web pages. |
| 215 */ | 188 */ |
| 216 Future<FileSystem> requestFileSystem(int size, {bool persistent: false}) { | 189 Future<FileSystem> requestFileSystem(int size, {bool persistent: false}) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 247 * | 220 * |
| 248 * * [Window.moveTo](https://developer.mozilla.org/en-US/docs/Web/API/Window.m
oveTo) | 221 * * [Window.moveTo](https://developer.mozilla.org/en-US/docs/Web/API/Window.m
oveTo) |
| 249 * from MDN. | 222 * from MDN. |
| 250 * * [Window.moveTo](http://dev.w3.org/csswg/cssom-view/#dom-window-moveto) | 223 * * [Window.moveTo](http://dev.w3.org/csswg/cssom-view/#dom-window-moveto) |
| 251 * from W3C. | 224 * from W3C. |
| 252 */ | 225 */ |
| 253 void moveTo(Point p) { | 226 void moveTo(Point p) { |
| 254 _moveTo(p.x, p.y); | 227 _moveTo(p.x, p.y); |
| 255 } | 228 } |
| 256 | 229 |
| 257 $if DART2JS | |
| 258 @DomName('Window.pageXOffset') | 230 @DomName('Window.pageXOffset') |
| 259 @DocsEditable() | 231 @DocsEditable() |
| 260 int get pageXOffset => JS('num', '#.pageXOffset', this).round(); | 232 int get pageXOffset => JS('num', '#.pageXOffset', this).round(); |
| 261 | 233 |
| 262 @DomName('Window.pageYOffset') | 234 @DomName('Window.pageYOffset') |
| 263 @DocsEditable() | 235 @DocsEditable() |
| 264 int get pageYOffset => JS('num', '#.pageYOffset', this).round(); | 236 int get pageYOffset => JS('num', '#.pageYOffset', this).round(); |
| 265 | 237 |
| 266 /** | 238 /** |
| 267 * The distance this window has been scrolled horizontally. | 239 * The distance this window has been scrolled horizontally. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 287 * * [The Screen interface | 259 * * [The Screen interface |
| 288 * specification](http://www.w3.org/TR/cssom-view/#screen) from W3C. | 260 * specification](http://www.w3.org/TR/cssom-view/#screen) from W3C. |
| 289 * * [scrollY](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY
) | 261 * * [scrollY](https://developer.mozilla.org/en-US/docs/Web/API/Window.scrollY
) |
| 290 * from MDN. | 262 * from MDN. |
| 291 */ | 263 */ |
| 292 @DomName('Window.scrollY') | 264 @DomName('Window.scrollY') |
| 293 @DocsEditable() | 265 @DocsEditable() |
| 294 int get scrollY => JS('bool', '("scrollY" in #)', this) ? | 266 int get scrollY => JS('bool', '("scrollY" in #)', this) ? |
| 295 JS('num', '#.scrollY', this).round() : | 267 JS('num', '#.scrollY', this).round() : |
| 296 document.documentElement.scrollTop; | 268 document.documentElement.scrollTop; |
| 297 $else | |
| 298 @DomName('Window.pageXOffset') | |
| 299 @DocsEditable() | |
| 300 int get pageXOffset => _blink.BlinkWindow.instance.pageXOffset_Getter_(this).r
ound(); | |
| 301 | |
| 302 @DomName('Window.pageYOffset') | |
| 303 @DocsEditable() | |
| 304 int get pageYOffset => _blink.BlinkWindow.instance.pageYOffset_Getter_(this).r
ound(); | |
| 305 | |
| 306 @DomName('Window.scrollX') | |
| 307 @DocsEditable() | |
| 308 int get scrollX => _blink.BlinkWindow.instance.scrollX_Getter_(this).round(); | |
| 309 | |
| 310 @DomName('Window.scrollY') | |
| 311 @DocsEditable() | |
| 312 int get scrollY => _blink.BlinkWindow.instance.scrollY_Getter_(this).round(); | |
| 313 $endif | |
| 314 } | 269 } |
| 315 | 270 |
| 316 $if DART2JS | |
| 317 class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent { | 271 class _BeforeUnloadEvent extends _WrappedEvent implements BeforeUnloadEvent { |
| 318 String _returnValue; | 272 String _returnValue; |
| 319 | 273 |
| 320 _BeforeUnloadEvent(Event base): super(base); | 274 _BeforeUnloadEvent(Event base): super(base); |
| 321 | 275 |
| 322 String get returnValue => _returnValue; | 276 String get returnValue => _returnValue; |
| 323 | 277 |
| 324 set returnValue(String value) { | 278 set returnValue(String value) { |
| 325 _returnValue = value; | 279 _returnValue = value; |
| 326 // FF and IE use the value as the return value, Chrome will return this from | 280 // FF and IE use the value as the return value, Chrome will return this from |
| 327 // the event callback function. | 281 // the event callback function. |
| 328 if (JS('bool', '("returnValue" in #)', wrapped)) { | 282 if (JS('bool', '("returnValue" in #)', wrapped)) { |
| 329 JS('void', '#.returnValue = #', wrapped, value); | 283 JS('void', '#.returnValue = #', wrapped, value); |
| 330 } | 284 } |
| 331 } | 285 } |
| 332 } | 286 } |
| 333 $endif | |
| 334 | 287 |
| 335 class _BeforeUnloadEventStreamProvider implements | 288 class _BeforeUnloadEventStreamProvider implements |
| 336 EventStreamProvider<BeforeUnloadEvent> { | 289 EventStreamProvider<BeforeUnloadEvent> { |
| 337 final String _eventType; | 290 final String _eventType; |
| 338 | 291 |
| 339 const _BeforeUnloadEventStreamProvider(this._eventType); | 292 const _BeforeUnloadEventStreamProvider(this._eventType); |
| 340 | 293 |
| 341 Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) { | 294 Stream<BeforeUnloadEvent> forTarget(EventTarget e, {bool useCapture: false}) { |
| 342 $if DART2JS | 295 // Specify the generic type for EventStream only in dart2js. |
| 343 // Specify the generic type for EventStream only in dart2js to avoid | |
| 344 // checked mode errors in dartium. | |
| 345 var stream = new _EventStream<BeforeUnloadEvent>(e, _eventType, useCapture); | 296 var stream = new _EventStream<BeforeUnloadEvent>(e, _eventType, useCapture); |
| 346 var controller = new StreamController<BeforeUnloadEvent>(sync: true); | 297 var controller = new StreamController<BeforeUnloadEvent>(sync: true); |
| 347 | 298 |
| 348 stream.listen((event) { | 299 stream.listen((event) { |
| 349 var wrapped = new _BeforeUnloadEvent(event); | 300 var wrapped = new _BeforeUnloadEvent(event); |
| 350 controller.add(wrapped); | 301 controller.add(wrapped); |
| 351 }); | 302 }); |
| 352 | 303 |
| 353 return controller.stream; | 304 return controller.stream; |
| 354 $else | |
| 355 var stream = new _EventStream(e, _eventType, useCapture); | |
| 356 return stream; | |
| 357 $endif | |
| 358 } | 305 } |
| 359 | 306 |
| 360 String getEventType(EventTarget target) { | 307 String getEventType(EventTarget target) { |
| 361 return _eventType; | 308 return _eventType; |
| 362 } | 309 } |
| 363 | 310 |
| 364 ElementStream<BeforeUnloadEvent> forElement(Element e, {bool useCapture: false
}) { | 311 ElementStream<BeforeUnloadEvent> forElement(Element e, {bool useCapture: false
}) { |
| 365 $if DART2JS | 312 // Specify the generic type for _ElementEventStreamImpl only in dart2js. |
| 366 // Specify the generic type for _ElementEventStreamImpl only in dart2js to | |
| 367 // avoid checked mode errors in dartium. | |
| 368 return new _ElementEventStreamImpl<BeforeUnloadEvent>(e, _eventType, useCapt
ure); | 313 return new _ElementEventStreamImpl<BeforeUnloadEvent>(e, _eventType, useCapt
ure); |
| 369 $else | |
| 370 return new _ElementEventStreamImpl(e, _eventType, useCapture); | |
| 371 $endif | |
| 372 } | 314 } |
| 373 | 315 |
| 374 ElementStream<BeforeUnloadEvent> _forElementList(ElementList e, | 316 ElementStream<BeforeUnloadEvent> _forElementList(ElementList e, |
| 375 {bool useCapture: false}) { | 317 {bool useCapture: false}) { |
| 376 $if DART2JS | 318 // Specify the generic type for _ElementEventStreamImpl only in dart2js. |
| 377 // Specify the generic type for _ElementEventStreamImpl only in dart2js to | |
| 378 // avoid checked mode errors in dartium. | |
| 379 return new _ElementListEventStreamImpl<BeforeUnloadEvent>(e, _eventType, use
Capture); | 319 return new _ElementListEventStreamImpl<BeforeUnloadEvent>(e, _eventType, use
Capture); |
| 380 $else | |
| 381 return new _ElementListEventStreamImpl(e, _eventType, useCapture); | |
| 382 $endif | |
| 383 } | 320 } |
| 384 } | 321 } |
| OLD | NEW |