Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/grit/generated_resources.h" | 8 #include "chrome/grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/resources/grit/ui_resources.h" | 11 #include "ui/resources/grit/ui_resources.h" |
| 12 #include "ui/views/border.h" | 12 #include "ui/views/border.h" |
| 13 #include "ui/views/controls/button/button.h" | 13 #include "ui/views/controls/button/button.h" |
| 14 #include "ui/views/controls/button/image_button.h" | 14 #include "ui/views/controls/button/image_button.h" |
| 15 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
| 16 #include "ui/views/controls/link.h" | 16 #include "ui/views/controls/link.h" |
| 17 #include "ui/views/controls/link_listener.h" | 17 #include "ui/views/controls/link_listener.h" |
| 18 #include "ui/views/layout/fill_layout.h" | 18 #include "ui/views/layout/fill_layout.h" |
| 19 #include "ui/views/layout/grid_layout.h" | 19 #include "ui/views/layout/grid_layout.h" |
| 20 #include "ui/views/layout/layout_constants.h" | 20 #include "ui/views/layout/layout_constants.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 int FirstFieldWidth() { | 24 enum ColumnSets { |
| 25 return std::max( | 25 TWO_COLUMN_SET, |
| 26 ManagePasswordsBubbleModel::UsernameFieldWidth(), | 26 THREE_COLUMN_SET |
| 27 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) | 27 }; |
| 28 .GetPreferredSize() | |
| 29 .width()); | |
| 30 } | |
| 31 | |
| 32 int SecondFieldWidth() { | |
| 33 return std::max( | |
| 34 ManagePasswordsBubbleModel::PasswordFieldWidth(), | |
| 35 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) | |
| 36 .GetPreferredSize() | |
| 37 .width()); | |
| 38 } | |
| 39 | |
| 40 enum ColumnSets { TWO_COLUMN_SET = 0, THREE_COLUMN_SET }; | |
| 41 | 28 |
| 42 void BuildColumnSet(views::GridLayout* layout, int column_set_id) { | 29 void BuildColumnSet(views::GridLayout* layout, int column_set_id) { |
| 43 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 30 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
| 44 | 31 |
| 45 // The username/"Deleted!" field. | 32 // The username/"Deleted!" field. |
| 46 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 33 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 47 column_set->AddColumn(views::GridLayout::FILL, | 34 column_set->AddColumn(views::GridLayout::FILL, |
| 48 views::GridLayout::FILL, | 35 views::GridLayout::FILL, |
| 36 2, | |
| 37 views::GridLayout::USE_PREF, | |
| 49 0, | 38 0, |
| 50 views::GridLayout::FIXED, | 39 0); |
| 51 FirstFieldWidth(), | |
| 52 FirstFieldWidth()); | |
|
Mike West
2014/09/16 15:20:42
Hrm. How does this end up looking? I'm worried abo
| |
| 53 | 40 |
| 54 // The password/"Undo!" field. | 41 // The password/"Undo!" field. |
| 55 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 42 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 56 column_set->AddColumn(views::GridLayout::FILL, | 43 column_set->AddColumn(views::GridLayout::FILL, |
| 57 views::GridLayout::FILL, | 44 views::GridLayout::FILL, |
| 58 1, | 45 1, |
| 59 views::GridLayout::USE_PREF, | 46 views::GridLayout::USE_PREF, |
| 60 SecondFieldWidth(), | 47 0, |
| 61 SecondFieldWidth()); | 48 0); |
| 62 | 49 |
| 63 // If we're in manage-mode, we need another column for the delete button. | 50 // If we're in manage-mode, we need another column for the delete button. |
| 64 if (column_set_id == THREE_COLUMN_SET) { | 51 if (column_set_id == THREE_COLUMN_SET) { |
| 65 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 52 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 66 column_set->AddColumn(views::GridLayout::TRAILING, | 53 column_set->AddColumn(views::GridLayout::TRAILING, |
| 67 views::GridLayout::FILL, | 54 views::GridLayout::FILL, |
| 68 0, | 55 0, |
| 69 views::GridLayout::USE_PREF, | 56 views::GridLayout::USE_PREF, |
| 70 0, | 57 0, |
| 71 0); | 58 0); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 | 202 |
| 216 void ManagePasswordItemView::UndoView::LinkClicked(views::Link* sender, | 203 void ManagePasswordItemView::UndoView::LinkClicked(views::Link* sender, |
| 217 int event_flags) { | 204 int event_flags) { |
| 218 DCHECK_EQ(undo_link_, sender); | 205 DCHECK_EQ(undo_link_, sender); |
| 219 parent_->NotifyClickedUndo(); | 206 parent_->NotifyClickedUndo(); |
| 220 } | 207 } |
| 221 | 208 |
| 222 // ManagePasswordItemView | 209 // ManagePasswordItemView |
| 223 ManagePasswordItemView::ManagePasswordItemView( | 210 ManagePasswordItemView::ManagePasswordItemView( |
| 224 ManagePasswordsBubbleModel* manage_passwords_bubble_model, | 211 ManagePasswordsBubbleModel* manage_passwords_bubble_model, |
| 225 autofill::PasswordForm password_form, | 212 const autofill::PasswordForm& password_form, |
| 226 password_manager::ui::PasswordItemPosition position) | 213 password_manager::ui::PasswordItemPosition position) |
| 227 : model_(manage_passwords_bubble_model), | 214 : model_(manage_passwords_bubble_model), |
| 228 password_form_(password_form), | 215 password_form_(password_form), |
| 229 delete_password_(false) { | 216 delete_password_(false) { |
| 230 views::FillLayout* layout = new views::FillLayout(); | 217 views::FillLayout* layout = new views::FillLayout(); |
| 231 SetLayoutManager(layout); | 218 SetLayoutManager(layout); |
| 232 | 219 |
| 233 // When a password is displayed as the first item in a list, it has borders | 220 // When a password is displayed as the first item in a list, it has borders |
| 234 // on both the top and bottom. When it's in the middle of a list, or at the | 221 // on both the top and bottom. When it's in the middle of a list, or at the |
| 235 // end, it has a border only on the bottom. | 222 // end, it has a border only on the bottom. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 AddChildView(new ManageView(this)); | 259 AddChildView(new ManageView(this)); |
| 273 GetLayoutManager()->Layout(this); | 260 GetLayoutManager()->Layout(this); |
| 274 | 261 |
| 275 // After the view is consistent, notify the model that the password needs to | 262 // After the view is consistent, notify the model that the password needs to |
| 276 // be updated (either removed or put back into the store, as appropriate. | 263 // be updated (either removed or put back into the store, as appropriate. |
| 277 model_->OnPasswordAction(password_form_, | 264 model_->OnPasswordAction(password_form_, |
| 278 delete_password_ | 265 delete_password_ |
| 279 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD | 266 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD |
| 280 : ManagePasswordsBubbleModel::ADD_PASSWORD); | 267 : ManagePasswordsBubbleModel::ADD_PASSWORD); |
| 281 } | 268 } |
| OLD | NEW |