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

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: 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"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/resources/grit/ui_resources.h" 18 #include "ui/resources/grit/ui_resources.h"
18 #include "ui/views/controls/button/button.h" 19 #include "ui/views/controls/button/button.h"
19 #include "ui/views/controls/button/image_button.h" 20 #include "ui/views/controls/button/image_button.h"
20 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/link.h" 22 #include "ui/views/controls/link.h"
22 #include "ui/views/controls/link_listener.h" 23 #include "ui/views/controls/link_listener.h"
23 #include "ui/views/layout/fill_layout.h" 24 #include "ui/views/layout/fill_layout.h"
24 #include "ui/views/layout/grid_layout.h" 25 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_constants.h"
26 26
27 namespace { 27 namespace {
28 28
29 enum ColumnSets { 29 enum ColumnSets {
30 ONE_COLUMN_SET, 30 ONE_COLUMN_SET,
31 TWO_COLUMN_SET, 31 TWO_COLUMN_SET,
32 THREE_COLUMN_SET 32 THREE_COLUMN_SET
33 }; 33 };
34 34
35 void BuildColumnSetIfNeeded(views::GridLayout* layout, int column_set_id) { 35 void BuildColumnSetIfNeeded(views::GridLayout* layout, int column_set_id) {
36 if (layout->GetColumnSet(column_set_id)) 36 if (layout->GetColumnSet(column_set_id))
37 return; 37 return;
38 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 38 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
39 39
40 // The username/"Deleted!"/Border field. 40 // The username/"Deleted!"/Border field.
41 column_set->AddColumn(views::GridLayout::FILL, 41 column_set->AddColumn(views::GridLayout::FILL,
42 views::GridLayout::FILL, 42 views::GridLayout::FILL,
43 1, 43 1,
44 views::GridLayout::USE_PREF, 44 views::GridLayout::USE_PREF,
45 0, 45 0,
46 0); 46 0);
47
48 const int column_divider = ChromeLayoutProvider::Get()->GetDistanceMetric(
49 views::DISTANCE_RELATED_CONTROL_HORIZONTAL);
47 if (column_set_id >= TWO_COLUMN_SET) { 50 if (column_set_id >= TWO_COLUMN_SET) {
48 // The password/"Undo!" field. 51 // The password/"Undo!" field.
49 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 52 column_set->AddPaddingColumn(0, column_divider);
50 column_set->AddColumn(views::GridLayout::FILL, 53 column_set->AddColumn(views::GridLayout::FILL,
51 views::GridLayout::FILL, 54 views::GridLayout::FILL,
52 1, 55 1,
53 views::GridLayout::USE_PREF, 56 views::GridLayout::USE_PREF,
54 0, 57 0,
55 0); 58 0);
56 } 59 }
57 // If we're in manage-mode, we need another column for the delete button. 60 // If we're in manage-mode, we need another column for the delete button.
58 if (column_set_id == THREE_COLUMN_SET) { 61 if (column_set_id == THREE_COLUMN_SET) {
59 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 62 column_set->AddPaddingColumn(0, column_divider);
60 column_set->AddColumn(views::GridLayout::TRAILING, 63 column_set->AddColumn(views::GridLayout::TRAILING,
61 views::GridLayout::FILL, 64 views::GridLayout::FILL,
62 0, 65 0,
63 views::GridLayout::USE_PREF, 66 views::GridLayout::USE_PREF,
64 0, 67 0,
65 0); 68 0);
66 } 69 }
67 } 70 }
68 71
69 std::unique_ptr<views::Label> GenerateUsernameLabel( 72 std::unique_ptr<views::Label> GenerateUsernameLabel(
70 const autofill::PasswordForm& form) { 73 const autofill::PasswordForm& form) {
71 std::unique_ptr<views::Label> label( 74 std::unique_ptr<views::Label> label(
72 new views::Label(GetDisplayUsername(form))); 75 new views::Label(GetDisplayUsername(form)));
tapted 2017/05/10 05:30:11 CONTEXT_DEPRECATED_SMALL
Patti Lor 2017/05/11 06:59:18 Done.
73 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 76 label->SetFontList(views::style::GetFont(views::style::CONTEXT_LABEL,
74 ui::ResourceBundle::SmallFont)); 77 views::style::STYLE_PRIMARY));
75 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 78 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
76 return label; 79 return label;
77 } 80 }
78 81
79 std::unique_ptr<views::Label> GeneratePasswordLabel( 82 std::unique_ptr<views::Label> GeneratePasswordLabel(
80 const autofill::PasswordForm& form) { 83 const autofill::PasswordForm& form) {
81 base::string16 text = 84 base::string16 text =
82 form.federation_origin.unique() 85 form.federation_origin.unique()
83 ? form.password_value 86 ? form.password_value
84 : l10n_util::GetStringFUTF16( 87 : l10n_util::GetStringFUTF16(
85 IDS_PASSWORDS_VIA_FEDERATION, 88 IDS_PASSWORDS_VIA_FEDERATION,
86 base::UTF8ToUTF16(form.federation_origin.host())); 89 base::UTF8ToUTF16(form.federation_origin.host()));
87 std::unique_ptr<views::Label> label(new views::Label(text)); 90 std::unique_ptr<views::Label> label(new views::Label(text));
tapted 2017/05/10 05:30:11 CONTEXT_DEPRECATED_SMALL
Patti Lor 2017/05/11 06:59:18 Done.
88 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 91 label->SetFontList(views::style::GetFont(views::style::CONTEXT_LABEL,
89 ui::ResourceBundle::SmallFont)); 92 views::style::STYLE_PRIMARY));
90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 93 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
91 if (form.federation_origin.unique()) 94 if (form.federation_origin.unique())
92 label->SetObscured(true); 95 label->SetObscured(true);
93 return label; 96 return label;
94 } 97 }
95 98
96 std::unique_ptr<views::ImageButton> GenerateDeleteButton( 99 std::unique_ptr<views::ImageButton> GenerateDeleteButton(
97 views::ButtonListener* listener) { 100 views::ButtonListener* listener) {
98 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 101 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
99 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener)); 102 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener));
100 button->SetImage(views::ImageButton::STATE_NORMAL, 103 button->SetImage(views::ImageButton::STATE_NORMAL,
101 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia()); 104 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia());
102 button->SetImage(views::ImageButton::STATE_HOVERED, 105 button->SetImage(views::ImageButton::STATE_HOVERED,
103 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); 106 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia());
104 button->SetImage(views::ImageButton::STATE_PRESSED, 107 button->SetImage(views::ImageButton::STATE_PRESSED,
105 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); 108 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia());
106 button->SetFocusForPlatform(); 109 button->SetFocusForPlatform();
107 button->SetTooltipText( 110 button->SetTooltipText(
108 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETE)); 111 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETE));
109 return button; 112 return button;
110 } 113 }
111 114
112 std::unique_ptr<views::Label> GenerateDeletedPasswordLabel() { 115 std::unique_ptr<views::Label> GenerateDeletedPasswordLabel() {
113 std::unique_ptr<views::Label> text(new views::Label( 116 std::unique_ptr<views::Label> text(new views::Label(
tapted 2017/05/10 05:30:11 CONTEXT_DEPRECATED_SMALL
Patti Lor 2017/05/11 06:59:18 Done.
114 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED))); 117 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)));
115 text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 118 text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
116 text->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 119 text->SetFontList(views::style::GetFont(views::style::CONTEXT_LABEL,
117 ui::ResourceBundle::SmallFont)); 120 views::style::STYLE_PRIMARY));
118 return text; 121 return text;
119 } 122 }
120 123
121 std::unique_ptr<views::Link> GenerateUndoLink(views::LinkListener* listener) { 124 std::unique_ptr<views::Link> GenerateUndoLink(views::LinkListener* listener) {
122 std::unique_ptr<views::Link> undo_link( 125 std::unique_ptr<views::Link> undo_link(
123 new views::Link(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO))); 126 new views::Link(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)));
124 undo_link->SetHorizontalAlignment(gfx::ALIGN_RIGHT); 127 undo_link->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
125 undo_link->set_listener(listener); 128 undo_link->set_listener(listener);
126 undo_link->SetUnderline(false); 129 undo_link->SetUnderline(false);
127 undo_link->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 130 undo_link->SetFontList(views::style::GetFont(views::style::CONTEXT_LABEL,
tapted 2017/05/10 05:30:11 CONTEXT_DEPRECATED_SMALL
Patti Lor 2017/05/11 06:59:18 Done.
128 ui::ResourceBundle::SmallFont)); 131 views::style::STYLE_LINK));
129 return undo_link; 132 return undo_link;
130 } 133 }
131 134
132 } // namespace 135 } // namespace
133 136
134 // Manage credentials: stores credentials state and adds proper row to layout 137 // Manage credentials: stores credentials state and adds proper row to layout
135 // based on credential state. 138 // based on credential state.
136 class ManagePasswordItemsView::PasswordFormRow : public views::ButtonListener, 139 class ManagePasswordItemsView::PasswordFormRow : public views::ButtonListener,
137 public views::LinkListener { 140 public views::LinkListener {
138 public: 141 public:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 base::MakeUnique<PasswordFormRow>(this, password_form, 0)); 288 base::MakeUnique<PasswordFormRow>(this, password_form, 0));
286 AddRows(); 289 AddRows();
287 } 290 }
288 291
289 ManagePasswordItemsView::~ManagePasswordItemsView() = default; 292 ManagePasswordItemsView::~ManagePasswordItemsView() = default;
290 293
291 void ManagePasswordItemsView::AddRows() { 294 void ManagePasswordItemsView::AddRows() {
292 views::GridLayout* layout = new views::GridLayout(this); 295 views::GridLayout* layout = new views::GridLayout(this);
293 SetLayoutManager(layout); 296 SetLayoutManager(layout);
294 for (const std::unique_ptr<PasswordFormRow>& row : password_forms_rows_) { 297 for (const std::unique_ptr<PasswordFormRow>& row : password_forms_rows_) {
295 if (row != password_forms_rows_[0]) 298 if (row != password_forms_rows_[0]) {
296 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 299 layout->AddPaddingRow(0, ChromeLayoutProvider::Get()->GetDistanceMetric(
tapted 2017/05/10 05:30:11 ChromeLayoutProvider::Get() -> local var
Patti Lor 2017/05/11 06:59:18 Oops, thank you. I made DISTANCE_RELATED_CONTROL_V
300 views::DISTANCE_RELATED_CONTROL_VERTICAL));
301 }
297 row->AddRow(layout); 302 row->AddRow(layout);
298 } 303 }
299 GetLayoutManager()->Layout(this); 304 GetLayoutManager()->Layout(this);
300 } 305 }
301 306
302 void ManagePasswordItemsView::NotifyPasswordFormStatusChanged( 307 void ManagePasswordItemsView::NotifyPasswordFormStatusChanged(
303 const autofill::PasswordForm& password_form, bool deleted) { 308 const autofill::PasswordForm& password_form, bool deleted) {
304 Refresh(); 309 Refresh();
305 // After the view is consistent, notify the model that the password needs to 310 // 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. 311 // be updated (either removed or put back into the store, as appropriate.
307 model_->OnPasswordAction(password_form, 312 model_->OnPasswordAction(password_form,
308 deleted 313 deleted
309 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD 314 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD
310 : ManagePasswordsBubbleModel::ADD_PASSWORD); 315 : ManagePasswordsBubbleModel::ADD_PASSWORD);
311 } 316 }
312 317
313 void ManagePasswordItemsView::Refresh() { 318 void ManagePasswordItemsView::Refresh() {
314 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); 319 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state());
315 RemoveAllChildViews(true); 320 RemoveAllChildViews(true);
316 AddRows(); 321 AddRows();
317 } 322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698