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

CrOS - Login Screen - Minor cleanup

Rename AnimationState to UiState and use it to determine the
visibility of elements. Remove multiple variables in favor of
UiState.

Bug: 1075994
Change-Id: I0d7413fb173dadbff22cde0eb3af6f43586bdee2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352883
Commit-Queue: Renato Silva <rrsilva@google.com>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798780}
parent 3906443e
......@@ -1774,7 +1774,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update,
DCHECK(to_update);
auto capture_animation_state_pre_layout = [&](LoginBigUserView* view) {
if (!animate || !view)
if (!view)
return;
if (view->auth_user())
view->auth_user()->CaptureStateForAnimationPreLayout();
......@@ -1829,10 +1829,10 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update,
};
auto apply_animation_post_layout = [&](LoginBigUserView* view) {
if (!animate || !view)
if (!view)
return;
if (view->auth_user())
view->auth_user()->ApplyAnimationPostLayout();
view->auth_user()->ApplyAnimationPostLayout(animate);
};
// The high-level layout flow:
......
This diff is collapsed.
......@@ -69,7 +69,7 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// This is determined by the current authentication methods
// that a user has.
enum class InputFieldMode {
DISABLED, // Not showing any input field.
NONE, // Not showing any input field.
PASSWORD_ONLY, // No PIN set. Password only field.
PIN_AND_PASSWORD, // PIN set.
};
......@@ -126,7 +126,8 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// Set the displayed set of auth methods. |auth_methods| contains or-ed
// together AuthMethod values. |auth_metadata| provides additional control
// parameters for the view.
// parameters for the view. Must always be called in conjunction with
// `CaptureStateForAnimationPreLayout` and `ApplyAnimationPostLayout`.
void SetAuthMethods(
uint32_t auth_methods,
AuthMethodsMetadata auth_metadata = AuthMethodsMetadata());
......@@ -141,8 +142,9 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// animation.
void CaptureStateForAnimationPreLayout();
// Applies animation based on current layout state compared to the most
// recently captured state.
void ApplyAnimationPostLayout();
// recently captured state. If `animate` is false, the previous UI state
// is released and no animation is performed.
void ApplyAnimationPostLayout(bool animate);
// Update the displayed name, icon, etc to that of |user|.
void UpdateForUser(const LoginUserInfo& user);
......@@ -175,7 +177,7 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
struct AnimationState;
struct UiState;
class FingerprintView;
class ChallengeResponseView;
class DisabledAuthMessageView;
......@@ -214,6 +216,9 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// starts the asynchronous authentication process against a security token.
void AttemptAuthenticateWithChallengeResponse();
// Updates the element in focus. Used in `ApplyAnimationPostLayout`.
void UpdateFocus();
// Determines the mode of the input field based on the available
// authentication methods.
void UpdateInputFieldMode();
......@@ -223,8 +228,8 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
bool ShouldShowPasswordField() const;
// Convenience methods to determine the necessary paddings.
gfx::Size GetPaddingBelowUserView() const;
gfx::Size GetPaddingBelowPasswordView() const;
int CalcPaddingHeightBelowUserView() const;
int CalcPaddingHeightBelowPasswordView() const;
// Convenience methods to determine UI text based on the InputFieldMode.
base::string16 GetPasswordViewPlaceholder() const;
......@@ -234,7 +239,7 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
AuthMethodsMetadata auth_metadata_ = AuthMethodsMetadata();
// Controls which input field is currently being shown.
InputFieldMode input_field_mode_ = InputFieldMode::DISABLED;
InputFieldMode input_field_mode_ = InputFieldMode::NONE;
LoginUserView* user_view_ = nullptr;
LoginPasswordView* password_view_ = nullptr;
......@@ -259,10 +264,10 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
bool tpm_is_locked_ = false;
// Animation state that was cached from before a layout. Generated by
// |CaptureStateForAnimationPreLayout| and consumed by
// |ApplyAnimationPostLayout|.
std::unique_ptr<AnimationState> cached_animation_state_;
// UI state that was stored before setting new authentication methods.
// Generated by `CaptureStateForAnimationPreLayout` and consumed by
// `ApplyAnimationPostLayout`.
std::unique_ptr<UiState> previous_state_;
base::WeakPtrFactory<LoginAuthUserView> weak_factory_{this};
......
......@@ -65,7 +65,9 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
auth_metadata.show_pinpad_for_pw = show_pinpad_for_pw;
auth_metadata.virtual_keyboard_visible = virtual_keyboard_visible;
auth_metadata.autosubmit_pin_length = autosubmit_pin_length;
view_->CaptureStateForAnimationPreLayout();
view_->SetAuthMethods(auth_methods, auth_metadata);
view_->ApplyAnimationPostLayout(true);
}
LoginUserInfo user_;
......@@ -183,18 +185,14 @@ TEST_F(LoginAuthUserViewUnittest,
password_test.textfield()->SetText(base::ASCIIToUTF16("Hello"));
// Enable some other auth method (PIN), password is not cleared.
view_->CaptureStateForAnimationPreLayout();
EXPECT_TRUE(has_password());
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
LoginAuthUserView::AUTH_PIN);
EXPECT_TRUE(has_password());
view_->ApplyAnimationPostLayout();
EXPECT_TRUE(has_password());
// Disable password, password is cleared.
view_->CaptureStateForAnimationPreLayout();
SetAuthMethods(LoginAuthUserView::AUTH_NONE);
EXPECT_TRUE(has_password());
view_->ApplyAnimationPostLayout();
SetAuthMethods(LoginAuthUserView::AUTH_NONE);
EXPECT_FALSE(has_password());
}
......
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