Chromium Code Reviews| 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 void _registerCustomElement(context, document, String tag, Type type) { | 21 const _typeNameToTag = const { |
| 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 extendsTagName) { | |
| 22 // Function follows the same pattern as the following JavaScript code for | 47 // Function follows the same pattern as the following JavaScript code for |
| 23 // registering a custom element. | 48 // registering a custom element. |
| 24 // | 49 // |
| 25 // var proto = Object.create(HTMLElement.prototype, { | 50 // var proto = Object.create(HTMLElement.prototype, { |
| 26 // createdCallback: { | 51 // createdCallback: { |
| 27 // value: function() { | 52 // value: function() { |
| 28 // window.console.log('here'); | 53 // window.console.log('here'); |
| 29 // } | 54 // } |
| 30 // } | 55 // } |
| 31 // }); | 56 // }); |
| 32 // document.register('x-foo', { prototype: proto }); | 57 // document.register('x-foo', { prototype: proto }); |
| 33 // ... | 58 // ... |
| 34 // var e = document.createElement('x-foo'); | 59 // var e = document.createElement('x-foo'); |
| 35 | 60 |
| 36 var interceptorClass = findInterceptorConstructorForType(type); | 61 var interceptorClass = findInterceptorConstructorForType(type); |
| 37 if (interceptorClass == null) { | 62 if (interceptorClass == null) { |
| 38 throw new ArgumentError(type); | 63 throw new ArgumentError(type); |
| 39 } | 64 } |
| 40 | 65 |
| 66 // Workaround for 13190- use an article element to ensure that HTMLElement's | |
| 67 // interceptor is resolved correctly. | |
| 68 getNativeInterceptor(new Element.tag('article')); | |
|
Jennifer Messerly
2013/09/09 21:46:57
should this create an instance of "extendsTagName"
blois
2013/09/09 21:56:58
This is just a workaround- needs to create an inst
| |
| 69 | |
| 41 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); | 70 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); |
| 42 if (baseClassName == null) { | 71 if (baseClassName == null) { |
| 43 throw new ArgumentError(type); | 72 throw new ArgumentError(type); |
| 44 } | 73 } |
| 45 if (baseClassName == 'Element') baseClassName = 'HTMLElement'; | 74 if (baseClassName == 'Element') baseClassName = 'HTMLElement'; |
| 46 | 75 |
| 47 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); | 76 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); |
| 48 | 77 |
| 49 var properties = JS('=Object', '{}'); | 78 var properties = JS('=Object', '{}'); |
| 50 | 79 |
| 51 var jsCreatedCallback = _makeCreatedCallbackMethod(); | 80 var jsCreatedCallback = _makeCreatedCallbackMethod(); |
| 52 | 81 |
| 53 JS('void', '#.createdCallback = #', properties, | 82 JS('void', '#.createdCallback = #', properties, |
| 54 JS('=Object', '{value: #}', jsCreatedCallback)); | 83 JS('=Object', '{value: #}', jsCreatedCallback)); |
| 55 | 84 |
| 56 var baseProto = JS('=Object', '#.prototype', baseConstructor); | 85 var baseProto = JS('=Object', '#.prototype', baseConstructor); |
| 57 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); | 86 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); |
| 58 | 87 |
| 59 var interceptor = JS('=Object', '#.prototype', interceptorClass); | 88 var interceptor = JS('=Object', '#.prototype', interceptorClass); |
| 60 | 89 |
| 61 setNativeSubclassDispatchRecord(proto, interceptor); | 90 setNativeSubclassDispatchRecord(proto, interceptor); |
| 62 | 91 |
| 63 JS('void', '#.register(#, #)', | 92 var options = JS('=Object', '{prototype: #}', proto); |
| 64 document, tag, JS('', '{prototype: #}', proto)); | 93 |
| 94 if (baseClassName != 'HTMLElement') { | |
| 95 if (extendsTagName != null) { | |
| 96 JS('=Object', '#.extends = #', options, extendsTagName); | |
| 97 } else if (_typeNameToTag.containsKey(baseClassName)) { | |
| 98 JS('=Object', '#.extends = #', options, _typeNameToTag[baseClassName]); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 JS('void', '#.register(#, #)', document, tag, options); | |
| 65 } | 103 } |
| OLD | NEW |