Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """This module provides shared functionality for the system to generate | 6 """This module provides shared functionality for the system to generate |
| 7 Dart:html APIs from the IDL database.""" | 7 Dart:html APIs from the IDL database.""" |
| 8 | 8 |
| 9 import emitter | 9 import emitter |
| 10 import logging | 10 import logging |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 return [] | 318 return [] |
| 319 infos = element_constructors[typename] | 319 infos = element_constructors[typename] |
| 320 if isinstance(infos, str): | 320 if isinstance(infos, str): |
| 321 infos = ElementConstructorInfo(tag=infos, | 321 infos = ElementConstructorInfo(tag=infos, |
| 322 factory_provider_name=factory_provider_name) | 322 factory_provider_name=factory_provider_name) |
| 323 if not isinstance(infos, list): | 323 if not isinstance(infos, list): |
| 324 infos = [infos] | 324 infos = [infos] |
| 325 return infos | 325 return infos |
| 326 | 326 |
| 327 # ------------------------------------------------------------------------------ | 327 # ------------------------------------------------------------------------------ |
| 328 | |
| 329 _html_element_tags = [ | |
| 330 # TODO(amouravski): add a custom factory constructor for h1..h6. | |
| 331 # TODO(amouravski): add a custom factory constructor for input | |
| 332 'a', | |
| 333 'article', | |
| 334 'aside', | |
| 335 'audio', | |
| 336 'br', | |
| 337 'canvas', | |
| 338 'div', | |
| 339 'footer', | |
| 340 'header', | |
| 341 'hr', | |
| 342 'iframe', | |
| 343 'img', | |
| 344 'li', | |
| 345 'nav', | |
| 346 'ol', | |
| 347 'option', | |
| 348 'p', | |
| 349 'pre', | |
| 350 'section', | |
| 351 'select', | |
| 352 'span', | |
| 353 'svg', | |
| 354 'table', | |
| 355 'td', | |
| 356 'textarea', | |
| 357 'th', | |
| 358 'tr', | |
| 359 'ul', | |
| 360 'video', | |
| 361 ] | |
| 362 | |
| 363 | |
| 364 # ------------------------------------------------------------------------------ | |
| 328 def SvgSupportStr(tagName): | 365 def SvgSupportStr(tagName): |
| 329 return 'Svg%s' % ElemSupportStr(tagName) | 366 return 'Svg%s' % ElemSupportStr(tagName) |
| 330 | 367 |
| 331 def ElemSupportStr(tagName): | 368 def ElemSupportStr(tagName): |
| 332 return "Element.isTagSupported('%s')" % tagName | 369 return "Element.isTagSupported('%s')" % tagName |
| 333 | 370 |
| 334 _js_support_checks_basic_element_with_constructors = [ | 371 _js_support_checks_basic_element_with_constructors = [ |
| 335 'HTMLContentElement', | 372 'HTMLContentElement', |
| 336 'HTMLDataListElement', | 373 'HTMLDataListElement', |
| 337 'HTMLDetailsElement', | 374 'HTMLDetailsElement', |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 if not base_class: | 573 if not base_class: |
| 537 base_class = 'Interceptor' | 574 base_class = 'Interceptor' |
| 538 | 575 |
| 539 annotations = self._metadata.GetFormattedMetadata( | 576 annotations = self._metadata.GetFormattedMetadata( |
| 540 self._library_name, self._interface, None, '') | 577 self._library_name, self._interface, None, '') |
| 541 | 578 |
| 542 class_modifiers = '' | 579 class_modifiers = '' |
| 543 if self._renamer.ShouldSuppressInterface(self._interface): | 580 if self._renamer.ShouldSuppressInterface(self._interface): |
| 544 class_modifiers = 'abstract ' | 581 class_modifiers = 'abstract ' |
| 545 | 582 |
| 583 # additional_methods = 'asdasdas' | |
|
blois
2013/06/28 00:28:11
delete.
Andrei Mouravski
2013/06/28 19:19:21
Done.
| |
| 584 # if self._interface.id == 'HTMLElement': | |
| 585 # additional_methods = ''.join(_ElementTagConstructors()) | |
| 586 | |
| 587 additional_methods = [] | |
| 588 if self._interface.id in 'HTMLElement': | |
| 589 for tag in _html_element_tags: | |
| 590 method = ( | |
| 591 "\n" | |
| 592 " /// Creates a new `<{0}>` element.\n" | |
|
blois
2013/06/28 00:28:11
Just put this into the template file.
Andrei Mouravski
2013/06/28 19:19:21
I don't understand. Do you mean inline all of the
| |
| 593 " ///\n" | |
| 594 " /// This is identical to calling `new Element.tag({0})`.\n" | |
| 595 " factory Element.{0}() => new Element.tag({0});\n").format(tag) | |
| 596 additional_methods.append(method) | |
| 597 additional_str = ''.join(additional_methods) | |
| 598 | |
| 546 self._implementation_members_emitter = implementation_emitter.Emit( | 599 self._implementation_members_emitter = implementation_emitter.Emit( |
| 547 self._backend.ImplementationTemplate(), | 600 self._backend.ImplementationTemplate(), |
| 548 LIBRARYNAME='dart.dom.%s' % self._library_name, | 601 LIBRARYNAME='dart.dom.%s' % self._library_name, |
| 549 ANNOTATIONS=annotations, | 602 ANNOTATIONS=annotations, |
| 550 CLASS_MODIFIERS=class_modifiers, | 603 CLASS_MODIFIERS=class_modifiers, |
| 551 CLASSNAME=self._interface_type_info.implementation_name(), | 604 CLASSNAME=self._interface_type_info.implementation_name(), |
| 552 EXTENDS=' extends %s' % base_class if base_class else '', | 605 EXTENDS=' extends %s' % base_class if base_class else '', |
| 553 IMPLEMENTS=implements_str, | 606 IMPLEMENTS=implements_str, |
| 554 MIXINS=mixins_str, | 607 MIXINS=mixins_str, |
| 555 DOMNAME=self._interface.doc_js_name, | 608 DOMNAME=self._interface.doc_js_name, |
| 556 NATIVESPEC=self._backend.NativeSpec()) | 609 NATIVESPEC=self._backend.NativeSpec(), |
| 610 ADDITIONAL_METHODS=additional_str) | |
| 557 self._backend.StartInterface(self._implementation_members_emitter) | 611 self._backend.StartInterface(self._implementation_members_emitter) |
| 558 | 612 |
| 559 self._backend.EmitHelpers(base_class) | 613 self._backend.EmitHelpers(base_class) |
| 560 self._event_generator.EmitStreamProviders( | 614 self._event_generator.EmitStreamProviders( |
| 561 self._interface, | 615 self._interface, |
| 562 self._backend.CustomJSMembers(), | 616 self._backend.CustomJSMembers(), |
| 563 self._implementation_members_emitter, | 617 self._implementation_members_emitter, |
| 564 self._library_name) | 618 self._library_name) |
| 565 self._backend.AddConstructors( | 619 self._backend.AddConstructors( |
| 566 constructors, factory_provider, factory_constructor_name) | 620 constructors, factory_provider, factory_constructor_name) |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1188 for library_name in libraries: | 1242 for library_name in libraries: |
| 1189 self._libraries[library_name] = DartLibrary( | 1243 self._libraries[library_name] = DartLibrary( |
| 1190 library_name, template_loader, library_type, output_dir) | 1244 library_name, template_loader, library_type, output_dir) |
| 1191 | 1245 |
| 1192 def AddFile(self, basename, library_name, path): | 1246 def AddFile(self, basename, library_name, path): |
| 1193 self._libraries[library_name].AddFile(path) | 1247 self._libraries[library_name].AddFile(path) |
| 1194 | 1248 |
| 1195 def Emit(self, emitter, auxiliary_dir): | 1249 def Emit(self, emitter, auxiliary_dir): |
| 1196 for lib in self._libraries.values(): | 1250 for lib in self._libraries.values(): |
| 1197 lib.Emit(emitter, auxiliary_dir) | 1251 lib.Emit(emitter, auxiliary_dir) |
| OLD | NEW |