Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of polymer; | 5 part of polymer; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * **Warning**: this class is experiental and subject to change. | 8 * **Warning**: this class is experiental and subject to change. |
| 9 * | 9 * |
| 10 * The implementation for the `polymer-element` element. | 10 * The implementation for the `polymer-element` element. |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 * Takes external stylesheets loaded in an `<element>` element and moves | 358 * Takes external stylesheets loaded in an `<element>` element and moves |
| 359 * their content into a style element inside the `<element>`'s template. | 359 * their content into a style element inside the `<element>`'s template. |
| 360 * The sheet is then removed from the `<element>`. This is done only so | 360 * The sheet is then removed from the `<element>`. This is done only so |
| 361 * that if the element is loaded in the main document, the sheet does | 361 * that if the element is loaded in the main document, the sheet does |
| 362 * not become active. | 362 * not become active. |
| 363 * Note, ignores sheets with the attribute 'polymer-scope'. | 363 * Note, ignores sheets with the attribute 'polymer-scope'. |
| 364 */ | 364 */ |
| 365 void installLocalSheets() { | 365 void installLocalSheets() { |
| 366 var sheets = this.sheets.where( | 366 var sheets = this.sheets.where( |
| 367 (s) => !s.attributes.containsKey(_SCOPE_ATTR)); | 367 (s) => !s.attributes.containsKey(_SCOPE_ATTR)); |
| 368 var content = this.templateContent; | 368 var content = templateContent; |
| 369 if (content != null) { | 369 if (content != null) { |
| 370 var cssText = new StringBuffer(); | 370 var cssText = new StringBuffer(); |
| 371 for (var sheet in sheets) { | 371 for (var sheet in sheets) { |
| 372 cssText..write(_cssTextFromSheet(sheet))..write('\n'); | 372 cssText..write(_cssTextFromSheet(sheet))..write('\n'); |
| 373 } | 373 } |
| 374 if (cssText.length > 0) { | 374 if (cssText.length > 0) { |
| 375 content.insertBefore( | 375 content.insertBefore( |
| 376 new StyleElement()..text = '$cssText', | 376 new StyleElement()..text = '$cssText', |
| 377 content.firstChild); | 377 content.firstChild); |
| 378 } | 378 } |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 | 381 |
| 382 List<Element> findNodes(String selector, [bool matcher(Element e)]) { | 382 List<Element> findNodes(String selector, [bool matcher(Element e)]) { |
| 383 var nodes = this.queryAll(selector).toList(); | 383 var nodes = this.querySelectorAll(selector).toList(); |
| 384 var content = this.templateContent; | 384 var content = templateContent; |
| 385 if (content != null) { | 385 if (content != null) { |
| 386 nodes = nodes..addAll(content.queryAll(selector)); | 386 nodes = nodes..addAll(content.queryAll(selector)); |
| 387 } | 387 } |
| 388 if (matcher != null) return nodes.where(matcher).toList(); | 388 if (matcher != null) return nodes.where(matcher).toList(); |
| 389 return nodes; | 389 return nodes; |
| 390 } | 390 } |
| 391 | 391 |
| 392 /** | 392 /** |
| 393 * Promotes external stylesheets and style elements with the attribute | 393 * Promotes external stylesheets and style elements with the attribute |
| 394 * polymer-scope='global' into global scope. | 394 * polymer-scope='global' into global scope. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 bool _hasEventPrefix(String attr) => attr.startsWith(_EVENT_PREFIX); | 547 bool _hasEventPrefix(String attr) => attr.startsWith(_EVENT_PREFIX); |
| 548 | 548 |
| 549 String _removeEventPrefix(String name) => name.substring(_EVENT_PREFIX.length); | 549 String _removeEventPrefix(String name) => name.substring(_EVENT_PREFIX.length); |
| 550 | 550 |
| 551 /** | 551 /** |
| 552 * Using Polymer's platform/src/ShadowCSS.js passing the style tag's content. | 552 * Using Polymer's platform/src/ShadowCSS.js passing the style tag's content. |
| 553 */ | 553 */ |
| 554 void _shimShadowDomStyling(DocumentFragment template, String name, | 554 void _shimShadowDomStyling(DocumentFragment template, String name, |
| 555 String extendee) { | 555 String extendee) { |
| 556 if (js.context == null || template == null) return; | 556 if (js.context == null || template == null) return; |
| 557 if (js.context.hasProperty('ShadowDOMPolyfill')) return; | 557 if (!js.context.hasProperty('ShadowDOMPolyfill')) return; |
|
Siggi Cherem (dart-lang)
2013/11/21 01:46:13
! o u c h
| |
| 558 | 558 |
| 559 var platform = js.context['Platform']; | 559 var platform = js.context['Platform']; |
| 560 if (platform == null) return; | 560 if (platform == null) return; |
| 561 var shadowCss = platform['ShadowCSS']; | 561 var shadowCss = platform['ShadowCSS']; |
| 562 if (shadowCss == null) return; | 562 if (shadowCss == null) return; |
| 563 shadowCss.callMethod('shimStyling', [template, name, extendee]); | 563 shadowCss.callMethod('shimStyling', [template, name, extendee]); |
| 564 } | 564 } |
| 565 | 565 |
| 566 const _STYLE_SELECTOR = 'style'; | 566 const _STYLE_SELECTOR = 'style'; |
| 567 const _SHEET_SELECTOR = '[rel=stylesheet]'; | 567 const _SHEET_SELECTOR = '[rel=stylesheet]'; |
| 568 const _STYLE_GLOBAL_SCOPE = 'global'; | 568 const _STYLE_GLOBAL_SCOPE = 'global'; |
| 569 const _SCOPE_ATTR = 'polymer-scope'; | 569 const _SCOPE_ATTR = 'polymer-scope'; |
| 570 const _STYLE_SCOPE_ATTRIBUTE = 'element'; | 570 const _STYLE_SCOPE_ATTRIBUTE = 'element'; |
| 571 const _STYLE_CONTROLLER_SCOPE = 'controller'; | 571 const _STYLE_CONTROLLER_SCOPE = 'controller'; |
| 572 | 572 |
| 573 String _cssTextFromSheet(Element sheet) { | 573 String _cssTextFromSheet(LinkElement sheet) { |
| 574 if (sheet == null || js.context == null) return ''; | 574 if (sheet == null) return ''; |
| 575 var resource = new js.JsObject.fromBrowserObject(sheet)['__resource']; | 575 |
| 576 return resource != null ? resource : ''; | 576 // TODO(jmesserly): sometimes the href property is wrong after deployment. |
| 577 var href = sheet.href; | |
| 578 if (href == '') href = sheet.attributes["href"]; | |
| 579 | |
| 580 if (js.context != null && js.context.hasProperty('HTMLImports')) { | |
| 581 var jsSheet = new js.JsObject.fromBrowserObject(sheet); | |
| 582 var resource = jsSheet['__resource']; | |
| 583 if (resource != null) return resource; | |
| 584 _sheetLog.fine('failed to get stylesheet text href="$href"'); | |
| 585 return ''; | |
| 586 } | |
| 587 // TODO(jmesserly): it seems like polymer-js is always polyfilling | |
| 588 // HTMLImports, because their code depends on "__resource" to work. | |
| 589 // We work around this by using a sync XHR to get the stylesheet text. | |
| 590 // Right now this code is only used in Dartium, but if it's going to stick | |
| 591 // around we will need to find a different approach. | |
| 592 try { | |
| 593 return (new HttpRequest() | |
| 594 ..open('GET', href, async: false) | |
| 595 ..send()) | |
| 596 .responseText; | |
| 597 } on DomException catch (e, t) { | |
| 598 _sheetLog.fine('failed to get stylesheet text href="$href" error: ' | |
| 599 '$e, trace: $t'); | |
| 600 return ''; | |
| 601 } | |
| 577 } | 602 } |
| 578 | 603 |
| 604 final Logger _sheetLog = new Logger('polymer.stylesheet'); | |
| 605 | |
| 579 const _OBSERVE_SUFFIX = 'Changed'; | 606 const _OBSERVE_SUFFIX = 'Changed'; |
| 580 | 607 |
| 581 // TODO(jmesserly): is this list complete? | 608 // TODO(jmesserly): is this list complete? |
| 582 final _eventTranslations = const { | 609 final _eventTranslations = const { |
| 583 // TODO(jmesserly): these three Polymer.js translations won't work in Dart, | 610 // TODO(jmesserly): these three Polymer.js translations won't work in Dart, |
| 584 // because we strip the webkit prefix (below). Reconcile. | 611 // because we strip the webkit prefix (below). Reconcile. |
| 585 'webkitanimationstart': 'webkitAnimationStart', | 612 'webkitanimationstart': 'webkitAnimationStart', |
| 586 'webkitanimationend': 'webkitAnimationEnd', | 613 'webkitanimationend': 'webkitAnimationEnd', |
| 587 'webkittransitionend': 'webkitTransitionEnd', | 614 'webkittransitionend': 'webkitTransitionEnd', |
| 588 | 615 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 611 return map; | 638 return map; |
| 612 }(); | 639 }(); |
| 613 | 640 |
| 614 // Dart note: we need this function because we have additional renames JS does | 641 // Dart note: we need this function because we have additional renames JS does |
| 615 // not have. The JS renames are simply case differences, whereas we have ones | 642 // not have. The JS renames are simply case differences, whereas we have ones |
| 616 // like doubleclick -> dblclick and stripping the webkit prefix. | 643 // like doubleclick -> dblclick and stripping the webkit prefix. |
| 617 String _eventNameFromType(String eventType) { | 644 String _eventNameFromType(String eventType) { |
| 618 final result = _reverseEventTranslations[eventType]; | 645 final result = _reverseEventTranslations[eventType]; |
| 619 return result != null ? result : eventType; | 646 return result != null ? result : eventType; |
| 620 } | 647 } |
| OLD | NEW |