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

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: Delete ARIA.js, add comment to aria_attributes.py 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..ca165f3253650dc16299385a5a0e76c4261099be
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/accessibility/ARIAMetadata.js
@@ -0,0 +1,150 @@
+// 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)
+{
+ /**
+ * @type {!Map<string, !WebInspector.ARIAMetadata.Attribute>}
lushnikov 2016/08/25 18:46:45 nit: we usually do one-line typedefs /** @type {!
aboxhall 2016/08/26 18:15:06 Oops, done, thanks.
+ */
+ this._attributes = new Map();
+
+ if (config)
+ this._initialize(config);
+}
+
+/**
+ * @param {!Object} config
+ */
+WebInspector.ARIAMetadata.initializeWithConfig = function(config)
+{
+ WebInspector.ARIAMetadata.instance = new WebInspector.ARIAMetadata(config);
lushnikov 2016/08/25 18:46:45 let's design it like WI.CSSMetadata object? This w
aboxhall 2016/08/26 18:15:06 Done.
+};
+
+WebInspector.ARIAMetadata.prototype = {
+ /**
+ * @param {!Object} config
+ */
+ _initialize: function(config)
+ {
+ 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.set(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));
lushnikov 2016/08/25 18:46:46 why store this as a global object? Can we just mak
aboxhall 2016/08/26 18:15:06 A future change will add back this._roles as the s
+ },
+
+ /**
+ * @param {string} property
+ * @return {!WebInspector.ARIAMetadata.ValueSet}
+ */
+ valueSetForProperty: function(property)
+ {
+ if (this._attributes.has(property))
+ return new WebInspector.ARIAMetadata.ValueSet(this._attributes.get(property).enum());
+
+ if (property === "role")
+ return WebInspector.ARIAMetadata.Roles;
+
+ return new WebInspector.ARIAMetadata.ValueSet([]);
+ }
+};
+
+/**
+ * @constructor
+ * @param {?Array<string>} values
lushnikov 2016/08/25 18:46:46 do we ever create it with a null?
aboxhall 2016/08/26 18:15:06 n/a
+ */
+WebInspector.ARIAMetadata.ValueSet = function(values)
lushnikov 2016/08/25 18:46:46 Let's get rid of this class altogether - it doesn'
aboxhall 2016/08/26 18:15:06 Done.
+{
+ 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;
lushnikov 2016/08/25 18:46:46 is this ever used?
aboxhall 2016/08/26 18:15:06 No.
+
+ /** @type {string} */
+ this._type = config.type;
+
+ /** @type {?string} */
+ this._default = null;
+
+ /** @type {?Array<string>} */
+ this._enum = null;
lushnikov 2016/08/25 18:46:46 it looks like you never actually expect these to b
aboxhall 2016/08/26 18:15:06 Done.
+
+ if ("default" in config)
+ this._default = config["default"];
+
+ if ("enum" in config)
+ this._enum = config.enum;
+};
+
+WebInspector.ARIAMetadata.Attribute.prototype = {
+ /**
+ * @return {string}
+ */
+ type: function()
lushnikov 2016/08/25 18:46:46 this seems to be unused as well
aboxhall 2016/08/26 18:15:06 Done.
+ {
+ return this._type;
+ },
+
+ /**
+ * @return {?string}
+ */
+ defaultValue: function()
lushnikov 2016/08/25 18:46:46 where do you use this?
aboxhall 2016/08/26 18:15:06 Not yet used.
+ {
+ return this._default;
+ },
+
+ /**
+ * @return {?Array<string>}
+ */
+ enum: function()
lushnikov 2016/08/25 18:46:46 are these values? we have a defaultValue, so this
aboxhall 2016/08/26 18:15:06 I'd rather keep it as enum, as it's only relevant
+ {
+ return this._enum
lushnikov 2016/08/25 18:46:45 nit: missing ;
aboxhall 2016/08/26 18:15:06 Done.
+ }
+};
+
+/** @enum {string} */
+WebInspector.ARIAMetadata.AttributeTypes = {
lushnikov 2016/08/25 18:46:45 are these ever used? I didn't find any occurrence.
aboxhall 2016/08/26 18:15:06 Not yet.
+ BOOLEAN: "boolean",
+ IDREF: "IDREF",
+ IDREF_LIST: "IDREF_list",
+ INTEGER: "integer",
+ NUMBER: "decimal",
+ STRING: "string",
+ TOKEN: "token",
+ TOKEN_LIST: "token_list",
+};

Powered by Google App Engine
This is Rietveld 408576698