Chromium Code Reviews| 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 /** Collects several code emitters for the template tool. */ | 5 /** Collects several code emitters for the template tool. */ |
| 6 // TODO(sigmund): add visitor that applies all emitters on a component | 6 // TODO(sigmund): add visitor that applies all emitters on a component |
| 7 // TODO(sigmund): add support for conditionals, so context is changed at that | 7 // TODO(sigmund): add support for conditionals, so context is changed at that |
| 8 // point. | 8 // point. |
| 9 library emitters; | 9 library emitters; |
| 10 | 10 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 if (e.oldValue != null && e.oldValue != '') { | 211 if (e.oldValue != null && e.oldValue != '') { |
| 212 $elemField.classes.remove(e.oldValue); | 212 $elemField.classes.remove(e.oldValue); |
| 213 } | 213 } |
| 214 if (e.newValue != null && e.newValue != '') { | 214 if (e.newValue != null && e.newValue != '') { |
| 215 $elemField.classes.add(e.newValue); | 215 $elemField.classes.add(e.newValue); |
| 216 } | 216 } |
| 217 }); | 217 }); |
| 218 '''); | 218 '''); |
| 219 } | 219 } |
| 220 } else { | 220 } else { |
| 221 // Note: it is important for correctness to use the DOM setter if it | |
| 222 // is available. Otherwise changes will not be applied. This is most | |
| 223 // easily observed with "InputElement.value", ".checked", etc. | |
| 224 var setter; | |
| 225 var allowedTags = htmlAttributeTags[name]; | |
|
Siggi Cherem (dart-lang)
2012/10/27 00:46:45
nit: maybe some alternative name? allowedTags ring
| |
| 226 if (allowedTags == allHtmlElements || | |
| 227 allowedTags != null && allowedTags.contains(elem.tagName)) { | |
| 228 var renamed = elementFieldRenames[name]; | |
|
Siggi Cherem (dart-lang)
2012/10/27 00:46:45
elementFieldRenames => domToDartHtml?
| |
| 229 setter = renamed != null ? renamed : name; | |
| 230 } else { | |
| 231 setter = 'attributes["$name"]'; | |
| 232 } | |
| 233 | |
| 221 var val = attrInfo.boundValue; | 234 var val = attrInfo.boundValue; |
| 222 var stopperName = attrInfo.stopperNames[0]; | 235 var stopperName = attrInfo.stopperNames[0]; |
| 223 var setter; | |
| 224 // TODO(sigmund): use setters when they are available (issue #112) | |
| 225 if (elem.tagName == 'input' && (name == 'value' || name == 'checked')) { | |
| 226 setter = name; | |
| 227 } else { | |
| 228 setter = 'attributes["$name"]'; | |
| 229 } | |
| 230 context.insertedMethod.add(''' | 236 context.insertedMethod.add(''' |
| 231 $stopperName = autogenerated.watchAndInvoke(() => $val, (e) { | 237 $stopperName = autogenerated.watchAndInvoke(() => $val, (e) { |
| 232 $elemField.$setter = e.newValue; | 238 $elemField.$setter = e.newValue; |
| 233 }); | 239 }); |
| 234 '''); | 240 '''); |
| 235 } | 241 } |
| 236 }); | 242 }); |
| 237 | 243 |
| 238 // stop-functions for watchers associated with data-bound content | 244 // stop-functions for watchers associated with data-bound content |
| 239 if (elemInfo.contentBinding != null) { | 245 if (elemInfo.contentBinding != null) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 (c) => PathInfo.relativePath(_info, c)); | 675 (c) => PathInfo.relativePath(_info, c)); |
| 670 printer.add(codegen.importList(imports)) | 676 printer.add(codegen.importList(imports)) |
| 671 .add(codegen.mainDartCode(codeInfo.code, | 677 .add(codegen.mainDartCode(codeInfo.code, |
| 672 _context.declarations.formatString(0), | 678 _context.declarations.formatString(0), |
| 673 _context.createdMethod.formatString(1), | 679 _context.createdMethod.formatString(1), |
| 674 _context.insertedMethod.formatString(1), | 680 _context.insertedMethod.formatString(1), |
| 675 document.body.innerHTML.trim())); | 681 document.body.innerHTML.trim())); |
| 676 return printer.formatString(); | 682 return printer.formatString(); |
| 677 } | 683 } |
| 678 } | 684 } |
| OLD | NEW |