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

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

Issue 10698049: Unfork html events generation in dart2js and dartium. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 5 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
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 def ImplementationClassName(self): 193 def ImplementationClassName(self):
194 return self._ImplClassName(self._interface.id) 194 return self._ImplClassName(self._interface.id)
195 195
196 def FilePathForDartImplementation(self): 196 def FilePathForDartImplementation(self):
197 return os.path.join(self._system._output_dir, 'dart', 197 return os.path.join(self._system._output_dir, 'dart',
198 '%sImplementation.dart' % self._interface.id) 198 '%sImplementation.dart' % self._interface.id)
199 199
200 def SetImplementationEmitter(self, implementation_emitter): 200 def SetImplementationEmitter(self, implementation_emitter):
201 self._dart_impl_emitter = implementation_emitter 201 self._dart_impl_emitter = implementation_emitter
202 202
203 def AddMergedMembers(self, merged_interface):
204 # We could not add merged functions to implementation class because
205 # underlying c++ object doesn't implement them. Merged functions are
206 # generated on merged interface implementation instead.
207 pass
208
203 def StartInterface(self): 209 def StartInterface(self):
204 # Create emitters for c++ implementation. 210 # Create emitters for c++ implementation.
205 if self.HasImplementation(): 211 if self.HasImplementation():
206 cpp_header_path = self._system._FilePathForCppHeader(self._interface.id) 212 cpp_header_path = self._system._FilePathForCppHeader(self._interface.id)
207 self._system._cpp_header_files.append(cpp_header_path) 213 self._system._cpp_header_files.append(cpp_header_path)
208 self._cpp_header_emitter = self._system._emitters.FileEmitter(cpp_header_p ath) 214 self._cpp_header_emitter = self._system._emitters.FileEmitter(cpp_header_p ath)
209 cpp_impl_path = self._system._FilePathForCppImplementation(self._interface .id) 215 cpp_impl_path = self._system._FilePathForCppImplementation(self._interface .id)
210 self._system._cpp_impl_files.append(cpp_impl_path) 216 self._system._cpp_impl_files.append(cpp_impl_path)
211 self._cpp_impl_emitter = self._system._emitters.FileEmitter(cpp_impl_path) 217 self._cpp_impl_emitter = self._system._emitters.FileEmitter(cpp_impl_path)
212 else: 218 else:
213 self._cpp_header_emitter = emitter.Emitter() 219 self._cpp_header_emitter = emitter.Emitter()
214 self._cpp_impl_emitter = emitter.Emitter() 220 self._cpp_impl_emitter = emitter.Emitter()
215 221
216 self._interface_type_info = GetIDLTypeInfo(self._interface.id) 222 self._interface_type_info = GetIDLTypeInfo(self._interface.id)
217 self._members_emitter = emitter.Emitter() 223 self._members_emitter = emitter.Emitter()
218 self._cpp_declarations_emitter = emitter.Emitter() 224 self._cpp_declarations_emitter = emitter.Emitter()
219 self._cpp_impl_includes = set() 225 self._cpp_impl_includes = set()
220 self._cpp_definitions_emitter = emitter.Emitter() 226 self._cpp_definitions_emitter = emitter.Emitter()
221 self._cpp_resolver_emitter = emitter.Emitter() 227 self._cpp_resolver_emitter = emitter.Emitter()
222 228
223 self._GenerateConstructors() 229 self._GenerateConstructors()
224 self._GenerateEvents() 230 return self._members_emitter
225 231
226 def _GenerateConstructors(self): 232 def _GenerateConstructors(self):
227 html_interface_name = self._HTMLInterfaceName(self._interface.id) 233 html_interface_name = self._HTMLInterfaceName(self._interface.id)
228 234
229 if not self._IsConstructable(): 235 if not self._IsConstructable():
230 return 236 return
231 237
232 # TODO(antonm): currently we don't have information about number of argument s expected by 238 # TODO(antonm): currently we don't have information about number of argument s expected by
233 # the constructor, so name only dispatch. 239 # the constructor, so name only dispatch.
234 self._cpp_resolver_emitter.Emit( 240 self._cpp_resolver_emitter.Emit(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ' goto fail;\n' 321 ' goto fail;\n'
316 ' }', 322 ' }',
317 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime'])) 323 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime']))
318 324
319 self._GenerateNativeCallback(callback_name='constructorCallback', 325 self._GenerateNativeCallback(callback_name='constructorCallback',
320 parameter_definitions=parameter_definitions_emitter.Fragments(), 326 parameter_definitions=parameter_definitions_emitter.Fragments(),
321 needs_receiver=False, invocation=invocation, 327 needs_receiver=False, invocation=invocation,
322 raises_exceptions=raises_exceptions, 328 raises_exceptions=raises_exceptions,
323 runtime_check=runtime_check) 329 runtime_check=runtime_check)
324 330
325 def _GenerateEvents(self):
326 if self._interface.id == 'DocumentFragment':
327 # Interface DocumentFragment extends Element in dart:html but this fact
328 # is not reflected in idls.
329 self._EmitEventGetter('_ElementEventsImpl')
330 return
331
332 events_attributes = [attr for attr in self._interface.attributes
333 if attr.type.id == 'EventListener']
334 if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
335 return
336
337 def IsEventTarget(interface):
338 return ('EventTarget' in interface.ext_attrs and
339 interface.id != 'EventTarget')
340 is_root = not _FindParent(self._interface, self._database, IsEventTarget)
341 if is_root:
342 self._members_emitter.Emit(' _EventsImpl _on;\n')
343
344 if not events_attributes:
345 if is_root:
346 self._EmitEventGetter('_EventsImpl')
347 return
348
349 events_class = '_%sEventsImpl' % self._interface.id
350 self._EmitEventGetter(events_class)
351
352 def HasEventAttributes(interface):
353 return any([a.type.id == 'EventListener' for a in interface.attributes])
354 parent = _FindParent(self._interface, self._database, HasEventAttributes)
355 if parent:
356 parent_events_class = '_%sEventsImpl' % parent.id
357 else:
358 parent_events_class = '_EventsImpl'
359
360 html_inteface = self._HTMLInterfaceName(self._interface.id)
361 events_members = self._dart_impl_emitter.Emit(
362 '\n'
363 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INT ERFACE {\n'
364 ' $EVENTS_CLASS(_ptr) : super(_ptr);\n'
365 '$!MEMBERS\n'
366 '}\n',
367 EVENTS_CLASS=events_class,
368 PARENT_EVENTS_CLASS=parent_events_class,
369 EVENTS_INTERFACE='%sEvents' % html_inteface)
370
371 events_attributes = DomToHtmlEvents(self._interface.id, events_attributes)
372 for event_name in events_attributes:
373 events_members.Emit(
374 ' EventListenerList get $HTML_NAME() => this[\'$DOM_NAME\'];\n',
375 HTML_NAME=DomToHtmlEvent(event_name),
376 DOM_NAME=event_name)
377
378 def _EmitEventGetter(self, events_class):
379 self._members_emitter.Emit(
380 '\n'
381 ' $EVENTS_CLASS get on() {\n'
382 ' if (_on === null) _on = new $EVENTS_CLASS(this);\n'
383 ' return _on;\n'
384 ' }\n',
385 EVENTS_CLASS=events_class)
386
387 def _ImplClassName(self, interface_name): 331 def _ImplClassName(self, interface_name):
388 return '_%sImpl' % interface_name 332 return '_%sImpl' % interface_name
389 333
390 def _DartType(self, idl_type): 334 def _DartType(self, idl_type):
391 return self._html_system.DartType(idl_type) 335 return self._html_system.DartType(idl_type)
392 336
393 def _BaseClassName(self): 337 def _BaseClassName(self):
394 root_class = 'NativeFieldWrapperClass1' 338 root_class = 'NativeFieldWrapperClass1'
395 339
396 if not self._interface.parents: 340 if not self._interface.parents:
397 return root_class 341 return root_class
398 342
399 supertype = self._interface.parents[0].type.id 343 supertype = self._interface.parents[0].type.id
400 344
401 if IsPureInterface(supertype): # The class is a root. 345 if IsPureInterface(supertype): # The class is a root.
402 return root_class 346 return root_class
403 347
404 # FIXME: We're currently injecting List<..> and EventTarget as 348 # FIXME: We're currently injecting List<..> and EventTarget as
405 # supertypes in dart.idl. We should annotate/preserve as 349 # supertypes in dart.idl. We should annotate/preserve as
406 # attributes instead. For now, this hack lets the self._interfaces 350 # attributes instead. For now, this hack lets the self._interfaces
407 # inherit, but not the classes. 351 # inherit, but not the classes.
408 # List methods are injected in AddIndexer. 352 # List methods are injected in AddIndexer.
409 if IsDartListType(supertype) or IsDartCollectionType(supertype): 353 if IsDartListType(supertype) or IsDartCollectionType(supertype):
410 return root_class 354 return root_class
411 355
412 if supertype == 'EventTarget':
413 # Most implementors of EventTarget specify the EventListener operations
414 # again. If the operations are not specified, try to inherit from the
415 # EventTarget implementation.
416 #
417 # Applies to MessagePort.
418 if not [op for op in self._interface.operations if op.id == 'addEventListe ner']:
419 return self._ImplClassName(supertype)
420 return root_class
421
422 return self._ImplClassName(supertype) 356 return self._ImplClassName(supertype)
423 357
424 def _HTMLInterfaceName(self, interface_name): 358 def _HTMLInterfaceName(self, interface_name):
425 return self._html_renames.get(interface_name, interface_name) 359 return self._html_renames.get(interface_name, interface_name)
426 360
427 def _IsConstructable(self): 361 def _IsConstructable(self):
428 # FIXME: support ConstructorTemplate. 362 # FIXME: support ConstructorTemplate.
429 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs) 363 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs)
430 364
431 def _EmitFactoryProvider(self, interface_name, constructor_info): 365 def _EmitFactoryProvider(self, interface_name, constructor_info):
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1003
1070 def _IsArgumentOptionalInWebCore(argument): 1004 def _IsArgumentOptionalInWebCore(argument):
1071 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 1005 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
1072 1006
1073 def _ToWebKitName(name): 1007 def _ToWebKitName(name):
1074 name = name[0].lower() + name[1:] 1008 name = name[0].lower() + name[1:]
1075 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 1009 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
1076 name) 1010 name)
1077 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 1011 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
1078 name) 1012 name)
OLDNEW
« no previous file with comments | « lib/dom/scripts/systemhtml.py ('k') | lib/dom/templates/html/dartium/impl_EventTarget.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698