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 const base::string16& name = form.display_name.empty() ? form.username_value |
| 37 : form.display_name; |
| 38 switch (style) { |
| 39 case CredentialsItemView::ACCOUNT_CHOOSER: |
| 40 return name; |
| 41 case CredentialsItemView::AUTO_SIGNIN: |
| 42 return l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_AUTO_SIGNIN_TITLE, |
| 43 name); |
| 44 } |
| 45 NOTREACHED(); |
| 46 return base::string16(); |
36 } | 47 } |
37 | 48 |
38 // Returns IDP information for federated credentials and username or empty | 49 // Returns the lower text for the button. |
39 // string for non-federated ones. | 50 base::string16 GetLowerLabelText(const autofill::PasswordForm& form, |
40 base::string16 GetLowerLabelText(const autofill::PasswordForm& form) { | 51 CredentialsItemView::Style style) { |
41 if (!form.federation_url.is_empty()) { | 52 if (!form.federation_url.is_empty()) { |
42 return l10n_util::GetStringFUTF16( | 53 return l10n_util::GetStringFUTF16( |
43 IDS_MANAGE_PASSWORDS_IDENTITY_PROVIDER, | 54 IDS_MANAGE_PASSWORDS_IDENTITY_PROVIDER, |
44 base::ASCIIToUTF16(form.federation_url.host())); | 55 base::ASCIIToUTF16(form.federation_url.host())); |
45 } | 56 } |
46 return form.display_name.empty() ? base::string16() : form.username_value; | 57 return form.display_name.empty() ? base::string16() : form.username_value; |
47 } | 58 } |
48 | 59 |
49 class CircularImageView : public views::ImageView { | 60 class CircularImageView : public views::ImageView { |
50 public: | 61 public: |
(...skipping 17 matching lines...) Expand all Loading... |
68 canvas->ClipPath(circular_mask, true); | 79 canvas->ClipPath(circular_mask, true); |
69 ImageView::OnPaint(canvas); | 80 ImageView::OnPaint(canvas); |
70 } | 81 } |
71 | 82 |
72 } // namespace | 83 } // namespace |
73 | 84 |
74 CredentialsItemView::CredentialsItemView( | 85 CredentialsItemView::CredentialsItemView( |
75 views::ButtonListener* button_listener, | 86 views::ButtonListener* button_listener, |
76 const autofill::PasswordForm& form, | 87 const autofill::PasswordForm& form, |
77 password_manager::CredentialType credential_type, | 88 password_manager::CredentialType credential_type, |
| 89 Style style, |
78 net::URLRequestContextGetter* request_context) | 90 net::URLRequestContextGetter* request_context) |
79 : LabelButton(button_listener, base::string16()), | 91 : LabelButton(button_listener, base::string16()), |
80 form_(form), | 92 form_(form), |
81 credential_type_(credential_type), | 93 credential_type_(credential_type), |
82 upper_label_(nullptr), | 94 upper_label_(nullptr), |
83 lower_label_(nullptr), | 95 lower_label_(nullptr), |
84 weak_ptr_factory_(this) { | 96 weak_ptr_factory_(this) { |
85 set_notify_enter_exit_on_child(true); | 97 set_notify_enter_exit_on_child(true); |
86 // Create an image-view for the avatar. Make sure it ignores events so that | 98 // Create an image-view for the avatar. Make sure it ignores events so that |
87 // the parent can receive the events instead. | 99 // the parent can receive the events instead. |
88 image_view_ = new CircularImageView; | 100 image_view_ = new CircularImageView; |
89 image_view_->set_interactive(false); | 101 image_view_->set_interactive(false); |
90 gfx::Image image = ResourceBundle::GetSharedInstance().GetImageNamed( | 102 gfx::Image image = ResourceBundle::GetSharedInstance().GetImageNamed( |
91 IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE); | 103 IDR_PROFILE_AVATAR_PLACEHOLDER_LARGE); |
92 DCHECK(image.Width() >= kAvatarImageSize && | 104 DCHECK(image.Width() >= kAvatarImageSize && |
93 image.Height() >= kAvatarImageSize); | 105 image.Height() >= kAvatarImageSize); |
94 UpdateAvatar(image.AsImageSkia()); | 106 UpdateAvatar(image.AsImageSkia()); |
95 if (form_.avatar_url.is_valid()) { | 107 if (form_.avatar_url.is_valid()) { |
96 // Fetch the actual avatar. | 108 // Fetch the actual avatar. |
97 AccountAvatarFetcher* fetcher = new AccountAvatarFetcher( | 109 AccountAvatarFetcher* fetcher = new AccountAvatarFetcher( |
98 form_.avatar_url, weak_ptr_factory_.GetWeakPtr()); | 110 form_.avatar_url, weak_ptr_factory_.GetWeakPtr()); |
99 fetcher->Start(request_context); | 111 fetcher->Start(request_context); |
100 } | 112 } |
101 AddChildView(image_view_); | 113 AddChildView(image_view_); |
102 | 114 |
103 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 115 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
104 upper_label_ = new views::Label( | 116 upper_label_ = new views::Label( |
105 GetUpperLabelText(form_), rb->GetFontList(ui::ResourceBundle::BoldFont)); | 117 GetUpperLabelText(form_, style), |
| 118 rb->GetFontList(ui::ResourceBundle::BoldFont)); |
106 upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 119 upper_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
107 AddChildView(upper_label_); | 120 AddChildView(upper_label_); |
108 | 121 |
109 base::string16 lower_text = GetLowerLabelText(form_); | 122 base::string16 lower_text = GetLowerLabelText(form_, style); |
110 if (!lower_text.empty()) { | 123 if (!lower_text.empty()) { |
111 lower_label_ = new views::Label( | 124 lower_label_ = new views::Label( |
112 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); | 125 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); |
113 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 126 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
114 lower_label_->SetEnabled(false); | 127 lower_label_->SetEnabled(false); |
115 AddChildView(lower_label_); | 128 AddChildView(lower_label_); |
116 } | 129 } |
117 | 130 |
118 SetFocusable(true); | 131 SetFocusable(true); |
119 } | 132 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 upper_label_->SetBoundsRect(gfx::Rect(label_origin, full_name_size)); | 170 upper_label_->SetBoundsRect(gfx::Rect(label_origin, full_name_size)); |
158 if (lower_label_) { | 171 if (lower_label_) { |
159 label_origin.Offset(0, full_name_size.height()); | 172 label_origin.Offset(0, full_name_size.height()); |
160 lower_label_->SetBoundsRect(gfx::Rect(label_origin, username_size)); | 173 lower_label_->SetBoundsRect(gfx::Rect(label_origin, username_size)); |
161 } | 174 } |
162 } | 175 } |
163 | 176 |
164 void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { | 177 void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { |
165 image_view_->SetImage(ScaleImageForAccountAvatar(image)); | 178 image_view_->SetImage(ScaleImageForAccountAvatar(image)); |
166 } | 179 } |
OLD | NEW |