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

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

Issue 23498053: Revert "Revert "Dart2js support for custom element lifecycle events"" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
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 _callEnteredView(receiver) {
12 return receiver.enteredView();
13 }
14
15 _callLeftView(receiver) {
16 return receiver.leftView();
17 }
18
19 _makeCallbackMethod(callback) {
12 return JS('', 20 return JS('',
13 '''((function(invokeCallback) { 21 '''((function(invokeCallback) {
14 return function() { 22 return function() {
15 return invokeCallback(this); 23 return invokeCallback(this);
16 }; 24 };
17 })(#))''', 25 })(#))''',
18 convertDartClosureToJS(_callCreated, 1)); 26 convertDartClosureToJS(callback, 1));
19 } 27 }
20 28
21 const _typeNameToTag = const { 29 const _typeNameToTag = const {
22 'HTMLAnchorElement': 'a', 30 'HTMLAnchorElement': 'a',
23 'HTMLAudioElement': 'audio', 31 'HTMLAudioElement': 'audio',
24 'HTMLButtonElement': 'button', 32 'HTMLButtonElement': 'button',
25 'HTMLCanvasElement': 'canvas', 33 'HTMLCanvasElement': 'canvas',
26 'HTMLDivElement': 'div', 34 'HTMLDivElement': 'div',
27 'HTMLImageElement': 'img', 35 'HTMLImageElement': 'img',
28 'HTMLInputElement': 'input', 36 'HTMLInputElement': 'input',
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass); 78 String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
71 if (baseClassName == null) { 79 if (baseClassName == null) {
72 throw new ArgumentError(type); 80 throw new ArgumentError(type);
73 } 81 }
74 if (baseClassName == 'Element') baseClassName = 'HTMLElement'; 82 if (baseClassName == 'Element') baseClassName = 'HTMLElement';
75 83
76 var baseConstructor = JS('=Object', '#[#]', context, baseClassName); 84 var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
77 85
78 var properties = JS('=Object', '{}'); 86 var properties = JS('=Object', '{}');
79 87
80 var jsCreatedCallback = _makeCreatedCallbackMethod(); 88 JS('void', '#.createdCallback = #', properties,
89 JS('=Object', '{value: #}', _makeCallbackMethod(_callCreated)));
90 JS('void', '#.enteredViewCallback = #', properties,
91 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView)));
92 JS('void', '#.leftViewCallback = #', properties,
93 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView)));
81 94
82 JS('void', '#.createdCallback = #', properties, 95 // TODO(blois): Bug 13220- remove once transition is complete
83 JS('=Object', '{value: #}', jsCreatedCallback)); 96 JS('void', '#.enteredDocumentCallback = #', properties,
97 JS('=Object', '{value: #}', _makeCallbackMethod(_callEnteredView)));
98 JS('void', '#.leftDocumentCallback = #', properties,
99 JS('=Object', '{value: #}', _makeCallbackMethod(_callLeftView)));
84 100
85 var baseProto = JS('=Object', '#.prototype', baseConstructor); 101 var baseProto = JS('=Object', '#.prototype', baseConstructor);
86 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties); 102 var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties);
87 103
88 var interceptor = JS('=Object', '#.prototype', interceptorClass); 104 var interceptor = JS('=Object', '#.prototype', interceptorClass);
89 105
90 setNativeSubclassDispatchRecord(proto, interceptor); 106 setNativeSubclassDispatchRecord(proto, interceptor);
91 107
92 var options = JS('=Object', '{prototype: #}', proto); 108 var options = JS('=Object', '{prototype: #}', proto);
93 109
94 if (baseClassName != 'HTMLElement') { 110 if (baseClassName != 'HTMLElement') {
95 if (extendsTagName != null) { 111 if (extendsTagName != null) {
96 JS('=Object', '#.extends = #', options, extendsTagName); 112 JS('=Object', '#.extends = #', options, extendsTagName);
97 } else if (_typeNameToTag.containsKey(baseClassName)) { 113 } else if (_typeNameToTag.containsKey(baseClassName)) {
98 JS('=Object', '#.extends = #', options, _typeNameToTag[baseClassName]); 114 JS('=Object', '#.extends = #', options, _typeNameToTag[baseClassName]);
99 } 115 }
100 } 116 }
101 117
102 JS('void', '#.register(#, #)', document, tag, options); 118 JS('void', '#.register(#, #)', document, tag, options);
103 } 119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698