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

Unified Diff: client/dom/scripts/systemhtml.py

Issue 9623017: Refactor the event-generation code to locate it in systemhtml.py. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 9 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: client/dom/scripts/systemhtml.py
diff --git a/client/dom/scripts/systemhtml.py b/client/dom/scripts/systemhtml.py
index 4c4945780abf44ed016d8882e35531a62661add9..b4d28397af09468de4b61ad9e22b9f4c0cdb110e 100644
--- a/client/dom/scripts/systemhtml.py
+++ b/client/dom/scripts/systemhtml.py
@@ -383,6 +383,11 @@ _html_event_names = {
'webkitTransitionEnd': 'transitionEnd'
}
+# These classes require an explicit declaration for the "on" method even though
+# they don't declare any unique events, because the concrete class hierarchy
+# doesn't match the interface hierarchy.
+_html_explicit_event_classes = set(['DocumentFragment'])
+
def _OnAttributeToEventName(on_method):
event_name = on_method.id[2:]
if event_name in _on_attribute_to_event_name_mapping:
@@ -496,6 +501,13 @@ class HtmlSystemShared(object):
def _ImplClassName(self, type_name):
return '_' + type_name + 'Impl'
+ def GetEventAttributes(self, interface):
+ events = set([attr for attr in interface.attributes
+ if self._generator._IsEventAttribute(interface, attr)])
+
+ if events or interface.id in _html_explicit_event_classes:
+ return events
+
class HtmlSystem(System):
def __init__(self, templates, database, emitters, output_dir, generator):
@@ -628,6 +640,12 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator):
CTOR=self._interface.id,
TYPE=DartType(element_type))
+ events = self._shared.GetEventAttributes(self._interface)
+ if events == set():
Jacob 2012/03/08 18:38:09 writing if events == set(): looks really odd can
nweiz 2012/03/08 20:47:16 len(None) doesn't work, and I don't want to make t
+ self.AddParentEvent()
+ elif events:
+ self.AddEventAttributes(events)
+
def AddAttribute(self, getter, setter):
html_getter_name = self._shared.RenameInHtmlLibrary(
self._interface, getter.id, 'get:')
@@ -678,12 +696,23 @@ class HtmlDartInterfaceGenerator(DartInterfaceGenerator):
def AddConstant(self, constant):
self._EmitConstant(self._members_emitter, constant)
+ def AddParentEvent(self):
+ parent_event_classes = self._shared.GetParentsEventsClasses(
+ self._interface)
+ if len(parent_event_classes) != 1:
+ raise Exception('Only one parent event class allowed '
+ + self._interface.id)
+
+ self._members_emitter.Emit('\n $TYPE get on();\n',
+ TYPE=parent_event_classes[0])
+
def AddEventAttributes(self, event_attrs):
event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs)
self._shared._event_classes.add(self._interface.id)
events_interface = self._interface.id + 'Events'
self._members_emitter.Emit('\n $TYPE get on();\n',
TYPE=events_interface)
+
events_members = self._emitter.Emit(
'\ninterface $INTERFACE extends $PARENTS {\n$!MEMBERS}\n',
INTERFACE=events_interface,
@@ -758,6 +787,12 @@ class HtmlFrogClassGenerator(FrogInterfaceGenerator):
if constructor_info:
self._EmitFactoryProvider(interface_name, constructor_info)
+ events = self._shared.GetEventAttributes(self._interface)
+ if events == set():
+ self.AddParentEvent()
+ elif events:
+ self.AddEventAttributes(events)
+
def _EmitFactoryProvider(self, interface_name, constructor_info):
template_file = 'factoryprovider_%s.darttemplate' % interface_name
template = self._system._templates.TryLoad(template_file)
@@ -982,6 +1017,19 @@ class HtmlFrogClassGenerator(FrogInterfaceGenerator):
PARAMS=info.ParametersImplementationDeclaration(
lambda type_name: self._NarrowInputType(type_name)))
+ def AddParentEvent(self):
Jacob 2012/03/08 18:38:09 seems like there is duplicated code in AddParentEv
nweiz 2012/03/08 20:47:16 Done.
+ parent_event_classes = self._shared.GetParentsEventsClasses(
+ self._interface)
+ if len(parent_event_classes) != 1:
+ raise Exception('Only one parent event class allowed '
+ + self._interface.id)
+
+ self._members_emitter.Emit(
+ '\n $TYPE get on() =>\n new $TYPE($EVENTTARGET);\n',
+ TYPE=parent_event_classes[0],
+ EVENTTARGET='_jsDocument' if self._interface.id == 'Document'
+ else 'this')
+
def AddEventAttributes(self, event_attrs):
event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs)
events_class = '_' + self._interface.id + 'EventsImpl'
@@ -1237,6 +1285,12 @@ class HtmlDartiumInterfaceGenerator(object):
if constructor_info:
self._EmitFactoryProvider(interface_name, constructor_info)
+ events = self._shared.GetEventAttributes(self._interface)
+ if events == set():
+ self.AddParentEvent()
+ elif events:
+ self.AddEventAttributes(events)
+
def _EmitFactoryProvider(self, interface_name, constructor_info):
template_file = 'factoryprovider_%s.darttemplate' % interface_name
template = self._system._templates.TryLoad(template_file)
@@ -1349,6 +1403,23 @@ class HtmlDartiumInterfaceGenerator(object):
self._SecondaryContext(interface)
self.AddOperation(info)
+ def AddParentEvent(self):
+ parent_event_classes = self._shared.GetParentsEventsClasses(
+ self._interface)
+ if len(parent_event_classes) != 1:
+ raise Exception('Only one parent event class allowed '
+ + self._interface.id)
+
+ self._members_emitter.Emit(
+ '\n'
+ ' $TYPE get on() {\n'
+ ' if (_on == null) _on = new $TYPE($EVENTTARGET);\n'
+ ' return _on;\n'
+ ' }\n',
+ TYPE=parent_event_classes[0],
+ EVENTTARGET='_wrappedDocumentPtr' if self._interface.id == 'Document'
+ else 'this')
+
def AddEventAttributes(self, event_attrs):
event_attrs = _DomToHtmlEvents(self._interface.id, event_attrs)
events_class = '_' + self._interface.id + 'EventsImpl'

Powered by Google App Engine
This is Rietveld 408576698