OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | |
5 /** | 4 /** |
6 * @constructor | 5 * @unrestricted |
7 * @param {?Object} config | |
8 */ | 6 */ |
9 WebInspector.ARIAMetadata = function(config) | 7 WebInspector.ARIAMetadata = class { |
10 { | 8 /** |
| 9 * @param {?Object} config |
| 10 */ |
| 11 constructor(config) { |
11 /** @type {!Map<string, !WebInspector.ARIAMetadata.Attribute>} */ | 12 /** @type {!Map<string, !WebInspector.ARIAMetadata.Attribute>} */ |
12 this._attributes = new Map(); | 13 this._attributes = new Map(); |
13 | 14 |
14 if (config) | 15 if (config) |
15 this._initialize(config); | 16 this._initialize(config); |
| 17 } |
| 18 |
| 19 /** |
| 20 * @param {!Object} config |
| 21 */ |
| 22 _initialize(config) { |
| 23 var attributes = config['attributes']; |
| 24 |
| 25 var booleanEnum = ['true', 'false']; |
| 26 for (var name in attributes) { |
| 27 var attributeConfig = attributes[name]; |
| 28 if (attributeConfig.type === 'boolean') |
| 29 attributeConfig.enum = booleanEnum; |
| 30 this._attributes.set(name, new WebInspector.ARIAMetadata.Attribute(attribu
teConfig)); |
| 31 } |
| 32 |
| 33 /** @type {!Array<string>} */ |
| 34 this._roleNames = Object.keys(config['roles']); |
| 35 } |
| 36 |
| 37 /** |
| 38 * @param {string} property |
| 39 * @return {!Array<string>} |
| 40 */ |
| 41 valuesForProperty(property) { |
| 42 if (this._attributes.has(property)) |
| 43 return this._attributes.get(property).getEnum(); |
| 44 |
| 45 if (property === 'role') |
| 46 return this._roleNames; |
| 47 |
| 48 return []; |
| 49 } |
16 }; | 50 }; |
17 | 51 |
18 /** | 52 /** |
19 * @return {!WebInspector.ARIAMetadata} | 53 * @return {!WebInspector.ARIAMetadata} |
20 */ | 54 */ |
21 WebInspector.ariaMetadata = function() | 55 WebInspector.ariaMetadata = function() { |
22 { | 56 if (!WebInspector.ARIAMetadata._instance) |
23 if (!WebInspector.ARIAMetadata._instance) | 57 WebInspector.ARIAMetadata._instance = new WebInspector.ARIAMetadata(WebInspe
ctor.ARIAMetadata._config || null); |
24 WebInspector.ARIAMetadata._instance = new WebInspector.ARIAMetadata(WebI
nspector.ARIAMetadata._config || null); | 58 return WebInspector.ARIAMetadata._instance; |
25 return WebInspector.ARIAMetadata._instance; | |
26 }; | |
27 | |
28 WebInspector.ARIAMetadata.prototype = { | |
29 /** | |
30 * @param {!Object} config | |
31 */ | |
32 _initialize: function(config) | |
33 { | |
34 var attributes = config["attributes"]; | |
35 | |
36 var booleanEnum = ["true", "false"]; | |
37 for (var name in attributes) { | |
38 var attributeConfig = attributes[name]; | |
39 if (attributeConfig.type === "boolean") | |
40 attributeConfig.enum = booleanEnum; | |
41 this._attributes.set(name, new WebInspector.ARIAMetadata.Attribute(a
ttributeConfig)); | |
42 } | |
43 | |
44 /** @type {!Array<string>} */ | |
45 this._roleNames = Object.keys(config["roles"]); | |
46 }, | |
47 | |
48 /** | |
49 * @param {string} property | |
50 * @return {!Array<string>} | |
51 */ | |
52 valuesForProperty: function(property) | |
53 { | |
54 if (this._attributes.has(property)) | |
55 return this._attributes.get(property).enum(); | |
56 | |
57 if (property === "role") | |
58 return this._roleNames; | |
59 | |
60 return []; | |
61 } | |
62 }; | 59 }; |
63 | 60 |
64 /** | 61 /** |
65 * @constructor | 62 * @unrestricted |
66 * @param {!Object} config | |
67 */ | 63 */ |
68 WebInspector.ARIAMetadata.Attribute = function(config) | 64 WebInspector.ARIAMetadata.Attribute = class { |
69 { | 65 /** |
| 66 * @param {!Object} config |
| 67 */ |
| 68 constructor(config) { |
70 /** @type {!Array<string>} */ | 69 /** @type {!Array<string>} */ |
71 this._enum = []; | 70 this._enum = []; |
72 | 71 |
73 if ("enum" in config) | 72 if ('enum' in config) |
74 this._enum = config.enum; | 73 this._enum = config.enum; |
| 74 } |
| 75 |
| 76 /** |
| 77 * @return {!Array<string>} |
| 78 */ |
| 79 getEnum() { |
| 80 return this._enum; |
| 81 } |
75 }; | 82 }; |
76 | |
77 WebInspector.ARIAMetadata.Attribute.prototype = { | |
78 /** | |
79 * @return {!Array<string>} | |
80 */ | |
81 enum: function() | |
82 { | |
83 return this._enum; | |
84 } | |
85 }; | |
OLD | NEW |