Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: pkg/polymer/lib/src/declaration.dart

Issue 60353013: Update TodoMVC based on https://github.com/polymer/todomvc (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix pubspecs Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 * Takes external stylesheets loaded in an `<element>` element and moves 356 * Takes external stylesheets loaded in an `<element>` element and moves
357 * their content into a style element inside the `<element>`'s template. 357 * their content into a style element inside the `<element>`'s template.
358 * The sheet is then removed from the `<element>`. This is done only so 358 * The sheet is then removed from the `<element>`. This is done only so
359 * that if the element is loaded in the main document, the sheet does 359 * that if the element is loaded in the main document, the sheet does
360 * not become active. 360 * not become active.
361 * Note, ignores sheets with the attribute 'polymer-scope'. 361 * Note, ignores sheets with the attribute 'polymer-scope'.
362 */ 362 */
363 void installLocalSheets() { 363 void installLocalSheets() {
364 var sheets = this.sheets.where( 364 var sheets = this.sheets.where(
365 (s) => !s.attributes.containsKey(_SCOPE_ATTR)); 365 (s) => !s.attributes.containsKey(_SCOPE_ATTR));
366 var content = this.templateContent; 366 var content = templateContent;
367 if (content != null) { 367 if (content != null) {
368 var cssText = new StringBuffer(); 368 var cssText = new StringBuffer();
369 for (var sheet in sheets) { 369 for (var sheet in sheets) {
370 cssText..write(_cssTextFromSheet(sheet))..write('\n'); 370 cssText..write(_cssTextFromSheet(sheet))..write('\n');
371 } 371 }
372 if (cssText.length > 0) { 372 if (cssText.length > 0) {
373 content.insertBefore( 373 content.insertBefore(
374 new StyleElement()..text = '$cssText', 374 new StyleElement()..text = '$cssText',
375 content.firstChild); 375 content.firstChild);
376 } 376 }
377 } 377 }
378 } 378 }
379 379
380 List<Element> findNodes(String selector, [bool matcher(Element e)]) { 380 List<Element> findNodes(String selector, [bool matcher(Element e)]) {
381 var nodes = this.queryAll(selector).toList(); 381 var nodes = this.querySelectorAll(selector).toList();
382 var content = this.templateContent; 382 var content = templateContent;
383 if (content != null) { 383 if (content != null) {
384 nodes = nodes..addAll(content.queryAll(selector)); 384 nodes = nodes..addAll(content.queryAll(selector));
385 } 385 }
386 if (matcher != null) return nodes.where(matcher).toList(); 386 if (matcher != null) return nodes.where(matcher).toList();
387 return nodes; 387 return nodes;
388 } 388 }
389 389
390 /** 390 /**
391 * Promotes external stylesheets and style elements with the attribute 391 * Promotes external stylesheets and style elements with the attribute
392 * polymer-scope='global' into global scope. 392 * polymer-scope='global' into global scope.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 } 562 }
563 563
564 const _STYLE_SELECTOR = 'style'; 564 const _STYLE_SELECTOR = 'style';
565 const _SHEET_SELECTOR = '[rel=stylesheet]'; 565 const _SHEET_SELECTOR = '[rel=stylesheet]';
566 const _STYLE_GLOBAL_SCOPE = 'global'; 566 const _STYLE_GLOBAL_SCOPE = 'global';
567 const _SCOPE_ATTR = 'polymer-scope'; 567 const _SCOPE_ATTR = 'polymer-scope';
568 const _STYLE_SCOPE_ATTRIBUTE = 'element'; 568 const _STYLE_SCOPE_ATTRIBUTE = 'element';
569 const _STYLE_CONTROLLER_SCOPE = 'controller'; 569 const _STYLE_CONTROLLER_SCOPE = 'controller';
570 570
571 String _cssTextFromSheet(Element sheet) { 571 String _cssTextFromSheet(Element sheet) {
572 if (sheet == null || js.context == null) return ''; 572 if (sheet == null) return '';
573 var resource = new js.JsObject.fromBrowserObject(sheet)['__resource']; 573
574 return resource != null ? resource : ''; 574 // TODO(jmesserly): sometimes the href property is wrong after deployment.
575 var href = sheet.href;
576 if (href == '') href = sheet.attributes["href"];
577
578 if (js.context != null && js.context.hasProperty('HTMLImports')) {
579 var jsSheet = new js.JsObject.fromBrowserObject(sheet);
580 var resource = jsSheet['__resource'];
581 if (resource != null) return resource;
582 _sheetLog.fine('failed to get stylesheet text href="$href"');
583 return '';
584 }
585 // TODO(jmesserly): it seems like polymer-js is always polyfilling
586 // HTMLImports, because their code depends on "__resource" to work.
587 // We work around this by using a sync XHR to get the stylesheet text.
588 // Right now this code is only used in Dartium, but if it's going to stick
589 // around we will need to find a different approach.
590 try {
591 return (new HttpRequest()
592 ..open('GET', href, async: false)
593 ..send())
594 .responseText;
595 } on DomException catch (e, t) {
596 _sheetLog.fine('failed to get stylesheet text href="$href" error: '
597 '$e, trace: $t');
598 return '';
599 }
575 } 600 }
576 601
602 final Logger _sheetLog = new Logger('polymer.stylesheet');
603
577 const _OBSERVE_SUFFIX = 'Changed'; 604 const _OBSERVE_SUFFIX = 'Changed';
578 605
579 // TODO(jmesserly): is this list complete? 606 // TODO(jmesserly): is this list complete?
580 final _eventTranslations = const { 607 final _eventTranslations = const {
581 // TODO(jmesserly): these three Polymer.js translations won't work in Dart, 608 // TODO(jmesserly): these three Polymer.js translations won't work in Dart,
582 // because we strip the webkit prefix (below). Reconcile. 609 // because we strip the webkit prefix (below). Reconcile.
583 'webkitanimationstart': 'webkitAnimationStart', 610 'webkitanimationstart': 'webkitAnimationStart',
584 'webkitanimationend': 'webkitAnimationEnd', 611 'webkitanimationend': 'webkitAnimationEnd',
585 'webkittransitionend': 'webkitTransitionEnd', 612 'webkittransitionend': 'webkitTransitionEnd',
586 613
(...skipping 22 matching lines...) Expand all
609 return map; 636 return map;
610 }(); 637 }();
611 638
612 // Dart note: we need this function because we have additional renames JS does 639 // Dart note: we need this function because we have additional renames JS does
613 // not have. The JS renames are simply case differences, whereas we have ones 640 // not have. The JS renames are simply case differences, whereas we have ones
614 // like doubleclick -> dblclick and stripping the webkit prefix. 641 // like doubleclick -> dblclick and stripping the webkit prefix.
615 String _eventNameFromType(String eventType) { 642 String _eventNameFromType(String eventType) {
616 final result = _reverseEventTranslations[eventType]; 643 final result = _reverseEventTranslations[eventType];
617 return result != null ? result : eventType; 644 return result != null ? result : eventType;
618 } 645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698