Commit 9ccbec24 authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

Update cursor position when textfield text changes.

Bug: 789190
Change-Id: I1f1b2546d126ad35e27bd977e17b295477e10938
Reviewed-on: https://chromium-review.googlesource.com/795011
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521474}
parent 62fe5b7c
......@@ -115,7 +115,7 @@ LoginAuthUserView::LoginAuthUserView(
password_view_->UpdateForUser(user);
pin_view_ =
new LoginPinView(base::BindRepeating(&LoginPasswordView::AppendNumber,
new LoginPinView(base::BindRepeating(&LoginPasswordView::InsertNumber,
base::Unretained(password_view_)),
base::BindRepeating(&LoginPasswordView::Backspace,
base::Unretained(password_view_)));
......
......@@ -482,11 +482,8 @@ void LoginPasswordView::Clear() {
ContentsChanged(textfield_, textfield_->text());
}
void LoginPasswordView::AppendNumber(int value) {
textfield_->SetText(textfield_->text() + base::IntToString16(value));
// |ContentsChanged| won't be called by |Textfield| if the text is changed
// by |Textfield::AppendText()|.
ContentsChanged(textfield_, textfield_->text());
void LoginPasswordView::InsertNumber(int value) {
textfield_->InsertOrReplaceText(base::IntToString16(value));
}
void LoginPasswordView::Backspace() {
......
......@@ -89,8 +89,9 @@ class ASH_EXPORT LoginPasswordView
// Clear all currently entered text.
void Clear();
// Add the given numeric value to the textfield.
void AppendNumber(int value);
// Inserts the given numeric value to the textfield at the current cursor
// position (most likely the end).
void InsertNumber(int value);
// Erase the last entered value.
void Backspace();
......
......@@ -78,6 +78,9 @@ class AXTreeSourceAuraTest : public ash::AshTestBase {
};
TEST_F(AXTreeSourceAuraTest, Accessors) {
// Focus the textfield so the cursor does not disappear.
textfield_->RequestFocus();
AXTreeSourceAura ax_tree;
ASSERT_TRUE(ax_tree.GetRoot());
......
......@@ -342,6 +342,8 @@ void Textfield::SetTextInputFlags(int flags) {
void Textfield::SetText(const base::string16& new_text) {
model_->SetText(new_text);
OnCaretBoundsChanged();
UpdateCursorViewPosition();
UpdateCursorVisibility();
SchedulePaint();
NotifyAccessibilityEvent(ui::AX_EVENT_VALUE_CHANGED, true);
}
......
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