diff options
author | Jonah <jonahshafran@gmail.com> | 2023-02-05 11:24:03 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-19 15:58:20 +0100 |
commit | 29d724d95c77858a8ecd0de4fc74513b9236dc73 (patch) | |
tree | c5674cf9386d49846673baec8192d3424bcc4bea /Userland/Libraries/LibWeb | |
parent | da5c9189b228d23459d284c464effe9630c09dcb (diff) | |
download | serenity-29d724d95c77858a8ecd0de4fc74513b9236dc73.zip |
LibWeb: Serialize Accessible Name and Description for Accessibility Tree
These will get displayed in the DOM inspector.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Document.cpp | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp b/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp index a8acbd2559..6c3766c645 100644 --- a/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp +++ b/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.cpp @@ -24,7 +24,7 @@ AccessibilityTreeNode::AccessibilityTreeNode(JS::GCPtr<DOM::Node> value) m_children = {}; } -void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) const +void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object, Document const& document) const { if (value()->is_document()) { VERIFY_NOT_REACHED(); @@ -37,6 +37,11 @@ void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializer<StringBu auto role = element->role_or_default(); bool has_role = role.has_value() && !ARIA::is_abstract_role(*role); + auto name = MUST(element->accessible_name(document)); + MUST(object.add("name"sv, name)); + auto description = MUST(element->accessible_description(document)); + MUST(object.add("description"sv, description)); + if (has_role) MUST(object.add("role"sv, ARIA::role_name(*role))); else @@ -54,11 +59,11 @@ void AccessibilityTreeNode::serialize_tree_as_json(JsonObjectSerializer<StringBu if (value()->has_child_nodes()) { auto node_children = MUST(object.add_array("children"sv)); - for (auto child : children()) { + for (auto* child : children()) { if (child->value()->is_uninteresting_whitespace_node()) continue; JsonObjectSerializer<StringBuilder> child_object = MUST(node_children.add_object()); - child->serialize_tree_as_json(child_object); + child->serialize_tree_as_json(child_object, document); MUST(child_object.finish()); } MUST(node_children.finish()); diff --git a/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.h b/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.h index fc0fc9235d..bfa556b4ad 100644 --- a/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.h +++ b/Userland/Libraries/LibWeb/DOM/AccessibilityTreeNode.h @@ -25,7 +25,7 @@ public: Vector<AccessibilityTreeNode*> children() const { return m_children; } void append_child(AccessibilityTreeNode* child) { m_children.append(child); } - void serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object) const; + void serialize_tree_as_json(JsonObjectSerializer<StringBuilder>& object, Document const&) const; protected: virtual void visit_edges(Visitor&) override; diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 826d7dda9a..940a91954f 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2362,7 +2362,7 @@ DeprecatedString Document::dump_accessibility_tree_as_json() MUST(json.add("type"sv, "element"sv)); MUST(json.add("role"sv, "document"sv)); } else { - accessibility_tree->serialize_tree_as_json(json); + accessibility_tree->serialize_tree_as_json(json, *this); } MUST(json.finish()); |