Commit 9b07e5e0 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Chromium LUCI CQ

[a11y] Add scrolling action to PP_PDF_SET_SELECTION

This CL adds scrolling when PDFiumEngine::HandleAccessibilityAction
is called with PP_PDF_SET_SELECTION and the selection is not
visible since Blink triggers also scrolling with setting selection.
So, this change makes PDF document scroll the page when a selection
is set.

AX-Relnotes: When SetSelection action is handled on pdf, it also
triggers scrolling if the selection is not in the visible area.
For instance, atk_text_set_caret_offset() on pdf scrolls the page
if the text is not in the view port.

Bug: 993456
Change-Id: I8323eff293b3216e2b862f8df3e896380b1c9945
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573975Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Reviewed-by: default avatarMartin Robinson <mrobinson@igalia.com>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#835994}
parent c34a2bbb
......@@ -144,6 +144,11 @@ bool PdfAXActionTarget::SetSelection(const ui::AXActionTarget* anchor_object,
return false;
}
pdf_action_data.action = PP_PdfAccessibilityAction::PP_PDF_SET_SELECTION;
pdf_action_data.target_rect = {
{target_plugin_node_.data().relative_bounds.bounds.x(),
target_plugin_node_.data().relative_bounds.bounds.y()},
{target_plugin_node_.data().relative_bounds.bounds.width(),
target_plugin_node_.data().relative_bounds.bounds.height()}};
pdf_accessibility_tree_source_->HandleAction(pdf_action_data);
return true;
}
......
......@@ -669,4 +669,64 @@ TEST_F(AccessibilityTest, TestSelectionActionHandling) {
}
}
// Tests if PP_PDF_SET_SELECTION updates scroll offsets if the selection is not
// in the current visible rect.
TEST_F(AccessibilityTest, TestSetSelectionAndScroll) {
struct Selection {
uint32_t start_page_index;
uint32_t start_char_index;
uint32_t end_page_index;
uint32_t end_char_index;
};
struct TestCase {
Selection action;
Selection expected_result;
gfx::Vector2d scroll_offset;
};
static constexpr TestCase kTestCases[] = {
{{0, 15, 0, 15}, {0, 15, 0, 15}, {0, 0}},
{{1, 15, 1, 15}, {1, 15, 1, 15}, {28, 517}},
};
ScrollEnabledTestClient client;
std::unique_ptr<PDFiumEngine> engine =
InitializeEngine(&client, FILE_PATH_LITERAL("hello_world2.pdf"));
ASSERT_TRUE(engine);
engine->PluginSizeUpdated({400, 400});
int index = 0;
for (const auto& test_case : kTestCases) {
PP_PdfAccessibilityActionData action_data;
action_data.action = PP_PdfAccessibilityAction::PP_PDF_SET_SELECTION;
const Selection& sel_action = test_case.action;
action_data.selection_start_index.page_index = sel_action.start_page_index;
action_data.selection_start_index.char_index = sel_action.start_char_index;
action_data.selection_end_index.page_index = sel_action.end_page_index;
action_data.selection_end_index.char_index = sel_action.end_char_index;
gfx::RectF char_bounds = engine->GetCharBounds(sel_action.start_page_index,
sel_action.start_char_index);
action_data.target_rect = {{char_bounds.x(), char_bounds.y() + 400 * index},
{char_bounds.width(), char_bounds.height()}};
engine->HandleAccessibilityAction(action_data);
Selection actual_selection;
engine->GetSelection(
&actual_selection.start_page_index, &actual_selection.start_char_index,
&actual_selection.end_page_index, &actual_selection.end_char_index);
const Selection& expected_selection = test_case.expected_result;
EXPECT_EQ(actual_selection.start_page_index,
expected_selection.start_page_index);
EXPECT_EQ(actual_selection.start_char_index,
expected_selection.start_char_index);
EXPECT_EQ(actual_selection.end_page_index,
expected_selection.end_page_index);
EXPECT_EQ(actual_selection.end_char_index,
expected_selection.end_char_index);
EXPECT_EQ(test_case.scroll_offset, client.GetScrollRequestDelta());
index++;
}
}
} // namespace chrome_pdf
......@@ -2180,6 +2180,10 @@ void PDFiumEngine::HandleAccessibilityAction(
IsPageCharacterIndexInBounds(action_data.selection_end_index)) {
SetSelection(action_data.selection_start_index,
action_data.selection_end_index);
gfx::Rect target_rect = RectFromPPRect(action_data.target_rect);
if (GetVisibleRect().Contains(target_rect))
return;
client_->ScrollBy(GetScreenRect(target_rect).OffsetFromOrigin());
}
break;
}
......
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