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

Side by Side Diff: tools/dom/src/native_DOMImplementation.dart

Issue 24491003: Revert "Revert "Start of dartium custom element lifecycle event support."" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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
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 html; 5 part of html;
6 6
7 class _ConsoleVariables { 7 class _ConsoleVariables {
8 Map<String, Object> _data = new Map<String, Object>(); 8 Map<String, Object> _data = new Map<String, Object>();
9 9
10 /** 10 /**
11 * Forward member accesses to the backing JavaScript object. 11 * Forward member accesses to the backing JavaScript object.
12 */ 12 */
13 noSuchMethod(Invocation invocation) { 13 noSuchMethod(Invocation invocation) {
14 String member = MirrorSystem.getName(invocation.memberName); 14 String member = MirrorSystem.getName(invocation.memberName);
15 if (invocation.isGetter) { 15 if (invocation.isGetter) {
16 return _data[member]; 16 return _data[member];
17 } else if (invocation.isSetter) { 17 } else if (invocation.isSetter) {
18 assert(member.endsWith('=')); 18 assert(member.endsWith('='));
19 member = member.substring(0, member.length - 1); 19 member = member.substring(0, member.length - 1);
20 _data[member] = invocation.positionalArguments[0]; 20 _data[member] = invocation.positionalArguments[0];
21 } else { 21 } else {
22 return Function.apply(_data[member], invocation.positionalArguments, invoc ation.namedArguments); 22 return Function.apply(_data[member], invocation.positionalArguments, invoc ation.namedArguments);
23 } 23 }
24 } 24 }
25 25
26 void clear() => _data.clear(); 26 void clear() => _data.clear();
27 27
28 /** 28 /**
29 * List all variables currently defined. 29 * List all variables currently defined.
30 */ 30 */
31 List variables() => _data.keys.toList(growable: false); 31 List variables() => _data.keys.toList(growable: false);
32 } 32 }
33 33
34 class _Utils { 34 class _Utils {
35 static double dateTimeToDouble(DateTime dateTime) => 35 static double dateTimeToDouble(DateTime dateTime) =>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 static bool isMap(obj) => obj is Map; 88 static bool isMap(obj) => obj is Map;
89 89
90 static Map createMap() => {}; 90 static Map createMap() => {};
91 91
92 static makeUnimplementedError(String fileName, int lineNo) { 92 static makeUnimplementedError(String fileName, int lineNo) {
93 return new UnsupportedError('[info: $fileName:$lineNo]'); 93 return new UnsupportedError('[info: $fileName:$lineNo]');
94 } 94 }
95 95
96 static bool isTypeSubclassOf(Type type, Type other) {
97 if (type == other) {
98 return true;
99 }
100 var superclass = reflectClass(type).superclass;
101 if (superclass != null) {
102 return isTypeSubclassOf(superclass.reflectedType, other);
103 }
104 return false;
105 }
106
96 static window() native "Utils_window"; 107 static window() native "Utils_window";
97 static forwardingPrint(String message) native "Utils_forwardingPrint"; 108 static forwardingPrint(String message) native "Utils_forwardingPrint";
98 static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFu nction"; 109 static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFu nction";
99 static int _getNewIsolateId() native "Utils_getNewIsolateId"; 110 static int _getNewIsolateId() native "Utils_getNewIsolateId";
100 111
101 // The following methods were added for debugger integration to make working 112 // The following methods were added for debugger integration to make working
102 // with the Dart C mirrors API simpler. 113 // with the Dart C mirrors API simpler.
103 // TODO(jacobr): consider moving them to a separate library. 114 // TODO(jacobr): consider moving them to a separate library.
104 // If Dart supported dynamic code injection, we would only inject this code 115 // If Dart supported dynamic code injection, we would only inject this code
105 // when the debugger is invoked. 116 // when the debugger is invoked.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // is more convenient to filter it out here than from C++ code. 165 // is more convenient to filter it out here than from C++ code.
155 // 'this' needs to be handled by calling Dart_EvaluateExpr with 166 // 'this' needs to be handled by calling Dart_EvaluateExpr with
156 // 'this' as the target rather than by passing it as an argument. 167 // 'this' as the target rather than by passing it as an argument.
157 if (arg == 'this') return; 168 if (arg == 'this') return;
158 if (args.isNotEmpty) { 169 if (args.isNotEmpty) {
159 sb.write(", "); 170 sb.write(", ");
160 } 171 }
161 sb.write("final $arg"); 172 sb.write("final $arg");
162 args[arg] = value; 173 args[arg] = value;
163 } 174 }
164 175
165 addArg("\$var", _consoleTempVariables); 176 addArg("\$var", _consoleTempVariables);
166 177
167 for (int i = 0; i < locals.length; i+= 2) { 178 for (int i = 0; i < locals.length; i+= 2) {
168 addArg(locals[i], locals[i+1]); 179 addArg(locals[i], locals[i+1]);
169 } 180 }
170 sb..write(')=>\n$expression'); 181 sb..write(')=>\n$expression');
171 return [sb.toString(), args.values.toList(growable: false)]; 182 return [sb.toString(), args.values.toList(growable: false)];
172 } 183 }
173 184
174 /** 185 /**
175 * Convenience helper to get the keys of a [Map] as a [List]. 186 * Convenience helper to get the keys of a [Map] as a [List].
176 */ 187 */
177 static List getMapKeyList(Map map) => map.keys.toList(); 188 static List getMapKeyList(Map map) => map.keys.toList();
178 189
179 /** 190 /**
180 * Returns the keys of an arbitrary Dart Map encoded as unique Strings. 191 * Returns the keys of an arbitrary Dart Map encoded as unique Strings.
181 * Keys that are strings are left unchanged except that the prefix ":" is 192 * Keys that are strings are left unchanged except that the prefix ":" is
182 * added to disambiguate keys from other Dart members. 193 * added to disambiguate keys from other Dart members.
183 * Keys that are not strings have # followed by the index of the key in the ma p 194 * Keys that are not strings have # followed by the index of the key in the ma p
184 * prepended to disambuguate. This scheme is simplistic but easy to encode and 195 * prepended to disambuguate. This scheme is simplistic but easy to encode and
185 * decode. The use case for this method is displaying all map keys in a human 196 * decode. The use case for this method is displaying all map keys in a human
186 * readable way in debugging tools. 197 * readable way in debugging tools.
187 */ 198 */
188 static List<String> getEncodedMapKeyList(dynamic obj) { 199 static List<String> getEncodedMapKeyList(dynamic obj) {
189 if (obj is! Map) return null; 200 if (obj is! Map) return null;
190 201
191 var ret = new List<String>(); 202 var ret = new List<String>();
192 int i = 0; 203 int i = 0;
193 return obj.keys.map((key) { 204 return obj.keys.map((key) {
194 var encodedKey; 205 var encodedKey;
195 if (key is String) { 206 if (key is String) {
196 encodedKey = ':$key'; 207 encodedKey = ':$key';
197 } else { 208 } else {
198 // If the key isn't a string, return a guaranteed unique for this map 209 // If the key isn't a string, return a guaranteed unique for this map
199 // string representation of the key that is still somewhat human 210 // string representation of the key that is still somewhat human
200 // readable. 211 // readable.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // DOM node rather than just a class that extends Node. 275 // DOM node rather than just a class that extends Node.
265 static bool isNode(obj) => obj is Node; 276 static bool isNode(obj) => obj is Node;
266 277
267 static bool _isBuiltinType(ClassMirror cls) { 278 static bool _isBuiltinType(ClassMirror cls) {
268 // TODO(vsm): Find a less hackish way to do this. 279 // TODO(vsm): Find a less hackish way to do this.
269 LibraryMirror lib = cls.owner; 280 LibraryMirror lib = cls.owner;
270 String libName = lib.uri.toString(); 281 String libName = lib.uri.toString();
271 return libName.startsWith('dart:'); 282 return libName.startsWith('dart:');
272 } 283 }
273 284
274 static void register(String tag, Type type) { 285 static void register(Document document, String tag, Type type,
286 String extendsTagName) {
275 // TODO(vsm): Move these checks into native code. 287 // TODO(vsm): Move these checks into native code.
276 if (type == null) {
277 throw new UnsupportedError("Invalid null type.");
278 }
279 ClassMirror cls = reflectClass(type); 288 ClassMirror cls = reflectClass(type);
280 if (_isBuiltinType(cls)) { 289 if (_isBuiltinType(cls)) {
281 throw new UnsupportedError("Invalid custom element from $libName."); 290 throw new UnsupportedError("Invalid custom element from $libName.");
282 } 291 }
283 ClassMirror superClass = cls.superclass; 292 _register(document, tag, type, extendsTagName);
284
285 Symbol objectName = reflectClass(Object).qualifiedName;
286 bool isRoot(ClassMirror cls) =>
287 cls == null || cls.qualifiedName == objectName;
288 // TODO(vsm): Support extending SvgElement as well.
289 Symbol elementName = reflectClass(HtmlElement).qualifiedName;
290 bool isElement(ClassMirror cls) =>
291 cls != null && cls.qualifiedName == elementName;
292
293 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null;
294 while(!isRoot(superClass) && !isElement(superClass)) {
295 superClass = superClass.superclass;
296 if (nativeClass == null && _isBuiltinType(superClass)) {
297 nativeClass = superClass;
298 }
299 }
300
301 if (isRoot(superClass)) {
302 throw new UnsupportedError("Invalid custom element doesn't inherit from Ht mlElement.");
303 }
304 _register(tag, type, nativeClass.reflectedType);
305 } 293 }
306 294
307 static void _register(String tag, Type customType, Type nativeType) native "Ut ils_register"; 295 static void _register(Document document, String tag, Type customType,
296 String extendsTagName) native "Utils_register";
297
298 static Element createElement(Document document, String tagName) native "Utils_ createElement";
308 } 299 }
309 300
310 class _NPObject extends NativeFieldWrapperClass1 { 301 class _NPObject extends NativeFieldWrapperClass1 {
311 _NPObject.internal(); 302 _NPObject.internal();
312 static _NPObject retrieve(String key) native "NPObject_retrieve"; 303 static _NPObject retrieve(String key) native "NPObject_retrieve";
313 property(String propertyName) native "NPObject_property"; 304 property(String propertyName) native "NPObject_property";
314 invoke(String methodName, [List args = null]) native "NPObject_invoke"; 305 invoke(String methodName, [List args = null]) native "NPObject_invoke";
315 } 306 }
316 307
317 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements 308 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 _send(msg) { 510 _send(msg) {
520 _sendToHelperIsolate(msg, _sendPort); 511 _sendToHelperIsolate(msg, _sendPort);
521 } 512 }
522 513
523 bool get isActive => _isActive; 514 bool get isActive => _isActive;
524 } 515 }
525 516
526 get _pureIsolateTimerFactoryClosure => 517 get _pureIsolateTimerFactoryClosure =>
527 ((int milliSeconds, void callback(Timer time), bool repeating) => 518 ((int milliSeconds, void callback(Timer time), bool repeating) =>
528 new _PureIsolateTimer(milliSeconds, callback, repeating)); 519 new _PureIsolateTimer(milliSeconds, callback, repeating));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698