| 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 | 8 $if DART2JS |
| 9 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "Wind
ow,DOMWindow" { | 9 $(ANNOTATIONS)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "Wind
ow,DOMWindow" { |
| 10 $else | 10 $else |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 */ | 63 */ |
| 64 WindowBase open(String url, String name, [String options]) { | 64 WindowBase open(String url, String name, [String options]) { |
| 65 if (options == null) { | 65 if (options == null) { |
| 66 return _DOMWindowCrossFrame._createSafe(_open2(url, name)); | 66 return _DOMWindowCrossFrame._createSafe(_open2(url, name)); |
| 67 } else { | 67 } else { |
| 68 return _DOMWindowCrossFrame._createSafe(_open3(url, name, options)); | 68 return _DOMWindowCrossFrame._createSafe(_open3(url, name, options)); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 // API level getter and setter for Location. | 72 // API level getter and setter for Location. |
| 73 // TODO: The cross domain safe wrapper can be inserted here or folded into | 73 // TODO: The cross domain safe wrapper can be inserted here. |
| 74 // _LocationWrapper. | |
| 75 /** | 74 /** |
| 76 * The current location of this window. | 75 * The current location of this window. |
| 77 * | 76 * |
| 78 * Location currentLocation = window.location; | 77 * Location currentLocation = window.location; |
| 79 * print(currentLocation.href); // 'http://www.example.com:80/' | 78 * print(currentLocation.href); // 'http://www.example.com:80/' |
| 80 */ | 79 */ |
| 81 Location get location { | 80 Location get location => _location; |
| 82 // Firefox work-around for Location. The Firefox location object cannot be | |
| 83 // made to behave like a Dart object so must be wrapped. | |
| 84 var result = _location; | |
| 85 if (_isDartLocation(result)) return result; // e.g. on Chrome. | |
| 86 if (null == _location_wrapper) { | |
| 87 _location_wrapper = new _LocationWrapper(result); | |
| 88 } | |
| 89 return _location_wrapper; | |
| 90 } | |
| 91 | 81 |
| 92 // TODO: consider forcing users to do: window.location.assign('string'). | 82 // TODO: consider forcing users to do: window.location.assign('string'). |
| 93 /** | 83 /** |
| 94 * Sets the window's location, which causes the browser to navigate to the new | 84 * Sets the window's location, which causes the browser to navigate to the new |
| 95 * location. [value] may be a Location object or a string. | 85 * location. [value] may be a Location object or a String. |
| 96 */ | 86 */ |
| 97 void set location(value) { | 87 void set location(value) { |
| 98 if (value is _LocationWrapper) { | 88 _location = value; |
| 99 _location = value._ptr; | |
| 100 } else { | |
| 101 _location = value; | |
| 102 } | |
| 103 } | 89 } |
| 104 | 90 |
| 105 _LocationWrapper _location_wrapper; // Cached wrapped Location object. | |
| 106 | |
| 107 // Native getter and setter to access raw Location object. | 91 // Native getter and setter to access raw Location object. |
| 108 dynamic get _location => JS('Location|=Object', '#.location', this); | 92 dynamic get _location => JS('Location|Null', '#.location', this); |
| 109 void set _location(value) { | 93 void set _location(value) { |
| 110 JS('void', '#.location = #', this, value); | 94 JS('void', '#.location = #', this, value); |
| 111 } | 95 } |
| 112 // Prevent compiled from thinking 'location' property is available for a Dart | |
| 113 // member. | |
| 114 @JSName('location') | |
| 115 _protect_location() native; | |
| 116 | |
| 117 static _isDartLocation(thing) { | |
| 118 // On Firefox the code that implements 'is Location' fails to find the patch | |
| 119 // stub on Object.prototype and throws an exception. | |
| 120 try { | |
| 121 return thing is Location; | |
| 122 } catch (e) { | |
| 123 return false; | |
| 124 } | |
| 125 } | |
| 126 | 96 |
| 127 /** | 97 /** |
| 128 * Called to draw an animation frame and then request the window to repaint | 98 * Called to draw an animation frame and then request the window to repaint |
| 129 * after [callback] has finished (creating the animation). | 99 * after [callback] has finished (creating the animation). |
| 130 * | 100 * |
| 131 * Use this method only if you need to later call [cancelAnimationFrame]. If | 101 * Use this method only if you need to later call [cancelAnimationFrame]. If |
| 132 * not, the preferred Dart idiom is to set animation frames by calling | 102 * not, the preferred Dart idiom is to set animation frames by calling |
| 133 * [animationFrame], which returns a Future. | 103 * [animationFrame], which returns a Future. |
| 134 * | 104 * |
| 135 * Returns a non-zero valued integer to represent the request id for this | 105 * Returns a non-zero valued integer to represent the request id for this |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 367 |
| 398 ElementStream<BeforeUnloadEvent> forElement(Element e, {bool useCapture: false
}) { | 368 ElementStream<BeforeUnloadEvent> forElement(Element e, {bool useCapture: false
}) { |
| 399 return new _ElementEventStreamImpl(e, _eventType, useCapture); | 369 return new _ElementEventStreamImpl(e, _eventType, useCapture); |
| 400 } | 370 } |
| 401 | 371 |
| 402 ElementStream<BeforeUnloadEvent> _forElementList(ElementList e, | 372 ElementStream<BeforeUnloadEvent> _forElementList(ElementList e, |
| 403 {bool useCapture: false}) { | 373 {bool useCapture: false}) { |
| 404 return new _ElementListEventStreamImpl(e, _eventType, useCapture); | 374 return new _ElementListEventStreamImpl(e, _eventType, useCapture); |
| 405 } | 375 } |
| 406 } | 376 } |
| OLD | NEW |