| 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 "grit/generated_resources.h" | 7 #include "grit/generated_resources.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_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" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 BuildColumnSet(layout, column_set_to_build); | 35 BuildColumnSet(layout, column_set_to_build); |
| 36 layout->StartRowWithPadding( | 36 layout->StartRowWithPadding( |
| 37 0, column_set_to_build, 0, views::kRelatedControlVerticalSpacing); | 37 0, column_set_to_build, 0, views::kRelatedControlVerticalSpacing); |
| 38 | 38 |
| 39 // Add the username field: fills the first non-padding column of the layout. | 39 // Add the username field: fills the first non-padding column of the layout. |
| 40 label_1_ = new views::Label(password_form_.username_value); | 40 label_1_ = new views::Label(password_form_.username_value); |
| 41 label_1_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 41 label_1_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 42 layout->AddView(label_1_); | 42 layout->AddView(label_1_); |
| 43 | 43 |
| 44 // Add the password field: fills the second non-padding column of the layout. | 44 // Add the password field: fills the second non-padding column of the layout. |
| 45 label_2_ = | 45 label_2_ = new views::Link(GetPasswordDisplayString()); |
| 46 new views::Link(GetPasswordDisplayString(password_form_.password_value)); | |
| 47 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 46 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 48 label_2_->set_listener(this); | 47 label_2_->set_listener(this); |
| 49 label_2_->SetFocusable(false); | 48 label_2_->SetFocusable(false); |
| 50 label_2_->SetEnabled(false); | 49 label_2_->SetEnabled(false); |
| 51 label_2_->SetUnderline(false); | 50 label_2_->SetUnderline(false); |
| 52 layout->AddView(label_2_); | 51 layout->AddView(label_2_); |
| 53 | 52 |
| 54 // If we're saving a password, construct and add the delete button: fills the | 53 // If we're saving a password, construct and add the delete button: fills the |
| 55 // third non-padding column of the layout. | 54 // third non-padding column of the layout. |
| 56 if (manage_passwords_bubble_model_->WaitingToSavePassword()) { | 55 if (manage_passwords_bubble_model_->WaitingToSavePassword()) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 views::GridLayout::FILL, | 95 views::GridLayout::FILL, |
| 97 0, | 96 0, |
| 98 views::GridLayout::USE_PREF, | 97 views::GridLayout::USE_PREF, |
| 99 0, | 98 0, |
| 100 0); | 99 0); |
| 101 } | 100 } |
| 102 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 101 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 103 } | 102 } |
| 104 | 103 |
| 105 // static | 104 // static |
| 106 base::string16 ManagePasswordItemView::GetPasswordDisplayString( | 105 base::string16 ManagePasswordItemView::GetPasswordDisplayString() { |
| 107 const base::string16& password) { | |
| 108 const wchar_t kPasswordBullet = 0x2022; | 106 const wchar_t kPasswordBullet = 0x2022; |
| 109 const size_t kMaxPasswordChar = 22; | 107 return base::string16(15, kPasswordBullet); |
| 110 return base::string16(std::min(password.length(), kMaxPasswordChar), | |
| 111 kPasswordBullet); | |
| 112 } | 108 } |
| 113 | 109 |
| 114 ManagePasswordItemView::~ManagePasswordItemView() { | 110 ManagePasswordItemView::~ManagePasswordItemView() { |
| 115 if (delete_password_) | 111 if (delete_password_) |
| 116 manage_passwords_bubble_model_->DeleteFromBestMatches(password_form_); | 112 manage_passwords_bubble_model_->DeleteFromBestMatches(password_form_); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void ManagePasswordItemView::Refresh() { | 115 void ManagePasswordItemView::Refresh() { |
| 120 // TODO(mkwst): We're currently swaping out values in the same view. We need | 116 // TODO(mkwst): We're currently swaping out values in the same view. We need |
| 121 // to swap out views in order to enable some future work (and to make the undo | 117 // to swap out views in order to enable some future work (and to make the undo |
| (...skipping 13 matching lines...) Expand all Loading... |
| 135 if (delete_button_) | 131 if (delete_button_) |
| 136 delete_button_->SetVisible(false); | 132 delete_button_->SetVisible(false); |
| 137 } else { | 133 } else { |
| 138 // The user clicked the "undo" button after deleting a password, so: | 134 // The user clicked the "undo" button after deleting a password, so: |
| 139 // | 135 // |
| 140 // Change the username string back to the username. | 136 // Change the username string back to the username. |
| 141 label_1_->SetText(password_form_.username_value); | 137 label_1_->SetText(password_form_.username_value); |
| 142 | 138 |
| 143 // Set the password string to the appropriate number of bullets, and | 139 // Set the password string to the appropriate number of bullets, and |
| 144 // disable the link. | 140 // disable the link. |
| 145 label_2_->SetText(GetPasswordDisplayString(password_form_.password_value)); | 141 label_2_->SetText(GetPasswordDisplayString()); |
| 146 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 142 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 147 label_2_->SetEnabled(false); | 143 label_2_->SetEnabled(false); |
| 148 | 144 |
| 149 if (delete_button_) | 145 if (delete_button_) |
| 150 delete_button_->SetVisible(true); | 146 delete_button_->SetVisible(true); |
| 151 } | 147 } |
| 152 | 148 |
| 153 // After the view is consistent, notify the model that the password needs to | 149 // After the view is consistent, notify the model that the password needs to |
| 154 // be updated (either removed or put back into the store, as appropriate. | 150 // be updated (either removed or put back into the store, as appropriate. |
| 155 manage_passwords_bubble_model_->OnPasswordAction( | 151 manage_passwords_bubble_model_->OnPasswordAction( |
| 156 password_form_, | 152 password_form_, |
| 157 delete_password_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD | 153 delete_password_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD |
| 158 : ManagePasswordsBubbleModel::ADD_PASSWORD); | 154 : ManagePasswordsBubbleModel::ADD_PASSWORD); |
| 159 } | 155 } |
| 160 | 156 |
| 161 void ManagePasswordItemView::ButtonPressed(views::Button* sender, | 157 void ManagePasswordItemView::ButtonPressed(views::Button* sender, |
| 162 const ui::Event& event) { | 158 const ui::Event& event) { |
| 163 DCHECK_EQ(delete_button_, sender); | 159 DCHECK_EQ(delete_button_, sender); |
| 164 delete_password_ = true; | 160 delete_password_ = true; |
| 165 Refresh(); | 161 Refresh(); |
| 166 } | 162 } |
| 167 | 163 |
| 168 void ManagePasswordItemView::LinkClicked(views::Link* source, | 164 void ManagePasswordItemView::LinkClicked(views::Link* source, |
| 169 int event_flags) { | 165 int event_flags) { |
| 170 DCHECK_EQ(source, label_2_); | 166 DCHECK_EQ(source, label_2_); |
| 171 delete_password_ = false; | 167 delete_password_ = false; |
| 172 Refresh(); | 168 Refresh(); |
| 173 } | 169 } |
| OLD | NEW |