Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @constructor | |
| 7 * @param {?Object} config | |
| 8 */ | |
| 9 WebInspector.ARIAMetadata = function(config) | |
| 10 { | |
| 11 /** | |
| 12 * @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.
| |
| 13 */ | |
| 14 this._attributes = new Map(); | |
| 15 | |
| 16 if (config) | |
| 17 this._initialize(config); | |
| 18 } | |
| 19 | |
| 20 /** | |
| 21 * @param {!Object} config | |
| 22 */ | |
| 23 WebInspector.ARIAMetadata.initializeWithConfig = function(config) | |
| 24 { | |
| 25 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.
| |
| 26 }; | |
| 27 | |
| 28 WebInspector.ARIAMetadata.prototype = { | |
| 29 /** | |
| 30 * @param {!Object} config | |
| 31 */ | |
| 32 _initialize: function(config) | |
| 33 { | |
| 34 var attributes = config["attributes"]; | |
| 35 WebInspector.ARIAMetadata.Attributes = new WebInspector.ARIAMetadata.Val ueSet(Object.keys(attributes)); | |
| 36 | |
| 37 var booleanEnum = ["true", "false"]; | |
| 38 for (var name in attributes) { | |
| 39 var attributeConfig = attributes[name]; | |
| 40 if (attributeConfig.type === "boolean") | |
| 41 attributeConfig.enum = booleanEnum; | |
| 42 this._attributes.set(name, new WebInspector.ARIAMetadata.Attribute(n ame, attributeConfig)); | |
| 43 } | |
| 44 | |
| 45 if (!("roles" in config)) | |
| 46 return; | |
| 47 | |
| 48 var roles = config["roles"]; | |
| 49 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
| |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * @param {string} property | |
| 54 * @return {!WebInspector.ARIAMetadata.ValueSet} | |
| 55 */ | |
| 56 valueSetForProperty: function(property) | |
| 57 { | |
| 58 if (this._attributes.has(property)) | |
| 59 return new WebInspector.ARIAMetadata.ValueSet(this._attributes.get(p roperty).enum()); | |
| 60 | |
| 61 if (property === "role") | |
| 62 return WebInspector.ARIAMetadata.Roles; | |
| 63 | |
| 64 return new WebInspector.ARIAMetadata.ValueSet([]); | |
| 65 } | |
| 66 }; | |
| 67 | |
| 68 /** | |
| 69 * @constructor | |
| 70 * @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
| |
| 71 */ | |
| 72 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.
| |
| 73 { | |
| 74 this._values = values; | |
| 75 }; | |
| 76 | |
| 77 WebInspector.ARIAMetadata.ValueSet.prototype = { | |
| 78 /** | |
| 79 * @param {string} prefix | |
| 80 * @return {!Array<string>} | |
| 81 */ | |
| 82 startsWith: function(prefix) | |
| 83 { | |
| 84 return this._values.filter((value) => value.startsWith(prefix)); | |
| 85 } | |
| 86 }; | |
| 87 | |
| 88 /** | |
| 89 * @constructor | |
| 90 * @param {string} name | |
| 91 * @param {!Object} config | |
| 92 */ | |
| 93 WebInspector.ARIAMetadata.Attribute = function(name, config) | |
| 94 { | |
| 95 /** @type {string} */ | |
| 96 this._name = name; | |
|
lushnikov
2016/08/25 18:46:46
is this ever used?
aboxhall
2016/08/26 18:15:06
No.
| |
| 97 | |
| 98 /** @type {string} */ | |
| 99 this._type = config.type; | |
| 100 | |
| 101 /** @type {?string} */ | |
| 102 this._default = null; | |
| 103 | |
| 104 /** @type {?Array<string>} */ | |
| 105 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.
| |
| 106 | |
| 107 if ("default" in config) | |
| 108 this._default = config["default"]; | |
| 109 | |
| 110 if ("enum" in config) | |
| 111 this._enum = config.enum; | |
| 112 }; | |
| 113 | |
| 114 WebInspector.ARIAMetadata.Attribute.prototype = { | |
| 115 /** | |
| 116 * @return {string} | |
| 117 */ | |
| 118 type: function() | |
|
lushnikov
2016/08/25 18:46:46
this seems to be unused as well
aboxhall
2016/08/26 18:15:06
Done.
| |
| 119 { | |
| 120 return this._type; | |
| 121 }, | |
| 122 | |
| 123 /** | |
| 124 * @return {?string} | |
| 125 */ | |
| 126 defaultValue: function() | |
|
lushnikov
2016/08/25 18:46:46
where do you use this?
aboxhall
2016/08/26 18:15:06
Not yet used.
| |
| 127 { | |
| 128 return this._default; | |
| 129 }, | |
| 130 | |
| 131 /** | |
| 132 * @return {?Array<string>} | |
| 133 */ | |
| 134 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
| |
| 135 { | |
| 136 return this._enum | |
|
lushnikov
2016/08/25 18:46:45
nit: missing ;
aboxhall
2016/08/26 18:15:06
Done.
| |
| 137 } | |
| 138 }; | |
| 139 | |
| 140 /** @enum {string} */ | |
| 141 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.
| |
| 142 BOOLEAN: "boolean", | |
| 143 IDREF: "IDREF", | |
| 144 IDREF_LIST: "IDREF_list", | |
| 145 INTEGER: "integer", | |
| 146 NUMBER: "decimal", | |
| 147 STRING: "string", | |
| 148 TOKEN: "token", | |
| 149 TOKEN_LIST: "token_list", | |
| 150 }; | |
| OLD | NEW |