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

Side by Side Diff: pkg/polymer/lib/polymer_element.dart

Issue 24046003: Fix TODO in polymer _shimCss, remove package:js dependency (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months 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
« no previous file with comments | « no previous file | pkg/polymer/lib/src/transform/polyfill_injector.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library polymer.polymer_element; 5 library polymer.polymer_element;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:mirrors'; 9 import 'dart:mirrors';
10 import 'dart:js' as dartJs; 10 import 'dart:js' as js;
11 11
12 import 'package:custom_element/custom_element.dart'; 12 import 'package:custom_element/custom_element.dart';
13 import 'package:js/js.dart' as js;
14 import 'package:mdv/mdv.dart' show NodeBinding; 13 import 'package:mdv/mdv.dart' show NodeBinding;
15 import 'package:observe/observe.dart'; 14 import 'package:observe/observe.dart';
16 import 'package:observe/src/microtask.dart'; 15 import 'package:observe/src/microtask.dart';
17 import 'package:polymer_expressions/polymer_expressions.dart'; 16 import 'package:polymer_expressions/polymer_expressions.dart';
18 17
19 import 'src/utils.dart' show toCamelCase, toHyphenedName; 18 import 'src/utils.dart' show toCamelCase, toHyphenedName;
20 19
21 /** 20 /**
22 * Registers a [PolymerElement]. This is similar to [registerCustomElement] 21 * Registers a [PolymerElement]. This is similar to [registerCustomElement]
23 * but it is designed to work with the `<element>` element and adds additional 22 * but it is designed to work with the `<element>` element and adds additional
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 Map<String, PathObserver> _publishedAttrs; 79 Map<String, PathObserver> _publishedAttrs;
81 Map<String, StreamSubscription> _bindings; 80 Map<String, StreamSubscription> _bindings;
82 final List<String> _localNames = []; 81 final List<String> _localNames = [];
83 82
84 void _initialize(String localName) { 83 void _initialize(String localName) {
85 if (localName == null) return; 84 if (localName == null) return;
86 85
87 var declaration = getDeclaration(localName); 86 var declaration = getDeclaration(localName);
88 if (declaration == null) return; 87 if (declaration == null) return;
89 88
90 if (declaration.attributes['extends'] != null) { 89 var extendee = declaration.attributes['extends'];
91 var base = declaration.attributes['extends']; 90 if (extendee != null) {
92 // Skip normal tags, only initialize parent custom elements. 91 // Skip normal tags, only initialize parent custom elements.
93 if (base.contains('-')) _initialize(base); 92 if (extendee.contains('-')) _initialize(extendee);
94 } 93 }
95 94
96 _parseHostEvents(declaration); 95 _parseHostEvents(declaration);
97 _parseLocalEvents(declaration); 96 _parseLocalEvents(declaration);
98 _publishAttributes(declaration); 97 _publishAttributes(declaration);
98
99 var templateContent = declaration.query('template').content;
100 _shimStyling(templateContent, localName);
101
99 _localNames.add(localName); 102 _localNames.add(localName);
100 } 103 }
101 104
102 void _publishAttributes(elementElement) { 105 void _publishAttributes(elementElement) {
103 _bindings = {}; 106 _bindings = {};
104 _publishedAttrs = {}; 107 _publishedAttrs = {};
105 108
106 var attrs = elementElement.attributes['attributes']; 109 var attrs = elementElement.attributes['attributes'];
107 if (attrs != null) { 110 if (attrs != null) {
108 // attributes='a b c' or attributes='a,b,c' 111 // attributes='a b c' or attributes='a,b,c'
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 147
145 void _initShadowRoot() { 148 void _initShadowRoot() {
146 for (var localName in _localNames) { 149 for (var localName in _localNames) {
147 var declaration = getDeclaration(localName); 150 var declaration = getDeclaration(localName);
148 var root = createShadowRoot(localName); 151 var root = createShadowRoot(localName);
149 _addInstanceListeners(root, localName); 152 _addInstanceListeners(root, localName);
150 153
151 root.applyAuthorStyles = applyAuthorStyles; 154 root.applyAuthorStyles = applyAuthorStyles;
152 root.resetStyleInheritance = resetStyleInheritance; 155 root.resetStyleInheritance = resetStyleInheritance;
153 156
154 var templateNode = declaration.children.firstWhere( 157 var templateNode = declaration.query('template');
Jennifer Messerly 2013/09/13 17:49:43 changed because polymer uses query: https://github
155 (n) => n.localName == 'template', orElse: () => null);
156 if (templateNode == null) return; 158 if (templateNode == null) return;
157 159
158 // Create the contents of the element's ShadowRoot, and add them. 160 // Create the contents of the element's ShadowRoot, and add them.
159 root.nodes.add(instanceTemplate(templateNode)); 161 root.nodes.add(instanceTemplate(templateNode));
160
161 var extendsName = declaration.attributes['extends'];
162 _shimCss(root, localName, extendsName);
163 } 162 }
164 } 163 }
165 164
166 NodeBinding createBinding(String name, model, String path) { 165 NodeBinding createBinding(String name, model, String path) {
167 var propObserver = _publishedAttrs[name]; 166 var propObserver = _publishedAttrs[name];
168 if (propObserver != null) { 167 if (propObserver != null) {
169 return new _PolymerBinding(this, name, model, path, propObserver); 168 return new _PolymerBinding(this, name, model, path, propObserver);
170 } 169 }
171 return super.createBinding(name, model, path); 170 return super.createBinding(name, model, path);
172 } 171 }
173 172
174 /** 173 /**
175 * Using Polymer's platform/src/ShadowCSS.js passing the style tag's content. 174 * Using Polymer's platform/src/ShadowCSS.js passing the style tag's content.
176 */ 175 */
177 void _shimCss(ShadowRoot root, String localName, String extendsName) { 176 void _shimStyling(DocumentFragment template, String localName) {
178 // TODO(terry): Need to detect if ShadowCSS.js has been loaded. Under 177 if (js.context == null) return;
179 // Dartium this wouldn't exist. However, dart:js isn't robust
180 // to use to detect in both Dartium and dart2js if Platform is
181 // defined. This bug is described in
182 // https://code.google.com/p/dart/issues/detail?id=12548
183 // When fixed only use dart:js. This is necessary under
184 // Dartium (no compile) we want to run w/o the JS polyfill.
185 if (dartJs.context == null || !dartJs.context.hasProperty('Platform')) {
186 return;
187 }
188 178
189 var platform = js.context["Platform"]; 179 var platform = js.context['Platform'];
190 if (platform == null) return; 180 if (platform == null) return;
191 var shadowCss = platform.ShadowCSS; 181
182 var style = template.query('style');
183 if (style == null) return;
184
185 var shadowCss = platform['ShadowCSS'];
192 if (shadowCss == null) return; 186 if (shadowCss == null) return;
193 187
194 // TODO(terry): Remove calls to shimShadowDOMStyling2 and replace with 188 // TODO(terry): Remove calls to shimShadowDOMStyling2 and replace with
195 // shimShadowDOMStyling when we support unwrapping dart:html 189 // shimShadowDOMStyling when we support unwrapping dart:html
196 // Element to a JS DOM node. 190 // Element to a JS DOM node.
197 var shimShadowDOMStyling2 = shadowCss.shimShadowDOMStyling2; 191 var shimShadowDOMStyling2 = shadowCss['shimShadowDOMStyling2'];
198 if (shimShadowDOMStyling2 == null) return; 192 if (shimShadowDOMStyling2 == null) return;
199 var style = root.query('style'); 193
200 if (style == null) return; 194 var scopedCSS = shimShadowDOMStyling2.apply(shadowCss,
201 var scopedCSS = shimShadowDOMStyling2(style.text, localName); 195 [style.text, localName]);
202 196
203 // TODO(terry): Remove when shimShadowDOMStyling is called we don't need to 197 // TODO(terry): Remove when shimShadowDOMStyling is called we don't need to
204 // replace original CSS with scoped CSS shimShadowDOMStyling 198 // replace original CSS with scoped CSS shimShadowDOMStyling
205 // does that. 199 // does that.
206 style.text = scopedCSS; 200 style.text = scopedCSS;
207 } 201 }
208 } 202 }
209 203
210 class _PolymerBinding extends NodeBinding { 204 class _PolymerBinding extends NodeBinding {
211 final PathObserver _publishedAttr; 205 final PathObserver _publishedAttr;
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 'onKeyMessage': MediaElement.keyMessageEvent, 549 'onKeyMessage': MediaElement.keyMessageEvent,
556 'onNeedKey': MediaElement.needKeyEvent, 550 'onNeedKey': MediaElement.needKeyEvent,
557 'onWebGlContextLost': CanvasElement.webGlContextLostEvent, 551 'onWebGlContextLost': CanvasElement.webGlContextLostEvent,
558 'onWebGlContextRestored': CanvasElement.webGlContextRestoredEvent, 552 'onWebGlContextRestored': CanvasElement.webGlContextRestoredEvent,
559 'onPointerLockChange': Document.pointerLockChangeEvent, 553 'onPointerLockChange': Document.pointerLockChangeEvent,
560 'onPointerLockError': Document.pointerLockErrorEvent, 554 'onPointerLockError': Document.pointerLockErrorEvent,
561 'onReadyStateChange': Document.readyStateChangeEvent, 555 'onReadyStateChange': Document.readyStateChangeEvent,
562 'onSelectionChange': Document.selectionChangeEvent, 556 'onSelectionChange': Document.selectionChangeEvent,
563 'onSecurityPolicyViolation': Document.securityPolicyViolationEvent, 557 'onSecurityPolicyViolation': Document.securityPolicyViolationEvent,
564 }; 558 };
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/lib/src/transform/polyfill_injector.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698