Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: lib/dom/scripts/systemnative.py

Issue 10332144: Move html events generation to domimpl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/dom/scripts/systemhtml.py ('k') | lib/dom/src/native_EventsImplementation.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 systems to generate 6 """This module provides shared functionality for the systems to generate
7 native binding from the IDL database.""" 7 native binding from the IDL database."""
8 8
9 import emitter 9 import emitter
10 import os 10 import os
11 from generator import * 11 from generator import *
12 from systembase import * 12 from systembase import *
13 from systemhtml import DomToHtmlEvent, DomToHtmlEvents
13 14
14 class NativeImplementationSystem(System): 15 class NativeImplementationSystem(System):
15 16
16 def __init__(self, templates, database, emitters, auxiliary_dir, output_dir): 17 def __init__(self, templates, database, html_renames, emitters, auxiliary_dir,
18 output_dir):
17 super(NativeImplementationSystem, self).__init__( 19 super(NativeImplementationSystem, self).__init__(
18 templates, database, emitters, output_dir) 20 templates, database, emitters, output_dir)
19 21
22 self._html_renames = html_renames
20 self._auxiliary_dir = auxiliary_dir 23 self._auxiliary_dir = auxiliary_dir
21 self._dom_public_files = [] 24 self._dom_public_files = []
22 self._dom_impl_files = [] 25 self._dom_impl_files = []
23 self._cpp_header_files = [] 26 self._cpp_header_files = []
24 self._cpp_impl_files = [] 27 self._cpp_impl_files = []
25 28
26 def InterfaceGenerator(self, 29 def InterfaceGenerator(self,
27 interface, 30 interface,
28 common_prefix, 31 common_prefix,
29 super_interface_name, 32 super_interface_name,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 def StartInterface(self): 241 def StartInterface(self):
239 self._class_name = self._ImplClassName(self._interface.id) 242 self._class_name = self._ImplClassName(self._interface.id)
240 self._interface_type_info = GetIDLTypeInfo(self._interface.id) 243 self._interface_type_info = GetIDLTypeInfo(self._interface.id)
241 self._members_emitter = emitter.Emitter() 244 self._members_emitter = emitter.Emitter()
242 self._cpp_declarations_emitter = emitter.Emitter() 245 self._cpp_declarations_emitter = emitter.Emitter()
243 self._cpp_impl_includes = set() 246 self._cpp_impl_includes = set()
244 self._cpp_definitions_emitter = emitter.Emitter() 247 self._cpp_definitions_emitter = emitter.Emitter()
245 self._cpp_resolver_emitter = emitter.Emitter() 248 self._cpp_resolver_emitter = emitter.Emitter()
246 249
247 self._GenerateConstructors() 250 self._GenerateConstructors()
251 self._GenerateEvents()
248 252
249 def _GenerateConstructors(self): 253 def _GenerateConstructors(self):
250 if not self._IsConstructable(): 254 if not self._IsConstructable():
251 return 255 return
252 256
253 # TODO(antonm): currently we don't have information about number of argument s expected by 257 # TODO(antonm): currently we don't have information about number of argument s expected by
254 # the constructor, so name only dispatch. 258 # the constructor, so name only dispatch.
255 self._cpp_resolver_emitter.Emit( 259 self._cpp_resolver_emitter.Emit(
256 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n' 260 ' if (name == "$(INTERFACE_NAME)_constructor_Callback")\n'
257 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n', 261 ' return Dart$(INTERFACE_NAME)Internal::constructorCallback;\n',
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 arguments.append(argument_expression) 311 arguments.append(argument_expression)
308 312
309 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function) 313 function_expression = '%s::%s' % (self._interface_type_info.native_type(), c reate_function)
310 invocation = self._GenerateWebCoreInvocation(function_expression, arguments, 314 invocation = self._GenerateWebCoreInvocation(function_expression, arguments,
311 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions) 315 self._interface.id, self._interface.ext_attrs, raises_dom_exceptions)
312 self._GenerateNativeCallback(callback_name='constructorCallback', 316 self._GenerateNativeCallback(callback_name='constructorCallback',
313 parameter_definitions=parameter_definitions_emitter.Fragments(), 317 parameter_definitions=parameter_definitions_emitter.Fragments(),
314 needs_receiver=False, invocation=invocation, 318 needs_receiver=False, invocation=invocation,
315 raises_exceptions=raises_exceptions) 319 raises_exceptions=raises_exceptions)
316 320
321 def _GenerateEvents(self):
322 if self._interface.id == 'DocumentFragment':
323 # Interface DocumentFragment extends Element in dart:html but this fact
324 # is not reflected in idls.
325 self._EmitEventGetter('ElementEventsImplementation')
326 return
327
328 events_attributes = [attr for attr in self._interface.attributes
329 if attr.type.id == 'EventListener']
330 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
331 return
332
333 def IsEventTarget(interface):
334 return ('EventTarget' in interface.ext_attrs and
335 interface.id != 'EventTarget')
336 is_root = not _FindParent(self._interface, self._system._database, IsEventTa rget)
337 if is_root:
338 self._members_emitter.Emit(' EventsImplementation _on;\n')
339
340 if not events_attributes:
341 if is_root:
342 self._EmitEventGetter('EventsImplementation')
343 return
344
345 events_class = '%sEventsImplementation' % self._interface.id
346 self._EmitEventGetter(events_class)
347
348 def HasEventAttributes(interface):
349 return any([a.type.id == 'EventListener' for a in interface.attributes])
350 parent = _FindParent(self._interface, self._system._database, HasEventAttrib utes)
351 if parent:
352 parent_events_class = '%sEventsImplementation' % parent.id
353 else:
354 parent_events_class = 'EventsImplementation'
355 html_inteface = self._system._html_renames.get(self._interface.id, self._int erface.id)
356 events_members = self._dart_impl_emitter.Emit(
357 '\n'
358 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n'
359 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n'
360 '$!MEMBERS\n'
361 '}\n',
362 EVENTS_CLASS=events_class,
363 PARENT_EVENTS_CLASS=parent_events_class,
364 EVENTS_INTERFACE='html.%sEvents' % html_inteface)
365
366 events_attributes = DomToHtmlEvents(self._interface.id, events_attributes)
367 for event_name in events_attributes:
368 events_members.Emit(
369 ' EventListenerList get $HTML_NAME() => this[\'$DOM_NAME\'];\n',
370 HTML_NAME=DomToHtmlEvent(event_name),
371 DOM_NAME=event_name)
372
373 def _EmitEventGetter(self, events_class):
374 self._members_emitter.Emit(
375 '\n'
376 ' $EVENTS_CLASS get on() {\n'
377 ' if (_on === null) _on = new $EVENTS_CLASS(this);\n'
378 ' return _on;\n'
379 ' }\n',
380 EVENTS_CLASS=events_class)
381
317 def _ImplClassName(self, interface_name): 382 def _ImplClassName(self, interface_name):
318 return interface_name + 'Implementation' 383 return interface_name + 'Implementation'
319 384
320 def _BaseClassName(self): 385 def _BaseClassName(self):
321 if not self._interface.parents: 386 if not self._interface.parents:
322 return 'DOMWrapperBase' 387 return 'DOMWrapperBase'
323 388
324 supertype = self._interface.parents[0].type.id 389 supertype = self._interface.parents[0].type.id
325 390
326 # FIXME: We're currently injecting List<..> and EventTarget as 391 # FIXME: We're currently injecting List<..> and EventTarget as
(...skipping 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments))) 1192 FUNCTION_CALL='%s(%s)' % (function_expression, ', '.join(arguments)))
1128 1193
1129 def _GenerateCPPIncludes(includes): 1194 def _GenerateCPPIncludes(includes):
1130 return ''.join(['#include %s\n' % include for include in includes]) 1195 return ''.join(['#include %s\n' % include for include in includes])
1131 1196
1132 def _DOMWrapperType(database, interface): 1197 def _DOMWrapperType(database, interface):
1133 if interface.id == 'MessagePort': 1198 if interface.id == 'MessagePort':
1134 return 'MessagePort' 1199 return 'MessagePort'
1135 1200
1136 type = 'Object' 1201 type = 'Object'
1137 if _InstanceOfNode(database, interface): 1202 def is_node(interface):
1203 return interface.id == 'Node'
1204 if is_node(interface) or _FindParent(interface, database, is_node):
1138 type = 'Node' 1205 type = 'Node'
1139 if 'ActiveDOMObject' in interface.ext_attrs: 1206 if 'ActiveDOMObject' in interface.ext_attrs:
1140 type = 'Active%s' % type 1207 type = 'Active%s' % type
1141 return type 1208 return type
1142 1209
1143 def _InstanceOfNode(database, interface): 1210 def _FindParent(interface, database, callback):
1144 if interface.id == 'Node':
1145 return True
1146 for parent in interface.parents: 1211 for parent in interface.parents:
1212 parent_name = parent.type.id
1147 if not database.HasInterface(parent.type.id): 1213 if not database.HasInterface(parent.type.id):
1148 continue 1214 continue
1149 parent_interface = database.GetInterface(parent.type.id) 1215 parent_interface = database.GetInterface(parent.type.id)
1150 if _InstanceOfNode(database, parent_interface): 1216 if callback(parent_interface):
1151 return True 1217 return parent_interface
1152 return False 1218 parent_interface = _FindParent(parent_interface, database, callback)
1219 if parent_interface:
1220 return parent_interface
OLDNEW
« no previous file with comments | « lib/dom/scripts/systemhtml.py ('k') | lib/dom/src/native_EventsImplementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698