Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: lib/html/templates/html/dart2js/impl_LocalWindow.darttemplate

Issue 11365019: Merging dart:html interfaces and implementations (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding generated files. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" { 5 class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
6 6
7 _DocumentImpl get document => JS('_DocumentImpl', '#.document', this); 7 Document get document => JS('Document', '#.document', this);
8 8
9 Window _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name); 9 Window _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name);
10 10
11 Window _open3(url, name, options) => 11 Window _open3(url, name, options) =>
12 JS('Window', '#.open(#,#,#)', this, url, name, options); 12 JS('Window', '#.open(#,#,#)', this, url, name, options);
13 13
14 Window open(String url, String name, [String options]) { 14 Window open(String url, String name, [String options]) {
15 if (options == null) { 15 if (options == null) {
16 return _DOMWindowCrossFrameImpl._createSafe(_open2(url, name)); 16 return _DOMWindowCrossFrame._createSafe(_open2(url, name));
17 } else { 17 } else {
18 return _DOMWindowCrossFrameImpl._createSafe(_open3(url, name, options)); 18 return _DOMWindowCrossFrame._createSafe(_open3(url, name, options));
19 } 19 }
20 } 20 }
21 21
22 // API level getter and setter for Location. 22 // API level getter and setter for Location.
23 // TODO: The cross domain safe wrapper can be inserted here or folded into 23 // TODO: The cross domain safe wrapper can be inserted here or folded into
24 // _LocationWrapper. 24 // _LocationWrapper.
25 LocalLocation get location => _get_location(); 25 LocalLocation get location() {
26 26 // Firefox work-around for Location. The Firefox location object cannot be
27 // TODO: consider forcing users to do: window.location.assign('string'). 27 // made to behave like a Dart object so must be wrapped.
28 /**
29 * Sets the window's location, which causes the browser to navigate to the new
30 * location. [value] may be a Location object or a string.
31 */
32 void set location(value) => _set_location(value);
33
34 // Firefox work-around for Location. The Firefox location object cannot be
35 // made to behave like a Dart object so must be wrapped.
36
37 LocalLocation _get_location() {
38 var result = _location; 28 var result = _location;
39 if (_isDartLocation(result)) return result; // e.g. on Chrome. 29 if (_isDartLocation(result)) return result; // e.g. on Chrome.
40 if (null == _location_wrapper) { 30 if (null == _location_wrapper) {
41 _location_wrapper = new _LocationWrapper(result); 31 _location_wrapper = new _LocationWrapper(result);
42 } 32 }
43 return _location_wrapper; 33 return _location_wrapper;
44 } 34 }
45 35
46 void _set_location(value) { 36 // TODO: consider forcing users to do: window.location.assign('string').
37 /**
38 * Sets the window's location, which causes the browser to navigate to the new
39 * location. [value] may be a Location object or a string.
40 */
41 void set location(value) {
47 if (value is _LocationWrapper) { 42 if (value is _LocationWrapper) {
48 _location = value._ptr; 43 _location = value._ptr;
49 } else { 44 } else {
50 _location = value; 45 _location = value;
51 } 46 }
52 } 47 }
53 48
54 var _location_wrapper; // Cached wrapped Location object. 49 var _location_wrapper; // Cached wrapped Location object.
55 50
56 // Native getter and setter to access raw Location object. 51 // Native getter and setter to access raw Location object.
57 Location get _location => JS('Location', '#.location', this); 52 Location get _location => JS('Location', '#.location', this);
58 void set _location(Location value) { 53 void set _location(Location value) {
59 JS('void', '#.location = #', this, value); 54 JS('void', '#.location = #', this, value);
60 } 55 }
61 // Prevent compiled from thinking 'location' property is available for a Dart 56 // Prevent compiled from thinking 'location' property is available for a Dart
62 // member. 57 // member.
63 _protect_location() native 'location'; 58 _protect_location() native 'location';
64 59
65 static _isDartLocation(thing) { 60 static _isDartLocation(thing) {
66 // On Firefox the code that implements 'is Location' fails to find the patch 61 // On Firefox the code that implements 'is Location' fails to find the patch
67 // stub on Object.prototype and throws an exception. 62 // stub on Object.prototype and throws an exception.
68 try { 63 try {
69 return thing is Location; 64 return thing is Location;
70 } catch (e) { 65 } catch (e) {
71 return false; 66 return false;
72 } 67 }
73 } 68 }
74 69
75 70 /**
71 * Executes a [callback] after the next batch of browser layout measurements
72 * has completed or would have completed if any browser layout measurements
73 * had been scheduled.
74 */
76 void requestLayoutFrame(TimeoutHandler callback) { 75 void requestLayoutFrame(TimeoutHandler callback) {
77 _addMeasurementFrameCallback(callback); 76 _addMeasurementFrameCallback(callback);
78 } 77 }
79 78
80 /** @domName DOMWindow.requestAnimationFrame */ 79 /** @domName DOMWindow.requestAnimationFrame */
81 int requestAnimationFrame(RequestAnimationFrameCallback callback) { 80 int requestAnimationFrame(RequestAnimationFrameCallback callback) {
82 _ensureRequestAnimationFrame(); 81 _ensureRequestAnimationFrame();
83 return _requestAnimationFrame(callback); 82 return _requestAnimationFrame(callback);
84 } 83 }
85 84
(...skipping 27 matching lines...) Expand all
113 $this.requestAnimationFrame = function(callback) { 112 $this.requestAnimationFrame = function(callback) {
114 return window.setTimeout(function() { 113 return window.setTimeout(function() {
115 callback(Date.now()); 114 callback(Date.now());
116 }, 16 /* 16ms ~= 60fps */); 115 }, 16 /* 16ms ~= 60fps */);
117 }; 116 };
118 $this.cancelAnimationFrame = function(id) { clearTimeout(id); } 117 $this.cancelAnimationFrame = function(id) { clearTimeout(id); }
119 })(#)""", 118 })(#)""",
120 this); 119 this);
121 } 120 }
122 121
123 122 IDBFactory get indexedDB() =>
124 _IDBFactoryImpl get indexedDB => _get_indexedDB(); 123 JS('IDBFactory',
125
126 _IDBFactoryImpl _get_indexedDB() =>
127 JS('_IDBFactoryImpl',
128 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB', 124 '#.indexedDB || #.webkitIndexedDB || #.mozIndexedDB',
129 this, this, this); 125 this, this, this);
130 126
131 // TODO(kasperl): Document these. 127 /**
132 lookupPort(String name) { 128 * Lookup a port by its [name]. Return null if no port is
129 * registered under [name].
130 */
131 SendPortSync lookupPort(String name) {
133 var port = JSON.parse(localStorage['dart-port:$name']); 132 var port = JSON.parse(localStorage['dart-port:$name']);
134 return _deserialize(port); 133 return _deserialize(port);
135 } 134 }
136 135
137 registerPort(String name, var port) { 136 /**
137 * Register a [port] on this window under the given [name]. This
138 * port may be retrieved by any isolate (or JavaScript script)
139 * running in this window.
140 */
141 void registerPort(String name, var port) {
138 var serialized = _serialize(port); 142 var serialized = _serialize(port);
139 localStorage['dart-port:$name'] = JSON.stringify(serialized); 143 localStorage['dart-port:$name'] = JSON.stringify(serialized);
140 } 144 }
141 145
146 /**
147 * Creates a new object URL for the specified object. The URL will be
148 * available until revokeObjectUrl is called.
149 * [object] can be a Blob, MediaStream or MediaSource.
150 */
142 String createObjectUrl(object) => 151 String createObjectUrl(object) =>
143 JS('String', 152 JS('String',
144 '(window.URL || window.webkitURL).createObjectURL(#)', object); 153 '(window.URL || window.webkitURL).createObjectURL(#)', object);
145 154
155 /** @domName DOMURL.revokeObjectURL */
146 void revokeObjectUrl(String objectUrl) { 156 void revokeObjectUrl(String objectUrl) {
147 JS('void', 157 JS('void',
148 '(window.URL || window.webkitURL).revokeObjectURL(#)', objectUrl); 158 '(window.URL || window.webkitURL).revokeObjectURL(#)', objectUrl);
149 } 159 }
150 160
151 $!MEMBERS 161 $!MEMBERS
152 } 162 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698