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

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

Issue 24479002: 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
107 static window() native "Utils_window"; 96 static window() native "Utils_window";
108 static forwardingPrint(String message) native "Utils_forwardingPrint"; 97 static forwardingPrint(String message) native "Utils_forwardingPrint";
109 static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFu nction"; 98 static void spawnDomFunction(Function f, int replyTo) native "Utils_spawnDomFu nction";
110 static int _getNewIsolateId() native "Utils_getNewIsolateId"; 99 static int _getNewIsolateId() native "Utils_getNewIsolateId";
111 100
112 // The following methods were added for debugger integration to make working 101 // The following methods were added for debugger integration to make working
113 // with the Dart C mirrors API simpler. 102 // with the Dart C mirrors API simpler.
114 // TODO(jacobr): consider moving them to a separate library. 103 // TODO(jacobr): consider moving them to a separate library.
115 // If Dart supported dynamic code injection, we would only inject this code 104 // If Dart supported dynamic code injection, we would only inject this code
116 // when the debugger is invoked. 105 // when the debugger is invoked.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // is more convenient to filter it out here than from C++ code. 154 // is more convenient to filter it out here than from C++ code.
166 // 'this' needs to be handled by calling Dart_EvaluateExpr with 155 // 'this' needs to be handled by calling Dart_EvaluateExpr with
167 // 'this' as the target rather than by passing it as an argument. 156 // 'this' as the target rather than by passing it as an argument.
168 if (arg == 'this') return; 157 if (arg == 'this') return;
169 if (args.isNotEmpty) { 158 if (args.isNotEmpty) {
170 sb.write(", "); 159 sb.write(", ");
171 } 160 }
172 sb.write("final $arg"); 161 sb.write("final $arg");
173 args[arg] = value; 162 args[arg] = value;
174 } 163 }
175 164
176 addArg("\$var", _consoleTempVariables); 165 addArg("\$var", _consoleTempVariables);
177 166
178 for (int i = 0; i < locals.length; i+= 2) { 167 for (int i = 0; i < locals.length; i+= 2) {
179 addArg(locals[i], locals[i+1]); 168 addArg(locals[i], locals[i+1]);
180 } 169 }
181 sb..write(')=>\n$expression'); 170 sb..write(')=>\n$expression');
182 return [sb.toString(), args.values.toList(growable: false)]; 171 return [sb.toString(), args.values.toList(growable: false)];
183 } 172 }
184 173
185 /** 174 /**
186 * Convenience helper to get the keys of a [Map] as a [List]. 175 * Convenience helper to get the keys of a [Map] as a [List].
187 */ 176 */
188 static List getMapKeyList(Map map) => map.keys.toList(); 177 static List getMapKeyList(Map map) => map.keys.toList();
189 178
190 /** 179 /**
191 * Returns the keys of an arbitrary Dart Map encoded as unique Strings. 180 * Returns the keys of an arbitrary Dart Map encoded as unique Strings.
192 * Keys that are strings are left unchanged except that the prefix ":" is 181 * Keys that are strings are left unchanged except that the prefix ":" is
193 * added to disambiguate keys from other Dart members. 182 * added to disambiguate keys from other Dart members.
194 * Keys that are not strings have # followed by the index of the key in the ma p 183 * Keys that are not strings have # followed by the index of the key in the ma p
195 * prepended to disambuguate. This scheme is simplistic but easy to encode and 184 * prepended to disambuguate. This scheme is simplistic but easy to encode and
196 * decode. The use case for this method is displaying all map keys in a human 185 * decode. The use case for this method is displaying all map keys in a human
197 * readable way in debugging tools. 186 * readable way in debugging tools.
198 */ 187 */
199 static List<String> getEncodedMapKeyList(dynamic obj) { 188 static List<String> getEncodedMapKeyList(dynamic obj) {
200 if (obj is! Map) return null; 189 if (obj is! Map) return null;
201 190
202 var ret = new List<String>(); 191 var ret = new List<String>();
203 int i = 0; 192 int i = 0;
204 return obj.keys.map((key) { 193 return obj.keys.map((key) {
205 var encodedKey; 194 var encodedKey;
206 if (key is String) { 195 if (key is String) {
207 encodedKey = ':$key'; 196 encodedKey = ':$key';
208 } else { 197 } else {
209 // If the key isn't a string, return a guaranteed unique for this map 198 // If the key isn't a string, return a guaranteed unique for this map
210 // string representation of the key that is still somewhat human 199 // string representation of the key that is still somewhat human
211 // readable. 200 // readable.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // DOM node rather than just a class that extends Node. 264 // DOM node rather than just a class that extends Node.
276 static bool isNode(obj) => obj is Node; 265 static bool isNode(obj) => obj is Node;
277 266
278 static bool _isBuiltinType(ClassMirror cls) { 267 static bool _isBuiltinType(ClassMirror cls) {
279 // TODO(vsm): Find a less hackish way to do this. 268 // TODO(vsm): Find a less hackish way to do this.
280 LibraryMirror lib = cls.owner; 269 LibraryMirror lib = cls.owner;
281 String libName = lib.uri.toString(); 270 String libName = lib.uri.toString();
282 return libName.startsWith('dart:'); 271 return libName.startsWith('dart:');
283 } 272 }
284 273
285 static void register(Document document, String tag, Type type, 274 static void register(String tag, Type type) {
286 String extendsTagName) {
287 // TODO(vsm): Move these checks into native code. 275 // TODO(vsm): Move these checks into native code.
276 if (type == null) {
277 throw new UnsupportedError("Invalid null type.");
278 }
288 ClassMirror cls = reflectClass(type); 279 ClassMirror cls = reflectClass(type);
289 if (_isBuiltinType(cls)) { 280 if (_isBuiltinType(cls)) {
290 throw new UnsupportedError("Invalid custom element from $libName."); 281 throw new UnsupportedError("Invalid custom element from $libName.");
291 } 282 }
292 _register(document, tag, type, extendsTagName); 283 ClassMirror superClass = cls.superclass;
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);
293 } 305 }
294 306
295 static void _register(Document document, String tag, Type customType, 307 static void _register(String tag, Type customType, Type nativeType) native "Ut ils_register";
296 String extendsTagName) native "Utils_register";
297 } 308 }
298 309
299 class _NPObject extends NativeFieldWrapperClass1 { 310 class _NPObject extends NativeFieldWrapperClass1 {
300 _NPObject.internal(); 311 _NPObject.internal();
301 static _NPObject retrieve(String key) native "NPObject_retrieve"; 312 static _NPObject retrieve(String key) native "NPObject_retrieve";
302 property(String propertyName) native "NPObject_property"; 313 property(String propertyName) native "NPObject_property";
303 invoke(String methodName, [List args = null]) native "NPObject_invoke"; 314 invoke(String methodName, [List args = null]) native "NPObject_invoke";
304 } 315 }
305 316
306 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements 317 class _DOMWindowCrossFrame extends NativeFieldWrapperClass1 implements
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 _send(msg) { 519 _send(msg) {
509 _sendToHelperIsolate(msg, _sendPort); 520 _sendToHelperIsolate(msg, _sendPort);
510 } 521 }
511 522
512 bool get isActive => _isActive; 523 bool get isActive => _isActive;
513 } 524 }
514 525
515 get _pureIsolateTimerFactoryClosure => 526 get _pureIsolateTimerFactoryClosure =>
516 ((int milliSeconds, void callback(Timer time), bool repeating) => 527 ((int milliSeconds, void callback(Timer time), bool repeating) =>
517 new _PureIsolateTimer(milliSeconds, callback, repeating)); 528 new _PureIsolateTimer(milliSeconds, callback, repeating));
OLDNEW
« no previous file with comments | « tools/dom/scripts/systemnative.py ('k') | tools/dom/templates/html/impl/impl_HTMLDocument.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698