Commit 5e4e3423 authored by Renato Silva's avatar Renato Silva Committed by Commit Bot

CrOS - Remove submit button from pinpad

Remove the submit button on the pin pad shown on the login/lock
screen. Change LoginPinView construction to only show the submit
button on the pinpad when the |on_submit| callback is valid.

Verified locally that it removes the memory leak LoginPinView from:
https://crbug.com/1099306#c1

Bug: 1075994, 1101326, 1099306
Change-Id: Ib7de615c9f5c6faec168e1205e44a981f739f9a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2339524
Commit-Queue: Renato Silva <rrsilva@google.com>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Auto-Submit: Renato Silva <rrsilva@google.com>
Cr-Commit-Position: refs/heads/master@{#795437}
parent 2adb94bd
...@@ -834,26 +834,12 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -834,26 +834,12 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
password_view_->SetDisplayPasswordButtonVisible( password_view_->SetDisplayPasswordButtonVisible(
user.show_display_password_button); user.show_display_password_button);
std::unique_ptr<LoginPinView> pin_view; auto pin_view = std::make_unique<LoginPinView>(
// If the display password button feature is disabled, the PIN view does not LoginPinView::Style::kAlphanumeric,
// need a submit button as the password view already has one. base::BindRepeating(&LoginPasswordView::InsertNumber,
if (chromeos::features::IsLoginDisplayPasswordButtonEnabled()) { base::Unretained(password_view.get())),
pin_view = std::make_unique<LoginPinView>( base::BindRepeating(&LoginPasswordView::Backspace,
LoginPinView::Style::kAlphanumeric, base::Unretained(password_view.get())));
base::BindRepeating(&LoginPasswordView::InsertNumber,
base::Unretained(password_view.get())),
base::BindRepeating(&LoginPasswordView::Backspace,
base::Unretained(password_view.get())),
base::BindRepeating(&LoginPasswordView::SubmitPassword,
base::Unretained(password_view.get())));
} else {
pin_view = std::make_unique<LoginPinView>(
LoginPinView::Style::kAlphanumeric,
base::BindRepeating(&LoginPasswordView::InsertNumber,
base::Unretained(password_view.get())),
base::BindRepeating(&LoginPasswordView::Backspace,
base::Unretained(password_view.get())));
}
pin_view_ = pin_view.get(); pin_view_ = pin_view.get();
DCHECK(pin_view_->layer()); DCHECK(pin_view_->layer());
......
...@@ -426,14 +426,9 @@ LoginPinView::LoginPinView(Style keyboard_style, ...@@ -426,14 +426,9 @@ LoginPinView::LoginPinView(Style keyboard_style,
const OnPinKey& on_key, const OnPinKey& on_key,
const OnPinBackspace& on_backspace, const OnPinBackspace& on_backspace,
const OnPinSubmit& on_submit) const OnPinSubmit& on_submit)
: NonAccessibleView(kLoginPinViewClassName), : NonAccessibleView(kLoginPinViewClassName) {
backspace_(new BackspacePinButton(kButtonSize, on_backspace)), DCHECK(on_key);
submit_button_(new SubmitPinButton(kButtonSize, on_submit)), DCHECK(on_backspace);
on_key_(on_key),
on_backspace_(on_backspace),
on_submit_(on_submit) {
DCHECK(on_key_);
DCHECK(on_backspace_);
// Layer rendering. // Layer rendering.
SetPaintToLayer(ui::LayerType::LAYER_NOT_DRAWN); SetPaintToLayer(ui::LayerType::LAYER_NOT_DRAWN);
...@@ -445,7 +440,7 @@ LoginPinView::LoginPinView(Style keyboard_style, ...@@ -445,7 +440,7 @@ LoginPinView::LoginPinView(Style keyboard_style,
auto add_digit_button = [&](View* row, int value) { auto add_digit_button = [&](View* row, int value) {
row->AddChildView( row->AddChildView(
new DigitPinButton(value, show_letters, kButtonSize, on_key_)); new DigitPinButton(value, show_letters, kButtonSize, on_key));
}; };
// 1-2-3 // 1-2-3
...@@ -468,19 +463,16 @@ LoginPinView::LoginPinView(Style keyboard_style, ...@@ -468,19 +463,16 @@ LoginPinView::LoginPinView(Style keyboard_style,
// backspace-0-submit // backspace-0-submit
row = BuildAndAddRow(); row = BuildAndAddRow();
row->AddChildView(backspace_); backspace_ = row->AddChildView(
std::make_unique<BackspacePinButton>(kButtonSize, on_backspace));
add_digit_button(row, 0); add_digit_button(row, 0);
if (!on_submit_.is_null())
row->AddChildView(submit_button_);
}
LoginPinView::LoginPinView(Style keyboard_style, // Only add the submit button if the callback is valid.
const OnPinKey& on_key, if (!on_submit.is_null()) {
const OnPinBackspace& on_backspace) submit_button_ = row->AddChildView(
: LoginPinView(keyboard_style, std::make_unique<SubmitPinButton>(kButtonSize, on_submit));
on_key, }
on_backspace, }
base::RepeatingClosure()) {}
LoginPinView::~LoginPinView() = default; LoginPinView::~LoginPinView() = default;
...@@ -495,7 +487,8 @@ void LoginPinView::NotifyAccessibilityLocationChanged() { ...@@ -495,7 +487,8 @@ void LoginPinView::NotifyAccessibilityLocationChanged() {
void LoginPinView::OnPasswordTextChanged(bool is_empty) { void LoginPinView::OnPasswordTextChanged(bool is_empty) {
backspace_->SetEnabled(!is_empty); backspace_->SetEnabled(!is_empty);
submit_button_->SetEnabled(!is_empty); if (submit_button_)
submit_button_->SetEnabled(!is_empty);
} }
NonAccessibleView* LoginPinView::BuildAndAddRow() { NonAccessibleView* LoginPinView::BuildAndAddRow() {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/login/ui/non_accessible_view.h" #include "ash/login/ui/non_accessible_view.h"
#include "base/bind_helpers.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -46,7 +47,7 @@ namespace ash { ...@@ -46,7 +47,7 @@ namespace ash {
// ------- ------- ------- // ------- ------- -------
// //
// The <- represents the delete button while -> represents the submit button. // The <- represents the delete button while -> represents the submit button.
// The submit button can be hidden. // The submit button is optional.
// //
class ASH_EXPORT LoginPinView : public NonAccessibleView { class ASH_EXPORT LoginPinView : public NonAccessibleView {
public: public:
...@@ -91,18 +92,12 @@ class ASH_EXPORT LoginPinView : public NonAccessibleView { ...@@ -91,18 +92,12 @@ class ASH_EXPORT LoginPinView : public NonAccessibleView {
// non-null. // non-null.
// |on_backspace| is called when the user wants to erase the most recently // |on_backspace| is called when the user wants to erase the most recently
// tapped key; must be non-null. // tapped key; must be non-null.
// |on_submit| is called when the user wants to submit the PIN / password. // If |on_submit| is valid, there will be a submit button on the pinpad that
// calls it when the user wants to submit the PIN / password.
LoginPinView(Style keyboard_style, LoginPinView(Style keyboard_style,
const OnPinKey& on_key, const OnPinKey& on_key,
const OnPinBackspace& on_backspace, const OnPinBackspace& on_backspace,
const OnPinSubmit& on_submit); const OnPinSubmit& on_submit = base::NullCallback());
// Creates PIN view without submit button. This is useful when a submit button
// is already present in the password view, which is the case when the display
// password button feature is disabled.
LoginPinView(Style keyboard_style,
const OnPinKey& on_key,
const OnPinBackspace& on_backspace);
~LoginPinView() override; ~LoginPinView() override;
...@@ -119,11 +114,9 @@ class ASH_EXPORT LoginPinView : public NonAccessibleView { ...@@ -119,11 +114,9 @@ class ASH_EXPORT LoginPinView : public NonAccessibleView {
// Builds and returns a new view which contains a row of the PIN keyboard. // Builds and returns a new view which contains a row of the PIN keyboard.
NonAccessibleView* BuildAndAddRow(); NonAccessibleView* BuildAndAddRow();
BackspacePinButton* backspace_; BackspacePinButton* backspace_ = nullptr;
SubmitPinButton* submit_button_; // The submit button does not exist when no |on_submit| callback is passed.
OnPinKey on_key_; SubmitPinButton* submit_button_ = nullptr;
OnPinBackspace on_backspace_;
OnPinSubmit on_submit_;
std::vector<NonAccessibleView*> rows; std::vector<NonAccessibleView*> rows;
......
...@@ -220,7 +220,7 @@ TEST_F(PinRequestViewTest, SubmitButton) { ...@@ -220,7 +220,7 @@ TEST_F(PinRequestViewTest, SubmitButton) {
// The submit button on the PIN keyboard shouldn't be shown. // The submit button on the PIN keyboard shouldn't be shown.
LoginPinView::TestApi test_pin_keyboard(test_api.pin_keyboard_view()); LoginPinView::TestApi test_pin_keyboard(test_api.pin_keyboard_view());
EXPECT_FALSE(test_pin_keyboard.GetSubmitButton()->parent()); EXPECT_FALSE(test_pin_keyboard.GetSubmitButton());
auto* generator = GetEventGenerator(); auto* generator = GetEventGenerator();
// Updating input code (here last digit) should clear error state. // Updating input code (here last digit) should clear error state.
......
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