| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // WARNING: Do not edit - generated code. | 5 // WARNING: Do not edit - generated code. |
| 6 | 6 |
| 7 part of $LIBRARYNAME; | 7 part of $LIBRARYNAME; |
| 8 | 8 |
| 9 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | 9 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ |
| 10 $!MEMBERS | 10 $!MEMBERS |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // | 406 // |
| 407 // var myProto = Object.create(HTMLElement.prototype); | 407 // var myProto = Object.create(HTMLElement.prototype); |
| 408 // var myElement = document.registerElement('x-foo', {prototype: myPro
to}); | 408 // var myElement = document.registerElement('x-foo', {prototype: myPro
to}); |
| 409 var baseElement = js.JsNative.getProperty(js.context, jsClassName); | 409 var baseElement = js.JsNative.getProperty(js.context, jsClassName); |
| 410 if (baseElement == null) { | 410 if (baseElement == null) { |
| 411 // Couldn't find the HTML element so use a generic one. | 411 // Couldn't find the HTML element so use a generic one. |
| 412 baseElement = js.JsNative.getProperty(js.context, 'HTMLElement'); | 412 baseElement = js.JsNative.getProperty(js.context, 'HTMLElement'); |
| 413 } | 413 } |
| 414 var elemProto = js.JsNative.callMethod(js.JsNative.getProperty(js.context,
'Object'), "create", [js.JsNative.getProperty(baseElement, 'prototype')]); | 414 var elemProto = js.JsNative.callMethod(js.JsNative.getProperty(js.context,
'Object'), "create", [js.JsNative.getProperty(baseElement, 'prototype')]); |
| 415 | 415 |
| 416 // Remember for any upgrading done in wrap_jso. | |
| 417 addCustomElementType(tag, customElementClass, extendsTag); | 416 addCustomElementType(tag, customElementClass, extendsTag); |
| 418 | 417 |
| 419 // TODO(terry): Hack to stop recursion re-creating custom element when the | 418 // TODO(terry): Hack to stop recursion re-creating custom element when the |
| 420 // created() constructor of the custom element does e.g., | 419 // created() constructor of the custom element does e.g., |
| 421 // | 420 // |
| 422 // MyElement.created() : super.created() { | 421 // MyElement.created() : super.created() { |
| 423 // this.innerHtml = "<b>I'm an x-foo-with-markup!</b>"; | 422 // this.innerHtml = "<b>I'm an x-foo-with-markup!</b>"; |
| 424 // } | 423 // } |
| 425 // | 424 // |
| 426 // sanitizing causes custom element to created recursively | 425 // sanitizing causes custom element to created recursively |
| 427 // until stack overflow. | 426 // until stack overflow. |
| 428 // | 427 // |
| 429 // See https://github.com/dart-lang/sdk/issues/23666 | 428 // See https://github.com/dart-lang/sdk/issues/23666 |
| 430 int creating = 0; | 429 int creating = 0; |
| 431 | 430 |
| 432 // If any JS code is hooked we want to call it too. | 431 // If any JS code is hooked we want to call it too. |
| 433 var oldCreatedCallback = elemProto['createdCallback']; | 432 var oldCreatedCallback = js.JsNative.getProperty(elemProto, 'createdCallba
ck'); |
| 434 var oldAttributeChangedCallback = elemProto['attributeChangedCallback']; | 433 var oldAttributeChangedCallback = js.JsNative.getProperty(elemProto, 'attr
ibuteChangedCallback'); |
| 435 var oldAttachedCallback = elemProto['attachedCallback']; | 434 var oldAttachedCallback = js.JsNative.getProperty(elemProto, 'attachedCall
back'); |
| 436 var oldDetachedCallback = elemProto['detachedCallback']; | 435 var oldDetachedCallback = js.JsNative.getProperty(elemProto, 'detachedCall
back'); |
| 437 | 436 |
| 438 // TODO(jacobr): warning: | 437 // TODO(jacobr): this code seems far more complex than it should be |
| 439 elemProto['createdCallback'] = js.JsNative.withThis(($this) { | 438 // unless I am missing something. |
| 439 js.JsNative.setProperty(elemProto, 'createdCallback', js.allowInteropCaptu
reThis(($this) { |
| 440 if (_getJSClassName(reflectClass(customElementClass).superclass) != null
&& creating < 2) { | 440 if (_getJSClassName(reflectClass(customElementClass).superclass) != null
&& creating < 2) { |
| 441 creating++; | 441 creating++; |
| 442 | 442 |
| 443 var dartClass; | 443 var dartClass; |
| 444 try { | 444 try { |
| 445 if (extendsTag != null) { | 445 if (extendsTag != null) { |
| 446 // If we're extending a native element then create that element. | 446 // If we're extending a native element then create that element. |
| 447 // Then upgrade that element to the customElementClass through | 447 // Then upgrade that element to the customElementClass through |
| 448 // normal flow. | 448 // normal flow. |
| 449 dartClass = document.createElement(extendsTag); | 449 dartClass = document.createElement(extendsTag); |
| 450 js.setDartHtmlWrapperFor($this, dartClass); | 450 // TODO(jacobr): THIS MAKES NO SENSE. WAAT? |
| 451 dartClass.blink_jsObject = $this; | 451 |
| 452 $this = js.JsNative.$setInstanceInterceptor($this, dartClass.runti
meType); |
| 453 dartClass = $this; // THIS IS CRAZY CODE CODE BUT IT MATCHES WHAT
HAD. WTH.. THIS CODE JUST SEEMS WRONG. |
| 452 } | 454 } |
| 453 | 455 |
| 454 // Upgrade to the CustomElement Dart class. | 456 // Upgrade to the CustomElement Dart class. |
| 455 dartClass = _blink.Blink_Utils.constructElement(customElementClass,
$this); | 457 dartClass = _blink.Blink_Utils.constructElement(customElementClass,
$this); |
| 456 } catch (e) { | 458 } catch (e) { |
| 457 // Got a problem make it an HtmlElement and rethrow the error. | 459 // Got a problem make it an HtmlElement and rethrow the error. |
| 458 dartClass = HtmlElement.internalCreateHtmlElement(); | 460 dartClass = js.JsNative.$setInstanceInterceptor($this, new HtmlEleme
nt.internalCreateHtmlElement().runtimeType); |
| 459 // We need to remember the JS object (because constructElement faile
d | |
| 460 // it normally sets up the blink_jsObject. | |
| 461 dartClass.blink_jsObject = $this; | |
| 462 | 461 |
| 463 // Mark to only try this once don't try upgrading from HtmlElement | 462 // Mark to only try this once don't try upgrading from HtmlElement |
| 464 // to the user's Dart class - we had a problem. | 463 // to the user's Dart class - we had a problem. |
| 465 dartClass._badUpgrade(); | 464 dartClass._badUpgrade(); |
| 466 throw e; | 465 throw e; |
| 467 } finally { | 466 } finally { |
| 468 // Need to remember the Dart class that was created for this custom
so | 467 // Need to remember the Dart class that was created for this custom
so |
| 469 // return it and setup the blink_jsObject to the $this that we'll be
working | 468 // return it and setup the blink_jsObject to the $this that we'll be
working |
| 470 // with as we talk to blink. | 469 // with as we talk to blink. |
| 471 js.setDartHtmlWrapperFor($this, dartClass); | 470 js.setDartHtmlWrapperFor($this, dartClass); |
| 472 | 471 // TODO(jacobr) THIS MAKES NO SENSE BUT MATCHES WHAT WE HAD BEFORE. |
| 472 js.JsNative.$setInstanceInterceptor($this, dartClass.runtimeType); |
| 473 creating--; | 473 creating--; |
| 474 } | 474 } |
| 475 } | 475 } |
| 476 | 476 |
| 477 if (oldCreatedCallback != null) | 477 if (oldCreatedCallback != null) |
| 478 oldCreatedCallback.apply([], thisArg: unwrap_jso($this)); | 478 oldCreatedCallback.apply([], thisArg: $this); |
| 479 }); | 479 })); |
| 480 elemProto['attributeChangedCallback'] = new js.JsFunction.withThis(($this,
attrName, oldVal, newVal) { | 480 js.JsNative.setProperty(elemProto, 'attributeChangedCallback', js.allowInt
eropCaptureThis(($this, attrName, oldVal, newVal) { |
| 481 $this.attributeChanged(attrName, oldVal, newVal); | 481 $this.attributeChanged(attrName, oldVal, newVal); |
| 482 | 482 |
| 483 if (oldAttributeChangedCallback != null) | 483 if (oldAttributeChangedCallback != null) |
| 484 oldAttributeChangedCallback.apply([], thisArg: unwrap_jso($this)); | 484 oldAttributeChangedCallback.apply([], thisArg: $this); |
| 485 }); | 485 })); |
| 486 elemProto['attachedCallback'] = new js.JsFunction.withThis(($this) { | 486 js.JsNative.setProperty(elemProto, 'attachedCallback', js.allowInteropCapt
ureThis(($this) { |
| 487 $this.attached(); | 487 $this.attached(); |
| 488 | 488 |
| 489 if (oldAttachedCallback != null) | 489 if (oldAttachedCallback != null) |
| 490 oldAttachedCallback.apply([], thisArg: unwrap_jso($this)); | 490 oldAttachedCallback.apply([], thisArg: $this); |
| 491 }); | 491 })); |
| 492 elemProto['detachedCallback'] = new js.JsFunction.withThis(($this) { | 492 js.JsNative.setProperty(elemProto, 'detachedCallback', js.allowInteropCapt
ureThis(($this) { |
| 493 $this.detached(); | 493 $this.detached(); |
| 494 | 494 |
| 495 if (oldDetachedCallback != null) | 495 if (oldDetachedCallback != null) |
| 496 oldDetachedCallback.apply([], thisArg: unwrap_jso($this)); | 496 oldDetachedCallback.apply([], thisArg: $this); |
| 497 }); | 497 })); |
| 498 // document.registerElement('x-foo', {prototype: elemProto, extends: exten
dsTag}); | 498 // document.registerElement('x-foo', {prototype: elemProto, extends: exten
dsTag}); |
| 499 var jsMap = new js.JsObject.jsify({'prototype': elemProto, 'extends': exte
ndsTag}); | 499 var jsMap = new js.JsObject.jsify({'prototype': elemProto, 'extends': exte
ndsTag}); |
| 500 js.JsNative.callMethod(js.JsNative.getProperty(js.context, 'document'), 'r
egisterElement', [tag, jsMap]); | 500 js.JsNative.callMethod(document, 'registerElement', [tag, jsMap]); |
| 501 } | 501 } |
| 502 $endif | 502 $endif |
| 503 } | 503 } |
| 504 | 504 |
| 505 /** *Deprecated*: use [registerElement] instead. */ | 505 /** *Deprecated*: use [registerElement] instead. */ |
| 506 @deprecated | 506 @deprecated |
| 507 @Experimental() | 507 @Experimental() |
| 508 void register(String tag, Type customElementClass, {String extendsTag}) { | 508 void register(String tag, Type customElementClass, {String extendsTag}) { |
| 509 return registerElement(tag, customElementClass, extendsTag: extendsTag); | 509 return registerElement(tag, customElementClass, extendsTag: extendsTag); |
| 510 } | 510 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 /// parameter must be provided. | 559 /// parameter must be provided. |
| 560 @Experimental() | 560 @Experimental() |
| 561 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { | 561 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { |
| 562 $if DART2JS | 562 $if DART2JS |
| 563 return new _JSElementUpgrader(this, type, extendsTag); | 563 return new _JSElementUpgrader(this, type, extendsTag); |
| 564 $else | 564 $else |
| 565 return new _VMElementUpgrader(this, type, extendsTag); | 565 return new _VMElementUpgrader(this, type, extendsTag); |
| 566 $endif | 566 $endif |
| 567 } | 567 } |
| 568 } | 568 } |
| OLD | NEW |