| 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 { |
| 82 // Firefox work-around for Location. The Firefox location object cannot be | 81 return _location; |
| 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 } | 82 } |
| 91 | 83 |
| 92 // TODO: consider forcing users to do: window.location.assign('string'). | 84 // TODO: consider forcing users to do: window.location.assign('string'). |
| 93 /** | 85 /** |
| 94 * Sets the window's location, which causes the browser to navigate to the new | 86 * 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. | 87 * location. [value] may be a Location object or a String. |
| 96 */ | 88 */ |
| 97 void set location(value) { | 89 void set location(value) { |
| 98 if (value is _LocationWrapper) { | 90 _location = value; |
| 99 _location = value._ptr; | |
| 100 } else { | |
| 101 _location = value; | |
| 102 } | |
| 103 } | 91 } |
| 104 | 92 |
| 105 _LocationWrapper _location_wrapper; // Cached wrapped Location object. | |
| 106 | |
| 107 // Native getter and setter to access raw Location object. | 93 // Native getter and setter to access raw Location object. |
| 108 dynamic get _location => JS('Location|=Object', '#.location', this); | 94 dynamic get _location => JS('Location|=Object', '#.location', this); |
| 109 void set _location(value) { | 95 void set _location(value) { |
| 110 JS('void', '#.location = #', this, value); | 96 JS('void', '#.location = #', this, value); |
| 111 } | 97 } |
| 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 | 98 |
| 127 /** | 99 /** |
| 128 * Called to draw an animation frame and then request the window to repaint | 100 * Called to draw an animation frame and then request the window to repaint |
| 129 * after [callback] has finished (creating the animation). | 101 * after [callback] has finished (creating the animation). |
| 130 * | 102 * |
| 131 * Use this method only if you need to later call [cancelAnimationFrame]. If | 103 * 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 | 104 * not, the preferred Dart idiom is to set animation frames by calling |
| 133 * [animationFrame], which returns a Future. | 105 * [animationFrame], which returns a Future. |
| 134 * | 106 * |
| 135 * Returns a non-zero valued integer to represent the request id for this | 107 * 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 | 369 |
| 398 ElementStream<BeforeUnloadEvent> forElement(Element e, {bool useCapture: false
}) { | 370 ElementStream<BeforeUnloadEvent> forElement(Element e, {bool useCapture: false
}) { |
| 399 return new _ElementEventStreamImpl(e, _eventType, useCapture); | 371 return new _ElementEventStreamImpl(e, _eventType, useCapture); |
| 400 } | 372 } |
| 401 | 373 |
| 402 ElementStream<BeforeUnloadEvent> _forElementList(ElementList e, | 374 ElementStream<BeforeUnloadEvent> _forElementList(ElementList e, |
| 403 {bool useCapture: false}) { | 375 {bool useCapture: false}) { |
| 404 return new _ElementListEventStreamImpl(e, _eventType, useCapture); | 376 return new _ElementListEventStreamImpl(e, _eventType, useCapture); |
| 405 } | 377 } |
| 406 } | 378 } |
| OLD | NEW |