0

Clear selection on tabbing to a form text area annotation

If there exists a selection, it should be cleared when we tab to a form
text area annotation.

Add unit tests to validate the scenario.

Bug: 1069465
Change-Id: I8c4f0e70acc0d560a2a45a3c38f43d750ce2a625
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2143783
Commit-Queue: Ankit Kumar 🌪️ <ankk@microsoft.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kevin Babbitt <kbabbitt@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#765575}
This commit is contained in:
Ankit Kumar
2020-05-05 16:05:05 +00:00
committed by Commit Bot
parent 22bfc9c166
commit 61b937c8f0
2 changed files with 55 additions and 5 deletions

@ -1220,11 +1220,6 @@ bool PDFiumEngine::OnRightMouseDown(const pp::MouseInputEvent& event) {
// Handle the case when focus starts outside a form text area and transitions
// into a form text area.
if (is_form_text_area) {
{
SelectionChangeInvalidator selection_invalidator(this);
selection_.clear();
}
FORM_OnFocus(form(), page, 0, page_x, page_y);
return true;
}
@ -3692,6 +3687,10 @@ void PDFiumEngine::OnFocusedAnnotationUpdated(FPDF_ANNOTATION annot) {
}
bool is_form_text_area =
PDFiumPage::FormTypeToArea(form_type) == PDFiumPage::FORM_TEXT_AREA;
if (is_form_text_area) {
SelectionChangeInvalidator selection_invalidator(this);
selection_.clear();
}
SetInFormTextArea(is_form_text_area);
editable_form_text_area_ =
is_form_text_area && IsAnnotationAnEditableFormTextArea(annot, form_type);

@ -259,6 +259,10 @@ class PDFiumEngineTabbingTest : public PDFiumTestBase {
return engine->in_form_text_area_;
}
size_t GetSelectionSize(PDFiumEngine* engine) {
return engine->selection_.size();
}
protected:
base::test::TaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME};
@ -613,4 +617,51 @@ TEST_F(PDFiumEngineTabbingTest, VerifyFormFieldStatesOnTabbing) {
EXPECT_FALSE(engine->CanEditText());
}
TEST_F(PDFiumEngineTabbingTest, ClearSelectionOnFocusInFormTextArea) {
TestClient client;
std::unique_ptr<PDFiumEngine> engine =
InitializeEngine(&client, FILE_PATH_LITERAL("form_text_fields.pdf"));
ASSERT_TRUE(engine);
ASSERT_EQ(1, engine->GetNumberOfPages());
EXPECT_EQ(PDFiumEngine::FocusElementType::kNone,
GetFocusedElementType(engine.get()));
EXPECT_EQ(-1, GetLastFocusedPage(engine.get()));
// Select all text.
engine->SelectAll();
EXPECT_EQ(1u, GetSelectionSize(engine.get()));
// Tab to bring focus to a form text area annotation.
ASSERT_TRUE(HandleTabEvent(engine.get(), 0));
ASSERT_TRUE(HandleTabEvent(engine.get(), 0));
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
GetFocusedElementType(engine.get()));
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
EXPECT_EQ(0u, GetSelectionSize(engine.get()));
}
TEST_F(PDFiumEngineTabbingTest, RetainSelectionOnFocusNotInFormTextArea) {
TestClient client;
std::unique_ptr<PDFiumEngine> engine =
InitializeEngine(&client, FILE_PATH_LITERAL("annots.pdf"));
ASSERT_TRUE(engine);
ASSERT_EQ(1, engine->GetNumberOfPages());
EXPECT_EQ(PDFiumEngine::FocusElementType::kNone,
GetFocusedElementType(engine.get()));
EXPECT_EQ(-1, GetLastFocusedPage(engine.get()));
// Select all text.
engine->SelectAll();
EXPECT_EQ(1u, GetSelectionSize(engine.get()));
// Tab to bring focus to a non form text area annotation (Button).
ASSERT_TRUE(HandleTabEvent(engine.get(), PP_INPUTEVENT_MODIFIER_SHIFTKEY));
EXPECT_EQ(PDFiumEngine::FocusElementType::kPage,
GetFocusedElementType(engine.get()));
EXPECT_EQ(0, GetLastFocusedPage(engine.get()));
EXPECT_EQ(1u, GetSelectionSize(engine.get()));
}
} // namespace chrome_pdf