| Index: tools/dom/src/dart2js_CustomElementSupport.dart
|
| diff --git a/tools/dom/src/dart2js_CustomElementSupport.dart b/tools/dom/src/dart2js_CustomElementSupport.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a40e81c69a13e304bc5c7d0a0936275308781c3a
|
| --- /dev/null
|
| +++ b/tools/dom/src/dart2js_CustomElementSupport.dart
|
| @@ -0,0 +1,68 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +part of dart.dom.html;
|
| +
|
| +_callOnCreated(receiver) {
|
| + return receiver.onCreated();
|
| +}
|
| +
|
| +_makeCreatedCallbackMethod() {
|
| + return JS('',
|
| + '''((function(invokeCallback) {
|
| + return function() {
|
| + return invokeCallback(this);
|
| + };
|
| + })(#))''',
|
| + convertDartClosureToJS(_callOnCreated, 1));
|
| +}
|
| +
|
| +void _registerCustomElement(context, document, String tag, Type type) {
|
| + // Function follows the same pattern as the following JavaScript code for
|
| + // registering a custom element.
|
| + //
|
| + // var proto = Object.create(HTMLElement.prototype, {
|
| + // createdCallback: {
|
| + // value: function() {
|
| + // window.console.log('here');
|
| + // }
|
| + // }
|
| + // });
|
| + // document.register('x-foo', { prototype: proto });
|
| + // ...
|
| + // var e = document.createElement('x-foo');
|
| +
|
| + var interceptorClass = findInterceptorConstructorForType(type);
|
| + if (interceptorClass == null) {
|
| + throw new ArgumentError(type);
|
| + }
|
| +
|
| + String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
|
| + if (baseClassName == null) {
|
| + throw new ArgumentError(type);
|
| + }
|
| + if (baseClassName == 'Element') baseClassName = 'HTMLElement';
|
| +
|
| + var baseConstructor = JS('=Object', '#[#]', context, baseClassName);
|
| + if (JS('bool', "typeof(#) != 'function'", baseConstructor)) {
|
| + throw new ArgumentError(type);
|
| + }
|
| +
|
| + var properties = JS('=Object', '{}');
|
| +
|
| + var jsCreatedCallback = _makeCreatedCallbackMethod();
|
| +
|
| + JS('void', '#.createdCallback = #', properties,
|
| + JS('=Object', '{value: #}', jsCreatedCallback));
|
| +
|
| + var baseProto = JS('=Object', '#.prototype', baseConstructor);
|
| + var proto = JS('=Object', 'Object.create(#, #)', baseProto, properties);
|
| +
|
| + var interceptor = JS('=Object', '#.prototype', interceptorClass);
|
| +
|
| + setNativeSubclassDispatchRecord(proto, interceptor);
|
| +
|
| + JS('void', '#.register(#, #)',
|
| + document, tag, JS('', '{prototype: #}', proto));
|
| +}
|
|
|