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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" |
10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
11 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
17 #include "ui/gfx/path.h" | 17 #include "ui/gfx/path.h" |
18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
19 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
21 #include "ui/views/layout/layout_constants.h" | 21 #include "ui/views/layout/layout_constants.h" |
| 22 #include "ui/views/style/platform_style.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 // The default spacing between the icon and text. | 25 // The default spacing between the icon and text. |
25 const int kSpacing = 12; | 26 const int kSpacing = 12; |
26 | 27 |
27 gfx::Size GetTextLabelsSize(const views::Label* upper_label, | 28 gfx::Size GetTextLabelsSize(const views::Label* upper_label, |
28 const views::Label* lower_label) { | 29 const views::Label* lower_label) { |
29 gfx::Size upper_label_size = upper_label ? upper_label->GetPreferredSize() | 30 gfx::Size upper_label_size = upper_label ? upper_label->GetPreferredSize() |
30 : gfx::Size(); | 31 : gfx::Size(); |
31 gfx::Size lower_label_size = lower_label ? lower_label->GetPreferredSize() | 32 gfx::Size lower_label_size = lower_label ? lower_label->GetPreferredSize() |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 AddChildView(upper_label_); | 99 AddChildView(upper_label_); |
99 } | 100 } |
100 | 101 |
101 if (!lower_text.empty()) { | 102 if (!lower_text.empty()) { |
102 lower_label_ = new views::Label( | 103 lower_label_ = new views::Label( |
103 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); | 104 lower_text, rb->GetFontList(ui::ResourceBundle::SmallFont)); |
104 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 105 lower_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
105 AddChildView(lower_label_); | 106 AddChildView(lower_label_); |
106 } | 107 } |
107 | 108 |
108 SetFocusable(true); | 109 views::PlatformStyle::ConfigureFocus( |
| 110 views::PlatformStyle::CONTROL::CREDENTIALS_ITEM_VIEW, this); |
109 } | 111 } |
110 | 112 |
111 CredentialsItemView::~CredentialsItemView() = default; | 113 CredentialsItemView::~CredentialsItemView() = default; |
112 | 114 |
113 void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { | 115 void CredentialsItemView::UpdateAvatar(const gfx::ImageSkia& image) { |
114 image_view_->SetImage(ScaleImageForAccountAvatar(image)); | 116 image_view_->SetImage(ScaleImageForAccountAvatar(image)); |
115 } | 117 } |
116 | 118 |
117 void CredentialsItemView::SetLowerLabelColor(SkColor color) { | 119 void CredentialsItemView::SetLowerLabelColor(SkColor color) { |
118 if (lower_label_) | 120 if (lower_label_) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 lower_label_->SetBoundsRect(gfx::Rect(label_origin, lower_size)); | 171 lower_label_->SetBoundsRect(gfx::Rect(label_origin, lower_size)); |
170 } | 172 } |
171 } | 173 } |
172 | 174 |
173 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { | 175 void CredentialsItemView::OnPaint(gfx::Canvas* canvas) { |
174 if (state() == STATE_PRESSED || state() == STATE_HOVERED) | 176 if (state() == STATE_PRESSED || state() == STATE_HOVERED) |
175 canvas->DrawColor(hover_color_); | 177 canvas->DrawColor(hover_color_); |
176 | 178 |
177 LabelButton::OnPaint(canvas); | 179 LabelButton::OnPaint(canvas); |
178 } | 180 } |
OLD | NEW |