Chromium Code Reviews| 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..fc77a01e952baeca92adfedd6bc16f4ff9f1d244 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/devtools/front_end/accessibility/ARIAMetadata.js |
| @@ -0,0 +1,87 @@ |
| +// 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>} */ |
| + this._attributes = new Map(); |
| + |
| + if (config) |
| + this._initialize(config); |
| +} |
| + |
| +/** |
| + * @return {!WebInspector.ARIAMetadata} |
| + */ |
| +WebInspector.ariaMetadata = function() |
| +{ |
| + if (!WebInspector.ARIAMetadata._instance) |
| + WebInspector.ARIAMetadata._instance = new WebInspector.ARIAMetadata(WebInspector.ARIAMetadata.config); |
| + return WebInspector.ARIAMetadata._instance; |
| +}; |
| + |
| +WebInspector.ARIAMetadata.prototype = { |
| + /** |
| + * @param {!Object} config |
| + */ |
| + _initialize: function(config) |
| + { |
| + var attributes = config["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(attributeConfig)); |
| + } |
| + |
| + var roles = config["roles"]; |
|
lushnikov
2016/08/26 23:32:20
nit: inlining this would be nice
|
| + |
| + /** @type {!Array<string>} */ |
| + this._roleNames = Object.keys(roles); |
| + }, |
| + |
| + /** |
| + * @param {string} property |
| + * @return {!Array<string>} |
| + */ |
| + valuesForProperty: function(property) |
|
lushnikov
2016/08/26 23:32:20
Feels a little weird that we call it values here a
aboxhall
2016/08/26 23:43:58
I can see that. It's kind of an implementation det
|
| + { |
| + if (this._attributes.has(property)) |
| + return this._attributes.get(property).enum(); |
| + |
| + if (property === "role") |
| + return this._roleNames; |
| + |
| + return []; |
| + } |
| +}; |
| + |
| +/** |
| + * @constructor |
| + * @param {!Object} config |
| + */ |
| +WebInspector.ARIAMetadata.Attribute = function(config) |
| +{ |
| + /** @type {!Array<string>} */ |
| + this._enum = []; |
| + |
| + if ("enum" in config) |
| + this._enum = config.enum; |
| +}; |
| + |
| +WebInspector.ARIAMetadata.Attribute.prototype = { |
| + /** |
| + * @return {!Array<string>} |
| + */ |
| + enum: function() |
| + { |
| + return this._enum; |
| + } |
| +}; |