| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of html; | |
| 6 | |
| 7 /// @domName $DOMNAME | |
| 8 class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { | |
| 9 | |
| 10 Document get document => JS('Document', '#.document', this); | |
| 11 | |
| 12 WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name); | |
| 13 | |
| 14 WindowBase _open3(url, name, options) => | |
| 15 JS('Window', '#.open(#,#,#)', this, url, name, options); | |
| 16 | |
| 17 WindowBase open(String url, String name, [String options]) { | |
| 18 if (options == null) { | |
| 19 return _DOMWindowCrossFrame._createSafe(_open2(url, name)); | |
| 20 } else { | |
| 21 return _DOMWindowCrossFrame._createSafe(_open3(url, name, options)); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 // API level getter and setter for Location. | |
| 26 // TODO: The cross domain safe wrapper can be inserted here or folded into | |
| 27 // _LocationWrapper. | |
| 28 Location get location { | |
| 29 // Firefox work-around for Location. The Firefox location object cannot be | |
| 30 // made to behave like a Dart object so must be wrapped. | |
| 31 var result = _location; | |
| 32 if (_isDartLocation(result)) return result; // e.g. on Chrome. | |
| 33 if (null == _location_wrapper) { | |
| 34 _location_wrapper = new _LocationWrapper(result); | |
| 35 } | |
| 36 return _location_wrapper; | |
| 37 } | |
| 38 | |
| 39 // TODO: consider forcing users to do: window.location.assign('string'). | |
| 40 /** | |
| 41 * Sets the window's location, which causes the browser to navigate to the new | |
| 42 * location. [value] may be a Location object or a string. | |
| 43 */ | |
| 44 void set location(value) { | |
| 45 if (value is _LocationWrapper) { | |
| 46 _location = value._ptr; | |
| 47 } else { | |
| 48 _location = value; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 _LocationWrapper _location_wrapper; // Cached wrapped Location object. | |
| 53 | |
| 54 // Native getter and setter to access raw Location object. | |
| 55 dynamic get _location => JS('Location|=Object', '#.location', this); | |
| 56 void set _location(value) { | |
| 57 JS('void', '#.location = #', this, value); | |
| 58 } | |
| 59 // Prevent compiled from thinking 'location' property is available for a Dart | |
| 60 // member. | |
| 61 @JSName('location') | |
| 62 _protect_location() native; | |
| 63 | |
| 64 static _isDartLocation(thing) { | |
| 65 // On Firefox the code that implements 'is Location' fails to find the patch | |
| 66 // stub on Object.prototype and throws an exception. | |
| 67 try { | |
| 68 return thing is Location; | |
| 69 } catch (e) { | |
| 70 return false; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 /** | |
| 75 * Executes a [callback] after the next batch of browser layout measurements | |
| 76 * has completed or would have completed if any browser layout measurements | |
| 77 * had been scheduled. | |
| 78 */ | |
| 79 void requestLayoutFrame(TimeoutHandler callback) { | |
| 80 _addMeasurementFrameCallback(callback); | |
| 81 } | |
| 82 | |
| 83 /** @domName DOMWindow.requestAnimationFrame */ | |
| 84 int requestAnimationFrame(RequestAnimationFrameCallback callback) { | |
| 85 _ensureRequestAnimationFrame(); | |
| 86 return _requestAnimationFrame(callback); | |
| 87 } | |
| 88 | |
| 89 void cancelAnimationFrame(id) { | |
| 90 _ensureRequestAnimationFrame(); | |
| 91 _cancelAnimationFrame(id); | |
| 92 } | |
| 93 | |
| 94 @JSName('requestAnimationFrame') | |
| 95 int _requestAnimationFrame(RequestAnimationFrameCallback callback) native; | |
| 96 | |
| 97 @JSName('cancelAnimationFrame') | |
| 98 void _cancelAnimationFrame(int id) native; | |
| 99 | |
| 100 _ensureRequestAnimationFrame() { | |
| 101 if (JS('bool', | |
| 102 '!!(#.requestAnimationFrame && #.cancelAnimationFrame)', this, this)) | |
| 103 return; | |
| 104 | |
| 105 JS('void', | |
| 106 r""" | |
| 107 (function($this) { | |
| 108 var vendors = ['ms', 'moz', 'webkit', 'o']; | |
| 109 for (var i = 0; i < vendors.length && !$this.requestAnimationFrame; ++i) { | |
| 110 $this.requestAnimationFrame = $this[vendors[i] + 'RequestAnimationFrame']; | |
| 111 $this.cancelAnimationFrame = | |
| 112 $this[vendors[i]+'CancelAnimationFrame'] || | |
| 113 $this[vendors[i]+'CancelRequestAnimationFrame']; | |
| 114 } | |
| 115 if ($this.requestAnimationFrame && $this.cancelAnimationFrame) return; | |
| 116 $this.requestAnimationFrame = function(callback) { | |
| 117 return window.setTimeout(function() { | |
| 118 callback(Date.now()); | |
| 119 }, 16 /* 16ms ~= 60fps */); | |
| 120 }; | |
| 121 $this.cancelAnimationFrame = function(id) { clearTimeout(id); } | |
| 122 })(#)""", | |
| 123 this); | |
| 124 } | |
| 125 | |
| 126 /** | |
| 127 * Gets an instance of the Indexed DB factory to being using Indexed DB. | |
| 128 * | |
| 129 * Use [IdbFactory.supported] to check if Indexed DB is supported on the | |
| 130 * current platform. | |
| 131 */ | |
| 132 @SupportedBrowser(SupportedBrowser.CHROME, '23.0') | |
| 133 @SupportedBrowser(SupportedBrowser.FIREFOX, '15.0') | |
| 134 @SupportedBrowser(SupportedBrowser.IE, '10.0') | |
| 135 @Experimental() | |
| 136 IdbFactory get indexedDB => | |
| 137 JS('IdbFactory', | |
| 138 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', | |
| 139 this, this, this); | |
| 140 | |
| 141 /** | |
| 142 * Lookup a port by its [name]. Return null if no port is | |
| 143 * registered under [name]. | |
| 144 */ | |
| 145 SendPortSync lookupPort(String name) { | |
| 146 var port = JSON.parse(document.documentElement.attributes['dart-port:$name']
); | |
| 147 return _deserialize(port); | |
| 148 } | |
| 149 | |
| 150 /** | |
| 151 * Register a [port] on this window under the given [name]. This | |
| 152 * port may be retrieved by any isolate (or JavaScript script) | |
| 153 * running in this window. | |
| 154 */ | |
| 155 void registerPort(String name, var port) { | |
| 156 var serialized = _serialize(port); | |
| 157 document.documentElement.attributes['dart-port:$name'] = JSON.stringify(seri
alized); | |
| 158 } | |
| 159 | |
| 160 /// @domName Window.console; @docsEditable true | |
| 161 Console get console => Console.safeConsole; | |
| 162 | |
| 163 $!MEMBERS | |
| 164 } | |
| OLD | NEW |