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

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

Issue 266973002: Password bubble: Create subviews for ManagePasswordsBubbleView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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_item_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
6 6
7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 7 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
8 #include "grit/generated_resources.h" 8 #include "grit/generated_resources.h"
9 #include "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/views/controls/button/button.h" 12 #include "ui/views/controls/button/button.h"
13 #include "ui/views/controls/button/image_button.h" 13 #include "ui/views/controls/button/image_button.h"
14 #include "ui/views/layout/fill_layout.h" 14 #include "ui/views/layout/fill_layout.h"
15 #include "ui/views/layout/grid_layout.h" 15 #include "ui/views/layout/grid_layout.h"
16 #include "ui/views/layout/layout_constants.h" 16 #include "ui/views/layout/layout_constants.h"
17 17
18 namespace {
19
20 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD };
21
22 // Upper limit on the size of the username and password fields.
23 const int kUsernameFieldSize = 30;
24 const int kPasswordFieldSize = 22;
25
26 // Returns the width of |type| field.
27 int GetFieldWidth(FieldType type) {
28 return ui::ResourceBundle::GetSharedInstance()
29 .GetFontList(ui::ResourceBundle::SmallFont)
30 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize
31 : kPasswordFieldSize);
32 }
33
34 int FirstFieldWidth() {
35 return std::max(
36 GetFieldWidth(USERNAME_FIELD),
37 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED))
38 .GetPreferredSize()
39 .width());
40 }
41
42 int SecondFieldWidth() {
43 return std::max(
44 GetFieldWidth(PASSWORD_FIELD),
45 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO))
46 .GetPreferredSize()
47 .width());
48 }
49
50 } // namespace
51
18 // Pending View 52 // Pending View
19 ManagePasswordItemView::PendingView::PendingView( 53 ManagePasswordItemView::PendingView::PendingView(
20 ManagePasswordItemView* parent) { 54 ManagePasswordItemView* parent) {
21 views::GridLayout* layout = new views::GridLayout(this); 55 views::GridLayout* layout = new views::GridLayout(this);
22 SetLayoutManager(layout); 56 SetLayoutManager(layout);
23 57
24 parent->BuildColumnSet(layout, TWO_COLUMN_SET); 58 parent->BuildColumnSet(layout, TWO_COLUMN_SET);
25 layout->StartRowWithPadding( 59 layout->StartRowWithPadding(
26 0, TWO_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); 60 0, TWO_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
27 layout->AddView(parent->GenerateUsernameLabel()); 61 layout->AddView(parent->GenerateUsernameLabel());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 DCHECK_EQ(undo_link_, sender); 126 DCHECK_EQ(undo_link_, sender);
93 parent_->NotifyClickedUndo(); 127 parent_->NotifyClickedUndo();
94 } 128 }
95 129
96 ManagePasswordItemView::UndoView::~UndoView() {} 130 ManagePasswordItemView::UndoView::~UndoView() {}
97 131
98 // ManagePasswordItemView 132 // ManagePasswordItemView
99 ManagePasswordItemView::ManagePasswordItemView( 133 ManagePasswordItemView::ManagePasswordItemView(
100 ManagePasswordsBubbleModel* manage_passwords_bubble_model, 134 ManagePasswordsBubbleModel* manage_passwords_bubble_model,
101 autofill::PasswordForm password_form, 135 autofill::PasswordForm password_form,
102 int field_1_width,
103 int field_2_width,
104 Position position) 136 Position position)
105 : manage_passwords_bubble_model_(manage_passwords_bubble_model), 137 : manage_passwords_bubble_model_(manage_passwords_bubble_model),
106 password_form_(password_form), 138 password_form_(password_form),
107 delete_password_(false), 139 delete_password_(false) {
108 field_1_width_(field_1_width),
109 field_2_width_(field_2_width) {
110 views::FillLayout* layout = new views::FillLayout(); 140 views::FillLayout* layout = new views::FillLayout();
111 SetLayoutManager(layout); 141 SetLayoutManager(layout);
112 142
113 // When a password is displayed as the first item in a list, it has borders 143 // When a password is displayed as the first item in a list, it has borders
114 // on both the top and bottom. When it's in the middle of a list, or at the 144 // on both the top and bottom. When it's in the middle of a list, or at the
115 // end, it has a border only on the bottom. 145 // end, it has a border only on the bottom.
116 SetBorder(views::Border::CreateSolidSidedBorder( 146 SetBorder(views::Border::CreateSolidSidedBorder(
117 position == FIRST_ITEM ? 1 : 0, 147 position == FIRST_ITEM ? 1 : 0,
118 0, 148 0,
119 1, 149 1,
(...skipping 13 matching lines...) Expand all
133 void ManagePasswordItemView::BuildColumnSet(views::GridLayout* layout, 163 void ManagePasswordItemView::BuildColumnSet(views::GridLayout* layout,
134 int column_set_id) { 164 int column_set_id) {
135 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 165 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
136 166
137 // The username/"Deleted!" field. 167 // The username/"Deleted!" field.
138 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 168 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
139 column_set->AddColumn(views::GridLayout::FILL, 169 column_set->AddColumn(views::GridLayout::FILL,
140 views::GridLayout::FILL, 170 views::GridLayout::FILL,
141 0, 171 0,
142 views::GridLayout::FIXED, 172 views::GridLayout::FIXED,
143 field_1_width_, 173 FirstFieldWidth(),
144 field_1_width_); 174 FirstFieldWidth());
145 175
146 // The password/"Undo!" field. 176 // The password/"Undo!" field.
147 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 177 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
148 column_set->AddColumn(views::GridLayout::FILL, 178 column_set->AddColumn(views::GridLayout::FILL,
149 views::GridLayout::FILL, 179 views::GridLayout::FILL,
150 1, 180 1,
151 views::GridLayout::USE_PREF, 181 views::GridLayout::USE_PREF,
152 field_2_width_, 182 SecondFieldWidth(),
153 field_2_width_); 183 SecondFieldWidth());
154 184
155 // If we're in manage-mode, we need another column for the delete button. 185 // If we're in manage-mode, we need another column for the delete button.
156 if (column_set_id == THREE_COLUMN_SET) { 186 if (column_set_id == THREE_COLUMN_SET) {
157 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); 187 column_set->AddPaddingColumn(0, views::kItemLabelSpacing);
158 column_set->AddColumn(views::GridLayout::TRAILING, 188 column_set->AddColumn(views::GridLayout::TRAILING,
159 views::GridLayout::FILL, 189 views::GridLayout::FILL,
160 0, 190 0,
161 views::GridLayout::USE_PREF, 191 views::GridLayout::USE_PREF,
162 0, 192 0,
163 0); 193 0);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 232
203 void ManagePasswordItemView::NotifyClickedDelete() { 233 void ManagePasswordItemView::NotifyClickedDelete() {
204 delete_password_ = true; 234 delete_password_ = true;
205 Refresh(); 235 Refresh();
206 } 236 }
207 237
208 void ManagePasswordItemView::NotifyClickedUndo() { 238 void ManagePasswordItemView::NotifyClickedUndo() {
209 delete_password_ = false; 239 delete_password_ = false;
210 Refresh(); 240 Refresh();
211 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698