Commit 10284b9e authored by vasilii's avatar vasilii Committed by Commit bot

Change the account chooser on Win to look like in the mocks.

BUG=550922

Review URL: https://codereview.chromium.org/1701363002

Cr-Commit-Position: refs/heads/master@{#376130}
parent e17b7491
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
const SkColor kButtonHoverColor = SkColorSetRGB(0xEA, 0xEA, 0xEA);
@interface AccountChooserViewController () { @interface AccountChooserViewController () {
NSButton* cancelButton_; // Weak. NSButton* cancelButton_; // Weak.
NSTextView* titleView_; // Weak. NSTextView* titleView_; // Weak.
......
...@@ -22,6 +22,9 @@ const int kTitleTopInset = 12; ...@@ -22,6 +22,9 @@ const int kTitleTopInset = 12;
// The color of the content in the autosign-in first run prompt. // The color of the content in the autosign-in first run prompt.
const SkColor kAutoSigninTextColor = SkColorSetRGB(0x64, 0x64, 0x64); const SkColor kAutoSigninTextColor = SkColorSetRGB(0x64, 0x64, 0x64);
// The hover color of the account chooser.
const SkColor kButtonHoverColor = SkColorSetRGB(0xEA, 0xEA, 0xEA);
// A platform-independent interface for the account chooser dialog. // A platform-independent interface for the account chooser dialog.
class AccountChooserPrompt { class AccountChooserPrompt {
public: public:
......
...@@ -23,22 +23,28 @@ ...@@ -23,22 +23,28 @@
namespace { namespace {
const int kVerticalAvatarMargin = 8;
// An identifier for views::ColumnSet. // An identifier for views::ColumnSet.
enum ColumnSetType { enum ColumnSetType {
SINGLE_VIEW_COLUMN_SET, SINGLE_VIEW_COLUMN_SET,
SINGLE_VIEW_COLUMN_SET_NO_PADDING,
}; };
// Construct a SINGLE_VIEW_COLUMN_SET ColumnSet and add it to |layout|. // Construct a |type| ColumnSet and add it to |layout|.
void BuildOneColumnSet(views::GridLayout* layout) { void BuildColumnSet(ColumnSetType type, views::GridLayout* layout) {
views::ColumnSet* column_set = layout->AddColumnSet(SINGLE_VIEW_COLUMN_SET); views::ColumnSet* column_set = layout->AddColumnSet(type);
column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); bool padding = (type == SINGLE_VIEW_COLUMN_SET);
if (padding)
column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
column_set->AddColumn(views::GridLayout::FILL, column_set->AddColumn(views::GridLayout::FILL,
views::GridLayout::FILL, views::GridLayout::FILL,
1, 1,
views::GridLayout::USE_PREF, views::GridLayout::USE_PREF,
0, 0,
0); 0);
column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); if (padding)
column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew);
} }
views::StyledLabel::RangeStyleInfo GetLinkStyle() { views::StyledLabel::RangeStyleInfo GetLinkStyle() {
...@@ -120,14 +126,15 @@ void AccountChooserDialogView::StyledLabelLinkClicked(views::StyledLabel* label, ...@@ -120,14 +126,15 @@ void AccountChooserDialogView::StyledLabelLinkClicked(views::StyledLabel* label,
void AccountChooserDialogView::ButtonPressed(views::Button* sender, void AccountChooserDialogView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
CredentialsItemView* view = static_cast<CredentialsItemView*>(sender); CredentialsItemView* view = static_cast<CredentialsItemView*>(sender);
controller_->OnChooseCredentials(*view->form(), controller_->OnChooseCredentials(
view->credential_type()); *view->form(),
password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
} }
void AccountChooserDialogView::InitWindow() { void AccountChooserDialogView::InitWindow() {
views::GridLayout* layout = new views::GridLayout(this); views::GridLayout* layout = new views::GridLayout(this);
SetLayoutManager(layout); SetLayoutManager(layout);
BuildOneColumnSet(layout); BuildColumnSet(SINGLE_VIEW_COLUMN_SET, layout);
// Create the title. // Create the title.
std::pair<base::string16, gfx::Range> title_content = std::pair<base::string16, gfx::Range> title_content =
...@@ -147,6 +154,7 @@ void AccountChooserDialogView::InitWindow() { ...@@ -147,6 +154,7 @@ void AccountChooserDialogView::InitWindow() {
// Show credentials. // Show credentials.
net::URLRequestContextGetter* request_context = net::URLRequestContextGetter* request_context =
GetProfileFromWebContents(web_contents_)->GetRequestContext(); GetProfileFromWebContents(web_contents_)->GetRequestContext();
BuildColumnSet(SINGLE_VIEW_COLUMN_SET_NO_PADDING, layout);
for (const auto& form : controller_->GetLocalForms()) { for (const auto& form : controller_->GetLocalForms()) {
const base::string16& upper_string = const base::string16& upper_string =
form->display_name.empty() ? form->username_value : form->display_name; form->display_name.empty() ? form->username_value : form->display_name;
...@@ -159,11 +167,15 @@ void AccountChooserDialogView::InitWindow() { ...@@ -159,11 +167,15 @@ void AccountChooserDialogView::InitWindow() {
IDS_PASSWORDS_VIA_FEDERATION, IDS_PASSWORDS_VIA_FEDERATION,
base::UTF8ToUTF16(form->federation_url.host())); base::UTF8ToUTF16(form->federation_url.host()));
} }
layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); layout->StartRow(0, SINGLE_VIEW_COLUMN_SET_NO_PADDING);
layout->AddView(new CredentialsItemView( CredentialsItemView* view = new CredentialsItemView(
this, form.get(), this, upper_string, lower_string, kButtonHoverColor,
password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD, form.get(), request_context);
upper_string, lower_string, request_context)); view->SetLowerLabelColor(kAutoSigninTextColor);
view->SetBorder(views::Border::CreateEmptyBorder(
kVerticalAvatarMargin, views::kButtonHEdgeMarginNew,
kVerticalAvatarMargin, views::kButtonHEdgeMarginNew));
layout->AddView(view);
} }
// DialogClientView adds kRelatedControlVerticalSpacing padding once more for // DialogClientView adds kRelatedControlVerticalSpacing padding once more for
// the buttons. // the buttons.
......
...@@ -18,10 +18,11 @@ ...@@ -18,10 +18,11 @@
#include "ui/views/border.h" #include "ui/views/border.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/layout_constants.h"
namespace { namespace {
// The default spacing between the icon and text. // The default spacing between the icon and text.
const int kSpacing = 5; const int kSpacing = 12;
gfx::Size GetTextLabelsSize(const views::Label* upper_label, gfx::Size GetTextLabelsSize(const views::Label* upper_label,
const views::Label* lower_label) { const views::Label* lower_label) {
...@@ -60,16 +61,16 @@ void CircularImageView::OnPaint(gfx::Canvas* canvas) { ...@@ -60,16 +61,16 @@ void CircularImageView::OnPaint(gfx::Canvas* canvas) {
CredentialsItemView::CredentialsItemView( CredentialsItemView::CredentialsItemView(
views::ButtonListener* button_listener, views::ButtonListener* button_listener,
const autofill::PasswordForm* form,
password_manager::CredentialType credential_type,
const base::string16& upper_text, const base::string16& upper_text,
const base::string16& lower_text, const base::string16& lower_text,
SkColor hover_color,
const autofill::PasswordForm* form,
net::URLRequestContextGetter* request_context) net::URLRequestContextGetter* request_context)
: LabelButton(button_listener, base::string16()), : LabelButton(button_listener, base::string16()),
form_(form), form_(form),
credential_type_(credential_type),
upper_label_(nullptr), upper_label_(nullptr),
lower_label_(nullptr), lower_label_(nullptr),
hover_color_(hover_color),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
set_notify_enter_exit_on_child(true); set_notify_enter_exit_on_child(true);
// Create an image-view for the avatar. Make sure it ignores events so that // Create an image-view for the avatar. Make sure it ignores events so that
...@@ -92,7 +93,7 @@ CredentialsItemView::CredentialsItemView( ...@@ -92,7 +93,7 @@ CredentialsItemView::CredentialsItemView(
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
if (!upper_text.empty()) { if (!upper_text.empty()) {
upper_label_ = new views::Label( upper_label_ = new views::Label(
upper_text, rb->GetFontList(ui::ResourceBundle::BoldFont)); upper_text, rb->GetFontList(ui::ResourceBundle::SmallFont));
upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(upper_label_); AddChildView(upper_label_);
} }
...@@ -109,6 +110,19 @@ CredentialsItemView::CredentialsItemView( ...@@ -109,6 +110,19 @@ CredentialsItemView::CredentialsItemView(
CredentialsItemView::~CredentialsItemView() = default; CredentialsItemView::~CredentialsItemView() = default;
void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) {
image_view_->SetImage(ScaleImageForAccountAvatar(image));
}
void CredentialsItemView::SetLowerLabelColor(SkColor color) {
if (lower_label_)
lower_label_->SetEnabledColor(color);
}
void CredentialsItemView::SetHoverColor(SkColor color) {
hover_color_ = color;
}
gfx::Size CredentialsItemView::GetPreferredSize() const { gfx::Size CredentialsItemView::GetPreferredSize() const {
gfx::Size labels_size = GetTextLabelsSize(upper_label_, lower_label_); gfx::Size labels_size = GetTextLabelsSize(upper_label_, lower_label_);
gfx::Size size = gfx::Size(kAvatarImageSize + labels_size.width(), gfx::Size size = gfx::Size(kAvatarImageSize + labels_size.width(),
...@@ -152,6 +166,9 @@ void CredentialsItemView::Layout() { ...@@ -152,6 +166,9 @@ void CredentialsItemView::Layout() {
} }
} }
void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { void CredentialsItemView::OnPaint(gfx::Canvas* canvas) {
image_view_->SetImage(ScaleImageForAccountAvatar(image)); if (state() == STATE_PRESSED || state() == STATE_HOVERED)
canvas->DrawColor(hover_color_);
LabelButton::OnPaint(canvas);
} }
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/passwords/account_avatar_fetcher.h" #include "chrome/browser/ui/passwords/account_avatar_fetcher.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
namespace autofill { namespace autofill {
...@@ -34,34 +33,36 @@ class CredentialsItemView : public AccountAvatarFetcherDelegate, ...@@ -34,34 +33,36 @@ class CredentialsItemView : public AccountAvatarFetcherDelegate,
public views::LabelButton { public views::LabelButton {
public: public:
CredentialsItemView(views::ButtonListener* button_listener, CredentialsItemView(views::ButtonListener* button_listener,
const autofill::PasswordForm* form,
password_manager::CredentialType credential_type,
const base::string16& upper_text, const base::string16& upper_text,
const base::string16& lower_text, const base::string16& lower_text,
SkColor hover_color,
const autofill::PasswordForm* form,
net::URLRequestContextGetter* request_context); net::URLRequestContextGetter* request_context);
~CredentialsItemView() override; ~CredentialsItemView() override;
const autofill::PasswordForm* form() const { return form_; } const autofill::PasswordForm* form() const { return form_; }
password_manager::CredentialType credential_type() const {
return credential_type_;
}
// AccountAvatarFetcherDelegate: // AccountAvatarFetcherDelegate:
void UpdateAvatar(const gfx::ImageSkia& image) override; void UpdateAvatar(const gfx::ImageSkia& image) override;
void SetLowerLabelColor(SkColor color);
void SetHoverColor(SkColor color);
private: private:
// views::LabelButton: // views::LabelButton:
gfx::Size GetPreferredSize() const override; gfx::Size GetPreferredSize() const override;
int GetHeightForWidth(int w) const override; int GetHeightForWidth(int w) const override;
void Layout() override; void Layout() override;
void OnPaint(gfx::Canvas* canvas) override;
const autofill::PasswordForm* form_; const autofill::PasswordForm* form_;
const password_manager::CredentialType credential_type_;
views::ImageView* image_view_; views::ImageView* image_view_;
views::Label* upper_label_; views::Label* upper_label_;
views::Label* lower_label_; views::Label* lower_label_;
SkColor hover_color_;
base::WeakPtrFactory<CredentialsItemView> weak_ptr_factory_; base::WeakPtrFactory<CredentialsItemView> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(CredentialsItemView); DISALLOW_COPY_AND_ASSIGN(CredentialsItemView);
......
...@@ -224,11 +224,13 @@ ManagePasswordsBubbleView::AutoSigninView::AutoSigninView( ...@@ -224,11 +224,13 @@ ManagePasswordsBubbleView::AutoSigninView::AutoSigninView(
SetLayoutManager(new views::FillLayout); SetLayoutManager(new views::FillLayout);
const autofill::PasswordForm& form = parent_->model()->pending_password(); const autofill::PasswordForm& form = parent_->model()->pending_password();
CredentialsItemView* credential = new CredentialsItemView( CredentialsItemView* credential = new CredentialsItemView(
this, &form, this,
password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD,
base::string16(), base::string16(),
l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_AUTO_SIGNIN_TITLE, l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_AUTO_SIGNIN_TITLE,
form.username_value), form.username_value),
GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_ButtonBackgroundColor),
&form,
parent_->model()->GetProfile()->GetRequestContext()); parent_->model()->GetProfile()->GetRequestContext());
credential->SetEnabled(false); credential->SetEnabled(false);
AddChildView(credential); AddChildView(credential);
......
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