| 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_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/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/resources/grit/ui_resources.h" | 17 #include "ui/resources/grit/ui_resources.h" |
| 18 #include "ui/views/controls/button/button.h" | |
| 19 #include "ui/views/controls/button/image_button.h" | 18 #include "ui/views/controls/button/image_button.h" |
| 20 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/controls/link.h" | 20 #include "ui/views/controls/link.h" |
| 22 #include "ui/views/controls/link_listener.h" | 21 #include "ui/views/controls/link_listener.h" |
| 23 #include "ui/views/layout/fill_layout.h" | 22 #include "ui/views/layout/fill_layout.h" |
| 24 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
| 25 #include "ui/views/layout/layout_constants.h" | 24 #include "ui/views/layout/layout_constants.h" |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 std::unique_ptr<views::Label> label(new views::Label(text)); | 86 std::unique_ptr<views::Label> label(new views::Label(text)); |
| 88 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 87 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 89 ui::ResourceBundle::SmallFont)); | 88 ui::ResourceBundle::SmallFont)); |
| 90 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 89 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 91 if (form.federation_origin.unique()) | 90 if (form.federation_origin.unique()) |
| 92 label->SetObscured(true); | 91 label->SetObscured(true); |
| 93 return label; | 92 return label; |
| 94 } | 93 } |
| 95 | 94 |
| 96 std::unique_ptr<views::ImageButton> GenerateDeleteButton( | 95 std::unique_ptr<views::ImageButton> GenerateDeleteButton( |
| 97 views::ButtonListener* listener) { | 96 views::ImageButtonDelegate* listener) { |
| 98 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 97 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 99 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener)); | 98 std::unique_ptr<views::ImageButton> button(new views::ImageButton(listener)); |
| 100 button->SetImage(views::ImageButton::STATE_NORMAL, | 99 button->SetImage(views::ImageButton::STATE_NORMAL, |
| 101 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia()); | 100 rb->GetImageNamed(IDR_CLOSE_2).ToImageSkia()); |
| 102 button->SetImage(views::ImageButton::STATE_HOVERED, | 101 button->SetImage(views::ImageButton::STATE_HOVERED, |
| 103 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); | 102 rb->GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); |
| 104 button->SetImage(views::ImageButton::STATE_PRESSED, | 103 button->SetImage(views::ImageButton::STATE_PRESSED, |
| 105 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); | 104 rb->GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); |
| 106 button->SetFocusForPlatform(); | 105 button->SetFocusForPlatform(); |
| 107 button->SetTooltipText( | 106 button->SetTooltipText( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 126 undo_link->SetUnderline(false); | 125 undo_link->SetUnderline(false); |
| 127 undo_link->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 126 undo_link->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 128 ui::ResourceBundle::SmallFont)); | 127 ui::ResourceBundle::SmallFont)); |
| 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 |
| 137 public views::LinkListener { | 136 : public views::ImageButtonDelegate, |
| 137 public views::LinkListener { |
| 138 public: | 138 public: |
| 139 PasswordFormRow(ManagePasswordItemsView* host, | 139 PasswordFormRow(ManagePasswordItemsView* host, |
| 140 const autofill::PasswordForm* password_form, | 140 const autofill::PasswordForm* password_form, |
| 141 int fixed_height); | 141 int fixed_height); |
| 142 ~PasswordFormRow() override = default; | 142 ~PasswordFormRow() override = default; |
| 143 | 143 |
| 144 void AddRow(views::GridLayout* layout); | 144 void AddRow(views::GridLayout* layout); |
| 145 | 145 |
| 146 // Returns the fixed height for a row excluding padding. 0 means no fixed | 146 // Returns the fixed height for a row excluding padding. 0 means no fixed |
| 147 // height required. | 147 // height required. |
| 148 // In MANAGE_STATE a row may represent a credential or a deleted credential. | 148 // In MANAGE_STATE a row may represent a credential or a deleted credential. |
| 149 // To avoid repositioning all the rows should have a fixed height. | 149 // To avoid repositioning all the rows should have a fixed height. |
| 150 static int GetFixedHeight(password_manager::ui::State state); | 150 static int GetFixedHeight(password_manager::ui::State state); |
| 151 | 151 |
| 152 private: | 152 private: |
| 153 void AddCredentialsRow(views::GridLayout* layout); | 153 void AddCredentialsRow(views::GridLayout* layout); |
| 154 void AddUndoRow(views::GridLayout* layout); | 154 void AddUndoRow(views::GridLayout* layout); |
| 155 | 155 |
| 156 // views::ButtonListener: | 156 // views::ImageButtonDelegate: |
| 157 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 157 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 158 // views::LinkListener: | 158 // views::LinkListener: |
| 159 void LinkClicked(views::Link* source, int event_flags) override; | 159 void LinkClicked(views::Link* source, int event_flags) override; |
| 160 | 160 |
| 161 void ResetControls(); | 161 void ResetControls(); |
| 162 | 162 |
| 163 ManagePasswordItemsView* host_; | 163 ManagePasswordItemsView* host_; |
| 164 const autofill::PasswordForm* password_form_; | 164 const autofill::PasswordForm* password_form_; |
| 165 // The UI elements pointers are weak and owned by their parent. | 165 // The UI elements pointers are weak and owned by their parent. |
| 166 views::Link* undo_link_; | 166 views::Link* undo_link_; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 deleted | 308 deleted |
| 309 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD | 309 ? ManagePasswordsBubbleModel::REMOVE_PASSWORD |
| 310 : ManagePasswordsBubbleModel::ADD_PASSWORD); | 310 : ManagePasswordsBubbleModel::ADD_PASSWORD); |
| 311 } | 311 } |
| 312 | 312 |
| 313 void ManagePasswordItemsView::Refresh() { | 313 void ManagePasswordItemsView::Refresh() { |
| 314 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); | 314 DCHECK_NE(password_manager::ui::PENDING_PASSWORD_STATE, model_->state()); |
| 315 RemoveAllChildViews(true); | 315 RemoveAllChildViews(true); |
| 316 AddRows(); | 316 AddRows(); |
| 317 } | 317 } |
| OLD | NEW |