5"""Generates the dart:html event providers and getters for the prototype."""
10OUTPUT_FILE =
'prototype_events.dart'
12_custom_events =
set([
'mouseWheel',
'transitionEnd',
'visibilityChange'])
14_type_specific_events =
set([
'doubleClick',
'error'])
16_deprecated_event_interfaces =
set([
17 'AccessibleNode',
'AccessibleNodeList',
'ApplicationCache',
'FileWriter',
20_deprecated_event_types =
set([
'ForeignFetchEvent',
'MediaStreamEvent'])
23 'prototype_htmleventgenerator._non_html_events', {
24 'ContextEvent':
'web_gl',
25 'Database':
'indexed_db',
26 'OpenDBRequest':
'indexed_db',
27 'Request':
'indexed_db',
29 'Transaction':
'indexed_db',
30 'VersionChangeEvent':
'indexed_db'
36 def __init__(self, database, renamer, metadata, htmleventgenerator):
51 for event_info
in events:
52 (dom_name, html_name, event_type) = event_info
54 if html_name
in _custom_events:
56 annotation_name = dom_name +
'Event'
58 annotations = self.
_metadata.FormatMetadata(
59 self.
_metadata.GetMetadata(library_name, interface,
60 annotation_name,
'on' + dom_name),
64 if '/**' in annotations:
65 annotations = annotations[annotations.index(
'*/') + 2:]
67 html_name = (html_name
if html_name
not in _type_specific_events
68 else html_name + interface.doc_js_name)
71 {html_name: [annotations, dom_name, event_type]})
79 for event_info
in events:
80 (dom_name, html_name, event_type) = event_info
82 if html_name
in _custom_events:
84 getter_name =
'on%s%s' % (html_name[:1].upper(), html_name[1:])
85 annotation_name =
'on' + dom_name
87 annotations = self.
_metadata.GetFormattedMetadata(
88 library_name, interface, annotation_name,
' ')
91 if '///' in annotations:
92 annotations = annotations[annotations.index(
'\n') + 1:]
95 html_name = (html_name
if html_name
not in _type_specific_events
96 else html_name + interface.doc_js_name)
97 provider = html_name +
'Event'
99 interface_events.update(
100 {getter_name: [annotations, event_type, provider]})
104 def _isElement(self, interface):
105 for parent
in self.
_database.Hierarchy(interface):
106 if parent.id ==
'Element':
111 def _formatEventType(self, event_type):
112 if '.' in event_type:
113 event_type = event_type[event_type.index(
'.') + 1:]
118 output_file = open(OUTPUT_FILE,
'w')
119 output_file.write(
"""
120/// Exposing the Streams of events for legacy dart:html.
121library dart.html_events;
123import 'dart:html' as html;
124import 'dart:html_common';
125import 'dart:indexed_db' as indexed_db;
126import 'dart:event_stream' show ElementStream, EventStreamProvider;
127import 'dart:svg' as svg;
128import 'dart:web_gl' as web_gl;
134 formatCommand =
' '.
join([dart_bin,
'format', OUTPUT_FILE])
135 subprocess.call([formatCommand], shell=
True)
138 def _writeProviders(self, output_file):
139 output_file.write(
"""
140/// Statically accessible `EventStreamProvider`s for all event types.
141class EventStreamProviders {
144 (annotations, dom_name, event_type) = info
145 if event_type
in _deprecated_event_types:
147 event_prefix = (
'html' if event_type
not in _non_html_types
else
148 _non_html_types[event_type])
149 output_file.write(
"""
150 %sstatic const EventStreamProvider<%s.%s> %sEvent =
151 const EventStreamProvider<%s.%s>('%s');
152""" % (annotations, event_prefix, event_type, html_name, event_prefix,
153 event_type, dom_name))
154 output_file.write("""\n}\n""")
157 def _writeEventGetters(self, output_file):
160 interface_name = interface.doc_js_name
161 if interface_name
in _deprecated_event_interfaces:
163 interface_name = self.
_renamer.RenameInterface(interface)
164 interface_prefix = (
'html' if interface_name
not in _non_html_types
165 else _non_html_types[interface_name])
166 output_file.write(
"""
168/// Additional Event getters for [%s].
169extension %sEventGetters on %s.%s {
170""" % (interface_name, interface_name, interface_prefix, interface_name))
171 for getter_name, info
in sorted(events.items()):
172 (annotations, event_type, provider) = info
173 if event_type
in _deprecated_event_types:
175 event_prefix = (
'html' if event_type
not in _non_html_types
else
176 _non_html_types[event_type])
177 output_file.write(
"""
179%sStream<%s.%s> get %s => EventStreamProviders.%s.%s(this);
180""" % (annotations,
'Element' if isElement
else '', event_prefix, event_type,
181 getter_name, provider,
'forElement' if isElement
else 'forTarget'))
182 output_file.write(
"""\n}\n""")
def __init__(self, database, renamer, metadata, htmleventgenerator)
def _writeEventGetters(self, output_file)
def _writeProviders(self, output_file)
def CollectStreamGetters(self, interface, custom_events, library_name)
def WriteFile(self, dart_bin)
def _formatEventType(self, event_type)
def CollectStreamProviders(self, interface, custom_events, library_name)
def _isElement(self, interface)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not set
static SkString join(const CommandLineFlags::StringArray &)