| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 _callCreated(receiver) { | 7 _callCreated(receiver) { |
| 8 return receiver.created(); | 8 return receiver.created(); |
| 9 } | 9 } |
| 10 | 10 |
| 11 _makeCreatedCallbackMethod() { | 11 _makeCreatedCallbackMethod() { |
| 12 return JS('', | 12 return JS('', |
| 13 '''((function(invokeCallback) { | 13 '''((function(invokeCallback) { |
| 14 return function() { | 14 return function() { |
| 15 return invokeCallback(this); | 15 return invokeCallback(this); |
| 16 }; | 16 }; |
| 17 })(#))''', | 17 })(#))''', |
| 18 convertDartClosureToJS(_callCreated, 1)); | 18 convertDartClosureToJS(_callCreated, 1)); |
| 19 } | 19 } |
| 20 | 20 |
| 21 const _typeNameToTag = const { | 21 void _registerCustomElement(context, document, String tag, Type type) { |
| 22 'HTMLAnchorElement': 'a', | |
| 23 'HTMLAudioElement': 'audio', | |
| 24 'HTMLButtonElement': 'button', | |
| 25 'HTMLCanvasElement': 'canvas', | |
| 26 'HTMLDivElement': 'div', | |
| 27 'HTMLImageElement': 'img', | |
| 28 'HTMLInputElement': 'input', | |
| 29 'HTMLLIElement': 'li', | |
| 30 'HTMLLabelElement': 'label', | |
| 31 'HTMLMenuElement': 'menu', | |
| 32 'HTMLMeterElement': 'meter', | |
| 33 'HTMLOListElement': 'ol', | |
| 34 'HTMLOptionElement': 'option', | |
| 35 'HTMLOutputElement': 'output', | |
| 36 'HTMLParagraphElement': 'p', | |
| 37 'HTMLPreElement': 'pre', | |
| 38 'HTMLProgressElement': 'progress', | |
| 39 'HTMLSelectElement': 'select', | |
| 40 'HTMLSpanElement': 'span', | |
| 41 'HTMLUListElement': 'ul', | |
| 42 'HTMLVideoElement': 'video', | |
| 43 }; | |
| 44 | |
| 45 void _registerCustomElement(context, document, String tag, Type type, | |
| 46 String nativeTagName) { | |
| 47 // Function follows the same pattern as the following JavaScript code for | 22 // Function follows the same pattern as the following JavaScript code for |
| 48 // registering a custom element. | 23 // registering a custom element. |
| 49 // | 24 // |
| 50 // var proto = Object.create(HTMLElement.prototype, { | 25 // var proto = Object.create(HTMLElement.prototype, { |
| 51 // createdCallback: { | 26 // createdCallback: { |
| 52 // value: function() { | 27 // value: function() { |
| 53 // window.console.log('here'); | 28 // window.console.log('here'); |
| 54 // } | 29 // } |
| 55 // } | 30 // } |
| 56 // }); | 31 // }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 78 JS('void', '#.createdCallback = #', properties, | 53 JS('void', '#.createdCallback = #', properties, |
| 79 JS('=Object', '{value: #}', jsCreatedCallback)); | 54 JS('=Object', '{value: #}', jsCreatedCallback)); |
| 80 | 55 |
| 81 var baseProto = JS('=Object', '#.prototype', baseConstructor); | 56 var baseProto = JS('=Object', '#.prototype', baseConstructor); |
| 82 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); | 57 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); |
| 83 | 58 |
| 84 var interceptor = JS('=Object', '#.prototype', interceptorClass); | 59 var interceptor = JS('=Object', '#.prototype', interceptorClass); |
| 85 | 60 |
| 86 setNativeSubclassDispatchRecord(proto, interceptor); | 61 setNativeSubclassDispatchRecord(proto, interceptor); |
| 87 | 62 |
| 88 var options = JS('=Object', '{prototype: #}', proto); | 63 JS('void', '#.register(#, #)', |
| 89 | 64 document, tag, JS('', '{prototype: #}', proto)); |
| 90 if (baseClassName != 'HTMLElement') { | |
| 91 if (nativeTagName != null) { | |
| 92 JS('=Object', '#.extends = #', options, nativeTagName); | |
| 93 } else if (_typeNameToTag.containsKey(baseClassName)) { | |
| 94 JS('=Object', '#.extends = #', options, _typeNameToTag[baseClassName]); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 JS('void', '#.register(#, #)', document, tag, options); | |
| 99 } | 65 } |
| OLD | NEW |