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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 def _TraverseParents(self, interface, callback): | 472 def _TraverseParents(self, interface, callback): |
468 for parent in interface.parents: | 473 for parent in interface.parents: |
469 parent_id = parent.type.id | 474 parent_id = parent.type.id |
470 if self._database.HasInterface(parent_id): | 475 if self._database.HasInterface(parent_id): |
471 parent_interface = self._database.GetInterface(parent_id) | 476 parent_interface = self._database.GetInterface(parent_id) |
472 callback(parent_interface) | 477 callback(parent_interface) |
473 self._TraverseParents(parent_interface, callback) | 478 self._TraverseParents(parent_interface, callback) |
474 | 479 |
475 # TODO(jacobr): this isn't quite right.... | 480 # TODO(jacobr): this isn't quite right.... |
476 def GetParentsEventsClasses(self, interface): | 481 def GetParentsEventsClasses(self, interface): |
477 # Ugly hack as we don't specify that Document inherits from Element | 482 # Ugly hack as we don't specify that Document and DocumentFragment inherit |
478 # in our IDL. | 483 # from Element in our IDL. |
479 if interface.id == 'Document': | 484 if interface.id == 'Document' or interface.id == 'DocumentFragment': |
480 return ['ElementEvents'] | 485 return ['ElementEvents'] |
481 | 486 |
482 interfaces_with_events = set() | 487 interfaces_with_events = set() |
483 def visit(parent): | 488 def visit(parent): |
484 if parent.id in self._event_classes: | 489 if parent.id in self._event_classes: |
485 interfaces_with_events.add(parent) | 490 interfaces_with_events.add(parent) |
486 | 491 |
487 self._TraverseParents(interface, visit) | 492 self._TraverseParents(interface, visit) |
488 if len(interfaces_with_events) == 0: | 493 if len(interfaces_with_events) == 0: |
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 |
| 501 def GetParentEventsClass(self, interface): |
| 502 parent_event_classes = self.GetParentsEventsClasses(interface) |
| 503 if len(parent_event_classes) != 1: |
| 504 raise Exception('Only one parent event class allowed ' + interface.id) |
| 505 return parent_event_classes[0] |
| 506 |
496 def _ImplClassName(self, type_name): | 507 def _ImplClassName(self, type_name): |
497 return '_' + type_name + 'Impl' | 508 return '_' + type_name + 'Impl' |
498 | 509 |
| 510 # This returns two values: the first is whether or not an "on" property should |
| 511 # be generated for the interface, and the second is the event attributes to |
| 512 # generate if it should. |
| 513 def GetEventAttributes(self, interface): |
| 514 events = set([attr for attr in interface.attributes |
| 515 if self._generator._IsEventAttribute(interface, attr)]) |
| 516 |
| 517 if events or interface.id in _html_explicit_event_classes: |
| 518 return True, events |
| 519 else: |
| 520 return False |
| 521 |
499 class HtmlSystem(System): | 522 class HtmlSystem(System): |
500 | 523 |
501 def __init__(self, templates, database, emitters, output_dir, generator): | 524 def __init__(self, templates, database, emitters, output_dir, generator): |
502 super(HtmlSystem, self).__init__( | 525 super(HtmlSystem, self).__init__( |
503 templates, database, emitters, output_dir) | 526 templates, database, emitters, output_dir) |
504 self._shared = HtmlSystemShared(database, generator) | 527 self._shared = HtmlSystemShared(database, generator) |
505 | 528 |
506 class HtmlInterfacesSystem(HtmlSystem): | 529 class HtmlInterfacesSystem(HtmlSystem): |
507 | 530 |
508 def __init__(self, templates, database, emitters, output_dir, generator): | 531 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( | 644 self._members_emitter.Emit( |
622 '\n' | 645 '\n' |
623 ' $CTOR(int length);\n' | 646 ' $CTOR(int length);\n' |
624 '\n' | 647 '\n' |
625 ' $CTOR.fromList(List<$TYPE> list);\n' | 648 ' $CTOR.fromList(List<$TYPE> list);\n' |
626 '\n' | 649 '\n' |
627 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | 650 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', |
628 CTOR=self._interface.id, | 651 CTOR=self._interface.id, |
629 TYPE=DartType(element_type)) | 652 TYPE=DartType(element_type)) |
630 | 653 |
| 654 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 655 if not emit_events: |
| 656 return |
| 657 elif events: |
| 658 self.AddEventAttributes(events) |
| 659 else: |
| 660 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) |
| 661 |
631 def AddAttribute(self, getter, setter): | 662 def AddAttribute(self, getter, setter): |
632 html_getter_name = self._shared.RenameInHtmlLibrary( | 663 html_getter_name = self._shared.RenameInHtmlLibrary( |
633 self._interface, getter.id, 'get:') | 664 self._interface, getter.id, 'get:') |
634 html_setter_name = self._shared.RenameInHtmlLibrary( | 665 html_setter_name = self._shared.RenameInHtmlLibrary( |
635 self._interface, getter.id, 'set:') | 666 self._interface, getter.id, 'set:') |
636 | 667 |
637 if not html_getter_name: | 668 if not html_getter_name: |
638 getter = None | 669 getter = None |
639 if not html_setter_name: | 670 if not html_setter_name: |
640 setter = None | 671 setter = None |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 def FinishInterface(self): | 706 def FinishInterface(self): |
676 pass | 707 pass |
677 | 708 |
678 def AddConstant(self, constant): | 709 def AddConstant(self, constant): |
679 self._EmitConstant(self._members_emitter, constant) | 710 self._EmitConstant(self._members_emitter, constant) |
680 | 711 |
681 def AddEventAttributes(self, event_attrs): | 712 def AddEventAttributes(self, event_attrs): |
682 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) | 713 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) |
683 self._shared._event_classes.add(self._interface.id) | 714 self._shared._event_classes.add(self._interface.id) |
684 events_interface = self._interface.id + 'Events' | 715 events_interface = self._interface.id + 'Events' |
685 self._members_emitter.Emit('\n $TYPE get on();\n', | 716 self._EmitEventGetter(events_interface) |
686 TYPE=events_interface) | 717 |
687 events_members = self._emitter.Emit( | 718 events_members = self._emitter.Emit( |
688 '\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n', | 719 '\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n', |
689 INTERFACE=events_interface, | 720 INTERFACE=events_interface, |
690 PARENTS=', '.join( | 721 PARENTS=', '.join( |
691 self._shared.GetParentsEventsClasses(self._interface))) | 722 self._shared.GetParentsEventsClasses(self._interface))) |
692 | 723 |
693 for event_name in event_attrs: | 724 for event_name in event_attrs: |
694 if event_name in _html_event_names: | 725 if event_name in _html_event_names: |
695 events_members.Emit('\n EventListenerList get $NAME();\n', | 726 events_members.Emit('\n EventListenerList get $NAME();\n', |
696 NAME=_html_event_names[event_name]) | 727 NAME=_html_event_names[event_name]) |
697 else: | 728 else: |
698 raise Exception('No known html even name for event: ' + event_name) | 729 raise Exception('No known html even name for event: ' + event_name) |
699 | 730 |
| 731 def _EmitEventGetter(self, interface): |
| 732 self._members_emitter.Emit('\n $TYPE get on();\n', |
| 733 TYPE=interface) |
| 734 |
700 # ------------------------------------------------------------------------------ | 735 # ------------------------------------------------------------------------------ |
701 | 736 |
702 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 737 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
703 # term, but it makes merging better for now. | 738 # term, but it makes merging better for now. |
704 class HtmlFrogClassGenerator(FrogInterfaceGenerator): | 739 class HtmlFrogClassGenerator(FrogInterfaceGenerator): |
705 """Generates a Frog class for the dart:html library from a DOM IDL | 740 """Generates a Frog class for the dart:html library from a DOM IDL |
706 interface. | 741 interface. |
707 """ | 742 """ |
708 | 743 |
709 def __init__(self, system, interface, template, super_interface, dart_code, | 744 def __init__(self, system, interface, template, super_interface, dart_code, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 NATIVESPEC=' native "' + native_spec + '"') | 786 NATIVESPEC=' native "' + native_spec + '"') |
752 | 787 |
753 if element_type: | 788 if element_type: |
754 self.AddTypedArrayConstructors(element_type) | 789 self.AddTypedArrayConstructors(element_type) |
755 | 790 |
756 # Emit a factory provider class for the constructor. | 791 # Emit a factory provider class for the constructor. |
757 constructor_info = AnalyzeConstructor(interface) | 792 constructor_info = AnalyzeConstructor(interface) |
758 if constructor_info: | 793 if constructor_info: |
759 self._EmitFactoryProvider(interface_name, constructor_info) | 794 self._EmitFactoryProvider(interface_name, constructor_info) |
760 | 795 |
| 796 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 797 if not emit_events: |
| 798 return |
| 799 elif events: |
| 800 self.AddEventAttributes(events) |
| 801 else: |
| 802 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) |
| 803 |
761 def _EmitFactoryProvider(self, interface_name, constructor_info): | 804 def _EmitFactoryProvider(self, interface_name, constructor_info): |
762 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 805 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
763 template = self._system._templates.TryLoad(template_file) | 806 template = self._system._templates.TryLoad(template_file) |
764 if not template: | 807 if not template: |
765 template = self._system._templates.Load('factoryprovider.darttemplate') | 808 template = self._system._templates.Load('factoryprovider.darttemplate') |
766 | 809 |
767 factory_provider = '_' + interface_name + 'FactoryProvider' | 810 factory_provider = '_' + interface_name + 'FactoryProvider' |
768 emitter = self._system._ImplFileEmitter(factory_provider) | 811 emitter = self._system._ImplFileEmitter(factory_provider) |
769 emitter.Emit( | 812 emitter.Emit( |
770 template, | 813 template, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 ' $TYPE $NAME($PARAMS) native;\n', | 1022 ' $TYPE $NAME($PARAMS) native;\n', |
980 TYPE=self._NarrowOutputType(info.type_name), | 1023 TYPE=self._NarrowOutputType(info.type_name), |
981 NAME=info.name, | 1024 NAME=info.name, |
982 PARAMS=info.ParametersImplementationDeclaration( | 1025 PARAMS=info.ParametersImplementationDeclaration( |
983 lambda type_name: self._NarrowInputType(type_name))) | 1026 lambda type_name: self._NarrowInputType(type_name))) |
984 | 1027 |
985 def AddEventAttributes(self, event_attrs): | 1028 def AddEventAttributes(self, event_attrs): |
986 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) | 1029 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) |
987 events_class = '_' + self._interface.id + 'EventsImpl' | 1030 events_class = '_' + self._interface.id + 'EventsImpl' |
988 events_interface = self._interface.id + 'Events' | 1031 events_interface = self._interface.id + 'Events' |
989 self._members_emitter.Emit( | 1032 self._EmitEventGetter(events_class) |
990 '\n $TYPE get on() =>\n new $TYPE($EVENTTARGET);\n', | |
991 TYPE=events_class, | |
992 EVENTTARGET='_jsDocument' if self._interface.id == 'Document' | |
993 else 'this') | |
994 | 1033 |
995 self._shared._event_classes.add(self._interface.id) | 1034 self._shared._event_classes.add(self._interface.id) |
996 | 1035 |
997 parent_event_classes = self._shared.GetParentsEventsClasses( | 1036 parent_event_class = self._shared.GetParentEventsClass(self._interface) |
998 self._interface) | |
999 if len(parent_event_classes) != 1: | |
1000 raise Exception('Only one parent event class allowed ' | |
1001 + self._interface.id) | |
1002 | 1037 |
1003 # TODO(jacobr): specify the type of _ptr as EventTarget | 1038 # TODO(jacobr): specify the type of _ptr as EventTarget |
1004 events_members = self._dart_code.Emit( | 1039 events_members = self._dart_code.Emit( |
1005 '\n' | 1040 '\n' |
1006 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' | 1041 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' |
1007 ' $CLASSNAME(_ptr) : super(_ptr);\n' | 1042 ' $CLASSNAME(_ptr) : super(_ptr);\n' |
1008 '$!MEMBERS}\n', | 1043 '$!MEMBERS}\n', |
1009 CLASSNAME=events_class, | 1044 CLASSNAME=events_class, |
1010 INTERFACE=events_interface, | 1045 INTERFACE=events_interface, |
1011 SUPER='_' + parent_event_classes[0] + 'Impl') | 1046 SUPER='_' + parent_event_class + 'Impl') |
1012 | 1047 |
1013 for event_name in event_attrs: | 1048 for event_name in event_attrs: |
1014 if event_name in _html_event_names: | 1049 if event_name in _html_event_names: |
1015 events_members.Emit( | 1050 events_members.Emit( |
1016 "\n" | 1051 "\n" |
1017 " EventListenerList get $NAME() => _get('$RAWNAME');\n", | 1052 " EventListenerList get $NAME() => _get('$RAWNAME');\n", |
1018 RAWNAME=event_name, | 1053 RAWNAME=event_name, |
1019 NAME=_html_event_names[event_name]) | 1054 NAME=_html_event_names[event_name]) |
1020 else: | 1055 else: |
1021 raise Exception('No known html even name for event: ' + event_name) | 1056 raise Exception('No known html even name for event: ' + event_name) |
1022 | 1057 |
| 1058 def _EmitEventGetter(self, interface): |
| 1059 self._members_emitter.Emit( |
| 1060 '\n $TYPE get on() =>\n new $TYPE($EVENTTARGET);\n', |
| 1061 TYPE=interface, |
| 1062 EVENTTARGET='_jsDocument' if self._interface.id == 'Document' |
| 1063 else 'this') |
| 1064 |
1023 # ------------------------------------------------------------------------------ | 1065 # ------------------------------------------------------------------------------ |
1024 | 1066 |
1025 class HtmlFrogSystem(HtmlSystem): | 1067 class HtmlFrogSystem(HtmlSystem): |
1026 | 1068 |
1027 def __init__(self, templates, database, emitters, output_dir, generator): | 1069 def __init__(self, templates, database, emitters, output_dir, generator): |
1028 super(HtmlFrogSystem, self).__init__( | 1070 super(HtmlFrogSystem, self).__init__( |
1029 templates, database, emitters, output_dir, generator) | 1071 templates, database, emitters, output_dir, generator) |
1030 self._dart_frog_file_paths = [] | 1072 self._dart_frog_file_paths = [] |
1031 | 1073 |
1032 | 1074 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1230 if dom_name != 'Document': | 1272 if dom_name != 'Document': |
1231 self._members_emitter.Emit( | 1273 self._members_emitter.Emit( |
1232 ' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', | 1274 ' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', |
1233 CLASSNAME=self._class_name) | 1275 CLASSNAME=self._class_name) |
1234 | 1276 |
1235 # Emit a factory provider class for the constructor. | 1277 # Emit a factory provider class for the constructor. |
1236 constructor_info = AnalyzeConstructor(interface) | 1278 constructor_info = AnalyzeConstructor(interface) |
1237 if constructor_info: | 1279 if constructor_info: |
1238 self._EmitFactoryProvider(interface_name, constructor_info) | 1280 self._EmitFactoryProvider(interface_name, constructor_info) |
1239 | 1281 |
| 1282 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 1283 if not emit_events: |
| 1284 return |
| 1285 elif events: |
| 1286 self.AddEventAttributes(events) |
| 1287 else: |
| 1288 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) |
| 1289 |
1240 def _EmitFactoryProvider(self, interface_name, constructor_info): | 1290 def _EmitFactoryProvider(self, interface_name, constructor_info): |
1241 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 1291 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
1242 template = self._system._templates.TryLoad(template_file) | 1292 template = self._system._templates.TryLoad(template_file) |
1243 if not template: | 1293 if not template: |
1244 template = self._system._templates.Load('factoryprovider.darttemplate') | 1294 template = self._system._templates.Load('factoryprovider.darttemplate') |
1245 | 1295 |
1246 factory_provider = '_' + interface_name + 'FactoryProvider' | 1296 factory_provider = '_' + interface_name + 'FactoryProvider' |
1247 emitter = self._system._ImplFileEmitter(factory_provider) | 1297 emitter = self._system._ImplFileEmitter(factory_provider) |
1248 emitter.Emit( | 1298 emitter.Emit( |
1249 template, | 1299 template, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 self.AddAttribute(getter, setter) | 1396 self.AddAttribute(getter, setter) |
1347 | 1397 |
1348 def AddSecondaryOperation(self, interface, info): | 1398 def AddSecondaryOperation(self, interface, info): |
1349 self._SecondaryContext(interface) | 1399 self._SecondaryContext(interface) |
1350 self.AddOperation(info) | 1400 self.AddOperation(info) |
1351 | 1401 |
1352 def AddEventAttributes(self, event_attrs): | 1402 def AddEventAttributes(self, event_attrs): |
1353 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) | 1403 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) |
1354 events_class = '_' + self._interface.id + 'EventsImpl' | 1404 events_class = '_' + self._interface.id + 'EventsImpl' |
1355 events_interface = self._interface.id + 'Events' | 1405 events_interface = self._interface.id + 'Events' |
1356 self._members_emitter.Emit( | 1406 self._EmitEventGetter(events_class) |
1357 '\n' | |
1358 ' $TYPE get on() {\n' | |
1359 ' if (_on == null) _on = new $TYPE($EVENTTARGET);\n' | |
1360 ' return _on;\n' | |
1361 ' }\n', | |
1362 TYPE=events_class, | |
1363 EVENTTARGET='_wrappedDocumentPtr' if self._interface.id == 'Document' | |
1364 else 'this') | |
1365 | 1407 |
1366 self._shared._event_classes.add(self._interface.id) | 1408 self._shared._event_classes.add(self._interface.id) |
1367 | 1409 |
1368 parent_event_classes = self._shared.GetParentsEventsClasses( | 1410 parent_event_class = self._shared.GetParentEventsClass(self._interface) |
1369 self._interface) | |
1370 if len(parent_event_classes) != 1: | |
1371 raise Exception('Only one parent event class allowed ' | |
1372 + self._interface.id) | |
1373 | 1411 |
1374 # TODO(jacobr): specify the type of _ptr as EventTarget | 1412 # TODO(jacobr): specify the type of _ptr as EventTarget |
1375 events_members = self._dart_code.Emit( | 1413 events_members = self._dart_code.Emit( |
1376 '\n' | 1414 '\n' |
1377 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' | 1415 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' |
1378 ' $CLASSNAME(_ptr) : super(_ptr);\n' | 1416 ' $CLASSNAME(_ptr) : super(_ptr);\n' |
1379 '$!MEMBERS}\n', | 1417 '$!MEMBERS}\n', |
1380 CLASSNAME=events_class, | 1418 CLASSNAME=events_class, |
1381 INTERFACE=events_interface, | 1419 INTERFACE=events_interface, |
1382 SUPER='_' + parent_event_classes[0] + 'Impl') | 1420 SUPER='_' + parent_event_class + 'Impl') |
1383 | 1421 |
1384 for event_name in event_attrs: | 1422 for event_name in event_attrs: |
1385 if event_name in _html_event_names: | 1423 if event_name in _html_event_names: |
1386 events_members.Emit( | 1424 events_members.Emit( |
1387 "\n" | 1425 "\n" |
1388 " EventListenerList get $NAME() => _get('$RAWNAME');\n", | 1426 " EventListenerList get $NAME() => _get('$RAWNAME');\n", |
1389 RAWNAME=event_name, | 1427 RAWNAME=event_name, |
1390 NAME=_html_event_names[event_name]) | 1428 NAME=_html_event_names[event_name]) |
1391 else: | 1429 else: |
1392 raise Exception('No known html even name for event: ' + event_name) | 1430 raise Exception('No known html even name for event: ' + event_name) |
1393 | 1431 |
| 1432 def _EmitEventGetter(self, events_class): |
| 1433 self._members_emitter.Emit( |
| 1434 '\n' |
| 1435 ' $TYPE get on() {\n' |
| 1436 ' if (_on == null) _on = new $TYPE($EVENTTARGET);\n' |
| 1437 ' return _on;\n' |
| 1438 ' }\n', |
| 1439 TYPE=events_class, |
| 1440 EVENTTARGET='_wrappedDocumentPtr' if self._interface.id == 'Document' |
| 1441 else 'this') |
| 1442 |
1394 def _SecondaryContext(self, interface): | 1443 def _SecondaryContext(self, interface): |
1395 if interface is not self._current_secondary_parent: | 1444 if interface is not self._current_secondary_parent: |
1396 self._current_secondary_parent = interface | 1445 self._current_secondary_parent = interface |
1397 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 1446 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
1398 | 1447 |
1399 # TODO(jacobr): change this to more directly match the frog version. | 1448 # TODO(jacobr): change this to more directly match the frog version. |
1400 def AddIndexer(self, element_type): | 1449 def AddIndexer(self, element_type): |
1401 """Adds all the methods required to complete implementation of List.""" | 1450 """Adds all the methods required to complete implementation of List.""" |
1402 # We would like to simply inherit the implementation of everything except | 1451 # We would like to simply inherit the implementation of everything except |
1403 # get length(), [], and maybe []=. It is possible to extend from a base | 1452 # get length(), [], and maybe []=. It is possible to extend from a base |
(...skipping 311 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 | 1764 # 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. | 1765 # that Y = Z-X, so we need to check for Y. |
1717 true_code = emitter.Emit( | 1766 true_code = emitter.Emit( |
1718 '$(INDENT)if ($COND) {\n' | 1767 '$(INDENT)if ($COND) {\n' |
1719 '$!TRUE' | 1768 '$!TRUE' |
1720 '$(INDENT)}\n', | 1769 '$(INDENT)}\n', |
1721 COND=test, INDENT=indent) | 1770 COND=test, INDENT=indent) |
1722 self.GenerateDispatch( | 1771 self.GenerateDispatch( |
1723 true_code, info, indent + ' ', position + 1, positive) | 1772 true_code, info, indent + ' ', position + 1, positive) |
1724 return True | 1773 return True |
OLD | NEW |