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

Side by Side Diff: client/dom/scripts/systemhtml.py

Issue 9600035: Enable new dart:html wrapperless frog bindings and wrapper dartium bindings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Handle all code review comments 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | client/dom/templates/html/dartium/impl_Document.darttemplate » ('j') | 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 shared functionality for the system to generate 6 """This module provides shared functionality for the system to generate
7 Dart:html APIs from the IDL database.""" 7 Dart:html APIs from the IDL database."""
8 8
9 from systemfrog import * 9 from systemfrog import *
10 from systeminterface import * 10 from systeminterface import *
(...skipping 16 matching lines...) Expand all
27 'Element.scrollHeight', 27 'Element.scrollHeight',
28 'Element.childElementCount', 28 'Element.childElementCount',
29 'Element.firstElementChild', 29 'Element.firstElementChild',
30 'Element.hasAttribute', 30 'Element.hasAttribute',
31 'Element.getAttribute', 31 'Element.getAttribute',
32 'Element.removeAttribute', 32 'Element.removeAttribute',
33 'Element.setAttribute', 33 'Element.setAttribute',
34 'Element.className', 34 'Element.className',
35 'Element.children', 35 'Element.children',
36 'Element.querySelectorAll', 36 'Element.querySelectorAll',
37 'NodeSelector.querySelectorAll',
37 'Document.querySelectorAll', 38 'Document.querySelectorAll',
39 'DocumentFragment.querySelectorAll',
38 'Element.getBoundingClientRect', 40 'Element.getBoundingClientRect',
39 'Element.getClientRects', 41 'Element.getClientRects',
40 'Node.appendChild', 42 'Node.appendChild',
41 'Node.removeChild', 43 'Node.removeChild',
42 'Node.replaceChild', 44 'Node.replaceChild',
43 'Node.attributes', 45 'Node.attributes',
44 'Node.childNodes', 46 'Node.childNodes',
45 'Document.createElement', 47 'Document.createElement',
46 'Document.createEvent', 48 'Document.createEvent',
47 'Document.createTextNode', 49 'Document.createTextNode',
48 'Document.createTouchList', 50 'Document.createTouchList',
49 'Window.getComputedStyle', 51 'Window.getComputedStyle',
50 'EventTarget.removeEventListener', 52 'EventTarget.removeEventListener',
51 'EventTarget.addEventListener', 53 'EventTarget.addEventListener',
52 'EventTarget.dispatchEvent', 54 'EventTarget.dispatchEvent',
53 'Event.initEvent', 55 'Event.initEvent',
54 'MouseEvent.initMouseEvent', 56 'MouseEvent.initMouseEvent',
55 ]) 57 ])
56 58
57 # Members from the standard dom that exist in the dart:html library with 59 # Members from the standard dom that exist in the dart:html library with
58 # identical functionality but with cleaner names. 60 # identical functionality but with cleaner names.
59 _html_library_renames = { 61 _html_library_renames = {
60 'Document.defaultView': 'window', 62 'Document.defaultView': 'window',
61 'DocumentFragment.querySelector': 'query', 63 'DocumentFragment.querySelector': 'query',
64 'NodeSelector.querySelector': 'query',
62 'Element.querySelector': 'query', 65 'Element.querySelector': 'query',
63 'Element.webkitMatchesSelector' : 'matchesSelector', 66 'Element.webkitMatchesSelector' : 'matchesSelector',
64 'Element.scrollIntoViewIfNeeded': 'scrollIntoView', 67 'Element.scrollIntoViewIfNeeded': 'scrollIntoView',
65 'Document.querySelector': 'query', 68 'Document.querySelector': 'query',
66 'DocumentFragment.querySelectorAll': 'queryAll',
67 'DocumentFragment.querySelectorAll': 'queryAll',
68 'Node.cloneNode': 'clone', 69 'Node.cloneNode': 'clone',
69 'Node.nextSibling': 'nextNode', 70 'Node.nextSibling': 'nextNode',
70 'Node.ownerDocument': 'document', 71 'Node.ownerDocument': 'document',
71 'Node.parentNode': 'parent', 72 'Node.parentNode': 'parent',
72 'Node.previousSibling': 'previousNode', 73 'Node.previousSibling': 'previousNode',
73 'Node.textContent': 'text', 74 'Node.textContent': 'text',
75 'SVGElement.className': '_svgClassName',
76 'SVGAnimatedString.className': '_svgClassName',
77 'SVGStylable.className': '_svgClassName',
74 } 78 }
75 79
76 #TODO(jacobr): inject annotations into the interfaces based on this table and 80 #TODO(jacobr): inject annotations into the interfaces based on this table and
77 # on _html_library_renames. 81 # on _html_library_renames.
78 _injected_doc_fragments = { 82 _injected_doc_fragments = {
79 'Element.query': ' /** @domName querySelector, Document.getElementById */', 83 'Element.query': ' /** @domName querySelector, Document.getElementById */',
80 } 84 }
81 # Members and classes from the dom that should be removed completelly from 85 # Members and classes from the dom that should be removed completelly from
82 # dart:html. These could be expressed in the IDL instead but expressing this 86 # dart:html. These could be expressed in the IDL instead but expressing this
83 # as a simple table instead is more concise. 87 # as a simple table instead is more concise.
84 # Syntax is: ClassName.(get\.|set\.)?MemberName 88 # Syntax is: ClassName.(get\.|set\.)?MemberName
85 # Using get: and set: is optional and should only be used when a getter needs 89 # Using get: and set: is optional and should only be used when a getter needs
86 # to be suppressed but not the setter, etc. 90 # to be suppressed but not the setter, etc.
87 # TODO(jacobr): cleanup and augment this list. 91 # TODO(jacobr): cleanup and augment this list.
88 _html_library_remove = set([ 92 _html_library_remove = set([
89 'Window.get:document', # Removed as we have a custom implementation. 93 'Window.get:document', # Removed as we have a custom implementation.
90 'NodeList.item', 94 'NodeList.item',
91 "Attr.*", 95 "Attr.*",
92 # "BarProp.*", 96 # "BarProp.*",
93 # "BarInfo.*", 97 # "BarInfo.*",
94 # "Blob.webkitSlice", 98 # "Blob.webkitSlice",
95 # "CDATASection.*", 99 # "CDATASection.*",
96 # "Comment.*", 100 # "Comment.*",
97 # "DOMImplementation.*", 101 # "DOMImplementation.*",
98 # TODO(jacobr): listing title here is a temporary hack due to a frog bug
99 # involving when an interface inherits from another interface and defines
100 # the same field. BUG(1633)
101 "Document.title",
102 "Element.title",
103 "Document.get:documentElement", 102 "Document.get:documentElement",
104 "Document.get:forms", 103 "Document.get:forms",
105 # "Document.get:selectedStylesheetSet", 104 # "Document.get:selectedStylesheetSet",
106 # "Document.set:selectedStylesheetSet", 105 # "Document.set:selectedStylesheetSet",
107 # "Document.get:preferredStylesheetSet", 106 # "Document.get:preferredStylesheetSet",
108 "Document.get:links", 107 "Document.get:links",
109 "Document.getElementsByTagName", 108 "Document.getElementsByTagName",
110 "Document.set:domain", 109 "Document.set:domain",
111 "Document.get:implementation", 110 "Document.get:implementation",
112 "Document.createAttributeNS", 111 "Document.createAttributeNS",
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 "Element.set:outerHTML", 193 "Element.set:outerHTML",
195 "Element.itemScope", 194 "Element.itemScope",
196 "Element.itemValue", 195 "Element.itemValue",
197 "Element.itemId", 196 "Element.itemId",
198 "Element.get:itemProp", 197 "Element.get:itemProp",
199 'Element.scrollIntoView', 198 'Element.scrollIntoView',
200 "EmbedElement.getSVGDocument", 199 "EmbedElement.getSVGDocument",
201 "FormElement.get:elements", 200 "FormElement.get:elements",
202 "HTMLFrameElement.*", 201 "HTMLFrameElement.*",
203 "HTMLFrameSetElement.*", 202 "HTMLFrameSetElement.*",
204 "HTMLHtmlElement.version", 203 "HtmlElement.version",
204 "HtmlElement.manifest",
205 "Document.version",
206 "Document.manifest",
205 # "IFrameElement.getSVGDocument", #TODO(jacobr): should this be removed 207 # "IFrameElement.getSVGDocument", #TODO(jacobr): should this be removed
206 "InputElement.dirName", 208 "InputElement.dirName",
207 "HTMLIsIndexElement.*", 209 "HTMLIsIndexElement.*",
208 "ObjectElement.getSVGDocument", 210 "ObjectElement.getSVGDocument",
209 "HTMLOptionsCollection.*", 211 "HTMLOptionsCollection.*",
210 "HTMLPropertiesCollection.*", 212 "HTMLPropertiesCollection.*",
211 "SelectElement.remove", 213 "SelectElement.remove",
212 "TextAreaElement.dirName", 214 "TextAreaElement.dirName",
213 "NamedNodeMap.*", 215 "NamedNodeMap.*",
214 "Node.isEqualNode", 216 "Node.isEqualNode",
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 self._event_classes = set() 405 self._event_classes = set()
404 self._seen_event_names = {} 406 self._seen_event_names = {}
405 self._database = database 407 self._database = database
406 self._generator = generator 408 self._generator = generator
407 409
408 def _AllowInHtmlLibrary(self, interface, member, member_prefix): 410 def _AllowInHtmlLibrary(self, interface, member, member_prefix):
409 return not self._Matches(interface, member, member_prefix, 411 return not self._Matches(interface, member, member_prefix,
410 _html_library_remove) 412 _html_library_remove)
411 413
412 def _Matches(self, interface, member, member_prefix, candidates): 414 def _Matches(self, interface, member, member_prefix, candidates):
413 for interface_name in ([interface.id] + 415 for interface_name in self._AllAncestorInterfaces(interface):
414 self._generator._AllImplementedInterfaces(interface)):
415 if (DartType(interface_name) + '.' + member in candidates or 416 if (DartType(interface_name) + '.' + member in candidates or
416 DartType(interface_name) + '.' + member_prefix + member in candidates) : 417 DartType(interface_name) + '.' + member_prefix + member in candidates) :
417 return True 418 return True
418 return False 419 return False
419 420
420 def MaybeReturnDocument(self, return_type): 421 def MaybeReturnDocument(self, return_type):
421 """ 422 """
422 To make it appear that there are not a distinct Document and 423 To make it appear that there are not a distinct Document and
423 HTMLHtmlElement (document.documentElement) objects we always use 424 HTMLHtmlElement (document.documentElement) objects we always use
424 documentElement instead of the regular document object so must not 425 documentElement instead of the regular document object so must not
425 allow a regular document to leak out. 426 allow a regular document to leak out.
426 """ 427 """
427 # TODO(jacobr): any method that returns a Node could also theoretically 428 # TODO(jacobr): any method that returns a Node could also theoretically
428 # really return a Document but there are alot of methods that return nodes 429 # really return a Document but there are alot of methods that return nodes
429 # and they all appear to be safe. Consider the alternate strategy of 430 # and they all appear to be safe. Consider the alternate strategy of
430 # whitelisting just the known safe methods that return Nodes. 431 # whitelisting just the known safe methods that return Nodes.
431 return (DartType(return_type) == 'EventTarget' or 432 return (DartType(return_type) == 'EventTarget' or
432 DartType(return_type) == 'Document') 433 DartType(return_type) == 'Document')
433 434
435 def _AllAncestorInterfaces(self, interface):
436 interfaces = ([interface.id] +
437 self._generator._AllImplementedInterfaces(interface))
438 return interfaces
439
434 def RenameInHtmlLibrary(self, interface, member, member_prefix=''): 440 def RenameInHtmlLibrary(self, interface, member, member_prefix=''):
435 """ 441 """
436 Returns the name of the member in the HTML library or None if the member is 442 Returns the name of the member in the HTML library or None if the member is
437 suppressed in the HTML library 443 suppressed in the HTML library
438 """ 444 """
439 if not self._AllowInHtmlLibrary(interface, member, member_prefix): 445 if not self._AllowInHtmlLibrary(interface, member, member_prefix):
440 return None 446 return None
441 447
442 for interface_name in ([interface.id] + 448 for interface_name in self._AllAncestorInterfaces(interface):
443 self._generator._AllImplementedInterfaces(interface)): 449 name = interface_name + '.' + member
444 name = interface.id + '.' + member
445 if name in _html_library_renames: 450 if name in _html_library_renames:
446 return _html_library_renames[name] 451 return _html_library_renames[name]
447 name = interface.id + '.' + member_prefix + member 452 name = interface.id + '.' + member_prefix + member
448 if name in _html_library_renames: 453 if name in _html_library_renames:
449 return _html_library_renames[name] 454 return _html_library_renames[name]
450 455
451 if self._PrivateInHtmlLibrary(interface, member, member_prefix): 456 if self._PrivateInHtmlLibrary(interface, member, member_prefix):
452 return '_' + member 457 return '_' + member
453 458
454 # No rename required 459 # No rename required
(...skipping 1205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee 1665 # dispatch has removed f(X), leaving only f(Y), but there is no guarantee
1661 # that Y = Z-X, so we need to check for Y. 1666 # that Y = Z-X, so we need to check for Y.
1662 true_code = emitter.Emit( 1667 true_code = emitter.Emit(
1663 '$(INDENT)if ($COND) {\n' 1668 '$(INDENT)if ($COND) {\n'
1664 '$!TRUE' 1669 '$!TRUE'
1665 '$(INDENT)}\n', 1670 '$(INDENT)}\n',
1666 COND=test, INDENT=indent) 1671 COND=test, INDENT=indent)
1667 self.GenerateDispatch( 1672 self.GenerateDispatch(
1668 true_code, info, indent + ' ', position + 1, positive) 1673 true_code, info, indent + ' ', position + 1, positive)
1669 return True 1674 return True
OLDNEW
« no previous file with comments | « no previous file | client/dom/templates/html/dartium/impl_Document.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698