Commit f74f5af4 authored by Martin Robinson's avatar Martin Robinson Committed by Commit Bot

Make AtkRole to string conversion more robust

Make the conversion between an AtkRole and the string representation a
bit more robust and share it between all accessibility formatters.

Bug: 1017106
Change-Id: Idfd77b4b2687fcbbcb2d4c8266115f68ba7bd041
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875096Reviewed-by: default avatarJoanmarie Diggs <jdiggs@igalia.com>
Commit-Queue: Martin Robinson <mrobinson@igalia.com>
Cr-Commit-Position: refs/heads/master@{#708605}
parent 455e7762
......@@ -192,7 +192,7 @@ bool AccessibilityEventRecorderAuraLinux::IncludeState(
std::string AccessibilityEventRecorderAuraLinux::AtkObjectToString(
AtkObject* obj,
bool include_name) {
std::string role = atk_role_get_name(atk_object_get_role(obj));
std::string role = AtkRoleToString(atk_object_get_role(obj));
base::ReplaceChars(role, " ", "_", &role);
std::string str =
base::StringPrintf("role=ROLE_%s", base::ToUpperASCII(role).c_str());
......
......@@ -198,136 +198,6 @@ void AccessibilityTreeFormatterAuraLinux::RecursiveBuildAccessibilityTree(
dict->Set(kChildrenDictAttr, std::move(children));
}
// TODO(aleventhal) Remove this and use atk_role_get_name() once the following
// GNOME bug is fixed: https://bugzilla.gnome.org/show_bug.cgi?id=795983
const char* const kRoleNames[] = {
"invalid", // ATK_ROLE_INVALID.
"accelerator label",
"alert",
"animation",
"arrow",
"calendar",
"canvas",
"check box",
"check menu item",
"color chooser",
"column header",
"combo box",
"dateeditor",
"desktop icon",
"desktop frame",
"dial",
"dialog",
"directory pane",
"drawing area",
"file chooser",
"filler",
"fontchooser",
"frame",
"glass pane",
"html container",
"icon",
"image",
"internal frame",
"label",
"layered pane",
"list",
"list item",
"menu",
"menu bar",
"menu item",
"option pane",
"page tab",
"page tab list",
"panel",
"password text",
"popup menu",
"progress bar",
"push button",
"radio button",
"radio menu item",
"root pane",
"row header",
"scroll bar",
"scroll pane",
"separator",
"slider",
"split pane",
"spin button",
"statusbar",
"table",
"table cell",
"table column header",
"table row header",
"tear off menu item",
"terminal",
"text",
"toggle button",
"tool bar",
"tool tip",
"tree",
"tree table",
"unknown",
"viewport",
"window",
"header",
"footer",
"paragraph",
"ruler",
"application",
"autocomplete",
"edit bar",
"embedded component",
"entry",
"chart",
"caption",
"document frame",
"heading",
"page",
"section",
"redundant object",
"form",
"link",
"input method window",
"table row",
"tree item",
"document spreadsheet",
"document presentation",
"document text",
"document web",
"document email",
"comment",
"list box",
"grouping",
"image map",
"notification",
"info bar",
"level bar",
"title bar",
"block quote",
"audio",
"video",
"definition",
"article",
"landmark",
"log",
"marquee",
"math",
"rating",
"timer",
"description list",
"description term",
"description value",
"static",
"math fraction",
"math root",
"subscript",
"superscript",
"footnote", // ATK_ROLE_FOOTNOTE = 122.
"content deletion", // ATK_ROLE_CONTENT_DELETION = 123.
"content insertion", // ATK_ROLE_CONTENT_DELETION = 124.
};
void AccessibilityTreeFormatterAuraLinux::AddTextProperties(
AtkText* atk_text,
base::DictionaryValue* dict) {
......@@ -540,8 +410,7 @@ void AccessibilityTreeFormatterAuraLinux::AddProperties(
AtkRole role = atk_object_get_role(atk_object);
if (role != ATK_ROLE_UNKNOWN) {
int role_index = static_cast<int>(role);
dict->SetString("role", kRoleNames[role_index]);
dict->SetString("role", AtkRoleToString(role));
}
const gchar* name = atk_object_get_name(atk_object);
......
......@@ -235,4 +235,143 @@ CONTENT_EXPORT const char* ATSPIRoleToString(AtspiRole role) {
return GetNameForPlatformConstant(role_table, base::size(role_table), role);
}
// This is used to ensure a standard set of AtkRole name conversions between
// different versions of ATK. Older versions may not have an implementation of
// a new role and newer versions may have changed the name returned by
// atk_role_get_name. This table should be kept up to date with newer ATK
// releases.
const char* const kRoleNames[] = {
"invalid", // ATK_ROLE_INVALID.
"accelerator label",
"alert",
"animation",
"arrow",
"calendar",
"canvas",
"check box",
"check menu item",
"color chooser",
"column header",
"combo box",
"dateeditor",
"desktop icon",
"desktop frame",
"dial",
"dialog",
"directory pane",
"drawing area",
"file chooser",
"filler",
"fontchooser",
"frame",
"glass pane",
"html container",
"icon",
"image",
"internal frame",
"label",
"layered pane",
"list",
"list item",
"menu",
"menu bar",
"menu item",
"option pane",
"page tab",
"page tab list",
"panel",
"password text",
"popup menu",
"progress bar",
"push button",
"radio button",
"radio menu item",
"root pane",
"row header",
"scroll bar",
"scroll pane",
"separator",
"slider",
"split pane",
"spin button",
"statusbar",
"table",
"table cell",
"table column header",
"table row header",
"tear off menu item",
"terminal",
"text",
"toggle button",
"tool bar",
"tool tip",
"tree",
"tree table",
"unknown",
"viewport",
"window",
"header",
"footer",
"paragraph",
"ruler",
"application",
"autocomplete",
"edit bar",
"embedded component",
"entry",
"chart",
"caption",
"document frame",
"heading",
"page",
"section",
"redundant object",
"form",
"link",
"input method window",
"table row",
"tree item",
"document spreadsheet",
"document presentation",
"document text",
"document web",
"document email",
"comment",
"list box",
"grouping",
"image map",
"notification",
"info bar",
"level bar",
"title bar",
"block quote",
"audio",
"video",
"definition",
"article",
"landmark",
"log",
"marquee",
"math",
"rating",
"timer",
"description list",
"description term",
"description value",
"static",
"math fraction",
"math root",
"subscript",
"superscript",
"footnote", // ATK_ROLE_FOOTNOTE = 122.
"content deletion", // ATK_ROLE_CONTENT_DELETION = 123.
"content insertion", // ATK_ROLE_CONTENT_DELETION = 124.
};
const char* AtkRoleToString(AtkRole role) {
if (role < G_N_ELEMENTS(kRoleNames))
return kRoleNames[role];
return "<unknown AtkRole>";
}
} // namespace content
......@@ -5,6 +5,7 @@
#ifndef CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_UTILS_AURALINUX_H_
#define CONTENT_BROWSER_ACCESSIBILITY_ACCESSIBILITY_TREE_FORMATTER_UTILS_AURALINUX_H_
#include <atk/atk.h>
#include <atspi/atspi.h>
#include "content/common/content_export.h"
......@@ -13,6 +14,7 @@ namespace content {
CONTENT_EXPORT const char* ATSPIStateToString(AtspiStateType state);
CONTENT_EXPORT const char* ATSPIRoleToString(AtspiRole role);
CONTENT_EXPORT const char* AtkRoleToString(AtkRole role);
} // namespace content
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment