Commit 2db08655 authored by Mansi Awasthi's avatar Mansi Awasthi Committed by Commit Bot

Set NameFrom property for text nodes in PdfAccessibilityTree

This CL sets the ax::mojom::NameFrom property for static text nodes and
inline text nodes in PdfAccessibilityTree. This property is used by
AXNode::GetInnerText() to compute the inner text of the nodes.

This CL also includes the relevant tests to validate the change.

Bug: 1112890
Change-Id: I782ceb4d93a07146a81b1d23ff9696af3267d7f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2337195
Commit-Queue: Dominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795564}
parent ccd4d465
...@@ -573,6 +573,7 @@ class PdfAccessibilityTreeBuilder { ...@@ -573,6 +573,7 @@ class PdfAccessibilityTreeBuilder {
ui::AXNodeData* static_text_node = CreateNode( ui::AXNodeData* static_text_node = CreateNode(
ax::mojom::Role::kStaticText, ax::mojom::Restriction::kReadOnly, ax::mojom::Role::kStaticText, ax::mojom::Restriction::kReadOnly,
render_accessibility_, nodes_); render_accessibility_, nodes_);
static_text_node->SetNameFrom(ax::mojom::NameFrom::kContents);
node_id_to_page_char_index_->emplace(static_text_node->id, page_char_index); node_id_to_page_char_index_->emplace(static_text_node->id, page_char_index);
return static_text_node; return static_text_node;
} }
...@@ -583,6 +584,7 @@ class PdfAccessibilityTreeBuilder { ...@@ -583,6 +584,7 @@ class PdfAccessibilityTreeBuilder {
ui::AXNodeData* inline_text_box_node = CreateNode( ui::AXNodeData* inline_text_box_node = CreateNode(
ax::mojom::Role::kInlineTextBox, ax::mojom::Restriction::kReadOnly, ax::mojom::Role::kInlineTextBox, ax::mojom::Restriction::kReadOnly,
render_accessibility_, nodes_); render_accessibility_, nodes_);
inline_text_box_node->SetNameFrom(ax::mojom::NameFrom::kContents);
std::string chars__utf8 = std::string chars__utf8 =
GetTextRunCharsAsUTF8(text_run, chars_, page_char_index.char_index); GetTextRunCharsAsUTF8(text_run, chars_, page_char_index.char_index);
...@@ -690,6 +692,7 @@ class PdfAccessibilityTreeBuilder { ...@@ -690,6 +692,7 @@ class PdfAccessibilityTreeBuilder {
ax::mojom::Role::kStaticText, ax::mojom::Restriction::kReadOnly, ax::mojom::Role::kStaticText, ax::mojom::Restriction::kReadOnly,
render_accessibility_, nodes_); render_accessibility_, nodes_);
static_popup_note_text_node->SetNameFrom(ax::mojom::NameFrom::kContents);
static_popup_note_text_node->AddStringAttribute( static_popup_note_text_node->AddStringAttribute(
ax::mojom::StringAttribute::kName, highlight.note_text); ax::mojom::StringAttribute::kName, highlight.note_text);
static_popup_note_text_node->relative_bounds.bounds = static_popup_note_text_node->relative_bounds.bounds =
......
...@@ -546,6 +546,8 @@ TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) { ...@@ -546,6 +546,8 @@ TEST_F(PdfAccessibilityTreeTest, TestHighlightCreation) {
ASSERT_TRUE(static_popup_note_text_node); ASSERT_TRUE(static_popup_note_text_node);
EXPECT_EQ(ax::mojom::Role::kStaticText, EXPECT_EQ(ax::mojom::Role::kStaticText,
static_popup_note_text_node->data().role); static_popup_note_text_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
static_popup_note_text_node->data().GetNameFrom());
EXPECT_EQ(kPopupNoteText, static_popup_note_text_node->GetStringAttribute( EXPECT_EQ(kPopupNoteText, static_popup_note_text_node->GetStringAttribute(
ax::mojom::StringAttribute::kName)); ax::mojom::StringAttribute::kName));
EXPECT_EQ(gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f), EXPECT_EQ(gfx::RectF(1.0f, 1.0f, 5.0f, 6.0f),
...@@ -1389,17 +1391,23 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) { ...@@ -1389,17 +1391,23 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) {
ui::AXNode* static_text_node = paragraph_node->children()[0]; ui::AXNode* static_text_node = paragraph_node->children()[0];
ASSERT_TRUE(static_text_node); ASSERT_TRUE(static_text_node);
EXPECT_EQ(ax::mojom::Role::kStaticText, static_text_node->data().role); EXPECT_EQ(ax::mojom::Role::kStaticText, static_text_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
static_text_node->data().GetNameFrom());
ASSERT_EQ(2u, static_text_node->children().size()); ASSERT_EQ(2u, static_text_node->children().size());
ui::AXNode* previous_inline_node = static_text_node->children()[0]; ui::AXNode* previous_inline_node = static_text_node->children()[0];
ASSERT_TRUE(previous_inline_node); ASSERT_TRUE(previous_inline_node);
EXPECT_EQ(ax::mojom::Role::kInlineTextBox, previous_inline_node->data().role); EXPECT_EQ(ax::mojom::Role::kInlineTextBox, previous_inline_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
previous_inline_node->data().GetNameFrom());
ASSERT_FALSE(previous_inline_node->HasIntAttribute( ASSERT_FALSE(previous_inline_node->HasIntAttribute(
ax::mojom::IntAttribute::kPreviousOnLineId)); ax::mojom::IntAttribute::kPreviousOnLineId));
ui::AXNode* next_inline_node = static_text_node->children()[1]; ui::AXNode* next_inline_node = static_text_node->children()[1];
ASSERT_TRUE(next_inline_node); ASSERT_TRUE(next_inline_node);
EXPECT_EQ(ax::mojom::Role::kInlineTextBox, next_inline_node->data().role); EXPECT_EQ(ax::mojom::Role::kInlineTextBox, next_inline_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
next_inline_node->data().GetNameFrom());
ASSERT_TRUE(next_inline_node->HasIntAttribute( ASSERT_TRUE(next_inline_node->HasIntAttribute(
ax::mojom::IntAttribute::kNextOnLineId)); ax::mojom::IntAttribute::kNextOnLineId));
...@@ -1420,11 +1428,15 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) { ...@@ -1420,11 +1428,15 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) {
static_text_node = link_node->children()[0]; static_text_node = link_node->children()[0];
ASSERT_TRUE(static_text_node); ASSERT_TRUE(static_text_node);
EXPECT_EQ(ax::mojom::Role::kStaticText, static_text_node->data().role); EXPECT_EQ(ax::mojom::Role::kStaticText, static_text_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
static_text_node->data().GetNameFrom());
ASSERT_EQ(2u, static_text_node->children().size()); ASSERT_EQ(2u, static_text_node->children().size());
previous_inline_node = static_text_node->children()[0]; previous_inline_node = static_text_node->children()[0];
ASSERT_TRUE(previous_inline_node); ASSERT_TRUE(previous_inline_node);
EXPECT_EQ(ax::mojom::Role::kInlineTextBox, previous_inline_node->data().role); EXPECT_EQ(ax::mojom::Role::kInlineTextBox, previous_inline_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
previous_inline_node->data().GetNameFrom());
ASSERT_TRUE(previous_inline_node->HasIntAttribute( ASSERT_TRUE(previous_inline_node->HasIntAttribute(
ax::mojom::IntAttribute::kPreviousOnLineId)); ax::mojom::IntAttribute::kPreviousOnLineId));
// Test that text and link on the same line are connected. // Test that text and link on the same line are connected.
...@@ -1435,6 +1447,8 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) { ...@@ -1435,6 +1447,8 @@ TEST_F(PdfAccessibilityTreeTest, TestPreviousNextOnLine) {
next_inline_node = static_text_node->children()[1]; next_inline_node = static_text_node->children()[1];
ASSERT_TRUE(next_inline_node); ASSERT_TRUE(next_inline_node);
EXPECT_EQ(ax::mojom::Role::kInlineTextBox, next_inline_node->data().role); EXPECT_EQ(ax::mojom::Role::kInlineTextBox, next_inline_node->data().role);
EXPECT_EQ(ax::mojom::NameFrom::kContents,
next_inline_node->data().GetNameFrom());
ASSERT_FALSE(next_inline_node->HasIntAttribute( ASSERT_FALSE(next_inline_node->HasIntAttribute(
ax::mojom::IntAttribute::kNextOnLineId)); ax::mojom::IntAttribute::kNextOnLineId));
......
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