| 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); | |
| 418 | |
| 419 // TODO(terry): Hack to stop recursion re-creating custom element when the | 416 // TODO(terry): Hack to stop recursion re-creating custom element when the |
| 420 // created() constructor of the custom element does e.g., | 417 // created() constructor of the custom element does e.g., |
| 421 // | 418 // |
| 422 // MyElement.created() : super.created() { | 419 // MyElement.created() : super.created() { |
| 423 // this.innerHtml = "<b>I'm an x-foo-with-markup!</b>"; | 420 // this.innerHtml = "<b>I'm an x-foo-with-markup!</b>"; |
| 424 // } | 421 // } |
| 425 // | 422 // |
| 426 // sanitizing causes custom element to created recursively | 423 // sanitizing causes custom element to created recursively |
| 427 // until stack overflow. | 424 // until stack overflow. |
| 428 // | 425 // |
| 429 // See https://github.com/dart-lang/sdk/issues/23666 | 426 // See https://github.com/dart-lang/sdk/issues/23666 |
| 430 int creating = 0; | 427 int creating = 0; // TODO(jacobr): I think I broke thise case. Will fix mo
nday. |
| 431 | 428 |
| 432 // If any JS code is hooked we want to call it too. | 429 // If any JS code is hooked we want to call it too. |
| 433 var oldCreatedCallback = elemProto['createdCallback']; | 430 var oldCreatedCallback = js.JsNative.getProperty(elemProto, 'createdCallba
ck'); |
| 434 var oldAttributeChangedCallback = elemProto['attributeChangedCallback']; | 431 var oldAttributeChangedCallback = js.JsNative.getProperty(elemProto, 'attr
ibuteChangedCallback'); |
| 435 var oldAttachedCallback = elemProto['attachedCallback']; | 432 var oldAttachedCallback = js.JsNative.getProperty(elemProto, 'attachedCall
back'); |
| 436 var oldDetachedCallback = elemProto['detachedCallback']; | 433 var oldDetachedCallback = js.JsNative.getProperty(elemProto, 'detachedCall
back'); |
| 437 | 434 |
| 438 // TODO(jacobr): warning: | 435 js.JsNative.setProperty(elemProto, 'createdCallback', js.allowInteropCaptu
reThis(($this) { |
| 439 elemProto['createdCallback'] = js.JsNative.withThis(($this) { | 436 // The created callback has already been called by the very act of passi
ng a JS |
| 440 if (_getJSClassName(reflectClass(customElementClass).superclass) != null
&& creating < 2) { | 437 // custom element from JS to Dart. |
| 441 creating++; | |
| 442 | |
| 443 var dartClass; | |
| 444 try { | |
| 445 if (extendsTag != null) { | |
| 446 // If we're extending a native element then create that element. | |
| 447 // Then upgrade that element to the customElementClass through | |
| 448 // normal flow. | |
| 449 dartClass = document.createElement(extendsTag); | |
| 450 js.setDartHtmlWrapperFor($this, dartClass); | |
| 451 dartClass.blink_jsObject = $this; | |
| 452 } | |
| 453 | |
| 454 // Upgrade to the CustomElement Dart class. | |
| 455 dartClass = _blink.Blink_Utils.constructElement(customElementClass,
$this); | |
| 456 } catch (e) { | |
| 457 // Got a problem make it an HtmlElement and rethrow the error. | |
| 458 dartClass = HtmlElement.internalCreateHtmlElement(); | |
| 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 | |
| 463 // Mark to only try this once don't try upgrading from HtmlElement | |
| 464 // to the user's Dart class - we had a problem. | |
| 465 dartClass._badUpgrade(); | |
| 466 throw e; | |
| 467 } finally { | |
| 468 // 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 | |
| 470 // with as we talk to blink. | |
| 471 js.setDartHtmlWrapperFor($this, dartClass); | |
| 472 | |
| 473 creating--; | |
| 474 } | |
| 475 } | |
| 476 | |
| 477 if (oldCreatedCallback != null) | 438 if (oldCreatedCallback != null) |
| 478 oldCreatedCallback.apply([], thisArg: unwrap_jso($this)); | 439 oldCreatedCallback.apply([], thisArg: $this); |
| 479 }); | 440 })); |
| 480 elemProto['attributeChangedCallback'] = new js.JsFunction.withThis(($this,
attrName, oldVal, newVal) { | 441 js.JsNative.setProperty(elemProto, 'attributeChangedCallback', js.allowInt
eropCaptureThis(($this, attrName, oldVal, newVal) { |
| 481 $this.attributeChanged(attrName, oldVal, newVal); | 442 $this.attributeChanged(attrName, oldVal, newVal); |
| 482 | 443 |
| 483 if (oldAttributeChangedCallback != null) | 444 if (oldAttributeChangedCallback != null) |
| 484 oldAttributeChangedCallback.apply([], thisArg: unwrap_jso($this)); | 445 oldAttributeChangedCallback.apply([], thisArg: $this); |
| 485 }); | 446 })); |
| 486 elemProto['attachedCallback'] = new js.JsFunction.withThis(($this) { | 447 js.JsNative.setProperty(elemProto, 'attachedCallback', js.allowInteropCapt
ureThis(($this) { |
| 487 $this.attached(); | 448 $this.attached(); |
| 488 | 449 |
| 489 if (oldAttachedCallback != null) | 450 if (oldAttachedCallback != null) |
| 490 oldAttachedCallback.apply([], thisArg: unwrap_jso($this)); | 451 oldAttachedCallback.apply([], thisArg: $this); |
| 491 }); | 452 })); |
| 492 elemProto['detachedCallback'] = new js.JsFunction.withThis(($this) { | 453 js.JsNative.setProperty(elemProto, 'detachedCallback', js.allowInteropCapt
ureThis(($this) { |
| 493 $this.detached(); | 454 $this.detached(); |
| 494 | 455 |
| 495 if (oldDetachedCallback != null) | 456 if (oldDetachedCallback != null) |
| 496 oldDetachedCallback.apply([], thisArg: unwrap_jso($this)); | 457 oldDetachedCallback.apply([], thisArg: $this); |
| 497 }); | 458 })); |
| 498 // document.registerElement('x-foo', {prototype: elemProto, extends: exten
dsTag}); | 459 // document.registerElement('x-foo', {prototype: elemProto, extends: exten
dsTag}); |
| 499 var jsMap = new js.JsObject.jsify({'prototype': elemProto, 'extends': exte
ndsTag}); | 460 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]); | 461 _blink.Blink_Utils.defineInterceptorCustomElement(elemProto, customElement
Class); |
| 462 js.JsNative.callMethod(document, 'registerElement', [tag, jsMap]); |
| 501 } | 463 } |
| 502 $endif | 464 $endif |
| 503 } | 465 } |
| 504 | 466 |
| 505 /** *Deprecated*: use [registerElement] instead. */ | 467 /** *Deprecated*: use [registerElement] instead. */ |
| 506 @deprecated | 468 @deprecated |
| 507 @Experimental() | 469 @Experimental() |
| 508 void register(String tag, Type customElementClass, {String extendsTag}) { | 470 void register(String tag, Type customElementClass, {String extendsTag}) { |
| 509 return registerElement(tag, customElementClass, extendsTag: extendsTag); | 471 return registerElement(tag, customElementClass, extendsTag: extendsTag); |
| 510 } | 472 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 /// parameter must be provided. | 521 /// parameter must be provided. |
| 560 @Experimental() | 522 @Experimental() |
| 561 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { | 523 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { |
| 562 $if DART2JS | 524 $if DART2JS |
| 563 return new _JSElementUpgrader(this, type, extendsTag); | 525 return new _JSElementUpgrader(this, type, extendsTag); |
| 564 $else | 526 $else |
| 565 return new _VMElementUpgrader(this, type, extendsTag); | 527 return new _VMElementUpgrader(this, type, extendsTag); |
| 566 $endif | 528 $endif |
| 567 } | 529 } |
| 568 } | 530 } |
| OLD | NEW |