OLD | NEW |
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 shared functionality for systems to generate | 6 """This module provides shared functionality for systems to generate |
7 Dart APIs from the IDL database.""" | 7 Dart APIs from the IDL database.""" |
8 | 8 |
9 import copy | 9 import copy |
10 import re | 10 import re |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 return None | 587 return None |
588 | 588 |
589 # ------------------------------------------------------------------------------ | 589 # ------------------------------------------------------------------------------ |
590 | 590 |
591 # Annotations to be placed on native members. The table is indexed by the IDL | 591 # Annotations to be placed on native members. The table is indexed by the IDL |
592 # interface and member name, and by IDL return or field type name. Both are | 592 # interface and member name, and by IDL return or field type name. Both are |
593 # used to assemble the annotations: | 593 # used to assemble the annotations: |
594 # | 594 # |
595 # INTERFACE.MEMBER: annotations for member. | 595 # INTERFACE.MEMBER: annotations for member. |
596 # +TYPE: add annotations only if there are member annotations. | 596 # +TYPE: add annotations only if there are member annotations. |
| 597 # -TYPE: add annotations only if there are no member annotations. |
597 # TYPE: add regardless of member annotations. | 598 # TYPE: add regardless of member annotations. |
598 | 599 |
599 dart2js_annotations = { | 600 dart2js_annotations = { |
600 | 601 |
601 'CanvasRenderingContext2D.createImageData': | 602 'CanvasRenderingContext2D.createImageData': |
602 "@Creates('ImageData|=Object')", | 603 "@Creates('ImageData|=Object')", |
603 | 604 |
604 'CanvasRenderingContext2D.getImageData': | 605 'CanvasRenderingContext2D.getImageData': |
605 "@Creates('ImageData|=Object')", | 606 "@Creates('ImageData|=Object')", |
606 | 607 |
607 'CanvasRenderingContext2D.webkitGetImageDataHD': | 608 'CanvasRenderingContext2D.webkitGetImageDataHD': |
608 "@Creates('ImageData|=Object')", | 609 "@Creates('ImageData|=Object')", |
609 | 610 |
610 # Methods returning Window can return a local window, or a cross-frame | 611 # Methods returning Window can return a local window, or a cross-frame |
611 # window (=Object) that needs wrapping. | 612 # window (=Object) that needs wrapping. |
612 'DOMWindow': | 613 'DOMWindow': |
613 "@Creates('LocalWindow|=Object') @Returns('LocalWindow|=Object')", | 614 "@Creates('LocalWindow|=Object') @Returns('LocalWindow|=Object')", |
614 | 615 |
615 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", | 616 'DOMWindow.openDatabase': "@Creates('Database') @Creates('DatabaseSync')", |
616 | 617 |
617 # Cross-frame windows are EventTargets. | 618 # Cross-frame windows are EventTargets. |
618 'EventTarget': | 619 '-EventTarget': |
619 #"@Creates('Null') @Returns('EventTarget|=Object')", | |
620 "@Creates('EventTarget|=Object') @Returns('EventTarget|=Object')", | 620 "@Creates('EventTarget|=Object') @Returns('EventTarget|=Object')", |
621 | 621 |
| 622 # To be in callback with the browser-created Event, we had to have called |
| 623 # addEventListener on the target, so we avoid |
| 624 'Event.currentTarget': |
| 625 "@Creates('Null') @Returns('EventTarget|=Object')", |
| 626 |
| 627 # Only nodes in the DOM bubble and have target !== currentTarget. |
| 628 'Event.target': |
| 629 "@Creates('Node') @Returns('EventTarget|=Object')", |
| 630 |
| 631 'MouseEvent.relatedTarget': |
| 632 "@Creates('Node') @Returns('EventTarget|=Object')", |
| 633 |
| 634 # Touch targets are Elements in a Document, or the Document. |
| 635 'Touch.target': |
| 636 "@Creates('Element|Document') @Returns('Element|Document')", |
| 637 |
| 638 |
622 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", | 639 'FileReader.result': "@Creates('String|ArrayBuffer|Null')", |
623 | 640 |
624 # Rather than have the result of an IDBRequest as a union over all possible | 641 # Rather than have the result of an IDBRequest as a union over all possible |
625 # results, we mark the result as instantiating any classes, and mark | 642 # results, we mark the result as instantiating any classes, and mark |
626 # each operation with the classes that it could cause to be asynchronously | 643 # each operation with the classes that it could cause to be asynchronously |
627 # instantiated. | 644 # instantiated. |
628 'IDBRequest.result': "@Creates('Null')", | 645 'IDBRequest.result': "@Creates('Null')", |
629 | 646 |
630 # The source is usually a participant in the operation that generated the | 647 # The source is usually a participant in the operation that generated the |
631 # IDBRequest. | 648 # IDBRequest. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) | 697 ann1 = dart2js_annotations.get("%s.%s" % (interface_name, member_name)) |
681 if ann1: | 698 if ann1: |
682 ann2 = dart2js_annotations.get('+' + idl_type) | 699 ann2 = dart2js_annotations.get('+' + idl_type) |
683 if ann2: | 700 if ann2: |
684 return ann2 + ' ' + ann1 | 701 return ann2 + ' ' + ann1 |
685 ann2 = dart2js_annotations.get(idl_type) | 702 ann2 = dart2js_annotations.get(idl_type) |
686 if ann2: | 703 if ann2: |
687 return ann2 + ' ' + ann1 | 704 return ann2 + ' ' + ann1 |
688 return ann1 | 705 return ann1 |
689 | 706 |
| 707 ann2 = dart2js_annotations.get('-' + idl_type) |
| 708 if ann2: |
| 709 return ann2 |
690 ann2 = dart2js_annotations.get(idl_type) | 710 ann2 = dart2js_annotations.get(idl_type) |
691 return ann2 | 711 return ann2 |
692 | 712 |
693 # ------------------------------------------------------------------------------ | 713 # ------------------------------------------------------------------------------ |
694 | 714 |
695 class IDLTypeInfo(object): | 715 class IDLTypeInfo(object): |
696 def __init__(self, idl_type, data): | 716 def __init__(self, idl_type, data): |
697 self._idl_type = idl_type | 717 self._idl_type = idl_type |
698 self._data = data | 718 self._data = data |
699 | 719 |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 self) | 1245 self) |
1226 | 1246 |
1227 if type_data.clazz == 'SVGTearOff': | 1247 if type_data.clazz == 'SVGTearOff': |
1228 dart_interface_name = self._renamer.RenameInterface( | 1248 dart_interface_name = self._renamer.RenameInterface( |
1229 self._database.GetInterface(type_name)) | 1249 self._database.GetInterface(type_name)) |
1230 return SVGTearOffIDLTypeInfo( | 1250 return SVGTearOffIDLTypeInfo( |
1231 type_name, type_data, dart_interface_name, self) | 1251 type_name, type_data, dart_interface_name, self) |
1232 | 1252 |
1233 class_name = '%sIDLTypeInfo' % type_data.clazz | 1253 class_name = '%sIDLTypeInfo' % type_data.clazz |
1234 return globals()[class_name](type_name, type_data) | 1254 return globals()[class_name](type_name, type_data) |
OLD | NEW |