OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 5 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 8 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 gfx::Size GetTextLabelsSize(const views::Label* upper_label, | 24 gfx::Size GetTextLabelsSize(const views::Label* upper_label, |
25 const views::Label* lower_label) { | 25 const views::Label* lower_label) { |
26 gfx::Size upper_label_size = upper_label->GetPreferredSize(); | 26 gfx::Size upper_label_size = upper_label->GetPreferredSize(); |
27 gfx::Size lower_label_size = lower_label ? lower_label->GetPreferredSize() : | 27 gfx::Size lower_label_size = lower_label ? lower_label->GetPreferredSize() : |
28 gfx::Size(); | 28 gfx::Size(); |
29 return gfx::Size(std::max(upper_label_size.width(), lower_label_size.width()), | 29 return gfx::Size(std::max(upper_label_size.width(), lower_label_size.width()), |
30 upper_label_size.height() + lower_label_size.height()); | 30 upper_label_size.height() + lower_label_size.height()); |
31 } | 31 } |
32 | 32 |
33 // Returns either full name or username if the former is empty. | 33 // Returns the bold upper text for the button. |
34 const base::string16& GetUpperLabelText(const autofill::PasswordForm& form) { | 34 base::string16 GetUpperLabelText(const autofill::PasswordForm& form, |
35 return form.display_name.empty() ? form.username_value : form.display_name; | 35 CredentialsItemView::Style style) { |
| 36 switch (style) { |
| 37 case CredentialsItemView::ACCOUNT_CHOOSER: |
| 38 return form.display_name.empty() ? form.username_value |
| 39 : form.display_name; |
| 40 case CredentialsItemView::AUTO_SIGNIN: |
| 41 return l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_AUTO_SIGNIN_TITLE); |
| 42 } |
36 } | 43 } |
37 | 44 |
38 // Returns IDP information for federated credentials and username or empty | 45 // Returns the lower text for the button. |
39 // string for non-federated ones. | 46 base::string16 GetLowerLabelText(const autofill::PasswordForm& form, |
40 base::string16 GetLowerLabelText(const autofill::PasswordForm& form) { | 47 CredentialsItemView::Style style) { |
41 if (!form.federation_url.is_empty()) { | 48 if (!form.federation_url.is_empty()) { |
42 return l10n_util::GetStringFUTF16( | 49 return l10n_util::GetStringFUTF16( |
43 IDS_MANAGE_PASSWORDS_IDENTITY_PROVIDER, | 50 IDS_MANAGE_PASSWORDS_IDENTITY_PROVIDER, |
44 base::ASCIIToUTF16(form.federation_url.host())); | 51 base::ASCIIToUTF16(form.federation_url.host())); |
45 } | 52 } |
46 return form.display_name.empty() ? base::string16() : form.username_value; | 53 switch (style) { |
| 54 case CredentialsItemView::ACCOUNT_CHOOSER: |
| 55 return form.display_name.empty() ? base::string16() : form.username_value; |
| 56 case CredentialsItemView::AUTO_SIGNIN: |
| 57 return form.username_value; |
| 58 } |
47 } | 59 } |
48 | 60 |
49 class CircularImageView : public views::ImageView { | 61 class CircularImageView : public views::ImageView { |
50 public: | 62 public: |
51 CircularImageView() = default; | 63 CircularImageView() = default; |
52 | 64 |
53 private: | 65 private: |
54 // views::ImageView: | 66 // views::ImageView: |
55 void OnPaint(gfx::Canvas* canvas) override; | 67 void OnPaint(gfx::Canvas* canvas) override; |
56 | 68 |
(...skipping 11 matching lines...) Expand all Loading... |
68 canvas->ClipPath(circular_mask, true); | 80 canvas->ClipPath(circular_mask, true); |
69 ImageView::OnPaint(canvas); | 81 ImageView::OnPaint(canvas); |
70 } | 82 } |
71 | 83 |
72 } // namespace | 84 } // namespace |
73 | 85 |
74 CredentialsItemView::CredentialsItemView( | 86 CredentialsItemView::CredentialsItemView( |
75 views::ButtonListener* button_listener, | 87 views::ButtonListener* button_listener, |
76 const autofill::PasswordForm& form, | 88 const autofill::PasswordForm& form, |
77 password_manager::CredentialType credential_type, | 89 password_manager::CredentialType credential_type, |
| 90 Style style, |
78 net::URLRequestContextGetter* request_context) | 91 net::URLRequestContextGetter* request_context) |
79 : LabelButton(button_listener, base::string16()), | 92 : LabelButton(button_listener, base::string16()), |
80 form_(form), | 93 form_(form), |
81 credential_type_(credential_type), | 94 credential_type_(credential_type), |
82 upper_label_(nullptr), | 95 upper_label_(nullptr), |
83 lower_label_(nullptr), | 96 lower_label_(nullptr), |
84 weak_ptr_factory_(this) { | 97 weak_ptr_factory_(this) { |
85 set_notify_enter_exit_on_child(true); | 98 set_notify_enter_exit_on_child(true); |
86 // Create an image-view for the avatar. Make sure it ignores events so that | 99 // Create an image-view for the avatar. Make sure it ignores events so that |
87 // the parent can receive the events instead. | 100 // the parent can receive the events instead. |
88 image_view_ = new CircularImageView; | 101 image_view_ = new CircularImageView; |
89 image_view_->set_interactive(false); | 102 image_view_->set_interactive(false); |
90 gfx::Image image = ResourceBundle::GetSharedInstance().GetImageNamed( | 103 gfx::Image image = ResourceBundle::GetSharedInstance().GetImageNamed( |
91 IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE); | 104 IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE); |
92 DCHECK(image.Width() >= kAvatarImageSize && | 105 DCHECK(image.Width() >= kAvatarImageSize && |
93 image.Height() >= kAvatarImageSize); | 106 image.Height() >= kAvatarImageSize); |
94 UpdateAvatar(image.AsImageSkia()); | 107 UpdateAvatar(image.AsImageSkia()); |
95 if (form_.avatar_url.is_valid()) { | 108 if (form_.avatar_url.is_valid()) { |
96 // Fetch the actual avatar. | 109 // Fetch the actual avatar. |
97 AccountAvatarFetcher* fetcher = new AccountAvatarFetcher( | 110 AccountAvatarFetcher* fetcher = new AccountAvatarFetcher( |
98 form_.avatar_url, weak_ptr_factory_.GetWeakPtr()); | 111 form_.avatar_url, weak_ptr_factory_.GetWeakPtr()); |
99 fetcher->Start(request_context); | 112 fetcher->Start(request_context); |
100 } | 113 } |
101 AddChildView(image_view_); | 114 AddChildView(image_view_); |
102 | 115 |
103 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 116 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
104 upper_label_ = new views::Label( | 117 upper_label_ = new views::Label( |
105 GetUpperLabelText(form_), rb->GetFontList(ui::ResourceBundle::BoldFont)); | 118 GetUpperLabelText(form_, style), |
| 119 rb->GetFontList(ui::ResourceBundle::BoldFont)); |
106 upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 120 upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
107 AddChildView(upper_label_); | 121 AddChildView(upper_label_); |
108 | 122 |
109 base::string16 lower_text = GetLowerLabelText(form_); | 123 base::string16 lower_text = GetLowerLabelText(form_, style); |
110 if (!lower_text.empty()) { | 124 if (!lower_text.empty()) { |
111 lower_label_ = new views::Label( | 125 lower_label_ = new views::Label( |
112 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); | 126 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); |
113 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 127 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
114 lower_label_->SetEnabled(false); | 128 lower_label_->SetEnabled(false); |
115 AddChildView(lower_label_); | 129 AddChildView(lower_label_); |
116 } | 130 } |
117 | 131 |
118 SetFocusable(true); | 132 SetFocusable(true); |
119 } | 133 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 upper_label_->SetBoundsRect(gfx::Rect(label_origin, full_name_size)); | 171 upper_label_->SetBoundsRect(gfx::Rect(label_origin, full_name_size)); |
158 if (lower_label_) { | 172 if (lower_label_) { |
159 label_origin.Offset(0, full_name_size.height()); | 173 label_origin.Offset(0, full_name_size.height()); |
160 lower_label_->SetBoundsRect(gfx::Rect(label_origin, username_size)); | 174 lower_label_->SetBoundsRect(gfx::Rect(label_origin, username_size)); |
161 } | 175 } |
162 } | 176 } |
163 | 177 |
164 void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { | 178 void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { |
165 image_view_->SetImage(ScaleImageForAccountAvatar(image)); | 179 image_view_->SetImage(ScaleImageForAccountAvatar(image)); |
166 } | 180 } |
OLD | NEW |