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

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

Issue 10913125: Remove lib/dom directory! (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
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 class $CLASSNAME$EXTENDS$IMPLEMENTS native "@*DOMWindow" {
6
7 _DocumentImpl get document() native "return this.document;";
8
9 Window get _top() native "return this.top;";
10
11 // Override top to return secure wrapper.
12 Window get top() => _DOMWindowCrossFrameImpl._createSafe(_top);
13
14 Window _open2(url, name) native "return this.open(url, name);";
15
16 Window _open3(url, name, options) native "return this.open(url, name, options) ;";
17
18 Window open(String url, String name, [String options]) {
19 if (options == null) {
20 return _DOMWindowCrossFrameImpl._createSafe(_open2(url, name));
21 } else {
22 return _DOMWindowCrossFrameImpl._createSafe(_open3(url, name, options));
23 }
24 }
25
26 // API level getter and setter for Location.
27 // TODO: The cross domain safe wrapper can be inserted here or folded into
28 // _LocationWrapper.
29 Location get location() => _get_location();
30
31 // TODO: consider forcing users to do: window.location.assign('string').
32 /**
33 * Sets the window's location, which causes the browser to navigate to the new
34 * location. [value] may be a Location object or a string.
35 */
36 void set location(value) => _set_location(value);
37
38 // Firefox work-around for Location. The Firefox location object cannot be
39 // made to behave like a Dart object so must be wrapped.
40
41 Location _get_location() {
42 var result = _location;
43 if (_isDartLocation(result)) return result; // e.g. on Chrome.
44 if (null == _location_wrapper) {
45 _location_wrapper = new _LocationWrapper(result);
46 }
47 return _location_wrapper;
48 }
49
50 void _set_location(value) {
51 if (value is _LocationWrapper) {
52 _location = value._ptr;
53 } else {
54 _location = value;
55 }
56 }
57
58 var _location_wrapper; // Cached wrapped Location object.
59
60 // Native getter and setter to access raw Location object.
61 Location get _location() native 'return this.location';
62 void set _location(Location value) native 'this.location = value';
63 // Prevent compiled from thinking 'location' property is available for a Dart
64 // member.
65 _protect_location() native 'location';
66
67 static _isDartLocation(thing) {
68 // On Firefox the code that implements 'is Location' fails to find the patch
69 // stub on Object.prototype and throws an exception.
70 try {
71 return thing is Location;
72 } catch (e) {
73 return false;
74 }
75 }
76
77
78 void requestLayoutFrame(TimeoutHandler callback) {
79 _addMeasurementFrameCallback(callback);
80 }
81
82 /** @domName DOMWindow.requestAnimationFrame */
83 int requestAnimationFrame(RequestAnimationFrameCallback callback) {
84 _ensureRequestAnimationFrame();
85 return _requestAnimationFrame(callback);
86 }
87
88 void cancelAnimationFrame(id) {
89 _ensureRequestAnimationFrame();
90 _cancelAnimationFrame(id);
91 }
92
93 int _requestAnimationFrame(RequestAnimationFrameCallback callback)
94 native 'requestAnimationFrame';
95
96 void _cancelAnimationFrame(int id)
97 native 'cancelAnimationFrame';
98
99 _ensureRequestAnimationFrame() native '''
100 if (this.requestAnimationFrame && this.cancelAnimationFrame) return;
101 var vendors = ['ms', 'moz', 'webkit', 'o'];
102 for (var i = 0; i < vendors.length && !this.requestAnimationFrame; ++i) {
103 this.requestAnimationFrame = this[vendors[i] + 'RequestAnimationFrame'];
104 this.cancelAnimationFrame =
105 this[vendors[i]+'CancelAnimationFrame'] ||
106 this[vendors[i]+'CancelRequestAnimationFrame'];
107 }
108 if (this.requestAnimationFrame && this.cancelAnimationFrame) return;
109 this.requestAnimationFrame = function(callback) {
110 return window.setTimeout(callback, 16 /* 16ms ~= 60fps */);
111 };
112 this.cancelAnimationFrame = function(id) { clearTimeout(id); }
113 ''';
114
115
116 _IDBFactoryImpl get indexedDB() => _get_indexedDB();
117
118 _IDBFactoryImpl _get_indexedDB() native
119 'return this.indexedDB || this.webkitIndexedDB || this.mozIndexedDB';
120
121 // TODO(kasperl): Document these.
122 lookupPort(String name) {
123 var port = JSON.parse(localStorage['dart-port:$name']);
124 return _deserialize(port);
125 }
126
127 registerPort(String name, var port) {
128 var serialized = _serialize(port);
129 localStorage['dart-port:$name'] = JSON.stringify(serialized);
130 }
131
132 String createObjectUrl(object) native '''
133 return (window.URL || window.webkitURL).createObjectURL(object)
134 ''';
135
136 void revokeObjectUrl(String objectUrl) native '''
137 (window.URL || window.webkitURL).revokeObjectURL(objectUrl)
138 ''';
139 $!MEMBERS
140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698