OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
4 # for details. All rights reserved. Use of this source code is governed by a | 4 # for details. All rights reserved. Use of this source code is governed by a |
5 # BSD-style license that can be found in the LICENSE file. | 5 # BSD-style license that can be found in the LICENSE file. |
6 | 6 |
7 """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.""" | 7 """Generates sdk/lib/_blink/dartium/_blink_dartium.dart file.""" |
8 | 8 |
9 import os | 9 import os |
10 from sets import Set | 10 from sets import Set |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 'NodeList.item', | 52 'NodeList.item', |
53 'ParentNode.children', | 53 'ParentNode.children', |
54 'ParentNode.firstElementChild', | 54 'ParentNode.firstElementChild', |
55 'ParentNode.lastElementChild', | 55 'ParentNode.lastElementChild', |
56 'Event.target', | 56 'Event.target', |
57 'MouseEvent.clientY', | 57 'MouseEvent.clientY', |
58 'MouseEvent.clientX', | 58 'MouseEvent.clientX', |
59 | 59 |
60 'Node.nodeType', | 60 'Node.nodeType', |
61 'Node.textContent', | 61 'Node.textContent', |
62 | 62 |
63 'HTMLCollection.length', | 63 'HTMLCollection.length', |
64 'HTMLCollection.item', | 64 'HTMLCollection.item', |
65 'Node.lastElementChild', | 65 'Node.lastElementChild', |
66 'Node.firstElementChild', | 66 'Node.firstElementChild', |
67 'HTMLElement_tabIndex', | 67 'HTMLElement_tabIndex', |
68 | 68 |
69 'Element.clientWidth', | 69 'Element.clientWidth', |
70 'Element.clientHeight', | 70 'Element.clientHeight', |
71 'Document.body', | 71 'Document.body', |
72 'Element.removeAttribute', | 72 'Element.removeAttribute', |
73 'Element.getBoundingClientRect', | 73 'Element.getBoundingClientRect', |
74 'CSSStyleDeclaration.getPropertyValue', | 74 'CSSStyleDeclaration.getPropertyValue', |
75 'CSSStyleDeclaration.setProperty', | 75 'CSSStyleDeclaration.setProperty', |
76 'CSSStyleDeclaration.__propertyQuery__', | 76 'CSSStyleDeclaration.__propertyQuery__', |
77 | 77 |
78 # TODO(jacobr): consider implementing these methods as well as they show | 78 # TODO(jacobr): consider implementing these methods as well as they show |
79 # up in benchmarks for some sample applications. | 79 # up in benchmarks for some sample applications. |
80 #'Document.createEvent', | 80 #'Document.createEvent', |
81 #'Document.initEvent', | 81 #'Document.initEvent', |
82 #'EventTarget.dispatchEvent', | 82 #'EventTarget.dispatchEvent', |
83 ]) | 83 ]) |
84 | 84 |
85 # Uncomment out this line to short circuited native methods and run all of | 85 # Uncomment out this line to short circuited native methods and run all of |
86 # dart:html through JS interop except for createElement which is slightly more | 86 # dart:html through JS interop except for createElement which is slightly more |
87 # tightly natively wired. | 87 # tightly natively wired. |
88 # _js_custom_members = Set([]) | 88 # _js_custom_members = Set([]) |
89 | 89 |
| 90 |
| 91 # Expose built-in methods support by an instance that is not shown in the IDL. |
| 92 _additional_methods = { |
| 93 # Support propertyIsEnumerable (available on all objects only needed by |
| 94 # CSSStyleDeclaration decides if style property is supported (handling |
| 95 # camelcase and inject hyphens between camelcase). |
| 96 # Format of dictionary is 'operation name', arguments, returns value (True or
False) |
| 97 'CSSStyleDeclaration': ('propertyIsEnumerable', 1, True), |
| 98 } |
| 99 |
| 100 |
90 HEADER = """/* Copyright (c) 2014, the Dart project authors. Please see the AUT
HORS file | 101 HEADER = """/* Copyright (c) 2014, the Dart project authors. Please see the AUT
HORS file |
91 * for details. All rights reserved. Use of this source code is governed by a | 102 * for details. All rights reserved. Use of this source code is governed by a |
92 * BSD-style license that can be found in the LICENSE file. | 103 * BSD-style license that can be found in the LICENSE file. |
93 * | 104 * |
94 * DO NOT EDIT | 105 * DO NOT EDIT |
95 * Auto-generated _blink library. | 106 * Auto-generated _blink library. |
96 */ | 107 */ |
97 library dart.dom._blink; | 108 library dart.dom._blink; |
98 | 109 |
99 import 'dart:async'; | 110 import 'dart:async'; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ' => Blink_JsNative_DomException.setProperty(mthis /* %s */,
"%s", __arg_0);\n\n', | 324 ' => Blink_JsNative_DomException.setProperty(mthis /* %s */,
"%s", __arg_0);\n\n', |
314 ' native "Blink_Setter_%s_%s";\n\n' | 325 ' native "Blink_Setter_%s_%s";\n\n' |
315 ] | 326 ] |
316 | 327 |
317 #(operation_name, operationName) | 328 #(operation_name, operationName) |
318 OPERATION_0 = [' %s_Callback_0_(mthis)', | 329 OPERATION_0 = [' %s_Callback_0_(mthis)', |
319 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[]);\n\n', | 330 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[]);\n\n', |
320 ' native "Blink_Operation_0_%s_%s";\n\n' | 331 ' native "Blink_Operation_0_%s_%s";\n\n' |
321 ] | 332 ] |
322 | 333 |
323 # getter, setter, deleter and propertyQuery code | 334 # getter, setter, deleter, propertyQuery code, and propertyIsEnumerable |
324 OPERATION_1 = [' $%s_Callback_1_(mthis, __arg_0)', | 335 OPERATION_1 = [' $%s_Callback_1_(mthis, __arg_0)', |
325 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[__arg_0]);\n\n', | 336 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[__arg_0]);\n\n', |
326 ' native "Blink_Operation_1_%s_%s";\n\n' | 337 ' native "Blink_Operation_1_%s_%s";\n\n' |
327 ] | 338 ] |
328 | 339 |
329 OPERATION_2 = [' $%s_Callback_2_(mthis, __arg_0, __arg_1)', | 340 OPERATION_2 = [' $%s_Callback_2_(mthis, __arg_0, __arg_1)', |
330 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[__arg_0, __arg_1]);\n\n', | 341 ' => Blink_JsNative_DomException.callMethod(mthis /* %s */, "%s",
[__arg_0, __arg_1]);\n\n', |
331 ' native "Blink_Operation_2_%s_%s";\n\n'] | 342 ' native "Blink_Operation_2_%s_%s";\n\n'] |
332 | 343 |
333 OPERATION_PQ = [' $%s_Callback_1_(mthis, __arg_0)', | 344 OPERATION_PQ = [' $%s_Callback_1_(mthis, __arg_0)', |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 blink_file.write(class_def); | 444 blink_file.write(class_def); |
434 | 445 |
435 analyzed_constructors = AnalyzeConstructor(interface) | 446 analyzed_constructors = AnalyzeConstructor(interface) |
436 if analyzed_constructors: | 447 if analyzed_constructors: |
437 _Emit_Blink_Constructors(blink_file, analyzed_constructors) | 448 _Emit_Blink_Constructors(blink_file, analyzed_constructors) |
438 elif 'Constructor' in interface.ext_attrs: | 449 elif 'Constructor' in interface.ext_attrs: |
439 # Zero parameter constructor. | 450 # Zero parameter constructor. |
440 blink_file.write(Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor'
)) % rename_constructor(name)) | 451 blink_file.write(Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor'
)) % rename_constructor(name)) |
441 | 452 |
442 _Process_Attributes(blink_file, interface, interface.attributes) | 453 _Process_Attributes(blink_file, interface, interface.attributes) |
443 _Process_Operations(blink_file, interface, interface.operations) | 454 _Process_Operations(blink_file, interface, interface.operations, True) |
| 455 |
| 456 _Emit_Extra_Operations(blink_file, name) |
444 | 457 |
445 secondary_parents = database.TransitiveSecondaryParents(interface, False) | 458 secondary_parents = database.TransitiveSecondaryParents(interface, False) |
446 for secondary in secondary_parents: | 459 for secondary in secondary_parents: |
447 _Process_Attributes(blink_file, secondary, secondary.attributes) | 460 _Process_Attributes(blink_file, secondary, secondary.attributes) |
448 _Process_Operations(blink_file, secondary, secondary.operations) | 461 _Process_Operations(blink_file, secondary, secondary.operations, False) |
449 | 462 |
450 blink_file.write(CLASS_DEFINITION_END); | 463 blink_file.write(CLASS_DEFINITION_END); |
451 | 464 |
452 blink_file.write(BLINK_UTILS) | 465 blink_file.write(BLINK_UTILS) |
453 | 466 |
454 blink_file.close() | 467 blink_file.close() |
455 | 468 |
| 469 def _Emit_Extra_Operations(blink_file, interface_name): |
| 470 if (interface_name in _additional_methods): |
| 471 (name, arg_count, return_value) = _additional_methods[interface_name] |
| 472 exposed_name = ''.join(['__get', '___', name]) if return_value else name |
| 473 blink_file.write(Select_Stub(OPERATION_1, False) % (exposed_name, interface_
name, name)) |
| 474 |
456 def _Emit_Blink_Constructors(blink_file, analyzed_constructors): | 475 def _Emit_Blink_Constructors(blink_file, analyzed_constructors): |
457 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed_construct
ors.param_infos) | 476 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed_construct
ors.param_infos) |
458 name = analyzed_constructors.js_name | 477 name = analyzed_constructors.js_name |
459 if not(name): | 478 if not(name): |
460 name = analyzed_constructors.type_name | 479 name = analyzed_constructors.type_name |
461 | 480 |
462 for callback_index in range(arg_min_count, arg_max_count): | 481 for callback_index in range(arg_min_count, arg_max_count): |
463 if callback_index == 0: | 482 if callback_index == 0: |
464 blink_file.write(Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor'
)) % (rename_constructor(name))) | 483 blink_file.write(Select_Stub(CONSTRUCTOR_0, _Is_Native(name, 'constructor'
)) % (rename_constructor(name))) |
465 else: | 484 else: |
(...skipping 12 matching lines...) Expand all Loading... |
478 if attribute.is_read_only: | 497 if attribute.is_read_only: |
479 if attribute.is_static: | 498 if attribute.is_static: |
480 class_property = CLASS_STATIC % interface.id | 499 class_property = CLASS_STATIC % interface.id |
481 blink_file.write(Select_Stub(STATIC_ATTRIBUTE_GETTER, is_native) % (name
, class_property, interface.id, name)) | 500 blink_file.write(Select_Stub(STATIC_ATTRIBUTE_GETTER, is_native) % (name
, class_property, interface.id, name)) |
482 else: | 501 else: |
483 blink_file.write(Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, inter
face.id, name)) | 502 blink_file.write(Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, inter
face.id, name)) |
484 else: | 503 else: |
485 blink_file.write(Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, interfa
ce.id, name)) | 504 blink_file.write(Select_Stub(ATTRIBUTE_GETTER, is_native) % (name, interfa
ce.id, name)) |
486 blink_file.write(Select_Stub(ATTRIBUTE_SETTER, is_native) % (name, interfa
ce.id, name)) | 505 blink_file.write(Select_Stub(ATTRIBUTE_SETTER, is_native) % (name, interfa
ce.id, name)) |
487 | 506 |
488 def _Process_Operations(blink_file, interface, operations): | 507 def _Process_Operations(blink_file, interface, operations, primary_interface = F
alse): |
489 analyzeOperations = [] | 508 analyzeOperations = [] |
490 | 509 |
491 for operation in sorted(operations, ConstantOutputOrder): | 510 for operation in sorted(operations, ConstantOutputOrder): |
492 if len(analyzeOperations) == 0: | 511 if len(analyzeOperations) == 0: |
493 analyzeOperations.append(operation) | 512 analyzeOperations.append(operation) |
494 else: | 513 else: |
495 if analyzeOperations[0].id == operation.id: | 514 if analyzeOperations[0].id == operation.id: |
496 # Handle overloads | 515 # Handle overloads |
497 analyzeOperations.append(operation) | 516 analyzeOperations.append(operation) |
498 else: | 517 else: |
499 _Emit_Blink_Operation(blink_file, interface, analyzeOperations) | 518 _Emit_Blink_Operation(blink_file, interface, analyzeOperations, primary_
interface) |
500 analyzeOperations = [operation] | 519 analyzeOperations = [operation] |
501 if len(analyzeOperations) > 0: | 520 if len(analyzeOperations) > 0: |
502 _Emit_Blink_Operation(blink_file, interface, analyzeOperations) | 521 _Emit_Blink_Operation(blink_file, interface, analyzeOperations, primary_inte
rface) |
503 | 522 |
504 def _Emit_Blink_Operation(blink_file, interface, analyzeOperations): | 523 # List of DartName operations to not emit (e.g., For now only WebGL2RenderingCon
textBase |
| 524 # has readPixels in both WebGLRenderingContextBase and WebGL2RenderingContextBas
e. |
| 525 # Furthermore, readPixels has the exact same number of arguments - in Javascript |
| 526 # there is no typing so they're the same. |
| 527 suppressed_operations = { |
| 528 'WebGL2RenderingContextBase': [ 'readPixels2', 'texImage2D2' ], |
| 529 } |
| 530 |
| 531 def _Suppress_Secondary_Interface_Operation(interface, analyzed): |
| 532 if interface.id in suppressed_operations: |
| 533 # Should this DartName (name property) be suppressed on this interface? |
| 534 return analyzed.name in suppressed_operations[interface.id] |
| 535 return False |
| 536 |
| 537 def _Emit_Blink_Operation(blink_file, interface, analyzeOperations, primary_inte
rface): |
505 analyzed = AnalyzeOperation(interface, analyzeOperations) | 538 analyzed = AnalyzeOperation(interface, analyzeOperations) |
| 539 |
| 540 if not(primary_interface) and _Suppress_Secondary_Interface_Operation(interfac
e, analyzed): |
| 541 return |
| 542 |
506 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed.param_inf
os) | 543 (arg_min_count, arg_max_count) = generate_parameter_entries(analyzed.param_inf
os) |
507 name = analyzed.js_name | 544 name = analyzed.js_name |
| 545 |
508 is_native = _Is_Native(interface.id, name) | 546 is_native = _Is_Native(interface.id, name) |
509 | 547 |
510 operation = analyzeOperations[0] | 548 operation = analyzeOperations[0] |
511 if (name.startswith('__') and \ | 549 if (name.startswith('__') and \ |
512 ('getter' in operation.specials or \ | 550 ('getter' in operation.specials or \ |
513 'setter' in operation.specials or \ | 551 'setter' in operation.specials or \ |
514 'deleter' in operation.specials)): | 552 'deleter' in operation.specials)): |
515 if name == '__propertyQuery__': | 553 if name == '__propertyQuery__': |
516 blink_file.write(Select_Stub(OPERATION_PQ, is_native) % (name, interface.i
d)) | 554 blink_file.write(Select_Stub(OPERATION_PQ, is_native) % (name, interface.i
d)) |
517 else: | 555 else: |
(...skipping 18 matching lines...) Expand all Loading... |
536 else: | 574 else: |
537 arguments = [] | 575 arguments = [] |
538 for i in range(0, callback_index): | 576 for i in range(0, callback_index): |
539 arguments.append(ARGUMENT_NUM % i) | 577 arguments.append(ARGUMENT_NUM % i) |
540 argument_list = ', '.join(arguments) | 578 argument_list = ', '.join(arguments) |
541 if operation.is_static: | 579 if operation.is_static: |
542 class_property = CLASS_STATIC % interface.id | 580 class_property = CLASS_STATIC % interface.id |
543 blink_file.write(Select_Stub(STATIC_OPERATION_ARGS, is_native) % (name,
callback_index, argument_list, class_property, interface.id, name, argument_list
)) | 581 blink_file.write(Select_Stub(STATIC_OPERATION_ARGS, is_native) % (name,
callback_index, argument_list, class_property, interface.id, name, argument_list
)) |
544 else: | 582 else: |
545 blink_file.write(Select_Stub(OPERATION_ARGS, is_native) % (name, callbac
k_index, argument_list, interface.id, name, argument_list)) | 583 blink_file.write(Select_Stub(OPERATION_ARGS, is_native) % (name, callbac
k_index, argument_list, interface.id, name, argument_list)) |
OLD | NEW |