OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 dart.dom.html; | 5 part of dart.dom.html; |
6 | 6 |
7 /// Dartium ElementUpgrader implementation. | 7 /// Dartium ElementUpgrader implementation. |
8 class _VMElementUpgrader implements ElementUpgrader { | 8 class _VMElementUpgrader implements ElementUpgrader { |
9 final Type _type; | 9 final Type _type; |
10 final Type _nativeType; | 10 final Type _nativeType; |
11 final String _extendsTag; | 11 final String _extendsTag; |
12 | 12 |
13 _VMElementUpgrader(Document document, Type type, String extendsTag) : | 13 _VMElementUpgrader(Document document, Type type, String extendsTag) |
14 _type = type, | 14 : _type = type, |
15 _extendsTag = extendsTag, | 15 _extendsTag = extendsTag, |
16 _nativeType = _validateCustomType(type).reflectedType { | 16 _nativeType = _validateCustomType(type).reflectedType { |
17 | |
18 if (extendsTag == null) { | 17 if (extendsTag == null) { |
19 if (_nativeType != HtmlElement) { | 18 if (_nativeType != HtmlElement) { |
20 throw new UnsupportedError('Class must provide extendsTag if base ' | 19 throw new UnsupportedError('Class must provide extendsTag if base ' |
21 'native class is not HtmlElement'); | 20 'native class is not HtmlElement'); |
22 } | 21 } |
23 } else { | 22 } else { |
24 if (document.createElement(extendsTag).runtimeType != _nativeType) { | 23 if (document.createElement(extendsTag).runtimeType != _nativeType) { |
25 throw new UnsupportedError( | 24 throw new UnsupportedError( |
26 'extendsTag does not match base native class'); | 25 'extendsTag does not match base native class'); |
27 } | 26 } |
28 } | 27 } |
29 } | 28 } |
30 | 29 |
31 Element upgrade(element) { | 30 Element upgrade(element) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 70 } |
72 | 71 |
73 Symbol objectName = reflectClass(Object).qualifiedName; | 72 Symbol objectName = reflectClass(Object).qualifiedName; |
74 bool isRoot(ClassMirror cls) => | 73 bool isRoot(ClassMirror cls) => |
75 cls == null || cls.qualifiedName == objectName; | 74 cls == null || cls.qualifiedName == objectName; |
76 Symbol elementName = reflectClass(HtmlElement).qualifiedName; | 75 Symbol elementName = reflectClass(HtmlElement).qualifiedName; |
77 bool isElement(ClassMirror cls) => | 76 bool isElement(ClassMirror cls) => |
78 cls != null && cls.qualifiedName == elementName; | 77 cls != null && cls.qualifiedName == elementName; |
79 ClassMirror superClass = cls.superclass; | 78 ClassMirror superClass = cls.superclass; |
80 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null; | 79 ClassMirror nativeClass = _isBuiltinType(superClass) ? superClass : null; |
81 while(!isRoot(superClass) && !isElement(superClass)) { | 80 while (!isRoot(superClass) && !isElement(superClass)) { |
82 superClass = superClass.superclass; | 81 superClass = superClass.superclass; |
83 if (nativeClass == null && _isBuiltinType(superClass)) { | 82 if (nativeClass == null && _isBuiltinType(superClass)) { |
84 nativeClass = superClass; | 83 nativeClass = superClass; |
85 } | 84 } |
86 } | 85 } |
87 return nativeClass; | 86 return nativeClass; |
88 } | 87 } |
89 | 88 |
90 | |
91 bool _isBuiltinType(ClassMirror cls) { | 89 bool _isBuiltinType(ClassMirror cls) { |
92 // TODO(vsm): Find a less hackish way to do this. | 90 // TODO(vsm): Find a less hackish way to do this. |
93 LibraryMirror lib = cls.owner; | 91 LibraryMirror lib = cls.owner; |
94 String libName = lib.uri.toString(); | 92 String libName = lib.uri.toString(); |
95 return libName.startsWith('dart:'); | 93 return libName.startsWith('dart:'); |
96 } | 94 } |
OLD | NEW |