Commit 31350ccf authored by Roman Aleksandrov's avatar Roman Aleksandrov Committed by Commit Bot

LoginPasswordView: Return focus to textfield on PinPad button click.

Since the pin pad buttons are no more tabbable
(see for more details: https://crbug.com/1043194)
we can return focus to textfield on number insert.

Bug: 1009417
Change-Id: I4b1ebeef0a8e32a5ff2ba9b39da3ee424b7bdb3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208864Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Roman Aleksandrov <raleksandrov@google.com>
Cr-Commit-Position: refs/heads/master@{#774346}
parent dce40536
...@@ -138,8 +138,10 @@ void FocusFirstOrLastFocusableChild(views::View* root, bool reverse) { ...@@ -138,8 +138,10 @@ void FocusFirstOrLastFocusableChild(views::View* root, bool reverse) {
views::FocusSearch::StartingViewPolicy::kSkipStartingView, views::FocusSearch::StartingViewPolicy::kSkipStartingView,
views::FocusSearch::AnchoredDialogPolicy::kCanGoIntoAnchoredDialog, views::FocusSearch::AnchoredDialogPolicy::kCanGoIntoAnchoredDialog,
&dummy_focus_traversable, &dummy_focus_traversable_view); &dummy_focus_traversable, &dummy_focus_traversable_view);
if (focusable_view) if (focusable_view) {
focusable_view->AboutToRequestFocusFromTabTraversal(reverse);
focusable_view->RequestFocus(); focusable_view->RequestFocus();
}
} }
// Make a section of the text bold. // Make a section of the text bold.
......
...@@ -199,6 +199,9 @@ class LoginPasswordView::LoginTextfield : public views::Textfield { ...@@ -199,6 +199,9 @@ class LoginPasswordView::LoginTextfield : public views::Textfield {
if (on_focus_closure_) if (on_focus_closure_)
on_focus_closure_.Run(); on_focus_closure_.Run();
views::Textfield::OnFocus(); views::Textfield::OnFocus();
}
void AboutToRequestFocusFromTabTraversal(bool reverse) override {
SelectAll(/*reversed=*/false); SelectAll(/*reversed=*/false);
} }
...@@ -589,6 +592,10 @@ void LoginPasswordView::Clear() { ...@@ -589,6 +592,10 @@ void LoginPasswordView::Clear() {
} }
void LoginPasswordView::InsertNumber(int value) { void LoginPasswordView::InsertNumber(int value) {
if (!textfield_->HasFocus()) {
// RequestFocus on textfield to activate cursor.
textfield_->RequestFocus();
}
textfield_->InsertOrReplaceText(base::NumberToString16(value)); textfield_->InsertOrReplaceText(base::NumberToString16(value));
} }
......
...@@ -317,4 +317,20 @@ TEST_F(LoginPasswordViewTest, ...@@ -317,4 +317,20 @@ TEST_F(LoginPasswordViewTest,
EXPECT_FALSE(test_api.display_password_button()->GetEnabled()); EXPECT_FALSE(test_api.display_password_button()->GetEnabled());
} }
// Verifies that focus returned to the textfield after InsertNumber is called.
TEST_F(LoginPasswordViewTest, FocusReturn) {
LoginPasswordView::TestApi test_api(view_);
ui::test::EventGenerator* generator = GetEventGenerator();
// Verify that focus is returned to view after the number insertion.
view_->InsertNumber(0);
EXPECT_TRUE(test_api.textfield()->HasFocus());
// Focus on the next element to check that following focus return will not
// delete what was already inserted into textfield.
generator->PressKey(ui::KeyboardCode::VKEY_TAB, ui::EventFlags::EF_NONE);
EXPECT_FALSE(test_api.textfield()->HasFocus());
view_->InsertNumber(1);
EXPECT_TRUE(test_api.textfield()->HasFocus());
EXPECT_EQ(test_api.textfield()->GetText().length(), 2u);
}
} // namespace ash } // namespace ash
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