Commit cb80e665 authored by Renato Silva's avatar Renato Silva Committed by Commit Bot

Chrome OS - PIN Auto Submit - Minor Fixes

Make the PIN input field on the login screen read only
during an authentication attempt.

Correctly focus the PIN input field when the login screen
is shown.

Bug: 663982, 1122694
Change-Id: Ib7f25e190281ce78ca9e33d19c06e4e574c7ef6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2379772Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Renato Silva <rrsilva@google.com>
Cr-Commit-Position: refs/heads/master@{#802646}
parent 278db084
...@@ -113,6 +113,10 @@ void FlexCodeInput::SetInputEnabled(bool input_enabled) { ...@@ -113,6 +113,10 @@ void FlexCodeInput::SetInputEnabled(bool input_enabled) {
code_field_->SetEnabled(input_enabled); code_field_->SetEnabled(input_enabled);
} }
void FlexCodeInput::SetReadOnly(bool read_only) {
NOTIMPLEMENTED();
}
void FlexCodeInput::ClearInput() { void FlexCodeInput::ClearInput() {
code_field_->SetText(base::string16()); code_field_->SetText(base::string16());
on_input_change_.Run(false); on_input_change_.Run(false);
...@@ -341,6 +345,9 @@ bool FixedLengthCodeInput::HandleKeyEvent(views::Textfield* sender, ...@@ -341,6 +345,9 @@ bool FixedLengthCodeInput::HandleKeyEvent(views::Textfield* sender,
if (key_event.IsAltDown()) if (key_event.IsAltDown())
return false; return false;
if (sender->GetReadOnly())
return false;
// FixedLengthCodeInput class responds to limited subset of key press // FixedLengthCodeInput class responds to limited subset of key press
// events. All key pressed events not handled below are ignored. // events. All key pressed events not handled below are ignored.
const ui::KeyboardCode key_code = key_event.key_code(); const ui::KeyboardCode key_code = key_event.key_code();
...@@ -417,6 +424,13 @@ void FixedLengthCodeInput::SetInputEnabled(bool input_enabled) { ...@@ -417,6 +424,13 @@ void FixedLengthCodeInput::SetInputEnabled(bool input_enabled) {
} }
} }
void FixedLengthCodeInput::SetReadOnly(bool read_only) {
for (auto* field : input_fields_) {
field->SetReadOnly(read_only);
field->SetCursorEnabled(!read_only);
}
}
void FixedLengthCodeInput::ClearInput() { void FixedLengthCodeInput::ClearInput() {
for (auto* field : input_fields_) { for (auto* field : input_fields_) {
field->SetText(base::string16()); field->SetText(base::string16());
......
...@@ -40,6 +40,10 @@ class AccessCodeInput : public views::View, public views::TextfieldController { ...@@ -40,6 +40,10 @@ class AccessCodeInput : public views::View, public views::TextfieldController {
virtual void SetInputEnabled(bool input_enabled) = 0; virtual void SetInputEnabled(bool input_enabled) = 0;
// Makes the internal fields read only. In contrast to 'SetInputEnabled',
// the focus remain on the element.
virtual void SetReadOnly(bool read_only) = 0;
// Clears the input field(s). // Clears the input field(s).
virtual void ClearInput() = 0; virtual void ClearInput() = 0;
}; };
...@@ -81,6 +85,8 @@ class FlexCodeInput : public AccessCodeInput { ...@@ -81,6 +85,8 @@ class FlexCodeInput : public AccessCodeInput {
void SetInputEnabled(bool input_enabled) override; void SetInputEnabled(bool input_enabled) override;
void SetReadOnly(bool read_only) override;
// Clears text in input text field. // Clears text in input text field.
void ClearInput() override; void ClearInput() override;
...@@ -204,10 +210,12 @@ class FixedLengthCodeInput : public AccessCodeInput { ...@@ -204,10 +210,12 @@ class FixedLengthCodeInput : public AccessCodeInput {
bool HandleGestureEvent(views::Textfield* sender, bool HandleGestureEvent(views::Textfield* sender,
const ui::GestureEvent& gesture_event) override; const ui::GestureEvent& gesture_event) override;
// Enables/disables entering a PIN. Currently, there is no use-case the uses // Enables/disables entering a PIN. Currently, there is no use-case that uses
// this with fixed length PINs. // this with fixed length PINs.
void SetInputEnabled(bool input_enabled) override; void SetInputEnabled(bool input_enabled) override;
void SetReadOnly(bool read_only) override;
// Clears the PIN fields. // Clears the PIN fields.
void ClearInput() override; void ClearInput() override;
......
...@@ -1332,7 +1332,10 @@ gfx::Size LoginAuthUserView::CalculatePreferredSize() const { ...@@ -1332,7 +1332,10 @@ gfx::Size LoginAuthUserView::CalculatePreferredSize() const {
} }
void LoginAuthUserView::RequestFocus() { void LoginAuthUserView::RequestFocus() {
password_view_->RequestFocus(); if (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE)
pin_input_view_->RequestFocus();
else
password_view_->RequestFocus();
} }
void LoginAuthUserView::ButtonPressed(views::Button* sender, void LoginAuthUserView::ButtonPressed(views::Button* sender,
...@@ -1355,6 +1358,8 @@ void LoginAuthUserView::OnAuthSubmit(const base::string16& password) { ...@@ -1355,6 +1358,8 @@ void LoginAuthUserView::OnAuthSubmit(const base::string16& password) {
} }
password_view_->SetReadOnly(true); password_view_->SetReadOnly(true);
pin_input_view_->SetReadOnly(true);
Shell::Get()->login_screen_controller()->AuthenticateUserWithPasswordOrPin( Shell::Get()->login_screen_controller()->AuthenticateUserWithPasswordOrPin(
current_user().basic_user_info.account_id, base::UTF16ToUTF8(password), current_user().basic_user_info.account_id, base::UTF16ToUTF8(password),
HasAuthMethod(AUTH_PIN), HasAuthMethod(AUTH_PIN),
...@@ -1370,6 +1375,8 @@ void LoginAuthUserView::OnAuthComplete(base::Optional<bool> auth_success) { ...@@ -1370,6 +1375,8 @@ void LoginAuthUserView::OnAuthComplete(base::Optional<bool> auth_success) {
if (!auth_success.has_value() || !auth_success.value()) { if (!auth_success.has_value() || !auth_success.value()) {
password_view_->Reset(); password_view_->Reset();
password_view_->SetReadOnly(false); password_view_->SetReadOnly(false);
pin_input_view_->Reset();
pin_input_view_->SetReadOnly(false);
} }
on_auth_.Run(auth_success.value(), /*display_error_messages=*/true); on_auth_.Run(auth_success.value(), /*display_error_messages=*/true);
......
...@@ -84,7 +84,6 @@ void LoginPinInput::OnModified(bool last_field_active, bool complete) { ...@@ -84,7 +84,6 @@ void LoginPinInput::OnModified(bool last_field_active, bool complete) {
// Submit the input if its the last field, and complete. // Submit the input if its the last field, and complete.
if (last_field_active && complete) { if (last_field_active && complete) {
base::Optional<std::string> user_input = GetCode(); base::Optional<std::string> user_input = GetCode();
ClearInput();
DCHECK(on_submit_); DCHECK(on_submit_);
on_submit_.Run(base::UTF8ToUTF16(user_input.value_or(std::string()))); on_submit_.Run(base::UTF8ToUTF16(user_input.value_or(std::string())));
} }
...@@ -188,6 +187,10 @@ void LoginPinInputView::InsertDigit(int digit) { ...@@ -188,6 +187,10 @@ void LoginPinInputView::InsertDigit(int digit) {
code_input_->InsertDigit(digit); code_input_->InsertDigit(digit);
} }
void LoginPinInputView::SetReadOnly(bool read_only) {
code_input_->SetReadOnly(read_only);
}
gfx::Size LoginPinInputView::CalculatePreferredSize() const { gfx::Size LoginPinInputView::CalculatePreferredSize() const {
const int ideal_size = kFieldWidth * length_ + const int ideal_size = kFieldWidth * length_ +
kFieldSpace * (length_ - 1); kFieldSpace * (length_ - 1);
......
...@@ -57,6 +57,10 @@ class ASH_EXPORT LoginPinInputView : public views::View { ...@@ -57,6 +57,10 @@ class ASH_EXPORT LoginPinInputView : public views::View {
void Backspace(); void Backspace();
void InsertDigit(int digit); void InsertDigit(int digit);
// Sets the field as read only. The field is made read only during an
// authentication request.
void SetReadOnly(bool read_only);
// views::View // views::View
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void RequestFocus() override; void RequestFocus() override;
......
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