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

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
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 events_attributes = [attr for attr in self._interface.attributes
323 if attr.type.id == 'EventListener']
324 if self._interface.id == 'DocumentFragment':
Anton Muhin 2012/05/15 14:54:57 nit: move to the very beginning of the method?
podivilov 2012/05/16 12:32:24 Done.
325 self._EmitEventGetter('ElementEventsImplementation')
326 return
327
328 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
329 return
330
331 is_root = not _HasEventTargetParent(self._system._database, self._interface)
332 if is_root:
333 self._members_emitter.Emit(' EventsImplementation _on;\n')
334
335 if not events_attributes:
336 if is_root:
337 self._EmitEventGetter('EventsImplementation')
338 return
339
340 events_class = '%sEventsImplementation' % self._interface.id
341 self._EmitEventGetter(events_class)
342
343 parent = _ParentWithEventAttributes(self._system._database, self._interface) or ''
Anton Muhin 2012/05/15 14:54:57 can it be ever a null?
podivilov 2012/05/16 12:32:24 Yes, for example Node doesn't have event target pa
Anton Muhin 2012/05/16 13:17:56 In this case, where are the guards? On 2012/05/16
podivilov 2012/05/16 15:19:44 Note or ''. And see new version.
344 html_inteface = self._system._html_renames.get(self._interface.id, self._int erface.id)
Anton Muhin 2012/05/15 14:54:57 do not we have a helper for this operation?
podivilov 2012/05/16 12:32:24 Do we?
345 events_members = self._dart_impl_emitter.Emit(
346 '\n'
347 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n'
348 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n'
349 '$!MEMBERS\n'
350 '}\n',
351 EVENTS_CLASS=events_class,
352 PARENT_EVENTS_CLASS='%sEventsImplementation' % parent,
353 EVENTS_INTERFACE='html.%sEvents' % html_inteface)
354
355 events_attributes = DomToHtmlEvents(self._interface.id, events_attributes)
356 for event_name in events_attributes:
357 events_members.Emit(
358 " EventListenerList get $HTML_NAME() => _get('$DOM_NAME');\n",
Anton Muhin 2012/05/15 14:54:57 nit: shouldn't you use '' for outer and "" for inn
podivilov 2012/05/16 12:32:24 Done.
359 HTML_NAME=DomToHtmlEvent(event_name),
360 DOM_NAME=event_name)
361
362 def _EmitEventGetter(self, events_class):
363 self._members_emitter.Emit(
364 '\n'
365 ' $EVENTS_CLASS get on() {\n'
366 ' if (_on == null) _on = new $EVENTS_CLASS(this);\n'
Anton Muhin 2012/05/15 14:54:57 nit: === null?
Anton Muhin 2012/05/15 14:54:57 btw, maybe not for this change, but I believe lazy
podivilov 2012/05/16 12:32:24 Done.
367 ' return _on;\n'
368 ' }\n',
369 EVENTS_CLASS=events_class)
370
317 def _ImplClassName(self, interface_name): 371 def _ImplClassName(self, interface_name):
318 return interface_name + 'Implementation' 372 return interface_name + 'Implementation'
319 373
320 def _BaseClassName(self): 374 def _BaseClassName(self):
321 if not self._interface.parents: 375 if not self._interface.parents:
322 return 'DOMWrapperBase' 376 return 'DOMWrapperBase'
323 377
324 supertype = self._interface.parents[0].type.id 378 supertype = self._interface.parents[0].type.id
325 379
326 # FIXME: We're currently injecting List<..> and EventTarget as 380 # FIXME: We're currently injecting List<..> and EventTarget as
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 def _InstanceOfNode(database, interface): 1197 def _InstanceOfNode(database, interface):
1144 if interface.id == 'Node': 1198 if interface.id == 'Node':
1145 return True 1199 return True
1146 for parent in interface.parents: 1200 for parent in interface.parents:
1147 if not database.HasInterface(parent.type.id): 1201 if not database.HasInterface(parent.type.id):
1148 continue 1202 continue
1149 parent_interface = database.GetInterface(parent.type.id) 1203 parent_interface = database.GetInterface(parent.type.id)
1150 if _InstanceOfNode(database, parent_interface): 1204 if _InstanceOfNode(database, parent_interface):
1151 return True 1205 return True
1152 return False 1206 return False
1207
1208 def _HasEventTargetParent(database, interface):
Anton Muhin 2012/05/15 14:54:57 nit: I believe in generator database argument is u
podivilov 2012/05/16 12:32:24 Done.
1209 for parent in interface.parents:
1210 parent_name = parent.type.id
1211 if parent_name == 'EventTarget' or not database.HasInterface(parent_name):
Anton Muhin 2012/05/15 14:54:57 it's time to abstract away tree traversal, wdyt?
podivilov 2012/05/16 12:32:24 Done.
1212 continue
1213 parent_interface = database.GetInterface(parent.type.id)
1214 if ('EventTarget' in parent_interface.ext_attrs or
1215 _HasEventTargetParent(database, parent_interface)):
1216 return True
1217 return False
1218
1219 def _ParentWithEventAttributes(database, interface):
1220 for parent in interface.parents:
1221 parent_name = parent.type.id
1222 if parent_name == 'EventTarget' or not database.HasInterface(parent_name):
1223 continue
1224 parent_interface = database.GetInterface(parent_name)
1225 for attribute in parent_interface.attributes:
1226 if attribute.type.id == 'EventListener':
1227 return parent_interface.id
1228 parent_interface = _ParentWithEventAttributes(database, parent_interface)
1229 if parent_interface:
1230 return parent_interface
1231 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698