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

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):
Anton Muhin 2012/07/02 10:49:48 why it doesn't need any implementation?
podivilov 2012/07/02 17:08:18 Underlying c++ object doesn't implement merged met
204 pass
205
203 def StartInterface(self): 206 def StartInterface(self):
204 # Create emitters for c++ implementation. 207 # Create emitters for c++ implementation.
205 if self.HasImplementation(): 208 if self.HasImplementation():
206 cpp_header_path = self._system._FilePathForCppHeader(self._interface.id) 209 cpp_header_path = self._system._FilePathForCppHeader(self._interface.id)
207 self._system._cpp_header_files.append(cpp_header_path) 210 self._system._cpp_header_files.append(cpp_header_path)
208 self._cpp_header_emitter = self._system._emitters.FileEmitter(cpp_header_p ath) 211 self._cpp_header_emitter = self._system._emitters.FileEmitter(cpp_header_p ath)
209 cpp_impl_path = self._system._FilePathForCppImplementation(self._interface .id) 212 cpp_impl_path = self._system._FilePathForCppImplementation(self._interface .id)
210 self._system._cpp_impl_files.append(cpp_impl_path) 213 self._system._cpp_impl_files.append(cpp_impl_path)
211 self._cpp_impl_emitter = self._system._emitters.FileEmitter(cpp_impl_path) 214 self._cpp_impl_emitter = self._system._emitters.FileEmitter(cpp_impl_path)
212 else: 215 else:
213 self._cpp_header_emitter = emitter.Emitter() 216 self._cpp_header_emitter = emitter.Emitter()
214 self._cpp_impl_emitter = emitter.Emitter() 217 self._cpp_impl_emitter = emitter.Emitter()
215 218
216 self._interface_type_info = GetIDLTypeInfo(self._interface.id) 219 self._interface_type_info = GetIDLTypeInfo(self._interface.id)
217 self._members_emitter = emitter.Emitter() 220 self._members_emitter = emitter.Emitter()
218 self._cpp_declarations_emitter = emitter.Emitter() 221 self._cpp_declarations_emitter = emitter.Emitter()
219 self._cpp_impl_includes = set() 222 self._cpp_impl_includes = set()
220 self._cpp_definitions_emitter = emitter.Emitter() 223 self._cpp_definitions_emitter = emitter.Emitter()
221 self._cpp_resolver_emitter = emitter.Emitter() 224 self._cpp_resolver_emitter = emitter.Emitter()
222 225
223 self._GenerateConstructors() 226 self._GenerateConstructors()
224 self._GenerateEvents() 227 return self._members_emitter
225 228
226 def _GenerateConstructors(self): 229 def _GenerateConstructors(self):
227 html_interface_name = self._HTMLInterfaceName(self._interface.id) 230 html_interface_name = self._HTMLInterfaceName(self._interface.id)
228 231
229 if not self._IsConstructable(): 232 if not self._IsConstructable():
230 return 233 return
231 234
232 # TODO(antonm): currently we don't have information about number of argument s expected by 235 # TODO(antonm): currently we don't have information about number of argument s expected by
233 # the constructor, so name only dispatch. 236 # the constructor, so name only dispatch.
234 self._cpp_resolver_emitter.Emit( 237 self._cpp_resolver_emitter.Emit(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 ' goto fail;\n' 318 ' goto fail;\n'
316 ' }', 319 ' }',
317 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime'])) 320 FEATURE=_ToWebKitName(ext_attrs['synthesizedV8EnabledAtRuntime']))
318 321
319 self._GenerateNativeCallback(callback_name='constructorCallback', 322 self._GenerateNativeCallback(callback_name='constructorCallback',
320 parameter_definitions=parameter_definitions_emitter.Fragments(), 323 parameter_definitions=parameter_definitions_emitter.Fragments(),
321 needs_receiver=False, invocation=invocation, 324 needs_receiver=False, invocation=invocation,
322 raises_exceptions=raises_exceptions, 325 raises_exceptions=raises_exceptions,
323 runtime_check=runtime_check) 326 runtime_check=runtime_check)
324 327
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): 328 def _ImplClassName(self, interface_name):
388 return '_%sImpl' % interface_name 329 return '_%sImpl' % interface_name
389 330
390 def _DartType(self, idl_type): 331 def _DartType(self, idl_type):
391 return self._html_system.DartType(idl_type) 332 return self._html_system.DartType(idl_type)
392 333
393 def _BaseClassName(self): 334 def _BaseClassName(self):
394 root_class = 'NativeFieldWrapperClass1' 335 root_class = 'NativeFieldWrapperClass1'
395 336
396 if not self._interface.parents: 337 if not self._interface.parents:
397 return root_class 338 return root_class
398 339
399 supertype = self._interface.parents[0].type.id 340 supertype = self._interface.parents[0].type.id
400 341
401 if IsPureInterface(supertype): # The class is a root. 342 if IsPureInterface(supertype): # The class is a root.
402 return root_class 343 return root_class
403 344
404 # FIXME: We're currently injecting List<..> and EventTarget as 345 # FIXME: We're currently injecting List<..> and EventTarget as
405 # supertypes in dart.idl. We should annotate/preserve as 346 # supertypes in dart.idl. We should annotate/preserve as
406 # attributes instead. For now, this hack lets the self._interfaces 347 # attributes instead. For now, this hack lets the self._interfaces
407 # inherit, but not the classes. 348 # inherit, but not the classes.
408 # List methods are injected in AddIndexer. 349 # List methods are injected in AddIndexer.
409 if IsDartListType(supertype) or IsDartCollectionType(supertype): 350 if IsDartListType(supertype) or IsDartCollectionType(supertype):
410 return root_class 351 return root_class
411 352
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) 353 return self._ImplClassName(supertype)
423 354
424 def _HTMLInterfaceName(self, interface_name): 355 def _HTMLInterfaceName(self, interface_name):
425 return self._html_renames.get(interface_name, interface_name) 356 return self._html_renames.get(interface_name, interface_name)
426 357
427 def _IsConstructable(self): 358 def _IsConstructable(self):
428 # FIXME: support ConstructorTemplate. 359 # FIXME: support ConstructorTemplate.
429 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs) 360 return set(['CustomConstructor', 'V8CustomConstructor', 'Constructor', 'Name dConstructor']) & set(self._interface.ext_attrs)
430 361
431 def _EmitFactoryProvider(self, interface_name, constructor_info): 362 def _EmitFactoryProvider(self, interface_name, constructor_info):
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 1000
1070 def _IsArgumentOptionalInWebCore(argument): 1001 def _IsArgumentOptionalInWebCore(argument):
1071 return IsOptional(argument) and not 'Callback' in argument.ext_attrs 1002 return IsOptional(argument) and not 'Callback' in argument.ext_attrs
1072 1003
1073 def _ToWebKitName(name): 1004 def _ToWebKitName(name):
1074 name = name[0].lower() + name[1:] 1005 name = name[0].lower() + name[1:]
1075 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(), 1006 name = re.sub(r'^(hTML|uRL|jS|xML|xSLT)', lambda s: s.group(1).lower(),
1076 name) 1007 name)
1077 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() , 1008 return re.sub(r'^(create|exclusive)', lambda s: 'is' + s.group(1).capitalize() ,
1078 name) 1009 name)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698