| 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 | 10 |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' | 709 'class $CLASSNAME extends $SUPER implements $INTERFACE {\n' |
| 710 ' $CLASSNAME(_ptr) : super(_ptr);\n' | 710 ' $CLASSNAME(_ptr) : super(_ptr);\n' |
| 711 '$!MEMBERS}\n', | 711 '$!MEMBERS}\n', |
| 712 CLASSNAME=events_class, | 712 CLASSNAME=events_class, |
| 713 INTERFACE=events_interface, | 713 INTERFACE=events_interface, |
| 714 SUPER=parent_events_class) | 714 SUPER=parent_events_class) |
| 715 | 715 |
| 716 event_attrs = DomToHtmlEvents(self._html_interface_name, event_attrs) | 716 event_attrs = DomToHtmlEvents(self._html_interface_name, event_attrs) |
| 717 for event_name in event_attrs: | 717 for event_name in event_attrs: |
| 718 if event_name in _html_event_names: | 718 if event_name in _html_event_names: |
| 719 events_members.Emit('\n EventListenerList get $NAME();\n', | 719 events_members.Emit('\n EventListenerList get $NAME;\n', |
| 720 NAME=_html_event_names[event_name]) | 720 NAME=_html_event_names[event_name]) |
| 721 implementation_events_members.Emit( | 721 implementation_events_members.Emit( |
| 722 "\n" | 722 "\n" |
| 723 " EventListenerList get $NAME() => this['$DOM_NAME'];\n", | 723 " EventListenerList get $NAME => this['$DOM_NAME'];\n", |
| 724 NAME=_html_event_names[event_name], | 724 NAME=_html_event_names[event_name], |
| 725 DOM_NAME=event_name) | 725 DOM_NAME=event_name) |
| 726 else: | 726 else: |
| 727 raise Exception('No known html even name for event: ' + event_name) | 727 raise Exception('No known html even name for event: ' + event_name) |
| 728 | 728 |
| 729 def _EmitEventGetter(self, events_interface, events_class): | 729 def _EmitEventGetter(self, events_interface, events_class): |
| 730 self._members_emitter.Emit( | 730 self._members_emitter.Emit( |
| 731 '\n /**' | 731 '\n /**' |
| 732 '\n * @domName EventTarget.addEventListener, ' | 732 '\n * @domName EventTarget.addEventListener, ' |
| 733 'EventTarget.removeEventListener, EventTarget.dispatchEvent' | 733 'EventTarget.removeEventListener, EventTarget.dispatchEvent' |
| 734 '\n */' | 734 '\n */' |
| 735 '\n $TYPE get on();\n', | 735 '\n $TYPE get on;\n', |
| 736 TYPE=events_interface) | 736 TYPE=events_interface) |
| 737 | 737 |
| 738 self._implementation_members_emitter.Emit( | 738 self._implementation_members_emitter.Emit( |
| 739 '\n $TYPE get on() =>\n new $TYPE(this);\n', | 739 '\n $TYPE get on =>\n new $TYPE(this);\n', |
| 740 TYPE=events_class) | 740 TYPE=events_class) |
| 741 | 741 |
| 742 | 742 |
| 743 class HtmlGeneratorDummyBackend(object): | 743 class HtmlGeneratorDummyBackend(object): |
| 744 def AddAttribute(self, attribute, html_name, read_only): | 744 def AddAttribute(self, attribute, html_name, read_only): |
| 745 pass | 745 pass |
| 746 | 746 |
| 747 def AddOperation(self, info, html_name): | 747 def AddOperation(self, info, html_name): |
| 748 pass | 748 pass |
| 749 | 749 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 template, | 849 template, |
| 850 FACTORYPROVIDER=factory_provider, | 850 FACTORYPROVIDER=factory_provider, |
| 851 CONSTRUCTOR=self._html_interface_name, | 851 CONSTRUCTOR=self._html_interface_name, |
| 852 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), | 852 PARAMETERS=constructor_info.ParametersImplementationDeclaration(self._Da
rtType), |
| 853 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, | 853 NAMED_CONSTRUCTOR=constructor_info.name or self._html_interface_name, |
| 854 ARGUMENTS=constructor_info.ParametersAsArgumentList()) | 854 ARGUMENTS=constructor_info.ParametersAsArgumentList()) |
| 855 | 855 |
| 856 def AddIndexer(self, element_type): | 856 def AddIndexer(self, element_type): |
| 857 """Adds all the methods required to complete implementation of List.""" | 857 """Adds all the methods required to complete implementation of List.""" |
| 858 # We would like to simply inherit the implementation of everything except | 858 # We would like to simply inherit the implementation of everything except |
| 859 # get length(), [], and maybe []=. It is possible to extend from a base | 859 # length, [], and maybe []=. It is possible to extend from a base |
| 860 # array implementation class only when there is no other implementation | 860 # array implementation class only when there is no other implementation |
| 861 # inheritance. There might be no implementation inheritance other than | 861 # inheritance. There might be no implementation inheritance other than |
| 862 # DOMBaseWrapper for many classes, but there might be some where the | 862 # DOMBaseWrapper for many classes, but there might be some where the |
| 863 # array-ness is introduced by a non-root interface: | 863 # array-ness is introduced by a non-root interface: |
| 864 # | 864 # |
| 865 # interface Y extends X, List<T> ... | 865 # interface Y extends X, List<T> ... |
| 866 # | 866 # |
| 867 # In the non-root case we have to choose between: | 867 # In the non-root case we have to choose between: |
| 868 # | 868 # |
| 869 # class YImpl extends XImpl { add List<T> methods; } | 869 # class YImpl extends XImpl { add List<T> methods; } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 self._AddRenamingGetter(attribute, html_name) | 958 self._AddRenamingGetter(attribute, html_name) |
| 959 if not read_only: | 959 if not read_only: |
| 960 self._AddRenamingSetter(attribute, html_name) | 960 self._AddRenamingSetter(attribute, html_name) |
| 961 | 961 |
| 962 def _AddRenamingGetter(self, attr, html_name): | 962 def _AddRenamingGetter(self, attr, html_name): |
| 963 conversion = self._OutputConversion(attr.type.id, attr.id) | 963 conversion = self._OutputConversion(attr.type.id, attr.id) |
| 964 if conversion: | 964 if conversion: |
| 965 return self._AddConvertingGetter(attr, html_name, conversion) | 965 return self._AddConvertingGetter(attr, html_name, conversion) |
| 966 return_type = self._NarrowOutputType(attr.type.id) | 966 return_type = self._NarrowOutputType(attr.type.id) |
| 967 self._members_emitter.Emit( | 967 self._members_emitter.Emit( |
| 968 '\n $TYPE get $HTML_NAME() native "return this.$NAME;";\n', | 968 '\n $TYPE get $HTML_NAME native "return this.$NAME;";\n', |
| 969 HTML_NAME=html_name, | 969 HTML_NAME=html_name, |
| 970 NAME=attr.id, | 970 NAME=attr.id, |
| 971 TYPE=return_type) | 971 TYPE=return_type) |
| 972 | 972 |
| 973 def _AddRenamingSetter(self, attr, html_name): | 973 def _AddRenamingSetter(self, attr, html_name): |
| 974 conversion = self._InputConversion(attr.type.id, attr.id) | 974 conversion = self._InputConversion(attr.type.id, attr.id) |
| 975 if conversion: | 975 if conversion: |
| 976 return self._AddConvertingSetter(attr, html_name, conversion) | 976 return self._AddConvertingSetter(attr, html_name, conversion) |
| 977 self._members_emitter.Emit( | 977 self._members_emitter.Emit( |
| 978 '\n void set $HTML_NAME($TYPE value)' | 978 '\n void set $HTML_NAME($TYPE value)' |
| 979 ' native "this.$NAME = value;";\n', | 979 ' native "this.$NAME = value;";\n', |
| 980 HTML_NAME=html_name, | 980 HTML_NAME=html_name, |
| 981 NAME=attr.id, | 981 NAME=attr.id, |
| 982 TYPE=self._NarrowInputType(attr.type.id)) | 982 TYPE=self._NarrowInputType(attr.type.id)) |
| 983 | 983 |
| 984 def _AddConvertingGetter(self, attr, html_name, conversion): | 984 def _AddConvertingGetter(self, attr, html_name, conversion): |
| 985 self._members_emitter.Emit( | 985 self._members_emitter.Emit( |
| 986 '\n $RETURN_TYPE get $HTML_NAME() => $CONVERT(this._$(HTML_NAME));' | 986 '\n $RETURN_TYPE get $HTML_NAME => $CONVERT(this._$(HTML_NAME));' |
| 987 '\n $NATIVE_TYPE get _$HTML_NAME() native "return this.$NAME;";' | 987 '\n $NATIVE_TYPE get _$HTML_NAME native "return this.$NAME;";' |
| 988 '\n', | 988 '\n', |
| 989 CONVERT=conversion.function_name, | 989 CONVERT=conversion.function_name, |
| 990 HTML_NAME=html_name, | 990 HTML_NAME=html_name, |
| 991 NAME=attr.id, | 991 NAME=attr.id, |
| 992 RETURN_TYPE=conversion.output_type, | 992 RETURN_TYPE=conversion.output_type, |
| 993 NATIVE_TYPE=conversion.input_type) | 993 NATIVE_TYPE=conversion.input_type) |
| 994 | 994 |
| 995 def _AddConvertingSetter(self, attr, html_name, conversion): | 995 def _AddConvertingSetter(self, attr, html_name, conversion): |
| 996 self._members_emitter.Emit( | 996 self._members_emitter.Emit( |
| 997 '\n void set $HTML_NAME($INPUT_TYPE value) {' | 997 '\n void set $HTML_NAME($INPUT_TYPE value) {' |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 return HtmlDart2JSClassGenerator(self, interface) | 1233 return HtmlDart2JSClassGenerator(self, interface) |
| 1234 | 1234 |
| 1235 def GenerateLibraries(self, dart_files): | 1235 def GenerateLibraries(self, dart_files): |
| 1236 self._GenerateLibFile( | 1236 self._GenerateLibFile( |
| 1237 'html_dart2js.darttemplate', | 1237 'html_dart2js.darttemplate', |
| 1238 os.path.join(self._output_dir, 'html_dart2js.dart'), | 1238 os.path.join(self._output_dir, 'html_dart2js.dart'), |
| 1239 dart_files) | 1239 dart_files) |
| 1240 | 1240 |
| 1241 def Finish(self): | 1241 def Finish(self): |
| 1242 pass | 1242 pass |
| OLD | NEW |