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

Side by Side Diff: tools/dom/scripts/htmleventgenerator.py

Issue 12025035: Adding annotations to event streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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
« no previous file with comments | « sdk/lib/web_audio/dartium/web_audio_dartium.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 functionality to generate dart:html event classes.""" 6 """This module provides functionality to generate dart:html event classes."""
7 7
8 import logging 8 import logging
9 from generator import FindCommonAnnotations, FormatAnnotations
9 10
10 _logger = logging.getLogger('dartgenerator') 11 _logger = logging.getLogger('dartgenerator')
11 12
12 # Events without onEventName attributes in the IDL we want to support. 13 # Events without onEventName attributes in the IDL we want to support.
13 # We can automatically extract most event names by checking for 14 # We can automatically extract most event names by checking for
14 # onEventName methods in the IDL but some events aren't listed so we need 15 # onEventName methods in the IDL but some events aren't listed so we need
15 # to manually add them here so that they are easy for users to find. 16 # to manually add them here so that they are easy for users to find.
16 _html_manual_events = { 17 _html_manual_events = {
17 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'], 18 'Element': ['touchleave', 'touchenter', 'webkitTransitionEnd'],
18 'Window': ['DOMContentLoaded'] 19 'Window': ['DOMContentLoaded']
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 if not events: 387 if not events:
387 return 388 return
388 389
389 for event_info in events: 390 for event_info in events:
390 (dom_name, html_name, event_type) = event_info 391 (dom_name, html_name, event_type) = event_info
391 392
392 # If we're using a different provider, then don't declare one. 393 # If we're using a different provider, then don't declare one.
393 if self._GetEventRedirection(interface, html_name, event_type): 394 if self._GetEventRedirection(interface, html_name, event_type):
394 continue 395 continue
395 396
397 annotations = FormatAnnotations(
398 FindCommonAnnotations(interface.id, dom_name), ' ')
399
396 members_emitter.Emit( 400 members_emitter.Emit(
397 "\n" 401 "\n"
398 " static const EventStreamProvider<$TYPE> $(NAME)Event = " 402 " $(ANNOTATIONS)static const EventStreamProvider<$TYPE> "
399 "const EventStreamProvider<$TYPE>('$DOM_NAME');\n", 403 "$(NAME)Event = const EventStreamProvider<$TYPE>('$DOM_NAME');\n",
404 ANNOTATIONS=annotations,
400 NAME=html_name, 405 NAME=html_name,
401 DOM_NAME=dom_name, 406 DOM_NAME=dom_name,
402 TYPE=event_type) 407 TYPE=event_type)
403 408
404 def EmitStreamGetters(self, interface, custom_events, 409 def EmitStreamGetters(self, interface, custom_events,
405 members_emitter): 410 members_emitter):
406 events = self._GetEvents(interface, custom_events) 411 events = self._GetEvents(interface, custom_events)
407 if not events: 412 if not events:
408 return 413 return
409 414
410 for event_info in events: 415 for event_info in events:
411 (dom_name, html_name, event_type) = event_info 416 (dom_name, html_name, event_type) = event_info
412 getter_name = 'on%s%s' % (html_name[:1].upper(), html_name[1:]) 417 getter_name = 'on%s%s' % (html_name[:1].upper(), html_name[1:])
413 418
414 # If the provider is declared elsewhere, point to that. 419 # If the provider is declared elsewhere, point to that.
415 redirection = self._GetEventRedirection(interface, html_name, event_type) 420 redirection = self._GetEventRedirection(interface, html_name, event_type)
416 if redirection: 421 if redirection:
417 provider = '%s.%sEvent' % (redirection, html_name) 422 provider = '%s.%sEvent' % (redirection, html_name)
418 else: 423 else:
419 provider = html_name + 'Event' 424 provider = html_name + 'Event'
420 425
426 annotations = FormatAnnotations(
427 FindCommonAnnotations(interface.id, dom_name), ' ')
428
421 members_emitter.Emit( 429 members_emitter.Emit(
422 "\n" 430 "\n"
423 " Stream<$TYPE> get $(NAME) => $PROVIDER.forTarget(this);\n", 431 " $(ANNOTATIONS)Stream<$TYPE> get $(NAME) => "
432 "$PROVIDER.forTarget(this);\n",
433 ANNOTATIONS=annotations,
424 NAME=getter_name, 434 NAME=getter_name,
425 PROVIDER=provider, 435 PROVIDER=provider,
426 TYPE=event_type) 436 TYPE=event_type)
427 437
428 def _GetEvents(self, interface, custom_events): 438 def _GetEvents(self, interface, custom_events):
429 """ Gets a list of all of the events for the specified interface. 439 """ Gets a list of all of the events for the specified interface.
430 """ 440 """
431 events = set([attr for attr in interface.attributes 441 events = set([attr for attr in interface.attributes
432 if attr.type.id == 'EventListener']) 442 if attr.type.id == 'EventListener'])
433 if not events and interface.id not in _html_explicit_event_classes: 443 if not events and interface.id not in _html_explicit_event_classes:
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 parent_events_class_name = 'Events' 585 parent_events_class_name = 'Events'
576 interfaces_with_events = set() 586 interfaces_with_events = set()
577 for parent in self._database.Hierarchy(interface): 587 for parent in self._database.Hierarchy(interface):
578 if parent != interface and parent.id in self._event_classes: 588 if parent != interface and parent.id in self._event_classes:
579 parent_name = self._renamer.RenameInterface(parent) 589 parent_name = self._renamer.RenameInterface(parent)
580 parent_events_class_name = parent_name + 'Events' 590 parent_events_class_name = parent_name + 'Events'
581 interfaces_with_events.add(parent) 591 interfaces_with_events.add(parent)
582 if len(interfaces_with_events) > 1: 592 if len(interfaces_with_events) > 1:
583 raise Exception('Only one parent event class allowed ' + interface.id) 593 raise Exception('Only one parent event class allowed ' + interface.id)
584 return parent_events_class_name 594 return parent_events_class_name
OLDNEW
« no previous file with comments | « sdk/lib/web_audio/dartium/web_audio_dartium.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698