| 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 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 const _STYLE_SELECTOR = 'style'; | 647 const _STYLE_SELECTOR = 'style'; |
| 648 const _SHEET_SELECTOR = '[rel=stylesheet]'; | 648 const _SHEET_SELECTOR = '[rel=stylesheet]'; |
| 649 const _STYLE_GLOBAL_SCOPE = 'global'; | 649 const _STYLE_GLOBAL_SCOPE = 'global'; |
| 650 const _SCOPE_ATTR = 'polymer-scope'; | 650 const _SCOPE_ATTR = 'polymer-scope'; |
| 651 const _STYLE_SCOPE_ATTRIBUTE = 'element'; | 651 const _STYLE_SCOPE_ATTRIBUTE = 'element'; |
| 652 const _STYLE_CONTROLLER_SCOPE = 'controller'; | 652 const _STYLE_CONTROLLER_SCOPE = 'controller'; |
| 653 | 653 |
| 654 String _cssTextFromSheet(LinkElement sheet) { | 654 String _cssTextFromSheet(LinkElement sheet) { |
| 655 if (sheet == null) return ''; | 655 if (sheet == null) return ''; |
| 656 | 656 |
| 657 // In deploy mode we should never do a sync XHR; link rel=stylesheet will |
| 658 // be inlined into a <style> tag by ImportInliner. |
| 659 if (_deployMode) return ''; |
| 660 |
| 657 // TODO(jmesserly): sometimes the href property is wrong after deployment. | 661 // TODO(jmesserly): sometimes the href property is wrong after deployment. |
| 658 var href = sheet.href; | 662 var href = sheet.href; |
| 659 if (href == '') href = sheet.attributes["href"]; | 663 if (href == '') href = sheet.attributes["href"]; |
| 660 | 664 |
| 661 // TODO(jmesserly): our build is not doing the right thing for | |
| 662 // link rel=stylesheet, see http://dartbug.com/16648 | |
| 663 if (js.context != null && js.context.hasProperty('HTMLImports')) { | |
| 664 var jsSheet = new js.JsObject.fromBrowserObject(sheet); | |
| 665 var resource = jsSheet['__resource']; | |
| 666 if (resource != null) return resource; | |
| 667 // TODO(jmesserly): figure out why HTMLImports is failing to load these. | |
| 668 // Falling back to sync XHR is no good. | |
| 669 // _sheetLog.fine('failed to get stylesheet text href="$href"'); | |
| 670 // return ''; | |
| 671 } | |
| 672 // TODO(jmesserly): it seems like polymer-js is always polyfilling | 665 // TODO(jmesserly): it seems like polymer-js is always polyfilling |
| 673 // HTMLImports, because their code depends on "__resource" to work. | 666 // HTMLImports, because their code depends on "__resource" to work, so I |
| 674 // We work around this by using a sync XHR to get the stylesheet text. | 667 // don't see how it can work with native HTML Imports. We use a sync-XHR |
| 675 // Right now this code is only used in Dartium, but if it's going to stick | 668 // under the assumption that the file is likely to have been already |
| 676 // around we will need to find a different approach. | 669 // downloaded and cached by HTML Imports. |
| 677 try { | 670 try { |
| 678 return (new HttpRequest() | 671 return (new HttpRequest() |
| 679 ..open('GET', href, async: false) | 672 ..open('GET', href, async: false) |
| 680 ..send()) | 673 ..send()) |
| 681 .responseText; | 674 .responseText; |
| 682 } on DomException catch (e, t) { | 675 } on DomException catch (e, t) { |
| 683 _sheetLog.fine('failed to get stylesheet text href="$href" error: ' | 676 _sheetLog.fine('failed to XHR stylesheet text href="$href" error: ' |
| 684 '$e, trace: $t'); | 677 '$e, trace: $t'); |
| 685 return ''; | 678 return ''; |
| 686 } | 679 } |
| 687 } | 680 } |
| 688 | 681 |
| 689 final Logger _sheetLog = new Logger('polymer.stylesheet'); | 682 final Logger _sheetLog = new Logger('polymer.stylesheet'); |
| 690 | 683 |
| 691 const _OBSERVE_SUFFIX = 'Changed'; | 684 const _OBSERVE_SUFFIX = 'Changed'; |
| 692 | 685 |
| 693 // TODO(jmesserly): is this list complete? | 686 // TODO(jmesserly): is this list complete? |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 | 719 |
| 727 // Dart note: we need this function because we have additional renames JS does | 720 // Dart note: we need this function because we have additional renames JS does |
| 728 // not have. The JS renames are simply case differences, whereas we have ones | 721 // not have. The JS renames are simply case differences, whereas we have ones |
| 729 // like doubleclick -> dblclick and stripping the webkit prefix. | 722 // like doubleclick -> dblclick and stripping the webkit prefix. |
| 730 String _eventNameFromType(String eventType) { | 723 String _eventNameFromType(String eventType) { |
| 731 final result = _reverseEventTranslations[eventType]; | 724 final result = _reverseEventTranslations[eventType]; |
| 732 return result != null ? result : eventType; | 725 return result != null ? result : eventType; |
| 733 } | 726 } |
| 734 | 727 |
| 735 final _ATTRIBUTES_REGEX = new RegExp(r'\s|,'); | 728 final _ATTRIBUTES_REGEX = new RegExp(r'\s|,'); |
| OLD | NEW |