| 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 | 218 |
| 219 classMirror = classMirror.superclass; | 219 classMirror = classMirror.superclass; |
| 220 } | 220 } |
| 221 | 221 |
| 222 // If we're an element then everything is okay. | 222 // If we're an element then everything is okay. |
| 223 return isElement ? jsClassName : null; | 223 return isElement ? jsClassName : null; |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Get the first class that's a super of a dart.dom library. |
| 227 ClassMirror _getDartHtmlClassName(ClassMirror classMirror) { |
| 228 while (classMirror.superclass != null) { |
| 229 var fullName = classMirror.superclass.qualifiedName; |
| 230 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); |
| 231 if (domLibrary) { |
| 232 return classMirror.superclass; |
| 233 } |
| 234 |
| 235 classMirror = classMirror.superclass; |
| 236 } |
| 237 |
| 238 return null; |
| 239 } |
| 240 |
| 226 /** | 241 /** |
| 227 * Get the class that immediately derived from a class in dart:html or | 242 * Get the class that immediately derived from a class in dart:html or |
| 228 * dart:svg (has an attribute DomName of either HTML* or SVG*). | 243 * dart:svg (has an attribute DomName of either HTML* or SVG*). |
| 229 */ | 244 */ |
| 230 ClassMirror _getDomSuperClass(ClassMirror classMirror) { | 245 ClassMirror _getDomSuperClass(ClassMirror classMirror) { |
| 231 var isElement = false; | 246 var isElement = false; |
| 247 var foundSuperElement = null; |
| 232 | 248 |
| 233 while (classMirror.superclass != null) { | 249 while (classMirror.superclass != null) { |
| 234 var fullName = classMirror.superclass.qualifiedName; | 250 var fullName = classMirror.superclass.qualifiedName; |
| 235 isElement = isElement || (fullName == #dart.dom.html.Element || fullName =
= #dart.dom.svg.Element); | 251 isElement = isElement || (fullName == #dart.dom.html.Element || fullName =
= #dart.dom.svg.Element); |
| 236 | 252 |
| 237 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); | 253 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); |
| 238 if (domLibrary) { | 254 if (domLibrary) { |
| 255 if (foundSuperElement == null) { |
| 256 foundSuperElement = classMirror.superclass; |
| 257 } |
| 239 // Lookup JS class (if not found). | 258 // Lookup JS class (if not found). |
| 240 var metadatas = classMirror.metadata; | 259 var metadatas = classMirror.metadata; |
| 241 for (var metadata in metadatas) { | 260 for (var metadata in metadatas) { |
| 242 var metaDataMirror = metadata.reflectee; | 261 var metaDataMirror = metadata.reflectee; |
| 243 var metaType = reflectClass(metaDataMirror.runtimeType); | 262 var metaType = reflectClass(metaDataMirror.runtimeType); |
| 244 if (MirrorSystem.getName(metaType.simpleName) == 'DomName' && | 263 if (MirrorSystem.getName(metaType.simpleName) == 'DomName' && |
| 245 (metaDataMirror.name.startsWith('HTML') || metaDataMirror.name.sta
rtsWith('SVG'))) { | 264 (metaDataMirror.name.startsWith('HTML') || metaDataMirror.name.sta
rtsWith('SVG'))) { |
| 246 if (isElement) return classMirror; | 265 if (isElement) return foundSuperElement; |
| 247 } | 266 } |
| 248 } | 267 } |
| 249 } | 268 } |
| 250 | 269 |
| 251 classMirror = classMirror.superclass; | 270 classMirror = classMirror.superclass; |
| 252 } | 271 } |
| 253 | 272 |
| 254 return null; | 273 return null; |
| 255 } | 274 } |
| 256 | 275 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (classMirror.isAbstract) { | 381 if (classMirror.isAbstract) { |
| 363 throw new DomException.jsInterop("HierarchyRequestError: Cannot register a
n abstract class."); | 382 throw new DomException.jsInterop("HierarchyRequestError: Cannot register a
n abstract class."); |
| 364 } | 383 } |
| 365 | 384 |
| 366 var jsClassName = _getJSClassName(classMirror); | 385 var jsClassName = _getJSClassName(classMirror); |
| 367 if (jsClassName == null) { | 386 if (jsClassName == null) { |
| 368 // Only components derived from HTML* can be extended. | 387 // Only components derived from HTML* can be extended. |
| 369 throw new DomException.jsInterop("HierarchyRequestError: Only HTML element
s can be customized."); | 388 throw new DomException.jsInterop("HierarchyRequestError: Only HTML element
s can be customized."); |
| 370 } | 389 } |
| 371 | 390 |
| 391 var customClassType = _getDartHtmlClassName(classMirror); |
| 392 |
| 393 if (extendsTag != null) { |
| 394 var nativeElement = document.createElement(extendsTag); |
| 395 |
| 396 // Trying to extend a native element is it the Dart class consistent with
the |
| 397 // extendsTag? |
| 398 if (nativeElement.runtimeType != customClassType.reflectedType) { |
| 399 var nativeElementClassMirror = reflectClass(nativeElement.runtimeType); |
| 400 var customClassNativeElement = MirrorSystem.getName(customClassType.simp
leName); |
| 401 var extendsNativeElement = MirrorSystem.getName(nativeElementClassMirror
.simpleName); |
| 402 throw new DomException.jsInterop("HierarchyRequestError: Custom class ty
pe ($customClassNativeElement) and extendsTag class ($extendsNativeElement) don'
t match ."); |
| 403 } |
| 404 } else if (customClassType.reflectedType != HtmlElement && customClassType.r
eflectedType != svg.SvgElement) { |
| 405 var customClassName = MirrorSystem.getName(classMirror.simpleName); |
| 406 var customClassElement = MirrorSystem.getName(customClassType.simpleName); |
| 407 throw new DomException.jsInterop("HierarchyRequestError: Custom element $c
ustomClassName is a native $customClassElement should be derived from HtmlElemen
t or SvgElement."); |
| 408 } |
| 409 |
| 372 if (_hasCreatedConstructor(classMirror)) { | 410 if (_hasCreatedConstructor(classMirror)) { |
| 373 // Start the hookup the JS way create an <x-foo> element that extends the | 411 // Start the hookup the JS way create an <x-foo> element that extends the |
| 374 // <x-base> custom element. Inherit its prototype and signal what tag is | 412 // <x-base> custom element. Inherit its prototype and signal what tag is |
| 375 // inherited: | 413 // inherited: |
| 376 // | 414 // |
| 377 // var myProto = Object.create(HTMLElement.prototype); | 415 // var myProto = Object.create(HTMLElement.prototype); |
| 378 // var myElement = document.registerElement('x-foo', {prototype: myPro
to}); | 416 // var myElement = document.registerElement('x-foo', {prototype: myPro
to}); |
| 379 var baseElement = js.JsNative.getProperty(js.context, jsClassName); | 417 var baseElement = js.JsNative.getProperty(js.context, jsClassName); |
| 380 if (baseElement == null) { | 418 if (baseElement == null) { |
| 381 // Couldn't find the HTML element so use a generic one. | 419 // Couldn't find the HTML element so use a generic one. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 398 // | 436 // |
| 399 // See https://github.com/dart-lang/sdk/issues/23666 | 437 // See https://github.com/dart-lang/sdk/issues/23666 |
| 400 int creating = 0; | 438 int creating = 0; |
| 401 // TODO(jacobr): warning: | 439 // TODO(jacobr): warning: |
| 402 elemProto['createdCallback'] = js.JsNative.withThis(($this) { | 440 elemProto['createdCallback'] = js.JsNative.withThis(($this) { |
| 403 if (_getJSClassName(reflectClass(customElementClass).superclass) != null
&& creating < 2) { | 441 if (_getJSClassName(reflectClass(customElementClass).superclass) != null
&& creating < 2) { |
| 404 creating++; | 442 creating++; |
| 405 | 443 |
| 406 var dartClass; | 444 var dartClass; |
| 407 try { | 445 try { |
| 446 if (extendsTag != null) { |
| 447 // If we're extending a native element then create that element. |
| 448 // Then upgrade that element to the customElementClass through |
| 449 // normal flow. |
| 450 dartClass = document.createElement(extendsTag); |
| 451 js.setDartHtmlWrapperFor($this, dartClass); |
| 452 dartClass.blink_jsObject = $this; |
| 453 } |
| 454 |
| 455 // Upgrade to the CustomElement Dart class. |
| 408 dartClass = _blink.Blink_Utils.constructElement(customElementClass,
$this); | 456 dartClass = _blink.Blink_Utils.constructElement(customElementClass,
$this); |
| 409 } catch (e) { | 457 } catch (e) { |
| 458 // Got a problem make it an HtmlElement and rethrow the error. |
| 410 dartClass = HtmlElement.internalCreateHtmlElement(); | 459 dartClass = HtmlElement.internalCreateHtmlElement(); |
| 460 // We need to remember the JS object (because constructElement faile
d |
| 461 // it normally sets up the blink_jsObject. |
| 462 dartClass.blink_jsObject = $this; |
| 463 |
| 464 // Mark to only try this once don't try upgrading from HtmlElement |
| 465 // to the user's Dart class - we had a problem. |
| 411 dartClass._badUpgrade(); | 466 dartClass._badUpgrade(); |
| 412 throw e; | 467 throw e; |
| 413 } finally { | 468 } finally { |
| 414 // Need to remember the Dart class that was created for this custom
so | 469 // Need to remember the Dart class that was created for this custom
so |
| 415 // return it and setup the blink_jsObject to the $this that we'll be
working | 470 // return it and setup the blink_jsObject to the $this that we'll be
working |
| 416 // with as we talk to blink. | 471 // with as we talk to blink. |
| 417 js.setDartHtmlWrapperFor($this, dartClass); | 472 js.setDartHtmlWrapperFor($this, dartClass); |
| 418 | 473 |
| 419 creating--; | 474 creating--; |
| 420 } | 475 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 /// parameter must be provided. | 548 /// parameter must be provided. |
| 494 @Experimental() | 549 @Experimental() |
| 495 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { | 550 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { |
| 496 $if DART2JS | 551 $if DART2JS |
| 497 return new _JSElementUpgrader(this, type, extendsTag); | 552 return new _JSElementUpgrader(this, type, extendsTag); |
| 498 $else | 553 $else |
| 499 return new _VMElementUpgrader(this, type, extendsTag); | 554 return new _VMElementUpgrader(this, type, extendsTag); |
| 500 $endif | 555 $endif |
| 501 } | 556 } |
| 502 } | 557 } |
| OLD | NEW |