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

Side by Side Diff: tools/dom/templates/html/dart2js/impl_Window.darttemplate

Issue 12253011: Reapply remove setInterval. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months 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
« no previous file with comments | « tools/dom/src/Timer.dart ('k') | tools/dom/templates/html/dartium/impl_Window.darttemplate » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 $LIBRARYNAME;
6
7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
8
9 Document get document => JS('Document', '#.document', this);
10
11 WindowBase _open2(url, name) => JS('Window', '#.open(#,#)', this, url, name);
12
13 WindowBase _open3(url, name, options) =>
14 JS('Window', '#.open(#,#,#)', this, url, name, options);
15
16 WindowBase open(String url, String name, [String options]) {
17 if (options == null) {
18 return _DOMWindowCrossFrame._createSafe(_open2(url, name));
19 } else {
20 return _DOMWindowCrossFrame._createSafe(_open3(url, name, options));
21 }
22 }
23
24 // API level getter and setter for Location.
25 // TODO: The cross domain safe wrapper can be inserted here or folded into
26 // _LocationWrapper.
27 Location get location {
28 // Firefox work-around for Location. The Firefox location object cannot be
29 // made to behave like a Dart object so must be wrapped.
30 var result = _location;
31 if (_isDartLocation(result)) return result; // e.g. on Chrome.
32 if (null == _location_wrapper) {
33 _location_wrapper = new _LocationWrapper(result);
34 }
35 return _location_wrapper;
36 }
37
38 // TODO: consider forcing users to do: window.location.assign('string').
39 /**
40 * Sets the window's location, which causes the browser to navigate to the new
41 * location. [value] may be a Location object or a string.
42 */
43 void set location(value) {
44 if (value is _LocationWrapper) {
45 _location = value._ptr;
46 } else {
47 _location = value;
48 }
49 }
50
51 _LocationWrapper _location_wrapper; // Cached wrapped Location object.
52
53 // Native getter and setter to access raw Location object.
54 dynamic get _location => JS('Location|=Object', '#.location', this);
55 void set _location(value) {
56 JS('void', '#.location = #', this, value);
57 }
58 // Prevent compiled from thinking 'location' property is available for a Dart
59 // member.
60 @JSName('location')
61 _protect_location() native;
62
63 static _isDartLocation(thing) {
64 // On Firefox the code that implements 'is Location' fails to find the patch
65 // stub on Object.prototype and throws an exception.
66 try {
67 return thing is Location;
68 } catch (e) {
69 return false;
70 }
71 }
72
73 /**
74 * Executes a [callback] after the immediate execution stack has completed.
75 *
76 * This will cause the callback to be executed after all processing has
77 * completed for the current event, but before any subsequent events.
78 */
79 void setImmediate(TimeoutHandler callback) {
80 _addMicrotaskCallback(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')
161 Console get console => Console.safeConsole;
162
163 /// Checks if _setImmediate is supported.
164 static bool get _supportsSetImmediate =>
165 JS('bool', '!!(window.setImmediate)');
166
167 // Set immediate implementation for IE
168 void _setImmediate(void callback()) {
169 JS('void', '#.setImmediate(#)', this, convertDartClosureToJS(callback, 0));
170 }
171
172 $!MEMBERS
173 }
OLDNEW
« no previous file with comments | « tools/dom/src/Timer.dart ('k') | tools/dom/templates/html/dartium/impl_Window.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698