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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Side-by-side diff isn't available for this file because of its large size.
Issue 23442011: Revert "Revert "Basic functionality is working with JS native support and polyfill, still some issu… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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:
Download patch
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index b1fdab9d5c6b52008c8529e4bb2c88958f480150..d1c969d3da01e4d6c23aea16f69746b645c45948 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -12,7 +12,7 @@
*
* * If you've never written a web app before, try our
* tutorials—[A Game of Darts](http://dartlang.org/docs/tutorials).
- *
+ *
* * To see some web-based Dart apps in action and to play with the code,
* download
* [Dart Editor](http://www.dartlang.org/#get-started)
@@ -54,7 +54,8 @@ import 'dart:_js_helper' show
JSName, Null, Returns,
findDispatchTagForInterceptorClass, setNativeSubclassDispatchRecord;
import 'dart:_interceptors' show
- Interceptor, JSExtendableArray, findInterceptorConstructorForType;
+ Interceptor, JSExtendableArray, findInterceptorConstructorForType,
+ getNativeInterceptor;
@@ -8819,8 +8820,8 @@ abstract class Element extends Node implements ParentNode, ChildNode native "Ele
*
* * [isTagSupported]
*/
- factory Element.tag(String tag) =>
- _ElementFactoryProvider.createElement_tag(tag);
+ factory Element.tag(String tag, [String typeExtention]) =>
+ _ElementFactoryProvider.createElement_tag(tag, typeExtention);
/// Creates a new `<a>` element.
///
@@ -9137,7 +9138,7 @@ abstract class Element extends Node implements ParentNode, ChildNode native "Ele
* The tag should be a valid HTML tag name.
*/
static bool isTagSupported(String tag) {
- var e = _ElementFactoryProvider.createElement_tag(tag);
+ var e = _ElementFactoryProvider.createElement_tag(tag, null);
return e is Element && !(e is UnknownElement);
}
@@ -10591,9 +10592,19 @@ class _ElementFactoryProvider {
@DomName('Document.createElement')
// Optimization to improve performance until the dart2js compiler inlines this
// method.
- static dynamic createElement_tag(String tag) =>
- // Firefox may return a JS function for some types (Embed, Object).
- JS('Element|=Object', 'document.createElement(#)', tag);
+ static dynamic createElement_tag(String tag, String typeExtension) {
+ // Firefox may return a JS function for some types (Embed, Object).
+ if (typeExtension != null) {
+ return JS('Element|=Object', 'document.createElement(#, #)',
+ tag, typeExtension);
+ }
+ // Should be able to eliminate this and just call the two-arg version above
+ // with null typeExtension, but Chrome treats the tag as case-sensitive if
+ // typeExtension is null.
+ // https://code.google.com/p/chromium/issues/detail?id=282467
+ return JS('Element|=Object', 'document.createElement(#)', tag);
+ }
+
}
@@ -12737,8 +12748,76 @@ class HtmlDocument extends Document native "HTMLDocument" {
'#.webkitVisibilityState)', this, this, this, this);
@Experimental
- void register(String tag, Type customElementClass) {
- _registerCustomElement(JS('', 'window'), this, tag, customElementClass);
+ /**
+ * Register a custom subclass of Element to be instantiatable by the DOM.
+ *
+ * This is necessary to allow the construction of any custom elements.
+ *
+ * The class being registered must either subclass HtmlElement or SvgElement.
+ * If they subclass these directly then they can be used as:
+ *
+ * class FooElement extends HtmlElement{
+ * void created() {
+ * print('FooElement created!');
+ * }
+ * }
+ *
+ * main() {
+ * document.register('x-foo', FooElement);
+ * var myFoo = new Element.tag('x-foo');
+ * // prints 'FooElement created!' to the console.
+ * }
+ *
+ * The custom element can also be instantiated via HTML using the syntax
+ * `<x-foo></x-foo>`
+ *
+ * Other elements can be subclassed as well:
+ *
+ * class BarElement extends InputElement{
+ * void created() {
+ * print('BarElement created!');
+ * }
+ * }
+ *
+ * main() {
+ * document.register('x-bar', BarElement);
+ * var myBar = new Element.tag('input', 'x-bar');
+ * // prints 'BarElement created!' to the console.
+ * }
+ *
+ * This custom element can also be instantiated via HTML using the syntax
+ * `<input is="x-bar"></input>`
+ *
+ * The [nativeTagName] parameter is needed by platforms without native support
+ * when subclassing a native type other than:
+ *
+ * * HtmlElement
+ * * SvgElement
+ * * AnchorElement
+ * * AudioElement
+ * * ButtonElement
+ * * CanvasElement
+ * * DivElement
+ * * ImageElement
+ * * InputElement
+ * * LIElement
+ * * LabelElement
+ * * MenuElement
+ * * MeterElement
+ * * OListElement
+ * * OptionElement
+ * * OutputElement
+ * * ParagraphElement
+ * * PreElement
+ * * ProgressElement
+ * * SelectElement
+ * * SpanElement
+ * * UListElement
+ * * VideoElement
+ */
+ void register(String tag, Type customElementClass, {String nativeTagName}) {
+ _registerCustomElement(JS('', 'window'), this, tag, customElementClass,
+ nativeTagName);
}
@Creates('Null') // Set from Dart code; does not instantiate a native type.
@@ -31969,7 +32048,32 @@ _makeCreatedCallbackMethod() {
convertDartClosureToJS(_callCreated, 1));
}
-void _registerCustomElement(context, document, String tag, Type type) {
+const _typeNameToTag = const {
+ 'HTMLAnchorElement': 'a',
+ 'HTMLAudioElement': 'audio',
+ 'HTMLButtonElement': 'button',
+ 'HTMLCanvasElement': 'canvas',
+ 'HTMLDivElement': 'div',
+ 'HTMLImageElement': 'img',
+ 'HTMLInputElement': 'input',
+ 'HTMLLIElement': 'li',
+ 'HTMLLabelElement': 'label',
+ 'HTMLMenuElement': 'menu',
+ 'HTMLMeterElement': 'meter',
+ 'HTMLOListElement': 'ol',
+ 'HTMLOptionElement': 'option',
+ 'HTMLOutputElement': 'output',
+ 'HTMLParagraphElement': 'p',
+ 'HTMLPreElement': 'pre',
+ 'HTMLProgressElement': 'progress',
+ 'HTMLSelectElement': 'select',
+ 'HTMLSpanElement': 'span',
+ 'HTMLUListElement': 'ul',
+ 'HTMLVideoElement': 'video',
+};
+
+void _registerCustomElement(context, document, String tag, Type type,
+ String extendsTagName) {
// Function follows the same pattern as the following JavaScript code for
// registering a custom element.
//
@@ -31989,6 +32093,10 @@ void _registerCustomElement(context, document, String tag, Type type) {
throw new ArgumentError(type);
}
+ // Workaround for 13190- use an article element to ensure that HTMLElement's
+ // interceptor is resolved correctly.
+ getNativeInterceptor(new Element.tag('article'));
+
String baseClassName = findDispatchTagForInterceptorClass(interceptorClass);
if (baseClassName == null) {
throw new ArgumentError(type);
@@ -32011,8 +32119,17 @@ void _registerCustomElement(context, document, String tag, Type type) {
setNativeSubclassDispatchRecord(proto, interceptor);
- JS('void', '#.register(#, #)',
- document, tag, JS('', '{prototype: #}', proto));
+ var options = JS('=Object', '{prototype: #}', proto);
+
+ if (baseClassName != 'HTMLElement') {
+ if (extendsTagName != null) {
+ JS('=Object', '#.extends = #', options, extendsTagName);
+ } else if (_typeNameToTag.containsKey(baseClassName)) {
+ JS('=Object', '#.extends = #', options, _typeNameToTag[baseClassName]);
+ }
+ }
+
+ JS('void', '#.register(#, #)', document, tag, options);
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a

Powered by Google App Engine
This is Rietveld 408576698