Commit 95dbdce3 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Chromium LUCI CQ

Reland "[a11y] Add scrolling action to PP_PDF_SET_SELECTION"

This is a reland of 9b07e5e0 with
a fix of a failure on Linux MSan Test builder.

Added an initial value for |action_data.target_rect| to
AccessibilityTest.TestSelectionActionHandling.

Original change's description:
> [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/+/2573975
> Reviewed-by: Dominic Mazzoni <dmazzoni@chromium.org>
> Reviewed-by: K. Moon <kmoon@chromium.org>
> Reviewed-by: Martin Robinson <mrobinson@igalia.com>
> Commit-Queue: Julie Kim <jkim@igalia.com>
> Cr-Commit-Position: refs/heads/master@{#835994}

Bug: 993456
Change-Id: Ie7c683d062c50d4eade2b5fb4990bc6ca2be12ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586644Reviewed-by: default avatarK. Moon <kmoon@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#836377}
parent 862d3445
...@@ -144,6 +144,11 @@ bool PdfAXActionTarget::SetSelection(const ui::AXActionTarget* anchor_object, ...@@ -144,6 +144,11 @@ bool PdfAXActionTarget::SetSelection(const ui::AXActionTarget* anchor_object,
return false; return false;
} }
pdf_action_data.action = PP_PdfAccessibilityAction::PP_PDF_SET_SELECTION; 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); pdf_accessibility_tree_source_->HandleAction(pdf_action_data);
return true; return true;
} }
......
...@@ -651,6 +651,7 @@ TEST_F(AccessibilityTest, TestSelectionActionHandling) { ...@@ -651,6 +651,7 @@ TEST_F(AccessibilityTest, TestSelectionActionHandling) {
action_data.selection_start_index.char_index = sel_action.start_char_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.page_index = sel_action.end_page_index;
action_data.selection_end_index.char_index = sel_action.end_char_index; action_data.selection_end_index.char_index = sel_action.end_char_index;
action_data.target_rect = {{0, 0}, {0, 0}};
engine->HandleAccessibilityAction(action_data); engine->HandleAccessibilityAction(action_data);
Selection actual_selection; Selection actual_selection;
...@@ -669,4 +670,64 @@ TEST_F(AccessibilityTest, TestSelectionActionHandling) { ...@@ -669,4 +670,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 } // namespace chrome_pdf
...@@ -2180,6 +2180,10 @@ void PDFiumEngine::HandleAccessibilityAction( ...@@ -2180,6 +2180,10 @@ void PDFiumEngine::HandleAccessibilityAction(
IsPageCharacterIndexInBounds(action_data.selection_end_index)) { IsPageCharacterIndexInBounds(action_data.selection_end_index)) {
SetSelection(action_data.selection_start_index, SetSelection(action_data.selection_start_index,
action_data.selection_end_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; 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