mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-10 13:44:39 +08:00
ARIAProperties.json5 represents the certain rules captured in the ARIA spec. This change also uses it to generate the list of ARIA attribute name constants, and to generate the ARIA autocompletion configuration for devtools. Also adds pyjson5 as a third_party library. Change-Id: I622e590196be667ed97288a73d040856380f3bf9 Reviewed-on: https://chromium-review.googlesource.com/737397 Commit-Queue: Alice Boxhall <aboxhall@chromium.org> Reviewed-by: Nico Weber <thakis@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Dirk Pranke <dpranke@chromium.org> Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org> Reviewed-by: Joel Einbinder <einbinder@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#560222} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: a39ce6e61cd170b5b549f119f3b6f7a08253cba9
82 lines
1.9 KiB
JavaScript
82 lines
1.9 KiB
JavaScript
// 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.
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
Accessibility.ARIAMetadata = class {
|
|
/**
|
|
* @param {?Object} config
|
|
*/
|
|
constructor(config) {
|
|
/** @type {!Map<string, !Accessibility.ARIAMetadata.Attribute>} */
|
|
this._attributes = new Map();
|
|
|
|
if (config)
|
|
this._initialize(config);
|
|
}
|
|
|
|
/**
|
|
* @param {!Object} config
|
|
*/
|
|
_initialize(config) {
|
|
const attributes = config['attributes'];
|
|
|
|
const booleanEnum = ['true', 'false'];
|
|
for (const attributeConfig of attributes) {
|
|
if (attributeConfig.type === 'boolean')
|
|
attributeConfig.enum = booleanEnum;
|
|
this._attributes.set(attributeConfig.name, new Accessibility.ARIAMetadata.Attribute(attributeConfig));
|
|
}
|
|
|
|
/** @type {!Array<string>} */
|
|
this._roleNames = config['roles'].map(roleConfig => roleConfig.name);
|
|
}
|
|
|
|
/**
|
|
* @param {string} property
|
|
* @return {!Array<string>}
|
|
*/
|
|
valuesForProperty(property) {
|
|
if (this._attributes.has(property))
|
|
return this._attributes.get(property).getEnum();
|
|
|
|
if (property === 'role')
|
|
return this._roleNames;
|
|
|
|
return [];
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @return {!Accessibility.ARIAMetadata}
|
|
*/
|
|
Accessibility.ariaMetadata = function() {
|
|
if (!Accessibility.ARIAMetadata._instance)
|
|
Accessibility.ARIAMetadata._instance = new Accessibility.ARIAMetadata(Accessibility.ARIAMetadata._config || null);
|
|
return Accessibility.ARIAMetadata._instance;
|
|
};
|
|
|
|
/**
|
|
* @unrestricted
|
|
*/
|
|
Accessibility.ARIAMetadata.Attribute = class {
|
|
/**
|
|
* @param {!Object} config
|
|
*/
|
|
constructor(config) {
|
|
/** @type {!Array<string>} */
|
|
this._enum = [];
|
|
|
|
if ('enum' in config)
|
|
this._enum = config.enum;
|
|
}
|
|
|
|
/**
|
|
* @return {!Array<string>}
|
|
*/
|
|
getEnum() {
|
|
return this._enum;
|
|
}
|
|
};
|