Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_password_items_view.cc

Issue 2869683003: Views/Harmony: Remove references to layout constants in c/b/u/v/passwords. (Closed)
Patch Set: Review comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/manage_password_items_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h"
6 6
7 #include <numeric> 7 #include <numeric>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h" 13 #include "chrome/browser/ui/passwords/manage_passwords_view_utils.h"
14 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
15 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
14 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 18 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/resources/grit/ui_resources.h" 19 #include "ui/resources/grit/ui_resources.h"
18 #include "ui/views/controls/button/button.h" 20 #include "ui/views/controls/button/button.h"
19 #include "ui/views/controls/button/image_button.h" 21 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/link.h" 23 #include "ui/views/controls/link.h"
22 #include "ui/views/controls/link_listener.h" 24 #include "ui/views/controls/link_listener.h"
23 #include "ui/views/layout/fill_layout.h" 25 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/layout/grid_layout.h" 26 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_constants.h"
26 27
27 namespace { 28 namespace {
28 29
29 enum ColumnSets { 30 enum ColumnSets {
30 ONE_COLUMN_SET, 31 ONE_COLUMN_SET,
31 TWO_COLUMN_SET, 32 TWO_COLUMN_SET,
32 THREE_COLUMN_SET 33 THREE_COLUMN_SET
33 }; 34 };
34 35
35 void BuildColumnSetIfNeeded(views::GridLayout* layout, int column_set_id) { 36 void BuildColumnSetIfNeeded(views::GridLayout* layout, int column_set_id) {
36 if (layout->GetColumnSet(column_set_id)) 37 if (layout->GetColumnSet(column_set_id))
37 return; 38 return;
38 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 39 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
39 40
40 // The username/"Deleted!"/Border field. 41 // The username/"Deleted!"/Border field.
41 column_set->AddColumn(views::GridLayout::FILL, 42 column_set->AddColumn(views::GridLayout::FILL,
42 views::GridLayout::FILL, 43 views::GridLayout::FILL,
43 1, 44 1,
44 views::GridLayout::USE_PREF, 45 views::GridLayout::USE_PREF,
45 0, 46 0,
46 0); 47 0);
48
49 const int column_divider = ChromeLayoutProvider::Get()->GetDistanceMetric(
50 views::DISTANCE_RELATED_CONTROL_HORIZONTAL);
47 if (column_set_id >= TWO_COLUMN_SET) { 51 if (column_set_id >= TWO_COLUMN_SET) {
48 // The password/"Undo!" field. 52 // The password/"Undo!" field.
49 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 53 column_set->AddPaddingColumn(0, column_divider);
50 column_set->AddColumn(views::GridLayout::FILL, 54 column_set->AddColumn(views::GridLayout::FILL,
51 views::GridLayout::FILL, 55 views::GridLayout::FILL,
52 1, 56 1,
53 views::GridLayout::USE_PREF, 57 views::GridLayout::USE_PREF,
54 0, 58 0,
55 0); 59 0);
56 } 60 }
57 // If we're in manage-mode, we need another column for the delete button. 61 // If we're in manage-mode, we need another column for the delete button.
58 if (column_set_id == THREE_COLUMN_SET) { 62 if (column_set_id == THREE_COLUMN_SET) {
59 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 63 column_set->AddPaddingColumn(0, column_divider);
60 column_set->AddColumn(views::GridLayout::TRAILING, 64 column_set->AddColumn(views::GridLayout::TRAILING,
61 views::GridLayout::FILL, 65 views::GridLayout::FILL,
62 0, 66 0,
63 views::GridLayout::USE_PREF, 67 views::GridLayout::USE_PREF,
64 0, 68 0,
65 0); 69 0);
66 } 70 }
67 } 71 }
68 72
69 std::unique_ptr<views::Label> GenerateUsernameLabel( 73 std::unique_ptr<views::Label> GenerateUsernameLabel(
70 const autofill::PasswordForm& form) { 74 const autofill::PasswordForm& form) {
71 std::unique_ptr<views::Label> label( 75 auto label = base::MakeUnique<views::Label>(GetDisplayUsername(form),
72 new views::Label(GetDisplayUsername(form))); 76 CONTEXT_DEPRECATED_SMALL);
73 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
74 ui::ResourceBundle::SmallFont));
75 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 77 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
76 return label; 78 return label;
77 } 79 }
78 80
79 std::unique_ptr<views::Label> GeneratePasswordLabel( 81 std::unique_ptr<views::Label> GeneratePasswordLabel(
80 const autofill::PasswordForm& form) { 82 const autofill::PasswordForm& form) {
81 base::string16 text = 83 base::string16 text =
82 form.federation_origin.unique() 84 form.federation_origin.unique()
83 ? form.password_value 85 ? form.password_value
84 : l10n_util::GetStringFUTF16( 86 : l10n_util::GetStringFUTF16(
85 IDS_PASSWORDS_VIA_FEDERATION, 87 IDS_PASSWORDS_VIA_FEDERATION,
86 base::UTF8ToUTF16(form.federation_origin.host())); 88 base::UTF8ToUTF16(form.federation_origin.host()));
87 std::unique_ptr<views::Label> label(new views::Label(text)); 89 auto label = base::MakeUnique<views::Label>(text, CONTEXT_DEPRECATED_SMALL);
88 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
89 ui::ResourceBundle::SmallFont));
90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
91 if (form.federation_origin.unique()) 91 if (form.federation_origin.unique())
92 label->SetObscured(true); 92 label->SetObscured(true);
93 return label; 93 return label;
94 } 94 }
95 95
96 std::unique_ptr<views::ImageButton> GenerateDeleteButton( 96 std::unique_ptr<views::ImageButton> GenerateDeleteButton(
97 views::ButtonListener* listener) { 97 views::ButtonListener* listener) {
98 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 98 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
99 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener)); 99 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener));
100 button->SetImage(views::ImageButton::STATE_NORMAL, 100 button->SetImage(views::ImageButton::STATE_NORMAL,
101 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia()); 101 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia());
102 button->SetImage(views::ImageButton::STATE_HOVERED, 102 button->SetImage(views::ImageButton::STATE_HOVERED,
103 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 103 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
104 button->SetImage(views::ImageButton::STATE_PRESSED, 104 button->SetImage(views::ImageButton::STATE_PRESSED,
105 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 105 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
106 button->SetFocusForPlatform(); 106 button->SetFocusForPlatform();
107 button->SetTooltipText( 107 button->SetTooltipText(
108 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETE)); 108 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETE));
109 return button; 109 return button;
110 } 110 }
111 111
112 std::unique_ptr<views::Label> GenerateDeletedPasswordLabel() { 112 std::unique_ptr<views::Label> GenerateDeletedPasswordLabel() {
113 std::unique_ptr<views::Label> text(new views::Label( 113 auto text = base::MakeUnique<views::Label>(
114 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED))); 114 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED),
115 CONTEXT_DEPRECATED_SMALL);
115 text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 116 text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
116 text->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
117 ui::ResourceBundle::SmallFont));
118 return text; 117 return text;
119 } 118 }
120 119
121 std::unique_ptr<views::Link> GenerateUndoLink(views::LinkListener* listener) { 120 std::unique_ptr<views::Link> GenerateUndoLink(views::LinkListener* listener) {
122 std::unique_ptr<views::Link> undo_link( 121 std::unique_ptr<views::Link> undo_link(
123 new views::Link(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO))); 122 new views::Link(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)));
124 undo_link->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 123 undo_link->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
125 undo_link->set_listener(listener); 124 undo_link->set_listener(listener);
126 undo_link->SetUnderline(false); 125 undo_link->SetUnderline(false);
127 undo_link->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 126 undo_link->SetFontList(views::style::GetFont(CONTEXT_DEPRECATED_SMALL,
128 ui::ResourceBundle::SmallFont)); 127 views::style::STYLE_LINK));
129 return undo_link; 128 return undo_link;
130 } 129 }
131 130
132 } // namespace 131 } // namespace
133 132
134 // Manage credentials: stores credentials state and adds proper row to layout 133 // Manage credentials: stores credentials state and adds proper row to layout
135 // based on credential state. 134 // based on credential state.
136 class ManagePasswordItemsView::PasswordFormRow : public views::ButtonListener, 135 class ManagePasswordItemsView::PasswordFormRow : public views::ButtonListener,
137 public views::LinkListener { 136 public views::LinkListener {
138 public: 137 public:
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 const autofill::PasswordForm* password_form) 281 const autofill::PasswordForm* password_form)
283 : model_(manage_passwords_bubble_model) { 282 : model_(manage_passwords_bubble_model) {
284 password_forms_rows_.push_back( 283 password_forms_rows_.push_back(
285 base::MakeUnique<PasswordFormRow>(this, password_form, 0)); 284 base::MakeUnique<PasswordFormRow>(this, password_form, 0));
286 AddRows(); 285 AddRows();
287 } 286 }
288 287
289 ManagePasswordItemsView::~ManagePasswordItemsView() = default; 288 ManagePasswordItemsView::~ManagePasswordItemsView() = default;
290 289
291 void ManagePasswordItemsView::AddRows() { 290 void ManagePasswordItemsView::AddRows() {
291 const int vertical_padding = ChromeLayoutProvider::Get()->GetDistanceMetric(
292 views::DISTANCE_RELATED_CONTROL_VERTICAL);
292 views::GridLayout* layout = new views::GridLayout(this); 293 views::GridLayout* layout = new views::GridLayout(this);
293 SetLayoutManager(layout); 294 SetLayoutManager(layout);
294 for (const std::unique_ptr<PasswordFormRow>& row : password_forms_rows_) { 295 for (const std::unique_ptr<PasswordFormRow>& row : password_forms_rows_) {
295 if (row != password_forms_rows_[0]) 296 if (row != password_forms_rows_[0])
296 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 297 layout->AddPaddingRow(0, vertical_padding);
297 row->AddRow(layout); 298 row->AddRow(layout);
298 } 299 }
299 GetLayoutManager()->Layout(this); 300 GetLayoutManager()->Layout(this);
300 } 301 }
301 302
302 void ManagePasswordItemsView::NotifyPasswordFormStatusChanged( 303 void ManagePasswordItemsView::NotifyPasswordFormStatusChanged(
303 const autofill::PasswordForm& password_form, bool deleted) { 304 const autofill::PasswordForm& password_form, bool deleted) {
304 Refresh(); 305 Refresh();
305 // After the view is consistent, notify the model that the password needs to 306 // After the view is consistent, notify the model that the password needs to
306 // be updated (either removed or put back into the store, as appropriate. 307 // be updated (either removed or put back into the store, as appropriate.
307 model_->OnPasswordAction(password_form, 308 model_->OnPasswordAction(password_form,
308 deleted 309 deleted
309 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD 310 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD
310 : ManagePasswordsBubbleModel::ADD_PASSWORD); 311 : ManagePasswordsBubbleModel::ADD_PASSWORD);
311 } 312 }
312 313
313 void ManagePasswordItemsView::Refresh() { 314 void ManagePasswordItemsView::Refresh() {
314 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); 315 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state());
315 RemoveAllChildViews(true); 316 RemoveAllChildViews(true);
316 AddRows(); 317 AddRows();
317 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698