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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: lib/dom/scripts/systemnative.py
diff --git a/lib/dom/scripts/systemnative.py b/lib/dom/scripts/systemnative.py
index bec4e5ea32943d8bddafab9b001c04d067b059e9..d6da06be2c3eabe6b823613664e36a240683f86b 100644
--- a/lib/dom/scripts/systemnative.py
+++ b/lib/dom/scripts/systemnative.py
@@ -10,13 +10,16 @@ import emitter
import os
from generator import *
from systembase import *
+from systemhtml import *
sra1 2012/05/14 17:29:15 Please make new imports more specific.
podivilov 2012/05/15 10:24:26 Done.
class NativeImplementationSystem(System):
- def __init__(self, templates, database, emitters, auxiliary_dir, output_dir):
+ def __init__(self, templates, database, html_renames, emitters, auxiliary_dir,
+ output_dir):
super(NativeImplementationSystem, self).__init__(
templates, database, emitters, output_dir)
+ self._html_renames = html_renames
self._auxiliary_dir = auxiliary_dir
self._dom_public_files = []
self._dom_impl_files = []
@@ -245,6 +248,7 @@ class NativeImplementationGenerator(object):
self._cpp_resolver_emitter = emitter.Emitter()
self._GenerateConstructors()
+ self._GenerateEvents()
def _GenerateConstructors(self):
if not self._IsConstructable():
@@ -314,6 +318,53 @@ class NativeImplementationGenerator(object):
needs_receiver=False, invocation=invocation,
raises_exceptions=raises_exceptions)
+ def _GenerateEvents(self):
+ events_attributes = [attr for attr in self._interface.attributes
+ if attr.type.id == 'EventListener']
+
+ if not 'EventTarget' in self._interface.ext_attrs and not events_attributes:
+ return
+
+ is_root = not _HasEventTargetParent(self._system._database, self._interface)
+ if is_root:
+ self._members_emitter.Emit(' EventsImplementation _on;\n')
+
+ if not events_attributes:
+ if is_root:
+ self._EmitEventGetter('EventsImplementation')
+ return
+
+ events_class = '%sEventsImplementation' % self._interface.id
+ self._EmitEventGetter(events_class)
+
+ parent = _ParentWithEventAttributes(self._system._database, self._interface) or ''
+ html_inteface = self._system._html_renames.get(self._interface.id, self._interface.id)
+ events_members = self._dart_impl_emitter.Emit(
+ '\n'
+ 'class $EVENTS_CLASS extends $PARENT_EVENTS_CLASS implements $EVENTS_INTERFACE {\n'
+ ' $EVENTS_CLASS(_ptr) : super(_ptr);\n'
+ '$!MEMBERS\n'
+ '}\n',
+ EVENTS_CLASS=events_class,
+ PARENT_EVENTS_CLASS='%sEventsImplementation' % parent,
+ EVENTS_INTERFACE='html.%sEvents' % html_inteface)
+
+ events_attributes = DomToHtmlEvents(self._interface.id, events_attributes)
+ for event_name in events_attributes:
+ events_members.Emit(
+ " EventListenerList get $HTML_NAME() => _get('$DOM_NAME');\n",
+ HTML_NAME=DomToHtmlEvent(event_name),
+ DOM_NAME=event_name)
+
+ def _EmitEventGetter(self, events_class):
+ self._members_emitter.Emit(
+ '\n'
+ ' $EVENTS_CLASS get on() {\n'
+ ' if (_on == null) _on = new $EVENTS_CLASS(this);\n'
+ ' return _on;\n'
+ ' }\n',
+ EVENTS_CLASS=events_class)
+
def _ImplClassName(self, interface_name):
return interface_name + 'Implementation'
@@ -1150,3 +1201,28 @@ def _InstanceOfNode(database, interface):
if _InstanceOfNode(database, parent_interface):
return True
return False
+
+def _HasEventTargetParent(database, interface):
+ for parent in interface.parents:
+ parent_name = parent.type.id
+ if parent_name == 'EventTarget' or not database.HasInterface(parent_name):
+ continue
+ parent_interface = database.GetInterface(parent.type.id)
+ if ('EventTarget' in parent_interface.ext_attrs or
+ _HasEventTargetParent(database, parent_interface)):
+ return True
+ return False
+
+def _ParentWithEventAttributes(database, interface):
+ for parent in interface.parents:
+ parent_name = parent.type.id
+ if parent_name == 'EventTarget' or not database.HasInterface(parent_name):
+ continue
+ parent_interface = database.GetInterface(parent_name)
+ for attribute in parent_interface.attributes:
+ if attribute.type.id == 'EventListener':
+ return parent_interface.id
+ parent_interface = _ParentWithEventAttributes(database, parent_interface)
+ if parent_interface:
+ return parent_interface
+ return None

Powered by Google App Engine
This is Rietveld 408576698