Commit c6b6d260 authored by Yicheng Li's avatar Yicheng Li Committed by Commit Bot

ash: Add user avatar to in-session auth dialog

This is to indicate to the user that this is an OS dialog.

Bug: b/156258540
Change-Id: I0c3b4f53682e348a1623e1f812c5991f58134468
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2511754
Commit-Queue: Yicheng Li <yichengli@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823723}
parent cc8f1674
......@@ -38,6 +38,7 @@ namespace {
const char kTitle[] = "Verify it's you";
const int kContainerPreferredWidth = 512;
const int kSpacingAfterAvatar = 18;
const int kSpacingAfterTitle = 16;
const int kBorderTopDp = 24;
......@@ -47,6 +48,7 @@ const int kBorderRightDp = 24;
const int kTitleFontSizeDeltaDp = 4;
constexpr int kAvatarSizeDp = 36;
constexpr int kFingerprintIconSizeDp = 28;
constexpr int kFingerprintIconTopSpacingDp = 20;
constexpr int kSpacingBetweenFingerprintIconAndLabelDp = 15;
......@@ -257,7 +259,8 @@ class AuthDialogContentsView::FingerprintView : public views::View {
AuthDialogContentsView::AuthDialogContentsView(
uint32_t auth_methods,
const AuthMethodsMetadata& auth_metadata)
const AuthMethodsMetadata& auth_metadata,
const UserAvatar& avatar)
: auth_methods_(auth_methods), auth_metadata_(auth_metadata) {
DCHECK(auth_methods_ & kAuthPassword);
......@@ -275,6 +278,8 @@ AuthDialogContentsView::AuthDialogContentsView(
main_layout_->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter);
AddAvatarView(avatar);
AddVerticalSpacing(kSpacingAfterAvatar);
AddTitleView();
AddVerticalSpacing(kSpacingAfterTitle);
if (auth_methods_ & kAuthPin) {
......@@ -312,6 +317,14 @@ void AuthDialogContentsView::AddedToWidget() {
}
}
void AuthDialogContentsView::AddAvatarView(const UserAvatar& avatar) {
avatar_view_ =
container_->AddChildView(std::make_unique<AnimatedRoundedImageView>(
gfx::Size(kAvatarSizeDp, kAvatarSizeDp),
kAvatarSizeDp / 2 /*corner_radius*/));
avatar_view_->SetImage(avatar.image);
}
void AuthDialogContentsView::AddTitleView() {
title_ = container_->AddChildView(std::make_unique<views::Label>());
title_->SetEnabledColor(SK_ColorBLACK);
......
......@@ -18,6 +18,7 @@ class Label;
namespace ash {
class AnimatedRoundedImageView;
class LoginPasswordView;
class LoginPinView;
class LoginPinInputView;
......@@ -41,7 +42,8 @@ class AuthDialogContentsView : public views::View {
};
AuthDialogContentsView(uint32_t auth_methods,
const AuthMethodsMetadata& auth_metadata);
const AuthMethodsMetadata& auth_metadata,
const UserAvatar& avatar);
AuthDialogContentsView(const AuthDialogContentsView&) = delete;
AuthDialogContentsView& operator=(const AuthDialogContentsView&) = delete;
~AuthDialogContentsView() override;
......@@ -57,6 +59,9 @@ class AuthDialogContentsView : public views::View {
// views::View:
void AddedToWidget() override;
// Add a view for user avatar.
void AddAvatarView(const UserAvatar& avatar);
// Add a view for dialog title.
void AddTitleView();
......@@ -97,6 +102,9 @@ class AuthDialogContentsView : public views::View {
// Layout for |container_|.
views::BoxLayout* main_layout_ = nullptr;
// User avatar to indicate this is an OS dialog.
AnimatedRoundedImageView* avatar_view_ = nullptr;
// Title of the auth dialog.
views::Label* title_ = nullptr;
......
......@@ -49,10 +49,11 @@ std::unique_ptr<views::Widget> CreateAuthDialogWidget(
InSessionAuthDialog::InSessionAuthDialog(
uint32_t auth_methods,
aura::Window* parent_window,
const AuthDialogContentsView::AuthMethodsMetadata& auth_metadata)
const AuthDialogContentsView::AuthMethodsMetadata& auth_metadata,
const UserAvatar& avatar)
: auth_methods_(auth_methods) {
widget_ = CreateAuthDialogWidget(
std::make_unique<AuthDialogContentsView>(auth_methods, auth_metadata),
widget_ = CreateAuthDialogWidget(std::make_unique<AuthDialogContentsView>(
auth_methods, auth_metadata, avatar),
parent_window);
gfx::Rect bounds = parent_window->GetBoundsInScreen();
gfx::Size preferred_size = widget_->GetContentsView()->GetPreferredSize();
......
......@@ -30,7 +30,8 @@ class InSessionAuthDialog {
InSessionAuthDialog(
uint32_t auth_methods,
aura::Window* parent_window,
const AuthDialogContentsView::AuthMethodsMetadata& auth_metadata);
const AuthDialogContentsView::AuthMethodsMetadata& auth_metadata,
const UserAvatar& avatar);
InSessionAuthDialog(const InSessionAuthDialog&) = delete;
InSessionAuthDialog& operator=(const InSessionAuthDialog&) = delete;
~InSessionAuthDialog();
......
......@@ -100,13 +100,21 @@ void InSessionAuthDialogControllerImpl::OnPinCanAuthenticate(
AccountId account_id =
Shell::Get()->session_controller()->GetActiveAccountId();
const UserSession* session =
Shell::Get()->session_controller()->GetUserSessionByAccountId(account_id);
DCHECK(session);
UserAvatar avatar = session->user_info.avatar;
// TODO(b/156258540): move UserSelectionScreen::BuildAshUserAvatarForUser to
// somewhere that UserToUserSession could call, to support animated avatars.
AuthDialogContentsView::AuthMethodsMetadata auth_metadata;
auth_metadata.autosubmit_pin_length =
user_manager::known_user::GetUserPinLength(account_id);
window_tracker_.Remove(source_window);
Shell::Get()->focus_controller()->AddObserver(this);
dialog_ = std::make_unique<InSessionAuthDialog>(auth_methods, source_window,
auth_metadata);
auth_metadata, avatar);
}
void InSessionAuthDialogControllerImpl::DestroyAuthenticationDialog() {
......
......@@ -134,6 +134,19 @@ const UserSession* SessionControllerImpl::GetUserSession(
return user_sessions_[index].get();
}
const UserSession* SessionControllerImpl::GetUserSessionByAccountId(
const AccountId& account_id) const {
auto it =
std::find_if(user_sessions_.begin(), user_sessions_.end(),
[&account_id](const std::unique_ptr<UserSession>& session) {
return session->user_info.account_id == account_id;
});
if (it == user_sessions_.end())
return nullptr;
return (*it).get();
}
const UserSession* SessionControllerImpl::GetPrimaryUserSession() const {
auto it = std::find_if(user_sessions_.begin(), user_sessions_.end(),
[this](const std::unique_ptr<UserSession>& session) {
......
......@@ -94,10 +94,15 @@ class ASH_EXPORT SessionControllerImpl : public SessionController {
// Gets the user sessions in LRU order with the active session being first.
const UserSessions& GetUserSessions() const;
// Convenience helper to gets the user session at a given index. Returns
// Convenience helper to get the user session at a given index. Returns
// nullptr if no user session is found for the index.
const UserSession* GetUserSession(UserIndex index) const;
// Convenience helper to get the user session with the given account id.
// Returns nullptr if no user session is found for the account id.
const UserSession* GetUserSessionByAccountId(
const AccountId& account_id) const;
// Gets the primary user session.
const UserSession* GetPrimaryUserSession() const;
......
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