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

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

Issue 224113003: Re-apply "Adding a mechanism to 'upgrade' the Dart type of elements" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 /**
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 389
390 static String addTrailingDot(String str) => '${str}.'; 390 static String addTrailingDot(String str) => '${str}.';
391 391
392 static String demangle(String str) { 392 static String demangle(String str) {
393 var atPos = str.indexOf('@'); 393 var atPos = str.indexOf('@');
394 return atPos == -1 ? str : str.substring(0, atPos); 394 return atPos == -1 ? str : str.substring(0, atPos);
395 } 395 }
396 396
397 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError; 397 static bool isNoSuchMethodError(obj) => obj is NoSuchMethodError;
398 398
399 static bool _isBuiltinType(ClassMirror cls) {
400 // TODO(vsm): Find a less hackish way to do this.
401 LibraryMirror lib = cls.owner;
402 String libName = lib.uri.toString();
403 return libName.startsWith('dart:');
404 }
405
406 static void register(Document document, String tag, Type type, 399 static void register(Document document, String tag, Type type,
407 String extendsTagName) { 400 String extendsTagName) {
408 // TODO(vsm): Move these checks into native code. 401 var nativeClass = _validateCustomType(type);
409 ClassMirror cls = reflectClass(type);
410 if (_isBuiltinType(cls)) {
411 throw new UnsupportedError("Invalid custom element from ${(cls.owner as Li braryMirror).uri}.");
412 }
413 var className = MirrorSystem.getName(cls.simpleName);
414 var createdConstructor = cls.declarations[new Symbol('$className.created')];
415 if (createdConstructor == null ||
416 createdConstructor is! MethodMirror ||
417 !createdConstructor.isConstructor) {
418 throw new UnsupportedError(
419 'Class is missing constructor $className.created');
420 }
421 402
422 if (createdConstructor.parameters.length > 0) {
423 throw new UnsupportedError(
424 'Constructor $className.created must take zero arguments');
425 }
426
427 Symbol objectName = reflectClass(Object).qualifiedName;
428 bool isRoot(ClassMirror cls) =>
429 cls == null || cls.qualifiedName == objectName;
430 Symbol elementName = reflectClass(HtmlElement).qualifiedName;
431 bool isElement(ClassMirror cls) =>
432 cls != null && cls.qualifiedName == elementName;
433 ClassMirror superClass = cls.superclass;
434 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null;
435 while(!isRoot(superClass) && !isElement(superClass)) {
436 superClass = superClass.superclass;
437 if (nativeClass == null && _isBuiltinType(superClass)) {
438 nativeClass = superClass;
439 }
440 }
441 if (extendsTagName == null) { 403 if (extendsTagName == null) {
442 if (nativeClass.reflectedType != HtmlElement) { 404 if (nativeClass.reflectedType != HtmlElement) {
443 throw new UnsupportedError('Class must provide extendsTag if base ' 405 throw new UnsupportedError('Class must provide extendsTag if base '
444 'native class is not HTMLElement'); 406 'native class is not HTMLElement');
445 } 407 }
446 } 408 }
447 409
448 _register(document, tag, type, extendsTagName); 410 _register(document, tag, type, extendsTagName);
449 } 411 }
450 412
451 static void _register(Document document, String tag, Type customType, 413 static void _register(Document document, String tag, Type customType,
452 String extendsTagName) native "Utils_register"; 414 String extendsTagName) native "Utils_register";
453 415
454 static Element createElement(Document document, String tagName) native "Utils_ createElement"; 416 static Element createElement(Document document, String tagName) native "Utils_ createElement";
455 417
456 static void initializeCustomElement(HtmlElement element) native "Utils_initial izeCustomElement"; 418 static void initializeCustomElement(HtmlElement element) native "Utils_initial izeCustomElement";
419
420 static void changeElementWrapper(HtmlElement element, Type type) native "Utils _changeElementWrapper";
457 } 421 }
458 422
459 class _DOMWindowCrossFrame extends NativeFieldWrapperClass2 implements 423 class _DOMWindowCrossFrame extends NativeFieldWrapperClass2 implements
460 WindowBase { 424 WindowBase {
461 _DOMWindowCrossFrame.internal(); 425 _DOMWindowCrossFrame.internal();
462 426
463 // Fields. 427 // Fields.
464 HistoryBase get history native "Window_history_cross_frame_Getter"; 428 HistoryBase get history native "Window_history_cross_frame_Getter";
465 LocationBase get location native "Window_location_cross_frame_Getter"; 429 LocationBase get location native "Window_location_cross_frame_Getter";
466 bool get closed native "Window_closed_Getter"; 430 bool get closed native "Window_closed_Getter";
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 _scheduleImmediateHelper._schedule(callback); 596 _scheduleImmediateHelper._schedule(callback);
633 }; 597 };
634 598
635 get _pureIsolateScheduleImmediateClosure => ((void callback()) => 599 get _pureIsolateScheduleImmediateClosure => ((void callback()) =>
636 throw new UnimplementedError("scheduleMicrotask in background isolates " 600 throw new UnimplementedError("scheduleMicrotask in background isolates "
637 "are not supported in the browser")); 601 "are not supported in the browser"));
638 602
639 void _initializeCustomElement(Element e) { 603 void _initializeCustomElement(Element e) {
640 _Utils.initializeCustomElement(e); 604 _Utils.initializeCustomElement(e);
641 } 605 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698