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 from systemfrog import * | 9 from systemfrog import * |
10 from systeminterface import * | 10 from systeminterface import * |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 'waiting': 'waiting', | 376 'waiting': 'waiting', |
377 'webkitAnimationEnd': 'animationEnd', | 377 'webkitAnimationEnd': 'animationEnd', |
378 'webkitAnimationIteration': 'animationIteration', | 378 'webkitAnimationIteration': 'animationIteration', |
379 'webkitAnimationStart': 'animationStart', | 379 'webkitAnimationStart': 'animationStart', |
380 'webkitfullscreenchange': 'fullscreenChange', | 380 'webkitfullscreenchange': 'fullscreenChange', |
381 'webkitfullscreenerror': 'fullscreenError', | 381 'webkitfullscreenerror': 'fullscreenError', |
382 'webkitSpeechChange': 'speechChange', | 382 'webkitSpeechChange': 'speechChange', |
383 'webkitTransitionEnd': 'transitionEnd' | 383 'webkitTransitionEnd': 'transitionEnd' |
384 } | 384 } |
385 | 385 |
386 # These classes require an explicit declaration for the "on" method even though | |
387 # they don't declare any unique events, because the concrete class hierarchy | |
388 # doesn't match the interface hierarchy. | |
389 _html_explicit_event_classes = set(['DocumentFragment']) | |
390 | |
386 def _OnAttributeToEventName(on_method): | 391 def _OnAttributeToEventName(on_method): |
387 event_name = on_method.id[2:] | 392 event_name = on_method.id[2:] |
388 if event_name in _on_attribute_to_event_name_mapping: | 393 if event_name in _on_attribute_to_event_name_mapping: |
389 return _on_attribute_to_event_name_mapping[event_name] | 394 return _on_attribute_to_event_name_mapping[event_name] |
390 else: | 395 else: |
391 return event_name | 396 return event_name |
392 | 397 |
393 def _DomToHtmlEvents(interface_id, events): | 398 def _DomToHtmlEvents(interface_id, events): |
394 event_names = set(map(_OnAttributeToEventName, events)) | 399 event_names = set(map(_OnAttributeToEventName, events)) |
395 if interface_id in _html_manual_events: | 400 if interface_id in _html_manual_events: |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 return ['Events'] | 494 return ['Events'] |
490 else: | 495 else: |
491 names = [] | 496 names = [] |
492 for interface in interfaces_with_events: | 497 for interface in interfaces_with_events: |
493 names.append(interface.id + 'Events') | 498 names.append(interface.id + 'Events') |
494 return names | 499 return names |
495 | 500 |
496 def _ImplClassName(self, type_name): | 501 def _ImplClassName(self, type_name): |
497 return '_' + type_name + 'Impl' | 502 return '_' + type_name + 'Impl' |
498 | 503 |
504 def GetEventAttributes(self, interface): | |
505 events = set([attr for attr in interface.attributes | |
506 if self._generator._IsEventAttribute(interface, attr)]) | |
507 | |
508 # Hack to generate no-op Element events for DocumentFragment. | |
Jacob
2012/03/07 23:24:05
this comment can now be removed.
nweiz
2012/03/08 01:03:51
Done.
| |
509 if events or interface.id in _html_explicit_event_classes: | |
510 return events | |
511 | |
499 class HtmlSystem(System): | 512 class HtmlSystem(System): |
500 | 513 |
501 def __init__(self, templates, database, emitters, output_dir, generator): | 514 def __init__(self, templates, database, emitters, output_dir, generator): |
502 super(HtmlSystem, self).__init__( | 515 super(HtmlSystem, self).__init__( |
503 templates, database, emitters, output_dir) | 516 templates, database, emitters, output_dir) |
504 self._shared = HtmlSystemShared(database, generator) | 517 self._shared = HtmlSystemShared(database, generator) |
505 | 518 |
506 class HtmlInterfacesSystem(HtmlSystem): | 519 class HtmlInterfacesSystem(HtmlSystem): |
507 | 520 |
508 def __init__(self, templates, database, emitters, output_dir, generator): | 521 def __init__(self, templates, database, emitters, output_dir, generator): |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 self._members_emitter.Emit( | 634 self._members_emitter.Emit( |
622 '\n' | 635 '\n' |
623 ' $CTOR(int length);\n' | 636 ' $CTOR(int length);\n' |
624 '\n' | 637 '\n' |
625 ' $CTOR.fromList(List<$TYPE> list);\n' | 638 ' $CTOR.fromList(List<$TYPE> list);\n' |
626 '\n' | 639 '\n' |
627 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | 640 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', |
628 CTOR=self._interface.id, | 641 CTOR=self._interface.id, |
629 TYPE=DartType(element_type)) | 642 TYPE=DartType(element_type)) |
630 | 643 |
644 events = self._shared.GetEventAttributes(self._interface) | |
645 if events != None: self.AddEventAttributes(events) | |
Jacob
2012/03/07 23:24:05
I believe we're using the style of placing the if
nweiz
2012/03/08 01:03:51
Done.
| |
646 | |
631 def AddAttribute(self, getter, setter): | 647 def AddAttribute(self, getter, setter): |
632 html_getter_name = self._shared.RenameInHtmlLibrary( | 648 html_getter_name = self._shared.RenameInHtmlLibrary( |
633 self._interface, getter.id, 'get:') | 649 self._interface, getter.id, 'get:') |
634 html_setter_name = self._shared.RenameInHtmlLibrary( | 650 html_setter_name = self._shared.RenameInHtmlLibrary( |
635 self._interface, getter.id, 'set:') | 651 self._interface, getter.id, 'set:') |
636 | 652 |
637 if not html_getter_name: | 653 if not html_getter_name: |
638 getter = None | 654 getter = None |
639 if not html_setter_name: | 655 if not html_setter_name: |
640 setter = None | 656 setter = None |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
751 NATIVESPEC=' native "' + native_spec + '"') | 767 NATIVESPEC=' native "' + native_spec + '"') |
752 | 768 |
753 if element_type: | 769 if element_type: |
754 self.AddTypedArrayConstructors(element_type) | 770 self.AddTypedArrayConstructors(element_type) |
755 | 771 |
756 # Emit a factory provider class for the constructor. | 772 # Emit a factory provider class for the constructor. |
757 constructor_info = AnalyzeConstructor(interface) | 773 constructor_info = AnalyzeConstructor(interface) |
758 if constructor_info: | 774 if constructor_info: |
759 self._EmitFactoryProvider(interface_name, constructor_info) | 775 self._EmitFactoryProvider(interface_name, constructor_info) |
760 | 776 |
777 events = self._shared.GetEventAttributes(interface) | |
778 if events != None: self.AddEventAttributes(events) | |
Jacob
2012/03/07 23:24:05
why not just
if events:
self.AddEventAttributes(
nweiz
2012/03/08 01:03:51
Because we want to run AddEventAttributes even if
Jacob
2012/03/08 18:38:09
same comment as above for all cases where == set()
| |
779 | |
761 def _EmitFactoryProvider(self, interface_name, constructor_info): | 780 def _EmitFactoryProvider(self, interface_name, constructor_info): |
762 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 781 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
763 template = self._system._templates.TryLoad(template_file) | 782 template = self._system._templates.TryLoad(template_file) |
764 if not template: | 783 if not template: |
765 template = self._system._templates.Load('factoryprovider.darttemplate') | 784 template = self._system._templates.Load('factoryprovider.darttemplate') |
766 | 785 |
767 factory_provider = '_' + interface_name + 'FactoryProvider' | 786 factory_provider = '_' + interface_name + 'FactoryProvider' |
768 emitter = self._system._ImplFileEmitter(factory_provider) | 787 emitter = self._system._ImplFileEmitter(factory_provider) |
769 emitter.Emit( | 788 emitter.Emit( |
770 template, | 789 template, |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 if dom_name != 'Document': | 1249 if dom_name != 'Document': |
1231 self._members_emitter.Emit( | 1250 self._members_emitter.Emit( |
1232 ' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', | 1251 ' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', |
1233 CLASSNAME=self._class_name) | 1252 CLASSNAME=self._class_name) |
1234 | 1253 |
1235 # Emit a factory provider class for the constructor. | 1254 # Emit a factory provider class for the constructor. |
1236 constructor_info = AnalyzeConstructor(interface) | 1255 constructor_info = AnalyzeConstructor(interface) |
1237 if constructor_info: | 1256 if constructor_info: |
1238 self._EmitFactoryProvider(interface_name, constructor_info) | 1257 self._EmitFactoryProvider(interface_name, constructor_info) |
1239 | 1258 |
1259 events = self._shared.GetEventAttributes(self._interface) | |
1260 if events != None: self.AddEventAttributes(events) | |
1261 | |
1240 def _EmitFactoryProvider(self, interface_name, constructor_info): | 1262 def _EmitFactoryProvider(self, interface_name, constructor_info): |
1241 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 1263 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
1242 template = self._system._templates.TryLoad(template_file) | 1264 template = self._system._templates.TryLoad(template_file) |
1243 if not template: | 1265 if not template: |
1244 template = self._system._templates.Load('factoryprovider.darttemplate') | 1266 template = self._system._templates.Load('factoryprovider.darttemplate') |
1245 | 1267 |
1246 factory_provider = '_' + interface_name + 'FactoryProvider' | 1268 factory_provider = '_' + interface_name + 'FactoryProvider' |
1247 emitter = self._system._ImplFileEmitter(factory_provider) | 1269 emitter = self._system._ImplFileEmitter(factory_provider) |
1248 emitter.Emit( | 1270 emitter.Emit( |
1249 template, | 1271 template, |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1715 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee | 1737 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee |
1716 # that Y = Z-X, so we need to check for Y. | 1738 # that Y = Z-X, so we need to check for Y. |
1717 true_code = emitter.Emit( | 1739 true_code = emitter.Emit( |
1718 '$(INDENT)if ($COND) {\n' | 1740 '$(INDENT)if ($COND) {\n' |
1719 '$!TRUE' | 1741 '$!TRUE' |
1720 '$(INDENT)}\n', | 1742 '$(INDENT)}\n', |
1721 COND=test, INDENT=indent) | 1743 COND=test, INDENT=indent) |
1722 self.GenerateDispatch( | 1744 self.GenerateDispatch( |
1723 true_code, info, indent + ' ', position + 1, positive) | 1745 true_code, info, indent + ' ', position + 1, positive) |
1724 return True | 1746 return True |
OLD | NEW |