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 GetOneParentEventsClass(self, interface): | |
Jacob
2012/03/08 21:45:11
Nit: remove the word "One" from this method name.
nweiz
2012/03/08 22:14:45
Done.
| |
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 def GetEventAttributes(self, interface): | |
sra1
2012/03/08 21:58:59
Since this returns two distinct falsy values, plea
nweiz
2012/03/08 22:14:45
Done.
| |
511 events = set([attr for attr in interface.attributes | |
512 if self._generator._IsEventAttribute(interface, attr)]) | |
513 | |
514 if events or interface.id in _html_explicit_event_classes: | |
515 return events | |
sra1
2012/03/08 21:58:59
Add 'return None'
Implicit return of None looks li
nweiz
2012/03/08 22:14:45
Done.
| |
516 | |
499 class HtmlSystem(System): | 517 class HtmlSystem(System): |
500 | 518 |
501 def __init__(self, templates, database, emitters, output_dir, generator): | 519 def __init__(self, templates, database, emitters, output_dir, generator): |
502 super(HtmlSystem, self).__init__( | 520 super(HtmlSystem, self).__init__( |
503 templates, database, emitters, output_dir) | 521 templates, database, emitters, output_dir) |
504 self._shared = HtmlSystemShared(database, generator) | 522 self._shared = HtmlSystemShared(database, generator) |
505 | 523 |
506 class HtmlInterfacesSystem(HtmlSystem): | 524 class HtmlInterfacesSystem(HtmlSystem): |
507 | 525 |
508 def __init__(self, templates, database, emitters, output_dir, generator): | 526 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( | 639 self._members_emitter.Emit( |
622 '\n' | 640 '\n' |
623 ' $CTOR(int length);\n' | 641 ' $CTOR(int length);\n' |
624 '\n' | 642 '\n' |
625 ' $CTOR.fromList(List<$TYPE> list);\n' | 643 ' $CTOR.fromList(List<$TYPE> list);\n' |
626 '\n' | 644 '\n' |
627 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', | 645 ' $CTOR.fromBuffer(ArrayBuffer buffer);\n', |
628 CTOR=self._interface.id, | 646 CTOR=self._interface.id, |
629 TYPE=DartType(element_type)) | 647 TYPE=DartType(element_type)) |
630 | 648 |
649 events = self._shared.GetEventAttributes(self._interface) | |
650 if events == set(): | |
sra1
2012/03/08 21:58:59
This is slightly confusing, since pythonic style i
nweiz
2012/03/08 22:14:45
Why is explicitly comparing to None less confusing
Jacob
2012/03/08 22:33:38
I think the issue is that making code behave diffe
nweiz
2012/03/08 22:52:45
Good idea. Done.
sra1
2012/03/08 23:07:32
Idea 1:
Do we need to emit the no-added-methods on
| |
651 self._EmitEventGetter( | |
652 self._shared.GetOneParentEventsClass(self._interface)) | |
653 elif events: | |
654 self.AddEventAttributes(events) | |
655 | |
631 def AddAttribute(self, getter, setter): | 656 def AddAttribute(self, getter, setter): |
632 html_getter_name = self._shared.RenameInHtmlLibrary( | 657 html_getter_name = self._shared.RenameInHtmlLibrary( |
633 self._interface, getter.id, 'get:') | 658 self._interface, getter.id, 'get:') |
634 html_setter_name = self._shared.RenameInHtmlLibrary( | 659 html_setter_name = self._shared.RenameInHtmlLibrary( |
635 self._interface, getter.id, 'set:') | 660 self._interface, getter.id, 'set:') |
636 | 661 |
637 if not html_getter_name: | 662 if not html_getter_name: |
638 getter = None | 663 getter = None |
639 if not html_setter_name: | 664 if not html_setter_name: |
640 setter = None | 665 setter = None |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 def FinishInterface(self): | 700 def FinishInterface(self): |
676 pass | 701 pass |
677 | 702 |
678 def AddConstant(self, constant): | 703 def AddConstant(self, constant): |
679 self._EmitConstant(self._members_emitter, constant) | 704 self._EmitConstant(self._members_emitter, constant) |
680 | 705 |
681 def AddEventAttributes(self, event_attrs): | 706 def AddEventAttributes(self, event_attrs): |
682 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) | 707 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) |
683 self._shared._event_classes.add(self._interface.id) | 708 self._shared._event_classes.add(self._interface.id) |
684 events_interface = self._interface.id + 'Events' | 709 events_interface = self._interface.id + 'Events' |
685 self._members_emitter.Emit('\n $TYPE get on();\n', | 710 self._EmitEventGetter(events_interface) |
686 TYPE=events_interface) | 711 |
687 events_members = self._emitter.Emit( | 712 events_members = self._emitter.Emit( |
688 '\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n', | 713 '\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n', |
689 INTERFACE=events_interface, | 714 INTERFACE=events_interface, |
690 PARENTS=', '.join( | 715 PARENTS=', '.join( |
691 self._shared.GetParentsEventsClasses(self._interface))) | 716 self._shared.GetParentsEventsClasses(self._interface))) |
692 | 717 |
693 for event_name in event_attrs: | 718 for event_name in event_attrs: |
694 if event_name in _html_event_names: | 719 if event_name in _html_event_names: |
695 events_members.Emit('\n EventListenerList get $NAME();\n', | 720 events_members.Emit('\n EventListenerList get $NAME();\n', |
696 NAME=_html_event_names[event_name]) | 721 NAME=_html_event_names[event_name]) |
697 else: | 722 else: |
698 raise Exception('No known html even name for event: ' + event_name) | 723 raise Exception('No known html even name for event: ' + event_name) |
699 | 724 |
725 def _EmitEventGetter(self, interface): | |
sra1
2012/03/08 23:07:32
can we call this events_interface for uniformity w
| |
726 self._members_emitter.Emit('\n $TYPE get on();\n', | |
727 TYPE=interface) | |
728 | |
700 # ------------------------------------------------------------------------------ | 729 # ------------------------------------------------------------------------------ |
701 | 730 |
702 # TODO(jmesserly): inheritance is probably not the right way to factor this long | 731 # TODO(jmesserly): inheritance is probably not the right way to factor this long |
703 # term, but it makes merging better for now. | 732 # term, but it makes merging better for now. |
704 class HtmlFrogClassGenerator(FrogInterfaceGenerator): | 733 class HtmlFrogClassGenerator(FrogInterfaceGenerator): |
705 """Generates a Frog class for the dart:html library from a DOM IDL | 734 """Generates a Frog class for the dart:html library from a DOM IDL |
706 interface. | 735 interface. |
707 """ | 736 """ |
708 | 737 |
709 def __init__(self, system, interface, template, super_interface, dart_code, | 738 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 + '"') | 780 NATIVESPEC=' native "' + native_spec + '"') |
752 | 781 |
753 if element_type: | 782 if element_type: |
754 self.AddTypedArrayConstructors(element_type) | 783 self.AddTypedArrayConstructors(element_type) |
755 | 784 |
756 # Emit a factory provider class for the constructor. | 785 # Emit a factory provider class for the constructor. |
757 constructor_info = AnalyzeConstructor(interface) | 786 constructor_info = AnalyzeConstructor(interface) |
758 if constructor_info: | 787 if constructor_info: |
759 self._EmitFactoryProvider(interface_name, constructor_info) | 788 self._EmitFactoryProvider(interface_name, constructor_info) |
760 | 789 |
790 events = self._shared.GetEventAttributes(self._interface) | |
791 if events == set(): | |
792 self._EmitEventGetter( | |
793 self._shared.GetOneParentEventsClass(self._interface)) | |
794 elif events: | |
795 self.AddEventAttributes(events) | |
796 | |
761 def _EmitFactoryProvider(self, interface_name, constructor_info): | 797 def _EmitFactoryProvider(self, interface_name, constructor_info): |
762 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 798 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
763 template = self._system._templates.TryLoad(template_file) | 799 template = self._system._templates.TryLoad(template_file) |
764 if not template: | 800 if not template: |
765 template = self._system._templates.Load('factoryprovider.darttemplate') | 801 template = self._system._templates.Load('factoryprovider.darttemplate') |
766 | 802 |
767 factory_provider = '_' + interface_name + 'FactoryProvider' | 803 factory_provider = '_' + interface_name + 'FactoryProvider' |
768 emitter = self._system._ImplFileEmitter(factory_provider) | 804 emitter = self._system._ImplFileEmitter(factory_provider) |
769 emitter.Emit( | 805 emitter.Emit( |
770 template, | 806 template, |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
979 ' $TYPE $NAME($PARAMS) native;\n', | 1015 ' $TYPE $NAME($PARAMS) native;\n', |
980 TYPE=self._NarrowOutputType(info.type_name), | 1016 TYPE=self._NarrowOutputType(info.type_name), |
981 NAME=info.name, | 1017 NAME=info.name, |
982 PARAMS=info.ParametersImplementationDeclaration( | 1018 PARAMS=info.ParametersImplementationDeclaration( |
983 lambda type_name: self._NarrowInputType(type_name))) | 1019 lambda type_name: self._NarrowInputType(type_name))) |
984 | 1020 |
985 def AddEventAttributes(self, event_attrs): | 1021 def AddEventAttributes(self, event_attrs): |
986 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) | 1022 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) |
987 events_class = '_' + self._interface.id + 'EventsImpl' | 1023 events_class = '_' + self._interface.id + 'EventsImpl' |
988 events_interface = self._interface.id + 'Events' | 1024 events_interface = self._interface.id + 'Events' |
989 self._members_emitter.Emit( | 1025 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 | 1026 |
995 self._shared._event_classes.add(self._interface.id) | 1027 self._shared._event_classes.add(self._interface.id) |
996 | 1028 |
997 parent_event_classes = self._shared.GetParentsEventsClasses( | 1029 parent_event_class = self._shared.GetOneParentEventsClass(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 | 1030 |
1003 # TODO(jacobr): specify the type of _ptr as EventTarget | 1031 # TODO(jacobr): specify the type of _ptr as EventTarget |
1004 events_members = self._dart_code.Emit( | 1032 events_members = self._dart_code.Emit( |
1005 '\n' | 1033 '\n' |
1006 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' | 1034 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' |
1007 ' $CLASSNAME(_ptr) : super(_ptr);\n' | 1035 ' $CLASSNAME(_ptr) : super(_ptr);\n' |
1008 '$!MEMBERS}\n', | 1036 '$!MEMBERS}\n', |
1009 CLASSNAME=events_class, | 1037 CLASSNAME=events_class, |
1010 INTERFACE=events_interface, | 1038 INTERFACE=events_interface, |
1011 SUPER='_' + parent_event_classes[0] + 'Impl') | 1039 SUPER='_' + parent_event_class + 'Impl') |
1012 | 1040 |
1013 for event_name in event_attrs: | 1041 for event_name in event_attrs: |
1014 if event_name in _html_event_names: | 1042 if event_name in _html_event_names: |
1015 events_members.Emit( | 1043 events_members.Emit( |
1016 "\n" | 1044 "\n" |
1017 " EventListenerList get $NAME() => _get('$RAWNAME');\n", | 1045 " EventListenerList get $NAME() => _get('$RAWNAME');\n", |
1018 RAWNAME=event_name, | 1046 RAWNAME=event_name, |
1019 NAME=_html_event_names[event_name]) | 1047 NAME=_html_event_names[event_name]) |
1020 else: | 1048 else: |
1021 raise Exception('No known html even name for event: ' + event_name) | 1049 raise Exception('No known html even name for event: ' + event_name) |
1022 | 1050 |
1051 def _EmitEventGetter(self, interface): | |
sra1
2012/03/08 23:07:32
interface -> events_class ?
| |
1052 self._members_emitter.Emit( | |
1053 '\n $TYPE get on() =>\n new $TYPE($EVENTTARGET);\n', | |
1054 TYPE=interface, | |
1055 EVENTTARGET='_jsDocument' if self._interface.id == 'Document' | |
1056 else 'this') | |
1057 | |
1023 # ------------------------------------------------------------------------------ | 1058 # ------------------------------------------------------------------------------ |
1024 | 1059 |
1025 class HtmlFrogSystem(HtmlSystem): | 1060 class HtmlFrogSystem(HtmlSystem): |
1026 | 1061 |
1027 def __init__(self, templates, database, emitters, output_dir, generator): | 1062 def __init__(self, templates, database, emitters, output_dir, generator): |
1028 super(HtmlFrogSystem, self).__init__( | 1063 super(HtmlFrogSystem, self).__init__( |
1029 templates, database, emitters, output_dir, generator) | 1064 templates, database, emitters, output_dir, generator) |
1030 self._dart_frog_file_paths = [] | 1065 self._dart_frog_file_paths = [] |
1031 | 1066 |
1032 | 1067 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1230 if dom_name != 'Document': | 1265 if dom_name != 'Document': |
1231 self._members_emitter.Emit( | 1266 self._members_emitter.Emit( |
1232 ' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', | 1267 ' $(CLASSNAME)._wrap(ptr) : super._wrap(ptr);\n', |
1233 CLASSNAME=self._class_name) | 1268 CLASSNAME=self._class_name) |
1234 | 1269 |
1235 # Emit a factory provider class for the constructor. | 1270 # Emit a factory provider class for the constructor. |
1236 constructor_info = AnalyzeConstructor(interface) | 1271 constructor_info = AnalyzeConstructor(interface) |
1237 if constructor_info: | 1272 if constructor_info: |
1238 self._EmitFactoryProvider(interface_name, constructor_info) | 1273 self._EmitFactoryProvider(interface_name, constructor_info) |
1239 | 1274 |
1275 events = self._shared.GetEventAttributes(self._interface) | |
1276 if events == set(): | |
1277 self._EmitEventGetter( | |
1278 self._shared.GetOneParentEventsClass(self._interface)) | |
1279 elif events: | |
1280 self.AddEventAttributes(events) | |
1281 | |
1240 def _EmitFactoryProvider(self, interface_name, constructor_info): | 1282 def _EmitFactoryProvider(self, interface_name, constructor_info): |
1241 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 1283 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
1242 template = self._system._templates.TryLoad(template_file) | 1284 template = self._system._templates.TryLoad(template_file) |
1243 if not template: | 1285 if not template: |
1244 template = self._system._templates.Load('factoryprovider.darttemplate') | 1286 template = self._system._templates.Load('factoryprovider.darttemplate') |
1245 | 1287 |
1246 factory_provider = '_' + interface_name + 'FactoryProvider' | 1288 factory_provider = '_' + interface_name + 'FactoryProvider' |
1247 emitter = self._system._ImplFileEmitter(factory_provider) | 1289 emitter = self._system._ImplFileEmitter(factory_provider) |
1248 emitter.Emit( | 1290 emitter.Emit( |
1249 template, | 1291 template, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1346 self.AddAttribute(getter, setter) | 1388 self.AddAttribute(getter, setter) |
1347 | 1389 |
1348 def AddSecondaryOperation(self, interface, info): | 1390 def AddSecondaryOperation(self, interface, info): |
1349 self._SecondaryContext(interface) | 1391 self._SecondaryContext(interface) |
1350 self.AddOperation(info) | 1392 self.AddOperation(info) |
1351 | 1393 |
1352 def AddEventAttributes(self, event_attrs): | 1394 def AddEventAttributes(self, event_attrs): |
1353 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) | 1395 event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs) |
1354 events_class = '_' + self._interface.id + 'EventsImpl' | 1396 events_class = '_' + self._interface.id + 'EventsImpl' |
1355 events_interface = self._interface.id + 'Events' | 1397 events_interface = self._interface.id + 'Events' |
1356 self._members_emitter.Emit( | 1398 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 | 1399 |
1366 self._shared._event_classes.add(self._interface.id) | 1400 self._shared._event_classes.add(self._interface.id) |
1367 | 1401 |
1368 parent_event_classes = self._shared.GetParentsEventsClasses( | 1402 parent_event_class = self._shared.GetOneParentEventsClass(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 | 1403 |
1374 # TODO(jacobr): specify the type of _ptr as EventTarget | 1404 # TODO(jacobr): specify the type of _ptr as EventTarget |
1375 events_members = self._dart_code.Emit( | 1405 events_members = self._dart_code.Emit( |
1376 '\n' | 1406 '\n' |
1377 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' | 1407 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' |
1378 ' $CLASSNAME(_ptr) : super(_ptr);\n' | 1408 ' $CLASSNAME(_ptr) : super(_ptr);\n' |
1379 '$!MEMBERS}\n', | 1409 '$!MEMBERS}\n', |
1380 CLASSNAME=events_class, | 1410 CLASSNAME=events_class, |
1381 INTERFACE=events_interface, | 1411 INTERFACE=events_interface, |
1382 SUPER='_' + parent_event_classes[0] + 'Impl') | 1412 SUPER='_' + parent_event_class + 'Impl') |
1383 | 1413 |
1384 for event_name in event_attrs: | 1414 for event_name in event_attrs: |
1385 if event_name in _html_event_names: | 1415 if event_name in _html_event_names: |
1386 events_members.Emit( | 1416 events_members.Emit( |
1387 "\n" | 1417 "\n" |
1388 " EventListenerList get $NAME() => _get('$RAWNAME');\n", | 1418 " EventListenerList get $NAME() => _get('$RAWNAME');\n", |
1389 RAWNAME=event_name, | 1419 RAWNAME=event_name, |
1390 NAME=_html_event_names[event_name]) | 1420 NAME=_html_event_names[event_name]) |
1391 else: | 1421 else: |
1392 raise Exception('No known html even name for event: ' + event_name) | 1422 raise Exception('No known html even name for event: ' + event_name) |
1393 | 1423 |
1424 def _EmitEventGetter(self, events_class): | |
1425 self._members_emitter.Emit( | |
1426 '\n' | |
1427 ' $TYPE get on() {\n' | |
1428 ' if (_on == null) _on = new $TYPE($EVENTTARGET);\n' | |
1429 ' return _on;\n' | |
1430 ' }\n', | |
1431 TYPE=events_class, | |
1432 EVENTTARGET='_wrappedDocumentPtr' if self._interface.id == 'Document' | |
1433 else 'this') | |
1434 | |
1394 def _SecondaryContext(self, interface): | 1435 def _SecondaryContext(self, interface): |
1395 if interface is not self._current_secondary_parent: | 1436 if interface is not self._current_secondary_parent: |
1396 self._current_secondary_parent = interface | 1437 self._current_secondary_parent = interface |
1397 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) | 1438 self._members_emitter.Emit('\n // From $WHERE\n', WHERE=interface.id) |
1398 | 1439 |
1399 # TODO(jacobr): change this to more directly match the frog version. | 1440 # TODO(jacobr): change this to more directly match the frog version. |
1400 def AddIndexer(self, element_type): | 1441 def AddIndexer(self, element_type): |
1401 """Adds all the methods required to complete implementation of List.""" | 1442 """Adds all the methods required to complete implementation of List.""" |
1402 # We would like to simply inherit the implementation of everything except | 1443 # We would like to simply inherit the implementation of everything except |
1403 # get length(), [], and maybe []=. It is possible to extend from a base | 1444 # 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 | 1756 # 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. | 1757 # that Y = Z-X, so we need to check for Y. |
1717 true_code = emitter.Emit( | 1758 true_code = emitter.Emit( |
1718 '$(INDENT)if ($COND) {\n' | 1759 '$(INDENT)if ($COND) {\n' |
1719 '$!TRUE' | 1760 '$!TRUE' |
1720 '$(INDENT)}\n', | 1761 '$(INDENT)}\n', |
1721 COND=test, INDENT=indent) | 1762 COND=test, INDENT=indent) |
1722 self.GenerateDispatch( | 1763 self.GenerateDispatch( |
1723 true_code, info, indent + ' ', position + 1, positive) | 1764 true_code, info, indent + ' ', position + 1, positive) |
1724 return True | 1765 return True |
OLD | NEW |