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

Unified Diff: third_party/WebKit/Source/devtools/front_end/accessibility/ARIAMetadata.js

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/front_end/accessibility/ARIAMetadata.js
diff --git a/third_party/WebKit/Source/devtools/front_end/accessibility/ARIAMetadata.js b/third_party/WebKit/Source/devtools/front_end/accessibility/ARIAMetadata.js
new file mode 100644
index 0000000000000000000000000000000000000000..c7209049cd57ab9abce7678ae3651c5785b7343f
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/accessibility/ARIAMetadata.js
@@ -0,0 +1,241 @@
+// Copyright (c) 2016 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.
+
+/**
+ * @constructor
+ * @param {?Object} config
+ */
+WebInspector.ARIAMetadata = function(config)
+{
+ this._attributes = {};
lushnikov 2016/08/23 17:23:51 can we use sets/maps here? also, let's jsdoc
aboxhall 2016/08/23 21:06:17 Done.
+ this._roles = {};
lushnikov 2016/08/23 17:23:51 ditto
aboxhall 2016/08/23 21:06:17 Actually this is unnecessary for this change (as i
+
+ if (!config)
+ return;
lushnikov 2016/08/23 17:23:51 let's not do fast-returns in constructors. Instead
aboxhall 2016/08/23 21:06:16 Done.
+
+ var attributes = config["attributes"];
+ WebInspector.ARIAMetadata.Attributes = new WebInspector.ARIAMetadata.ValueSet(Object.keys(attributes));
+
+ var booleanEnum = ["true", "false"];
+ for (var name in attributes) {
+ var attributeConfig = attributes[name];
+ if (attributeConfig.type === "boolean")
+ attributeConfig.enum = booleanEnum;
+ this._attributes[name] = new WebInspector.ARIAMetadata.Attribute(name, attributeConfig);
+ }
+
+ if (!("roles" in config))
+ return;
+ var roles = config["roles"];
+ WebInspector.ARIAMetadata.Roles = new WebInspector.ARIAMetadata.ValueSet(Object.keys(roles));
+
+ var inheritedProperties = ["supportedAttributes", "requiredAttributes"];
+
+ // Do one pass to flip the inheritance hierarchy and turn arrays into sets
lushnikov 2016/08/23 17:23:51 nit: comments in blink should end with period.
aboxhall 2016/08/23 21:06:17 Done.
+ for (var roleName in roles) {
+ var role = roles[roleName];
+ if (!("subclasses" in role))
+ role.subclasses = [];
+
+ if ("superclasses" in role) {
+ for (var superclass of role.superclasses) {
+ var superRole = roles[superclass];
+ if ("subclasses" in superRole)
+ superRole.subclasses.push(roleName);
+ else
+ superRole.subclasses = [roleName];
+ }
+ }
+ for (var prop of inheritedProperties) {
+ if (prop in role)
+ role[prop] = new Set(role[prop]);
+ else
+ role[prop] = new Set();
+ }
+ }
+
+ function _inheritAttributes(parentRole, childRole)
lushnikov 2016/08/23 17:23:51 nit: we only start private class methods and membe
aboxhall 2016/08/23 21:06:17 Done.
+ {
+ if (parentRole) {
+ for (var prop of inheritedProperties) {
+ for (var attribute of parentRole[prop])
+ childRole[prop].add(attribute);
+ }
+ }
+
+ for (var subclass of childRole.subclasses)
+ _inheritAttributes(childRole, roles[subclass]);
+ }
+
+ _inheritAttributes(null, roles["roletype"]);
+
+ this._roles = {};
+ for (var name in roles) {
+ var roleConfig = roles[name];
+ this._roles[name] = new WebInspector.ARIAMetadata.Role(name, roleConfig);
+ }
+};
+
+WebInspector.ARIAMetadata.initializeWithConfig = function(config)
lushnikov 2016/08/23 17:23:51 please add jsdoc
aboxhall 2016/08/23 21:06:17 Done.
+{
+ WebInspector.ARIAMetadata.instance = new WebInspector.ARIAMetadata(config);
+};
+
+WebInspector.ARIAMetadata.prototype = {
+ /**
+ * @param {string} property
+ * @return {!WebInspector.ARIAMetadata.ValueSet}
+ */
+ valueSetForProperty: function(property)
+ {
+ if (property in this._attributes)
+ return new WebInspector.ARIAMetadata.ValueSet(this._attributes[property].enum());
+
+ if (property === "role")
+ return WebInspector.ARIAMetadata.Roles;
+
+ return new WebInspector.ARIAMetadata.ValueSet([]);
+ }
+};
+
+/**
+ * @constructor
+ * @param {!Array<string>} values
+ */
+WebInspector.ARIAMetadata.ValueSet = function(values)
+{
+ this._values = values;
+};
+
+WebInspector.ARIAMetadata.ValueSet.prototype = {
+ /**
+ * @param {string} prefix
+ * @return {!Array<string>}
+ */
+ startsWith: function(prefix)
+ {
+ return this._values.filter((value) => value.startsWith(prefix));
+ }
+};
+
+/**
+ * @constructor
+ * @param {string} name
+ * @param {!Object} config
+ */
+WebInspector.ARIAMetadata.Attribute = function(name, config)
+{
+ /** @type {string} */
+ this._name = name;
+
+ /** @type {string} */
+ this._type = config.type;
+
+ /** @type {?string} */
+ this._default = null;
+
+ /** @type {?Array<string>} */
+ this._enum = null;
+
+ if ("default" in config)
+ this._default = config["default"];
+
+ if ("enum" in config)
+ this._enum = config.enum;
+};
+
+WebInspector.ARIAMetadata.Attribute.prototype = {
+ /**
+ * @return {string}
+ */
+ type: function()
+ {
+ return this._type;
+ },
+
+ /**
+ * @return {?string}
+ */
+ defaultValue: function()
+ {
+ return this._default;
+ },
+
+ /**
+ * @return {?Array<string>}
+ */
+ enum: function()
+ {
+ return this._enum
+ }
+};
+
+/** @enum {string} */
+WebInspector.ARIAMetadata.AttributeTypes = {
+ BOOLEAN: "boolean",
+ IDREF: "IDREF",
+ IDREF_LIST: "IDREF_list",
+ INTEGER: "integer",
+ NUMBER: "decimal",
+ STRING: "string",
+ TOKEN: "token",
+ TOKEN_LIST: "token_list",
+};
+
+/**
+ * @constructor
+ * @param {string} name
+ * @param {!Object} config
+ */
+WebInspector.ARIAMetadata.Role = function(name, config)
+{
+ /** @type {string} */
+ this._name = name;
+
+ /** @type {boolean} */
+ this._abstract = !!(config.abstract);
+
+ /** @type {boolean} */
+ this._nameFromContents = false;
+ if ("nameFrom" in config) {
+ this._nameFromContents = config.nameFrom.some(
+ (value) => value === WebInspector.ARIAMetadata.NameFrom.CONTENTS);
+ }
+
+ /** @type {boolean} */
+ this._nameFromAuthor = false;
+ if ("nameFrom" in config) {
+ this._nameFromAuthor = config.nameFrom.some(
+ (value) => value === WebInspector.ARIAMetadata.NameFrom.AUTHOR);
+ }
+
+ /** @type Set<string> */
+ this._supportedAttributes = new Set();
+ if ("supportedAttributes" in config)
+ this._supportedAttributes = config.supportedAttributes;
+
+ /** @type Set<string> */
+ this._requiredAttributes = new Set();
+ if ("requiredAttributes" in config) {
+ this._requiredAttributes = config.requiredAttributes;
+ for (var attribute of this._requiredAttributes)
+ this._supportedAttributes.add(attribute);
+ }
+
+ /** @type {!Array<string>} */
+ this._scope = [];
+ if ("scope" in config)
+ this._scope = config.scope;
+
+ /** @type {!Array<string>} */
+ this._mustContain = [];
+ if ("mustContain" in config)
+ this._mustContain = config.mustContain;
+}
+
+/** @enum {string} */
+WebInspector.ARIAMetadata.NameFrom = {
+ AUTHOR: "author",
+ CONTENTS: "contents"
+}

Powered by Google App Engine
This is Rietveld 408576698