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

Unified Diff: third_party/WebKit/Source/devtools/scripts/aria_attributes.py

Issue 2200893003: DevTools: Add autocomplete for ARIA (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove done TODO Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/scripts/aria_attributes.py
diff --git a/third_party/WebKit/Source/devtools/scripts/aria_attributes.py b/third_party/WebKit/Source/devtools/scripts/aria_attributes.py
new file mode 100755
index 0000000000000000000000000000000000000000..69e535d2cf1161d21f1be248e797d2bb21089991
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/aria_attributes.py
@@ -0,0 +1,86 @@
+#!/usr/bin/env python
+#
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import json
+import urllib2
+import xml.dom.minidom
+
+import sys
+
+
+def add_array_property(obj, name, info_node):
+ value = ''
+ if info_node.hasAttribute('rdf:resource'):
+ value = info_node.getAttribute('rdf:resource').split('#')[-1]
+ else:
+ text_node = info_node.firstChild
+ value = text_node.data.strip()
+ if value == '':
+ return
+ if name in obj:
+ obj[name].append(value)
+ else:
+ obj[name] = [value]
+
+
+def fetch_roles():
+ response = urllib2.urlopen("http://www.w3.org/WAI/ARIA/schemata/aria-1.rdf", timeout=5)
lushnikov 2016/08/23 17:23:51 do you intend to run this script as a part of buil
aboxhall 2016/08/23 21:06:17 No, if anything it'd be manually run occasionally
lushnikov 2016/08/24 23:05:10 I see; can we put a clarifying comment in the begi
+ content = response.read()
+ tree = xml.dom.minidom.parseString(content)
+ roles = {}
+ for role_node in tree.getElementsByTagName('owl:Class'):
+ role = {}
+ for info_node in role_node.childNodes:
+ if info_node.nodeType != xml.dom.minidom.Node.ELEMENT_NODE:
+ continue
+ if info_node.tagName == 'rdfs:subClassOf':
+ add_array_property(role, 'superclasses', info_node)
+ elif info_node.tagName == 'role:supportedState':
+ add_array_property(role, 'supportedAttributes', info_node)
+ elif info_node.tagName == 'role:requiredState':
+ add_array_property(role, 'requiredAttributes', info_node)
+ elif info_node.tagName == 'role:scope':
+ add_array_property(role, 'scope', info_node)
+ elif info_node.tagName == 'role:mustContain':
+ add_array_property(role, 'mustContain', info_node)
+ elif info_node.tagName == 'role:nameFrom':
+ add_array_property(role, 'nameFrom', info_node)
+ roles[role_node.getAttribute('rdf:ID')] = role
+ return roles
+
+
+def fetch_attributes():
+ xs = 'http://www.w3.org/2001/XMLSchema'
+ response = urllib2.urlopen("https://www.w3.org/MarkUp/SCHEMA/aria-attributes-1.xsd", timeout=5)
+ content = response.read()
+ tree = xml.dom.minidom.parseString(content)
+ attributes = {}
+ for attribute_node in tree.getElementsByTagNameNS(xs, 'attribute'):
+ attribute = {}
+ if attribute_node.hasAttribute('type'):
+ attribute['type'] = attribute_node.getAttribute('type').split(':')[-1]
+ else:
+ type_node = attribute_node.getElementsByTagNameNS(xs, 'simpleType')[0]
+ restriction_node = type_node.getElementsByTagNameNS(xs, 'restriction')[0]
+ attribute['type'] = restriction_node.getAttribute('base').split(':')[-1]
+ attribute['enum'] = []
+ for enum in restriction_node.getElementsByTagNameNS(xs, 'enumeration'):
+ attribute['enum'].append(enum.getAttribute('value'))
+ if attribute_node.hasAttribute('default'):
+ attribute['default'] = attribute_node.getAttribute('default')
+ attributes[attribute_node.getAttribute('name')] = attribute
+ return attributes
+
+
+def main(_):
aboxhall 2016/08/22 18:47:07 Not sure whether to commit this file or not.
+ aria = {}
+ aria['roles'] = fetch_roles()
+ aria['attributes'] = fetch_attributes()
+
+ print json.dumps(aria, sort_keys=True, indent=4)
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))

Powered by Google App Engine
This is Rietveld 408576698