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

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: Address comments 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..4ea6b2ec5e36450fd3a85788a6b75e80fb1e0dab 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 DomToHtmlEvent, DomToHtmlEvents
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,69 @@ class NativeImplementationGenerator(object):
needs_receiver=False, invocation=invocation,
raises_exceptions=raises_exceptions)
+ def _GenerateEvents(self):
+ if self._interface.id == 'DocumentFragment':
Anton Muhin 2012/05/16 13:17:57 may you add a comment why this is special-cased?
podivilov 2012/05/16 15:19:44 Done.
+ self._EmitEventGetter('ElementEventsImplementation')
+ return
+
+ 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
+
Anton Muhin 2012/05/16 13:17:57 nit: intentional two blanks?
podivilov 2012/05/16 15:19:44 Done.
+
+ def is_event_target(interface):
Anton Muhin 2012/05/16 13:17:57 q: is it a correct style for nest functions? just
podivilov 2012/05/16 15:19:44 Done.
+ return ('EventTarget' in interface.ext_attrs and
+ interface.id != 'EventTarget')
+ is_root = not _FindParent(self._interface, self._system._database, is_event_target)
+ 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)
+
+ def has_event_attributes(interface):
+ for attribute in interface.attributes:
Anton Muhin 2012/05/16 13:17:57 as a variant: return any((attr.type.id == 'EventLi
podivilov 2012/05/16 15:19:44 Done.
+ if attribute.type.id == 'EventListener':
+ return True
+ return False
+ parent = _FindParent(self._interface, self._system._database, has_event_attributes)
+ if parent:
+ parent_events_class = '%sEventsImplementation' % parent.id
+ else:
+ parent_events_class = 'EventsImplementation'
+ 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=parent_events_class,
+ 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'
@@ -1134,19 +1201,22 @@ def _DOMWrapperType(database, interface):
return 'MessagePort'
type = 'Object'
- if _InstanceOfNode(database, interface):
+ def is_node(interface):
+ return interface.id == 'Node'
+ if is_node(interface) or _FindParent(interface, database, is_node):
type = 'Node'
if 'ActiveDOMObject' in interface.ext_attrs:
type = 'Active%s' % type
return type
-def _InstanceOfNode(database, interface):
- if interface.id == 'Node':
- return True
+def _FindParent(interface, database, callback):
for parent in interface.parents:
+ parent_name = parent.type.id
if not database.HasInterface(parent.type.id):
continue
parent_interface = database.GetInterface(parent.type.id)
- if _InstanceOfNode(database, parent_interface):
- return True
- return False
+ if callback(parent_interface):
+ return parent_interface
+ parent_interface = _FindParent(parent_interface, database, callback)
+ if parent_interface:
+ return parent_interface

Powered by Google App Engine
This is Rietveld 408576698