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

Add level attribute to AtkObjects

The level attributes specifies the hierarchical level of the element.
This is used for HTML heading elements.

TEST=accessibility_unittests --gtest_filter=AXPlatformNodeAuraLinuxTest.*

Bug: 866612
Change-Id: If3e1d5192dc6d0749bdaffda203d4539ea02bf63
Reviewed-on: https://chromium-review.googlesource.com/1150144Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577917}
parent 9310bd64
......@@ -7,6 +7,7 @@
#include <stdint.h>
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/accessibility/ax_action_data.h"
......@@ -306,7 +307,13 @@ static AtkRelationSet* ax_platform_node_auralinux_ref_relation_set(
static AtkAttributeSet* ax_platform_node_auralinux_get_attributes(
AtkObject* atk_object) {
return NULL;
ui::AXPlatformNodeAuraLinux* obj =
AtkObjectToAXPlatformNodeAuraLinux(atk_object);
if (!obj)
return nullptr;
return obj->GetAtkAttributes();
}
static AtkRole ax_platform_node_auralinux_get_role(AtkObject* atk_object) {
......@@ -1533,6 +1540,15 @@ const gchar* AXPlatformNodeAuraLinux::GetDefaultActionName() {
ATK_AURALINUX_RETURN_STRING(base::UTF16ToUTF8(action_verb));
}
AtkAttributeSet* AXPlatformNodeAuraLinux::GetAtkAttributes() const {
AtkAttributeSet* atk_attributes = nullptr;
atk_attributes = AddIntAttributeToAtkAttributeSet(
atk_attributes, ax::mojom::IntAttribute::kHierarchicalLevel, "level");
return atk_attributes;
}
// AtkDocumentHelpers
const gchar* AXPlatformNodeAuraLinux::GetDocumentAttributeValue(
......@@ -1549,6 +1565,17 @@ const gchar* AXPlatformNodeAuraLinux::GetDocumentAttributeValue(
return nullptr;
}
static AtkAttributeSet* PrependAtkAttributeToAtkAttributeSet(
AtkAttributeSet* attribute_set,
const char* name,
const char* value) {
AtkAttribute* attribute =
static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
attribute->name = g_strdup(name);
attribute->value = g_strdup(value);
return g_slist_prepend(attribute_set, attribute);
}
AtkAttributeSet* AXPlatformNodeAuraLinux::GetDocumentAttributes() const {
AtkAttributeSet* attribute_set = nullptr;
const gchar* doc_attributes[] = {"DocType", "MimeType", "Title", "URI"};
......@@ -1557,11 +1584,8 @@ AtkAttributeSet* AXPlatformNodeAuraLinux::GetDocumentAttributes() const {
for (unsigned i = 0; i < G_N_ELEMENTS(doc_attributes); i++) {
value = GetDocumentAttributeValue(doc_attributes[i]);
if (value) {
AtkAttribute* attribute =
static_cast<AtkAttribute*>(g_malloc(sizeof(AtkAttribute)));
attribute->name = g_strdup(doc_attributes[i]);
attribute->value = g_strdup(value);
attribute_set = g_slist_prepend(attribute_set, attribute);
attribute_set = PrependAtkAttributeToAtkAttributeSet(
attribute_set, doc_attributes[i], value);
}
}
......@@ -1601,4 +1625,17 @@ void AXPlatformNodeAuraLinux::GetFloatAttributeInGValue(
}
}
AtkAttributeSet* AXPlatformNodeAuraLinux::AddIntAttributeToAtkAttributeSet(
AtkAttributeSet* attributes,
ax::mojom::IntAttribute attribute,
const char* atk_attribute) const {
int value;
if (GetIntAttribute(attribute, &value)) {
attributes = PrependAtkAttributeToAtkAttributeSet(
attributes, atk_attribute, base::IntToString(value).c_str());
}
return attributes;
}
} // namespace ui
......@@ -57,6 +57,7 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
bool GrabFocus();
bool DoDefaultAction();
const gchar* GetDefaultActionName();
AtkAttributeSet* GetAtkAttributes() const;
void SetExtentsRelativeToAtkCoordinateType(
gint* x, gint* y, gint* width, gint* height,
......@@ -71,6 +72,10 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
// Misc helpers
void GetFloatAttributeInGValue(ax::mojom::FloatAttribute attr, GValue* value);
AtkAttributeSet* AddIntAttributeToAtkAttributeSet(
AtkAttributeSet* attributes,
ax::mojom::IntAttribute attribute,
const char* atk_attribute) const;
// Event helpers
void OnFocused();
......
......@@ -35,6 +35,44 @@ class AXPlatformNodeAuraLinuxTest : public AXPlatformNodeTest {
AtkObject* GetRootAtkObject() { return AtkObjectFromNode(GetRootNode()); }
};
static void EnsureAtkObjectHasAttributeWithValue(
AtkObject* atk_object,
const gchar* attribute_name,
const gchar* attribute_value) {
AtkAttributeSet* attributes = atk_object_get_attributes(atk_object);
bool saw_attribute = false;
AtkAttributeSet* current = attributes;
while (current) {
AtkAttribute* attribute = static_cast<AtkAttribute*>(current->data);
if (0 == strcmp(attribute_name, attribute->name)) {
// Ensure that we only see this attribute once.
ASSERT_FALSE(saw_attribute);
EXPECT_STREQ(attribute_value, attribute->value);
saw_attribute = true;
}
current = current->next;
}
ASSERT_TRUE(saw_attribute);
atk_attribute_set_free(attributes);
}
static void EnsureAtkObjectDoesNotHaveAttribute(
AtkObject* atk_object,
const gchar* attribute_name) {
AtkAttributeSet* attributes = atk_object_get_attributes(atk_object);
AtkAttributeSet* current = attributes;
while (current) {
AtkAttribute* attribute = static_cast<AtkAttribute*>(current->data);
ASSERT_NE(0, strcmp(attribute_name, attribute->name));
}
atk_attribute_set_free(attributes);
}
//
// AtkObject tests
//
......@@ -244,6 +282,39 @@ TEST_F(AXPlatformNodeAuraLinuxTest, TestAtkObjectIndexInParent) {
g_object_unref(root_obj);
}
TEST_F(AXPlatformNodeAuraLinuxTest, TestAtkObjectAttributes) {
AXNodeData root_data;
root_data.id = 1;
Init(root_data);
AXNode* root_node = GetRootNode();
AtkObject* root_atk_object(AtkObjectFromNode(root_node));
ASSERT_TRUE(ATK_IS_OBJECT(root_atk_object));
g_object_ref(root_atk_object);
EnsureAtkObjectDoesNotHaveAttribute(root_atk_object, "level");
root_data = AXNodeData();
root_data.id = 1;
root_data.AddIntAttribute(ax::mojom::IntAttribute::kHierarchicalLevel, 1);
root_node->SetData(root_data);
EnsureAtkObjectHasAttributeWithValue(root_atk_object, "level", "1");
root_data = AXNodeData();
root_data.id = 1;
root_data.AddIntAttribute(ax::mojom::IntAttribute::kHierarchicalLevel, 2);
root_node->SetData(root_data);
EnsureAtkObjectHasAttributeWithValue(root_atk_object, "level", "2");
root_data = AXNodeData();
root_data.id = 1;
root_data.AddIntAttribute(ax::mojom::IntAttribute::kHierarchicalLevel, 34);
root_node->SetData(root_data);
EnsureAtkObjectHasAttributeWithValue(root_atk_object, "level", "34");
g_object_unref(root_atk_object);
}
//
// AtkComponent tests
//
......
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