Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
scripts.systemhtml.HtmlDartInterfaceGenerator Class Reference
Inheritance diagram for scripts.systemhtml.HtmlDartInterfaceGenerator:

Public Member Functions

def __init__ (self, options, library_emitter, event_generator, prototype_event_generator, interface, backend)
 
def Generate (self)
 
def GenerateCallback (self)
 
def GenerateInterface (self)
 

Detailed Description

Generates dart interface and implementation for the DOM IDL interface.

Definition at line 596 of file systemhtml.py.

Constructor & Destructor Documentation

◆ __init__()

def scripts.systemhtml.HtmlDartInterfaceGenerator.__init__ (   self,
  options,
  library_emitter,
  event_generator,
  prototype_event_generator,
  interface,
  backend 
)

Definition at line 599 of file systemhtml.py.

600 prototype_event_generator, interface, backend):
601 self._renamer = options.renamer
602 self._database = options.database
603 self._template_loader = options.templates
604 self._type_registry = options.type_registry
605 self._options = options
606 self._library_emitter = library_emitter
607 self._event_generator = event_generator
608 self._prototype_event_generator = prototype_event_generator
609 self._interface = interface
610 self._backend = backend
611 self._interface_type_info = self._type_registry.TypeInfo(
612 self._interface.id)
613 self._library_name = self._renamer.GetLibraryName(self._interface)
614 self._metadata = options.metadata
615

Member Function Documentation

◆ Generate()

def scripts.systemhtml.HtmlDartInterfaceGenerator.Generate (   self)

Definition at line 616 of file systemhtml.py.

616 def Generate(self):
617 if IsCustomType(self._interface.id):
618 pass
619 elif 'Callback' in self._interface.ext_attrs:
620 if len(GetCallbackHandlers(self._interface)) > 0:
621 self.GenerateCallback()
622 elif generateCallbackInterface(self._interface.id):
623 self.GenerateInterface()
624 else:
625 return
626 else:
627 self.GenerateInterface()
628

◆ GenerateCallback()

def scripts.systemhtml.HtmlDartInterfaceGenerator.GenerateCallback (   self)
Generates a typedef for the callback interface.

Definition at line 629 of file systemhtml.py.

629 def GenerateCallback(self):
630 """Generates a typedef for the callback interface."""
631 typedef_name = self._renamer.RenameInterface(self._interface)
632 if not typedef_name:
633 return
634
635 info = GetCallbackInfo(self._interface)
636 code = self._library_emitter.FileEmitter(self._interface.id,
637 self._library_name)
638 code.Emit(self._template_loader.Load('callback.darttemplate'))
639
640 annotations = self._metadata.GetFormattedMetadata(
641 self._library_name, self._interface)
642
643 params = info.ParametersAsDeclaration(self._DartType)
644
645 types = params.split()
646 if len(types) > 0:
647 mapType = types[0] in _callback_list_generics_mapping
648 if mapType is True:
649 types[0] = 'List'
650 params = " ".join(types)
651
652 code.Emit(
653 '$(ANNOTATIONS)typedef void $NAME($PARAMS);\n',
654 ANNOTATIONS=annotations,
655 NAME=typedef_name,
656 PARAMS=params)
657 self._backend.GenerateCallback(info)
658
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741

◆ GenerateInterface()

def scripts.systemhtml.HtmlDartInterfaceGenerator.GenerateInterface (   self)

Definition at line 659 of file systemhtml.py.

659 def GenerateInterface(self):
660 interface_name = self._interface_type_info.interface_name()
661
662 implementation_name = self._interface_type_info.implementation_name()
663 self._library_emitter.AddTypeEntry(
664 self._library_name, self._interface.id, implementation_name)
665
666 factory_provider = None
667 if interface_name in interface_factories:
668 factory_provider = interface_factories[interface_name]
669 factory_constructor_name = None
670
671 constructors = []
672 if interface_name in _static_classes:
673 constructor_info = None
674 else:
675 constructor_info = AnalyzeConstructor(self._interface)
676 if constructor_info:
677 constructors.append(constructor_info)
678 # TODO(antonm): consider removing it later.
679 factory_provider = interface_name
680
681 # HTML Elements and SVG Elements have convenience constructors.
683 self._interface.id,
684 _element_constructors[self._library_name],
685 factory_provider_name=_factory_ctr_strings[self._library_name]
686 ['provider_name'])
687
688 if infos:
689 factory_constructor_name = _factory_ctr_strings[
690 self._library_name]['constructor_name']
691
692 for info in infos:
693 constructors.append(info.ConstructorInfo(self._interface.id))
694 if factory_provider and factory_provider != info.factory_provider_name:
695 _logger.warn('Conflicting factory provider names: %s != %s' %
696 (factory_provider, info.factory_provider_name))
697 factory_provider = info.factory_provider_name
698
699 implementation_emitter = self._ImplementationEmitter()
700
701 base_type_info = None
702 if self._interface.parents:
703 supertype = self._interface.parents[0].type.id
704 if not IsDartCollectionType(supertype) and not IsPureInterface(
705 supertype, self._database):
706 base_type_info = self._type_registry.TypeInfo(supertype)
707
708 if base_type_info:
709 base_class = base_type_info.implementation_name()
710 else:
711 base_class = self._backend.RootClassName()
712
713 implements = self._backend.AdditionalImplementedInterfaces()
714 for parent in self._interface.parents:
715 parent_type_info = self._type_registry.TypeInfo(parent.type.id)
716 if parent_type_info.interface_name() != base_class and \
717 parent_type_info != base_type_info:
718 implements.append(parent_type_info.interface_name())
719
720 secure_base_name = self._backend.SecureBaseName(interface_name)
721 if secure_base_name:
722 implements.append(secure_base_name)
723
724 implements_str = ''
725 if implements:
726 # Get rid of duplicates using OrderedDict.
727 implements = list(OrderedDict([(i, None) for i in implements]))
728 implements_str = ' implements ' + ', '.join(implements)
729
730 mixins = self._backend.Mixins()
731
732 mixins_str = ''
733 if mixins:
734 mixins_str = ' with ' + ', '.join(mixins)
735 if not base_class:
736 base_class = 'JavaScriptObject'
737 elif (base_class == 'NativeFieldWrapperClass2' and
738 self._options.dart_js_interop and
739 not (isinstance(self._backend, Dart2JSBackend))):
740 base_class = 'DartHtmlDomObject'
741
742 annotations = self._metadata.GetFormattedMetadata(
743 self._library_name, self._interface, None, '')
744
745 class_modifiers = ''
746 if (self._renamer.ShouldSuppressInterface(self._interface) or
747 IsPureInterface(self._interface.id, self._database)):
748 # XMLHttpRequestProgressEvent can't be abstract we need to instantiate
749 # for JsInterop.
750 if (not (isinstance(self._backend, Dart2JSBackend)) and
751 (self._interface.id == 'XMLHttpRequestProgressEvent' or
752 self._interface.id == 'DOMStringMap')):
753 # Suppress abstract for XMLHttpRequestProgressEvent and DOMStringMap
754 # for Dartium. Need to be able to instantiate the class; can't be abstract.
755 class_modifiers = ''
756 else:
757 # For Dartium w/ JsInterop these suppressed interfaces are needed to
758 # instantiate the internal classes.
759 if (self._renamer.ShouldSuppressInterface(self._interface) and
760 not (isinstance(self._backend, Dart2JSBackend)) and
761 self._options.dart_js_interop):
762 class_modifiers = ''
763 else:
764 class_modifiers = 'abstract '
765
766 native_spec = ''
767 if not IsPureInterface(self._interface.id, self._database):
768 native_spec = self._backend.NativeSpec()
769
770 class_name = self._interface_type_info.implementation_name()
771
772 js_interop_wrapper = '''
773
774 @Deprecated("Internal Use Only")
775 external static Type get instanceRuntimeType;
776
777 @Deprecated("Internal Use Only")
778 {0}.internal_() : super.internal_();
779
780'''.format(class_name)
781 if base_class == 'NativeFieldWrapperClass2' or base_class == 'DartHtmlDomObject':
782 js_interop_wrapper = '''
783
784 @Deprecated("Internal Use Only")
785 external static Type get instanceRuntimeType;
786
787 @Deprecated("Internal Use Only")
788 {0}.internal_() {{ }}
789'''.format(class_name)
790 # Change to use the synthesized class so we can construct with a mixin
791 # classes prefixed with name of NativeFieldWrapperClass2 don't have a
792 # default constructor so classes with mixins can't be new'd.
793 if (self._options.templates._conditions['DARTIUM'] and
794 self._options.dart_js_interop and
795 (self._interface.id == 'NamedNodeMap' or
796 self._interface.id == 'CSSStyleDeclaration')):
797 base_class = 'DartHtmlDomObject'
798
799 maplikeKeyType = ''
800 maplikeValueType = ''
801 if self._interface.isMaplike:
802 maplikeKeyType = self._type_registry.\
803 _TypeInfo(self._interface.maplike_key_value[0].id).dart_type()
804 maplikeValueType = 'dynamic'
805 mixins_str = " with MapMixin<%s, %s>" % (maplikeKeyType,
806 maplikeValueType)
807
808 implementation_members_emitter = implementation_emitter.Emit(
809 self._backend.ImplementationTemplate(),
810 LIBRARYNAME='dart.dom.%s' % self._library_name,
811 ANNOTATIONS=annotations,
812 CLASS_MODIFIERS=class_modifiers,
813 CLASSNAME=class_name,
814 EXTENDS=' extends %s' % base_class if base_class else '',
815 IMPLEMENTS=implements_str,
816 MIXINS=mixins_str,
817 DOMNAME=self._interface.doc_js_name,
818 NATIVESPEC=native_spec,
819 KEYTYPE=maplikeKeyType,
820 VALUETYPE=maplikeValueType,
821 NULLABLE='?',
822 NULLSAFECAST=True,
823 NULLASSERT='!')
824 if self._interface.doc_js_name is 'RadioNodeList':
825 print(self._backend.ImplementationTemplate())
826 print(implementation_members_emitter)
827 stream_getter_signatures_emitter = None
828 element_stream_getters_emitter = None
829 class_members_emitter = None
830 if type(implementation_members_emitter) == tuple:
831 # We add event stream getters for both Element and ElementList, so in
832 # impl_Element.darttemplate, we have two additional "holes" for emitters
833 # to fill in, with small variations. These store these specialized
834 # emitters.
835 if (len(implementation_members_emitter) == 3):
836 stream_getter_signatures_emitter = \
837 implementation_members_emitter[0]
838 element_stream_getters_emitter = implementation_members_emitter[
839 1]
840 implementation_members_emitter = \
841 implementation_members_emitter[2]
842
843 # We add special emitters for classes migrated to static type extensions
844 elif (len(implementation_members_emitter) == 2):
845 class_members_emitter = \
846 implementation_members_emitter[0]
847 implementation_members_emitter = \
848 implementation_members_emitter[1]
849 self._backend.StartInterface(implementation_members_emitter)
850 self._backend.EmitHelpers(base_class, class_members_emitter)
851 self._event_generator.EmitStreamProviders(
852 self._interface, self._backend.CustomJSMembers(),
853 implementation_members_emitter, self._library_name)
854 self._prototype_event_generator.CollectStreamProviders(
855 self._interface, self._backend.CustomJSMembers(),
856 self._library_name)
857 self._backend.AddConstructors(constructors, factory_provider,
858 factory_constructor_name,
859 class_members_emitter)
860
861 isElement = False
862 for parent in self._database.Hierarchy(self._interface):
863 if parent.id == 'Element':
864 isElement = True
865
866 # Write out the JsInterop code.
867 if (implementation_members_emitter and
868 self._options.templates._conditions['DARTIUM'] and
869 self._options.dart_js_interop and
870 not IsPureInterface(self._interface.id, self._database)):
871 implementation_members_emitter.Emit(js_interop_wrapper)
872
873 if isElement and self._interface.id != 'Element':
874 implementation_members_emitter.Emit(
875 ' /**\n'
876 ' * Constructor instantiated by the DOM when a custom element has been created.\n'
877 ' *\n'
878 ' * This can only be called by subclasses from their created constructor.\n'
879 ' */\n'
880 ' $CLASSNAME.created() : super.created();\n',
881 CLASSNAME=self._interface_type_info.implementation_name())
882
883 self._backend.EmitSupportCheck()
884
885 merged_interface = self._interface_type_info.merged_interface()
886 if merged_interface:
887 self._backend.AddMembers(
888 self._database.GetInterface(merged_interface),
889 not self._backend.ImplementsMergedMembers())
890
891 self._backend.AddMembers(self._interface, False,
892 self._options.dart_js_interop)
893 self._backend.AddSecondaryMembers(self._interface)
894 self._event_generator.EmitStreamGetters(
895 self._interface, [], implementation_members_emitter,
896 self._library_name, stream_getter_signatures_emitter,
897 element_stream_getters_emitter)
898 self._prototype_event_generator.CollectStreamGetters(
899 self._interface, [], self._library_name)
900 self._backend.FinishInterface()
901
GLenum type
def print(*args, **kwargs)
Definition: run_tests.py:49
def ElementConstructorInfos(typename, element_constructors, factory_provider_name='_Elements')
Definition: systemhtml.py:444

The documentation for this class was generated from the following file: