def _GenerateEvent(self, event): event_dict = { 'name': event.simple_name, 'description': self._FormatDescription(event.description), 'filters': [self._GenerateProperty(f) for f in event.filters], 'conditions': [self._GetLink(condition) for condition in event.conditions], 'actions': [self._GetLink(action) for action in event.actions], 'supportsRules': event.supports_rules, 'supportsListeners': event.supports_listeners, 'properties': [], 'id': _CreateId(event, 'event'), 'byName': {}, } if event.deprecated is not None: event_dict['deprecated'] = self._FormatDescription( event.deprecated) if (event.parent is not None and not isinstance(event.parent, model.Namespace)): event_dict['parentName'] = event.parent.simple_name # Add the Event members to each event in this object. # If refs are disabled then don't worry about this, since it's only needed # for rendering, and disable_refs=True implies we're not rendering. if self._event_byname_function and not self._disable_refs: event_dict['byName'].update(self._event_byname_function()) # We need to create the method description for addListener based on the # information stored in |event|. if event.supports_listeners: callback_object = model.Function(parent=event, name='callback', json={}, namespace=event.parent, origin='') callback_object.params = event.params if event.callback: callback_object.callback = event.callback callback_parameters = self._GenerateCallbackProperty( callback_object) callback_parameters['last'] = True event_dict['byName']['addListener'] = { 'name': 'addListener', 'callback': self._GenerateFunction(callback_object), 'parameters': [callback_parameters] } if event.supports_dom: # Treat params as properties of the custom Event object associated with # this DOM Event. event_dict['properties'] += [ self._GenerateProperty(param) for param in event.params ] return event_dict
def _GenerateEvent(self, event): event_dict = { 'name': event.simple_name, 'description': event.description, 'filters': [self._GenerateProperty(f) for f in event.filters], 'conditions': [self._GetLink(condition) for condition in event.conditions], 'actions': [self._GetLink(action) for action in event.actions], 'supportsRules': event.supports_rules, 'supportsListeners': event.supports_listeners, 'properties': [], 'id': _CreateId(event, 'event'), 'byName': {}, } self._AddCommonProperties(event_dict, event) # Add the Event members to each event in this object. if self._event_byname_function: event_dict['byName'].update(self._event_byname_function()) # We need to create the method description for addListener based on the # information stored in |event|. if event.supports_listeners: callback_object = model.Function(parent=event, name='callback', json={}, namespace=event.parent, origin='') callback_object.params = event.params if event.callback: callback_object.callback = event.callback callback_parameters = self._GenerateCallbackProperty( callback_object) callback_parameters['last'] = True event_dict['byName']['addListener'] = { 'name': 'addListener', 'callback': self._GenerateFunction(callback_object), 'parameters': [callback_parameters] } if event.supports_dom: # Treat params as properties of the custom Event object associated with # this DOM Event. event_dict['properties'] += [ self._GenerateProperty(param) for param in event.params ] return event_dict
def _GenerateEvent(self, event): '''Returns a dictionary representation of an event from JSON Schema Compiler. Note that although events are modeled as functions in JSON Schema Compiler, we model them differently for the templates. ''' with self._current_node.Descend(event.simple_name, ignore=('properties', )): event_dict = { 'name': event.simple_name, 'description': event.description, 'filters': [self._GenerateProperty(f) for f in event.filters], 'conditions': [self._GetLink(condition) for condition in event.conditions], 'actions': [self._GetLink(action) for action in event.actions], 'supportsRules': event.supports_rules, 'supportsListeners': event.supports_listeners, 'properties': [], 'id': _CreateId(event, 'event'), 'byName': {}, 'availability': self._GetAvailabilityTemplate() } self._AddCommonProperties(event_dict, event) # Add the Event members to each event in this object. if self._event_byname_future: event_dict['byName'].update(self._event_byname_future.Get()) # We need to create the method description for addListener based on the # information stored in |event|. if event.supports_listeners: callback_object = model.Function(parent=event, name='callback', json={}, namespace=event.parent, origin='') callback_object.params = event.params if event.callback: callback_object.callback = event.callback with self._current_node.Descend(event.simple_name): callback = self._GenerateFunction(callback_object) callback_parameter = self._GenerateCallbackProperty( callback_object, callback) callback_parameter['last'] = True event_dict['byName']['addListener'] = { 'name': 'addListener', 'callback': callback, 'parameters': [callback_parameter] } if event.supports_dom: # Treat params as properties of the custom Event object associated with # this DOM Event. with self._current_node.Descend(event.simple_name, ignore=('properties', )): event_dict['properties'] += [ self._GenerateProperty(param) for param in event.params ] return event_dict