1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:37:43 +00:00

LibWeb: Add Functionality to Dump to Accessibility Tree

This will be used to display the accessibility tree in the inspector.
This commit is contained in:
Jonah 2022-12-11 10:56:37 -06:00 committed by Sam Atkins
parent 3eef54823a
commit a469bbd178
4 changed files with 70 additions and 0 deletions

View file

@ -2338,4 +2338,23 @@ JS::NonnullGCPtr<DOM::Document> Document::appropriate_template_contents_owner_do
return *this;
}
DeprecatedString Document::dump_accessibility_tree_as_json()
{
StringBuilder builder;
auto accessibility_tree = AccessibilityTreeNode::create(this, nullptr);
build_accessibility_tree(*&accessibility_tree);
auto json = MUST(JsonObjectSerializer<>::try_create(builder));
// Empty document
if (!accessibility_tree->value()) {
MUST(json.add("type"sv, "element"sv));
MUST(json.add("role"sv, "document"sv));
} else {
accessibility_tree->serialize_tree_as_json(json);
}
MUST(json.finish());
return builder.to_deprecated_string();
}
}