| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 "Window.get:frameElement", | 255 "Window.get:frameElement", |
| 256 ]) | 256 ]) |
| 257 | 257 |
| 258 _html_library_custom = set([ | 258 _html_library_custom = set([ |
| 259 'IFrameElement.get:contentWindow', | 259 'IFrameElement.get:contentWindow', |
| 260 'Window.get:document', | 260 'Window.get:document', |
| 261 'Window.get:top', | 261 'Window.get:top', |
| 262 'IDBDatabase.transaction', | 262 'IDBDatabase.transaction', |
| 263 ]) | 263 ]) |
| 264 | 264 |
| 265 # This map controls merging of interfaces in dart:html library. |
| 266 # All constants, attributes, and operations of merged interface (key) are |
| 267 # added to target interface (value). All references to the merged interface |
| 268 # (e.g. parameter types, return types, parent interfaces) are replaced with |
| 269 # target interface. There are two important restrictions: |
| 270 # 1) Merged and target interfaces shouldn't have common members, otherwise there |
| 271 # would be duplicated declarations in generated Dart code. |
| 272 # 2) Merged interface should be direct child of target interface, so the |
| 273 # children of merged interface are not affected by the merge. |
| 274 # As a consequence, target interface implementation and its direct children |
| 275 # interface implementations should implement merged attribute accessors and |
| 276 # operations. For example, SVGElement and Element implementation classes should |
| 277 # implement HTMLElement.insertAdjacentElement(), HTMLElement.innerHTML, etc. |
| 278 _merged_html_interfaces = { |
| 279 'HTMLDocument': 'Document', |
| 280 'HTMLElement': 'Element' |
| 281 } |
| 282 |
| 265 # Events without onEventName attributes in the IDL we want to support. | 283 # Events without onEventName attributes in the IDL we want to support. |
| 266 # We can automatically extract most event event names by checking for | 284 # We can automatically extract most event event names by checking for |
| 267 # onEventName methods in the IDL but some events aren't listed so we need | 285 # onEventName methods in the IDL but some events aren't listed so we need |
| 268 # to manually add them here so that they are easy for users to find. | 286 # to manually add them here so that they are easy for users to find. |
| 269 _html_manual_events = { | 287 _html_manual_events = { |
| 270 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'], | 288 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'], |
| 271 'Window': ['DOMContentLoaded'] | 289 'Window': ['DOMContentLoaded'] |
| 272 } | 290 } |
| 273 | 291 |
| 274 # These event names must be camel case when attaching event listeners | 292 # These event names must be camel case when attaching event listeners |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 templates, database, emitters, output_dir) | 714 templates, database, emitters, output_dir) |
| 697 self._dart_interface_file_paths = [] | 715 self._dart_interface_file_paths = [] |
| 698 self._factory_provider_emitters = {} | 716 self._factory_provider_emitters = {} |
| 699 | 717 |
| 700 def InterfaceGenerator(self, | 718 def InterfaceGenerator(self, |
| 701 interface, | 719 interface, |
| 702 common_prefix, | 720 common_prefix, |
| 703 super_interface_name, | 721 super_interface_name, |
| 704 source_filter): | 722 source_filter): |
| 705 """.""" | 723 """.""" |
| 724 if interface.id in _merged_html_interfaces: |
| 725 return None |
| 726 |
| 706 interface_name = interface.id | 727 interface_name = interface.id |
| 707 dart_interface_file_path = self._FilePathForDartInterface(interface_name) | 728 dart_interface_file_path = self._FilePathForDartInterface(interface_name) |
| 708 | 729 |
| 709 self._dart_interface_file_paths.append(dart_interface_file_path) | 730 self._dart_interface_file_paths.append(dart_interface_file_path) |
| 710 | 731 |
| 711 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) | 732 dart_interface_code = self._emitters.FileEmitter(dart_interface_file_path) |
| 712 | 733 |
| 713 template_file = 'interface_%s.darttemplate' % interface_name | 734 template_file = 'interface_%s.darttemplate' % interface_name |
| 714 template = self._templates.TryLoad(template_file) | 735 template = self._templates.TryLoad(template_file) |
| 715 if not template: | 736 if not template: |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 TYPE=DartType(element_type)) | 852 TYPE=DartType(element_type)) |
| 832 | 853 |
| 833 emit_events, events = self._shared.GetEventAttributes(self._interface) | 854 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 834 if not emit_events: | 855 if not emit_events: |
| 835 return | 856 return |
| 836 elif events: | 857 elif events: |
| 837 self.AddEventAttributes(events) | 858 self.AddEventAttributes(events) |
| 838 else: | 859 else: |
| 839 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) | 860 self._EmitEventGetter(self._shared.GetParentEventsClass(self._interface)) |
| 840 | 861 |
| 862 for merged_interface in _merged_html_interfaces: |
| 863 if _merged_html_interfaces[merged_interface] == self._interface.id: |
| 864 self.AddMembers(self._database.GetInterface(merged_interface)) |
| 841 | 865 |
| 842 def AddAttribute(self, getter, setter): | 866 def AddAttribute(self, getter, setter): |
| 843 dom_name = DartDomNameOfAttribute(getter) | 867 dom_name = DartDomNameOfAttribute(getter) |
| 844 html_getter_name = self._shared.RenameInHtmlLibrary( | 868 html_getter_name = self._shared.RenameInHtmlLibrary( |
| 845 self._interface.id, dom_name, 'get:') | 869 self._interface.id, dom_name, 'get:') |
| 846 html_setter_name = self._shared.RenameInHtmlLibrary( | 870 html_setter_name = self._shared.RenameInHtmlLibrary( |
| 847 self._interface.id, dom_name, 'set:') | 871 self._interface.id, dom_name, 'set:') |
| 848 | 872 |
| 849 if not html_getter_name or self._shared.IsPrivate(html_getter_name): | 873 if not html_getter_name or self._shared.IsPrivate(html_getter_name): |
| 850 getter = None | 874 getter = None |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 | 1020 |
| 997 emit_events, events = self._shared.GetEventAttributes(self._interface) | 1021 emit_events, events = self._shared.GetEventAttributes(self._interface) |
| 998 if not emit_events: | 1022 if not emit_events: |
| 999 return | 1023 return |
| 1000 elif events: | 1024 elif events: |
| 1001 self.AddEventAttributes(events) | 1025 self.AddEventAttributes(events) |
| 1002 else: | 1026 else: |
| 1003 parent_events_class = self._shared.GetParentEventsClass(self._interface) | 1027 parent_events_class = self._shared.GetParentEventsClass(self._interface) |
| 1004 self._EmitEventGetter('_' + parent_events_class + 'Impl') | 1028 self._EmitEventGetter('_' + parent_events_class + 'Impl') |
| 1005 | 1029 |
| 1030 for merged_interface in _merged_html_interfaces: |
| 1031 if _merged_html_interfaces[merged_interface] == self._interface.id: |
| 1032 self.AddMembers(self._database.GetInterface(merged_interface)) |
| 1033 |
| 1006 def _EmitFactoryProvider(self, interface_name, constructor_info): | 1034 def _EmitFactoryProvider(self, interface_name, constructor_info): |
| 1007 template_file = 'factoryprovider_%s.darttemplate' % interface_name | 1035 template_file = 'factoryprovider_%s.darttemplate' % interface_name |
| 1008 template = self._system._templates.TryLoad(template_file) | 1036 template = self._system._templates.TryLoad(template_file) |
| 1009 if not template: | 1037 if not template: |
| 1010 template = self._system._templates.Load('factoryprovider.darttemplate') | 1038 template = self._system._templates.Load('factoryprovider.darttemplate') |
| 1011 | 1039 |
| 1012 factory_provider = '_' + interface_name + 'FactoryProvider' | 1040 factory_provider = '_' + interface_name + 'FactoryProvider' |
| 1013 emitter = self._system._ImplFileEmitter(factory_provider) | 1041 emitter = self._system._ImplFileEmitter(factory_provider) |
| 1014 emitter.Emit( | 1042 emitter.Emit( |
| 1015 template, | 1043 template, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1100 if ((getter and html_getter_name != getter.id) or | 1128 if ((getter and html_getter_name != getter.id) or |
| 1101 (setter and html_setter_name != setter.id)): | 1129 (setter and html_setter_name != setter.id)): |
| 1102 if getter: | 1130 if getter: |
| 1103 self._AddRenamingGetter(getter, html_getter_name) | 1131 self._AddRenamingGetter(getter, html_getter_name) |
| 1104 if setter: | 1132 if setter: |
| 1105 self._AddRenamingSetter(setter, html_setter_name) | 1133 self._AddRenamingSetter(setter, html_setter_name) |
| 1106 return | 1134 return |
| 1107 | 1135 |
| 1108 # If the (getter, setter) pair is shadowing, we can't generate a shadowing | 1136 # If the (getter, setter) pair is shadowing, we can't generate a shadowing |
| 1109 # field (Issue 1633). | 1137 # field (Issue 1633). |
| 1110 (super_getter, super_getter_interface) = self._FindShadowedAttribute(getter) | 1138 (super_getter, super_getter_interface) = self._FindShadowedAttribute(getter,
_merged_html_interfaces) |
| 1111 (super_setter, super_setter_interface) = self._FindShadowedAttribute(setter) | 1139 (super_setter, super_setter_interface) = self._FindShadowedAttribute(setter,
_merged_html_interfaces) |
| 1112 if super_getter or super_setter: | 1140 if super_getter or super_setter: |
| 1113 if getter and not setter and super_getter and not super_setter: | 1141 if getter and not setter and super_getter and not super_setter: |
| 1114 if DartType(getter.type.id) == DartType(super_getter.type.id): | 1142 if DartType(getter.type.id) == DartType(super_getter.type.id): |
| 1115 # Compatible getter, use the superclass property. This works because | 1143 # Compatible getter, use the superclass property. This works because |
| 1116 # JavaScript will do its own dynamic dispatch. | 1144 # JavaScript will do its own dynamic dispatch. |
| 1117 output_type = getter and self._NarrowOutputType(getter.type.id) | 1145 output_type = getter and self._NarrowOutputType(getter.type.id) |
| 1118 self._members_emitter.Emit( | 1146 self._members_emitter.Emit( |
| 1119 '\n' | 1147 '\n' |
| 1120 ' // Use implementation from $SUPER.\n' | 1148 ' // Use implementation from $SUPER.\n' |
| 1121 ' // final $TYPE $NAME;\n', | 1149 ' // final $TYPE $NAME;\n', |
| 1122 SUPER=super_getter_interface.id, | 1150 SUPER=super_getter_interface, |
| 1123 NAME=DartDomNameOfAttribute(getter), | 1151 NAME=DartDomNameOfAttribute(getter), |
| 1124 TYPE=output_type) | 1152 TYPE=output_type) |
| 1125 return | 1153 return |
| 1126 | 1154 |
| 1127 self._members_emitter.Emit('\n // Shadowing definition.') | 1155 self._members_emitter.Emit('\n // Shadowing definition.') |
| 1128 self._AddAttributeUsingProperties(getter, setter) | 1156 self._AddAttributeUsingProperties(getter, setter) |
| 1129 return | 1157 return |
| 1130 | 1158 |
| 1131 output_type = getter and self._NarrowOutputType(getter.type.id) | 1159 output_type = getter and self._NarrowOutputType(getter.type.id) |
| 1132 input_type = setter and self._NarrowInputType(setter.type.id) | 1160 input_type = setter and self._NarrowInputType(setter.type.id) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 templates, database, emitters, output_dir) | 1280 templates, database, emitters, output_dir) |
| 1253 self._dart_frog_file_paths = [] | 1281 self._dart_frog_file_paths = [] |
| 1254 self._factory_provider_emitters = {} | 1282 self._factory_provider_emitters = {} |
| 1255 | 1283 |
| 1256 def InterfaceGenerator(self, | 1284 def InterfaceGenerator(self, |
| 1257 interface, | 1285 interface, |
| 1258 common_prefix, | 1286 common_prefix, |
| 1259 super_interface_name, | 1287 super_interface_name, |
| 1260 source_filter): | 1288 source_filter): |
| 1261 """.""" | 1289 """.""" |
| 1290 if interface.id in _merged_html_interfaces: |
| 1291 return None |
| 1292 |
| 1262 if IsPureInterface(interface.id): | 1293 if IsPureInterface(interface.id): |
| 1263 return | 1294 return |
| 1264 template_file = 'impl_%s.darttemplate' % interface.id | 1295 template_file = 'impl_%s.darttemplate' % interface.id |
| 1265 template = self._templates.TryLoad(template_file) | 1296 template = self._templates.TryLoad(template_file) |
| 1266 if not template: | 1297 if not template: |
| 1267 template = self._templates.Load('frog_impl.darttemplate') | 1298 template = self._templates.Load('frog_impl.darttemplate') |
| 1268 | 1299 |
| 1269 dart_code = self._ImplFileEmitter(interface.id) | 1300 dart_code = self._ImplFileEmitter(interface.id) |
| 1270 return HtmlFrogClassGenerator(self, interface, template, | 1301 return HtmlFrogClassGenerator(self, interface, template, |
| 1271 super_interface_name, dart_code, self._shared) | 1302 super_interface_name, dart_code, self._shared) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 Collect(database.GetInterface(parent.type.id), | 1384 Collect(database.GetInterface(parent.type.id), |
| 1354 seen, collected) | 1385 seen, collected) |
| 1355 | 1386 |
| 1356 inheritance_closure = {} | 1387 inheritance_closure = {} |
| 1357 for interface in database.GetInterfaces(): | 1388 for interface in database.GetInterfaces(): |
| 1358 seen = set() | 1389 seen = set() |
| 1359 collected = [] | 1390 collected = [] |
| 1360 Collect(interface, seen, collected) | 1391 Collect(interface, seen, collected) |
| 1361 inheritance_closure[interface.id] = collected | 1392 inheritance_closure[interface.id] = collected |
| 1362 return inheritance_closure | 1393 return inheritance_closure |
| OLD | NEW |