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

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

Issue 1400843002: Added Alan's CL 1398603003 and augmented with upgrade for HtmlElement and HTMLElement (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
OLDNEW
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 11
12 _VMElementUpgrader(Document document, Type type, String extendsTag) : 12 _VMElementUpgrader(Document document, Type type, String extendsTag) :
13 _type = type, 13 _type = type,
14 _nativeType = _validateCustomType(type).reflectedType { 14 _nativeType = _validateCustomType(type).reflectedType {
15 15
16 if (extendsTag == null) { 16 if (extendsTag == null) {
17 if (_nativeType != HtmlElement) { 17 if (_nativeType != HtmlElement) {
18 throw new UnsupportedError('Class must provide extendsTag if base ' 18 throw new UnsupportedError('Class must provide extendsTag if base '
19 'native class is not HtmlElement'); 19 'native class is not HtmlElement');
20 } 20 }
21 } else { 21 } else {
22 if (document.createElement(extendsTag).runtimeType != _nativeType) { 22 if (document.createElement(extendsTag).runtimeType != _nativeType) {
23 throw new UnsupportedError( 23 throw new UnsupportedError(
24 'extendsTag does not match base native class'); 24 'extendsTag does not match base native class');
25 } 25 }
26 } 26 }
27 } 27 }
28 28
29 Element upgrade(element) { 29 Element upgrade(element) {
30 if (element.runtimeType != js.JsObjectImpl) { 30 var jsObject;
31 throw new UnsupportedError('Element is incorrect type'); 31 var tag;
32 if (element.runtimeType == HtmlElement) {
33 jsObject = unwrap_jso(element);
34 tag = element.localName;
35 } else if (element.runtimeType == js.JsObjectImpl) {
36 // It's a Polymer core element (written in JS).
37 jsObject = element;
38 tag = element['localName'];
39 } else {
40 throw new UnsupportedError('Element is incorrect type. Got ${element.runti meType}, expected HtmlElement/JsObjectImpl.');
32 } 41 }
33 42
34 // Remember Dart class to tagName for any upgrading done in wrap_jso. 43 // Remember Dart class to tagName for any upgrading done in wrap_jso.
35 var tag = element['localName'];
36 _knownCustomeElements[tag] = _type; 44 _knownCustomeElements[tag] = _type;
37 45
38 return createCustomUpgrader(_nativeType, element); 46 return createCustomUpgrader(_nativeType, jsObject);
39 } 47 }
40 } 48 }
41 49
42 /// Validates that the custom type is properly formed- 50 /// Validates that the custom type is properly formed-
43 /// 51 ///
44 /// * Is a user-defined class. 52 /// * Is a user-defined class.
45 /// * Has a created constructor with zero args. 53 /// * Has a created constructor with zero args.
46 /// * Derives from an Element subclass. 54 /// * Derives from an Element subclass.
47 /// 55 ///
48 /// Then returns the native base class. 56 /// Then returns the native base class.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return nativeClass; 97 return nativeClass;
90 } 98 }
91 99
92 100
93 bool _isBuiltinType(ClassMirror cls) { 101 bool _isBuiltinType(ClassMirror cls) {
94 // TODO(vsm): Find a less hackish way to do this. 102 // TODO(vsm): Find a less hackish way to do this.
95 LibraryMirror lib = cls.owner; 103 LibraryMirror lib = cls.owner;
96 String libName = lib.uri.toString(); 104 String libName = lib.uri.toString();
97 return libName.startsWith('dart:'); 105 return libName.startsWith('dart:');
98 } 106 }
OLDNEW
« no previous file with comments | « tools/deps/dartium.deps/DEPS ('k') | tools/dom/templates/html/dartium/html_dartium.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698