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 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.
| |
| 12 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
| |
| 13 | |
| 14 if (!config) | |
| 15 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.
| |
| 16 | |
| 17 var attributes = config["attributes"]; | |
| 18 WebInspector.ARIAMetadata.Attributes = new WebInspector.ARIAMetadata.ValueSe t(Object.keys(attributes)); | |
| 19 | |
| 20 var booleanEnum = ["true", "false"]; | |
| 21 for (var name in attributes) { | |
| 22 var attributeConfig = attributes[name]; | |
| 23 if (attributeConfig.type === "boolean") | |
| 24 attributeConfig.enum = booleanEnum; | |
| 25 this._attributes[name] = new WebInspector.ARIAMetadata.Attribute(name, a ttributeConfig); | |
| 26 } | |
| 27 | |
| 28 if (!("roles" in config)) | |
| 29 return; | |
| 30 var roles = config["roles"]; | |
| 31 WebInspector.ARIAMetadata.Roles = new WebInspector.ARIAMetadata.ValueSet(Obj ect.keys(roles)); | |
| 32 | |
| 33 var inheritedProperties = ["supportedAttributes", "requiredAttributes"]; | |
| 34 | |
| 35 // 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.
| |
| 36 for (var roleName in roles) { | |
| 37 var role = roles[roleName]; | |
| 38 if (!("subclasses" in role)) | |
| 39 role.subclasses = []; | |
| 40 | |
| 41 if ("superclasses" in role) { | |
| 42 for (var superclass of role.superclasses) { | |
| 43 var superRole = roles[superclass]; | |
| 44 if ("subclasses" in superRole) | |
| 45 superRole.subclasses.push(roleName); | |
| 46 else | |
| 47 superRole.subclasses = [roleName]; | |
| 48 } | |
| 49 } | |
| 50 for (var prop of inheritedProperties) { | |
| 51 if (prop in role) | |
| 52 role[prop] = new Set(role[prop]); | |
| 53 else | |
| 54 role[prop] = new Set(); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 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.
| |
| 59 { | |
| 60 if (parentRole) { | |
| 61 for (var prop of inheritedProperties) { | |
| 62 for (var attribute of parentRole[prop]) | |
| 63 childRole[prop].add(attribute); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 for (var subclass of childRole.subclasses) | |
| 68 _inheritAttributes(childRole, roles[subclass]); | |
| 69 } | |
| 70 | |
| 71 _inheritAttributes(null, roles["roletype"]); | |
| 72 | |
| 73 this._roles = {}; | |
| 74 for (var name in roles) { | |
| 75 var roleConfig = roles[name]; | |
| 76 this._roles[name] = new WebInspector.ARIAMetadata.Role(name, roleConfig) ; | |
| 77 } | |
| 78 }; | |
| 79 | |
| 80 WebInspector.ARIAMetadata.initializeWithConfig = function(config) | |
|
lushnikov
2016/08/23 17:23:51
please add jsdoc
aboxhall
2016/08/23 21:06:17
Done.
| |
| 81 { | |
| 82 WebInspector.ARIAMetadata.instance = new WebInspector.ARIAMetadata(config); | |
| 83 }; | |
| 84 | |
| 85 WebInspector.ARIAMetadata.prototype = { | |
| 86 /** | |
| 87 * @param {string} property | |
| 88 * @return {!WebInspector.ARIAMetadata.ValueSet} | |
| 89 */ | |
| 90 valueSetForProperty: function(property) | |
| 91 { | |
| 92 if (property in this._attributes) | |
| 93 return new WebInspector.ARIAMetadata.ValueSet(this._attributes[prope rty].enum()); | |
| 94 | |
| 95 if (property === "role") | |
| 96 return WebInspector.ARIAMetadata.Roles; | |
| 97 | |
| 98 return new WebInspector.ARIAMetadata.ValueSet([]); | |
| 99 } | |
| 100 }; | |
| 101 | |
| 102 /** | |
| 103 * @constructor | |
| 104 * @param {!Array<string>} values | |
| 105 */ | |
| 106 WebInspector.ARIAMetadata.ValueSet = function(values) | |
| 107 { | |
| 108 this._values = values; | |
| 109 }; | |
| 110 | |
| 111 WebInspector.ARIAMetadata.ValueSet.prototype = { | |
| 112 /** | |
| 113 * @param {string} prefix | |
| 114 * @return {!Array<string>} | |
| 115 */ | |
| 116 startsWith: function(prefix) | |
| 117 { | |
| 118 return this._values.filter((value) => value.startsWith(prefix)); | |
| 119 } | |
| 120 }; | |
| 121 | |
| 122 /** | |
| 123 * @constructor | |
| 124 * @param {string} name | |
| 125 * @param {!Object} config | |
| 126 */ | |
| 127 WebInspector.ARIAMetadata.Attribute = function(name, config) | |
| 128 { | |
| 129 /** @type {string} */ | |
| 130 this._name = name; | |
| 131 | |
| 132 /** @type {string} */ | |
| 133 this._type = config.type; | |
| 134 | |
| 135 /** @type {?string} */ | |
| 136 this._default = null; | |
| 137 | |
| 138 /** @type {?Array<string>} */ | |
| 139 this._enum = null; | |
| 140 | |
| 141 if ("default" in config) | |
| 142 this._default = config["default"]; | |
| 143 | |
| 144 if ("enum" in config) | |
| 145 this._enum = config.enum; | |
| 146 }; | |
| 147 | |
| 148 WebInspector.ARIAMetadata.Attribute.prototype = { | |
| 149 /** | |
| 150 * @return {string} | |
| 151 */ | |
| 152 type: function() | |
| 153 { | |
| 154 return this._type; | |
| 155 }, | |
| 156 | |
| 157 /** | |
| 158 * @return {?string} | |
| 159 */ | |
| 160 defaultValue: function() | |
| 161 { | |
| 162 return this._default; | |
| 163 }, | |
| 164 | |
| 165 /** | |
| 166 * @return {?Array<string>} | |
| 167 */ | |
| 168 enum: function() | |
| 169 { | |
| 170 return this._enum | |
| 171 } | |
| 172 }; | |
| 173 | |
| 174 /** @enum {string} */ | |
| 175 WebInspector.ARIAMetadata.AttributeTypes = { | |
| 176 BOOLEAN: "boolean", | |
| 177 IDREF: "IDREF", | |
| 178 IDREF_LIST: "IDREF_list", | |
| 179 INTEGER: "integer", | |
| 180 NUMBER: "decimal", | |
| 181 STRING: "string", | |
| 182 TOKEN: "token", | |
| 183 TOKEN_LIST: "token_list", | |
| 184 }; | |
| 185 | |
| 186 /** | |
| 187 * @constructor | |
| 188 * @param {string} name | |
| 189 * @param {!Object} config | |
| 190 */ | |
| 191 WebInspector.ARIAMetadata.Role = function(name, config) | |
| 192 { | |
| 193 /** @type {string} */ | |
| 194 this._name = name; | |
| 195 | |
| 196 /** @type {boolean} */ | |
| 197 this._abstract = !!(config.abstract); | |
| 198 | |
| 199 /** @type {boolean} */ | |
| 200 this._nameFromContents = false; | |
| 201 if ("nameFrom" in config) { | |
| 202 this._nameFromContents = config.nameFrom.some( | |
| 203 (value) => value === WebInspector.ARIAMetadata.NameFrom.CONTENTS); | |
| 204 } | |
| 205 | |
| 206 /** @type {boolean} */ | |
| 207 this._nameFromAuthor = false; | |
| 208 if ("nameFrom" in config) { | |
| 209 this._nameFromAuthor = config.nameFrom.some( | |
| 210 (value) => value === WebInspector.ARIAMetadata.NameFrom.AUTHOR); | |
| 211 } | |
| 212 | |
| 213 /** @type Set<string> */ | |
| 214 this._supportedAttributes = new Set(); | |
| 215 if ("supportedAttributes" in config) | |
| 216 this._supportedAttributes = config.supportedAttributes; | |
| 217 | |
| 218 /** @type Set<string> */ | |
| 219 this._requiredAttributes = new Set(); | |
| 220 if ("requiredAttributes" in config) { | |
| 221 this._requiredAttributes = config.requiredAttributes; | |
| 222 for (var attribute of this._requiredAttributes) | |
| 223 this._supportedAttributes.add(attribute); | |
| 224 } | |
| 225 | |
| 226 /** @type {!Array<string>} */ | |
| 227 this._scope = []; | |
| 228 if ("scope" in config) | |
| 229 this._scope = config.scope; | |
| 230 | |
| 231 /** @type {!Array<string>} */ | |
| 232 this._mustContain = []; | |
| 233 if ("mustContain" in config) | |
| 234 this._mustContain = config.mustContain; | |
| 235 } | |
| 236 | |
| 237 /** @enum {string} */ | |
| 238 WebInspector.ARIAMetadata.NameFrom = { | |
| 239 AUTHOR: "author", | |
| 240 CONTENTS: "contents" | |
| 241 } | |
| OLD | NEW |