| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 layout->StartRowWithPadding( | 48 layout->StartRowWithPadding( |
| 49 0, column_set_to_build, 0, views::kRelatedControlVerticalSpacing); | 49 0, column_set_to_build, 0, views::kRelatedControlVerticalSpacing); |
| 50 | 50 |
| 51 // Add the username field: fills the first non-padding column of the layout. | 51 // Add the username field: fills the first non-padding column of the layout. |
| 52 label_1_ = new views::Label(password_form_.username_value); | 52 label_1_ = new views::Label(password_form_.username_value); |
| 53 label_1_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 53 label_1_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 54 layout->AddView(label_1_); | 54 layout->AddView(label_1_); |
| 55 | 55 |
| 56 // Add the password field: fills the second non-padding column of the layout. | 56 // Add the password field: fills the second non-padding column of the layout. |
| 57 label_2_ = | 57 label_2_ = |
| 58 new views::Link(GetPasswordDisplayString(password_form_.password_value)); | 58 new views::Link(password_form_.password_value); |
| 59 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 59 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 60 label_2_->set_listener(this); | 60 label_2_->set_listener(this); |
| 61 label_2_->SetObscured(true); |
| 61 label_2_->SetFocusable(false); | 62 label_2_->SetFocusable(false); |
| 62 label_2_->SetEnabled(false); | 63 label_2_->SetEnabled(false); |
| 63 label_2_->SetUnderline(false); | 64 label_2_->SetUnderline(false); |
| 64 layout->AddView(label_2_); | 65 layout->AddView(label_2_); |
| 65 | 66 |
| 66 // If we're managing passwords (that is, we're not currently in the process | 67 // If we're managing passwords (that is, we're not currently in the process |
| 67 // of saving a password), construct and add the delete button: fills the | 68 // of saving a password), construct and add the delete button: fills the |
| 68 // third non-padding column of the layout. | 69 // third non-padding column of the layout. |
| 69 if (!manage_passwords_bubble_model_->WaitingToSavePassword()) { | 70 if (!manage_passwords_bubble_model_->WaitingToSavePassword()) { |
| 70 delete_button_ = new views::ImageButton(this); | 71 delete_button_ = new views::ImageButton(this); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 column_set->AddColumn(views::GridLayout::TRAILING, | 109 column_set->AddColumn(views::GridLayout::TRAILING, |
| 109 views::GridLayout::FILL, | 110 views::GridLayout::FILL, |
| 110 0, | 111 0, |
| 111 views::GridLayout::USE_PREF, | 112 views::GridLayout::USE_PREF, |
| 112 0, | 113 0, |
| 113 0); | 114 0); |
| 114 } | 115 } |
| 115 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 116 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 116 } | 117 } |
| 117 | 118 |
| 118 // static | |
| 119 base::string16 ManagePasswordItemView::GetPasswordDisplayString( | |
| 120 const base::string16& password) { | |
| 121 const wchar_t kPasswordBullet = 0x2022; | |
| 122 const size_t kMaxPasswordChar = 22; | |
| 123 return base::string16(std::min(password.length(), kMaxPasswordChar), | |
| 124 kPasswordBullet); | |
| 125 } | |
| 126 | |
| 127 ManagePasswordItemView::~ManagePasswordItemView() { | 119 ManagePasswordItemView::~ManagePasswordItemView() { |
| 128 if (delete_password_) | 120 if (delete_password_) |
| 129 manage_passwords_bubble_model_->DeleteFromBestMatches(password_form_); | 121 manage_passwords_bubble_model_->DeleteFromBestMatches(password_form_); |
| 130 } | 122 } |
| 131 | 123 |
| 132 void ManagePasswordItemView::Refresh() { | 124 void ManagePasswordItemView::Refresh() { |
| 133 // TODO(mkwst): We're currently swaping out values in the same view. We need | 125 // TODO(mkwst): We're currently swaping out values in the same view. We need |
| 134 // to swap out views in order to enable some future work (and to make the undo | 126 // to swap out views in order to enable some future work (and to make the undo |
| 135 // button's alignment work correctly). | 127 // button's alignment work correctly). |
| 136 | 128 |
| 137 if (delete_password_) { | 129 if (delete_password_) { |
| 138 // The user clicked the "delete password" button, so: | 130 // The user clicked the "delete password" button, so: |
| 139 // | 131 // |
| 140 // Change the username string to "Deleted" | 132 // Change the username string to "Deleted" |
| 141 label_1_->SetText(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)); | 133 label_1_->SetText(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)); |
| 142 | 134 |
| 143 // Change the password's text to "Undo", and enable the link. | 135 // Change the password's text to "Undo", and enable the link. |
| 144 label_2_->SetText(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)); | 136 label_2_->SetText(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)); |
| 145 label_2_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 137 label_2_->SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 138 label_2_->SetObscured(false); |
| 146 label_2_->SetEnabled(true); | 139 label_2_->SetEnabled(true); |
| 147 label_2_->SetFocusable(true); | 140 label_2_->SetFocusable(true); |
| 148 | 141 |
| 149 if (delete_button_) | 142 if (delete_button_) |
| 150 delete_button_->SetVisible(false); | 143 delete_button_->SetVisible(false); |
| 151 } else { | 144 } else { |
| 152 // The user clicked the "undo" button after deleting a password, so: | 145 // The user clicked the "undo" button after deleting a password, so: |
| 153 | 146 |
| 154 // Move focus to the parent in order to get the focus ring off the link | 147 // Move focus to the parent in order to get the focus ring off the link |
| 155 // that the user just clicked. | 148 // that the user just clicked. |
| 156 parent()->RequestFocus(); | 149 parent()->RequestFocus(); |
| 157 | 150 |
| 158 // Change the username string back to the username. | 151 // Change the username string back to the username. |
| 159 label_1_->SetText(password_form_.username_value); | 152 label_1_->SetText(password_form_.username_value); |
| 160 | 153 |
| 161 // Set the password string to the appropriate number of bullets, and | 154 // Change the second column back to the password, obscure and disable it. |
| 162 // disable the link. | 155 // disable the link. |
| 163 label_2_->SetText(GetPasswordDisplayString(password_form_.password_value)); | 156 label_2_->SetObscured(true); |
| 164 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 165 label_2_->SetEnabled(false); | 157 label_2_->SetEnabled(false); |
| 166 label_2_->SetFocusable(false); | 158 label_2_->SetFocusable(false); |
| 159 label_2_->SetText(password_form_.password_value); |
| 160 label_2_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 167 | 161 |
| 168 if (delete_button_) | 162 if (delete_button_) |
| 169 delete_button_->SetVisible(true); | 163 delete_button_->SetVisible(true); |
| 170 } | 164 } |
| 171 | 165 |
| 172 // After the view is consistent, notify the model that the password needs to | 166 // After the view is consistent, notify the model that the password needs to |
| 173 // be updated (either removed or put back into the store, as appropriate. | 167 // be updated (either removed or put back into the store, as appropriate. |
| 174 manage_passwords_bubble_model_->OnPasswordAction( | 168 manage_passwords_bubble_model_->OnPasswordAction( |
| 175 password_form_, | 169 password_form_, |
| 176 delete_password_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD | 170 delete_password_ ? ManagePasswordsBubbleModel::REMOVE_PASSWORD |
| 177 : ManagePasswordsBubbleModel::ADD_PASSWORD); | 171 : ManagePasswordsBubbleModel::ADD_PASSWORD); |
| 178 } | 172 } |
| 179 | 173 |
| 180 void ManagePasswordItemView::ButtonPressed(views::Button* sender, | 174 void ManagePasswordItemView::ButtonPressed(views::Button* sender, |
| 181 const ui::Event& event) { | 175 const ui::Event& event) { |
| 182 DCHECK_EQ(delete_button_, sender); | 176 DCHECK_EQ(delete_button_, sender); |
| 183 delete_password_ = true; | 177 delete_password_ = true; |
| 184 Refresh(); | 178 Refresh(); |
| 185 } | 179 } |
| 186 | 180 |
| 187 void ManagePasswordItemView::LinkClicked(views::Link* source, | 181 void ManagePasswordItemView::LinkClicked(views::Link* source, |
| 188 int event_flags) { | 182 int event_flags) { |
| 189 DCHECK_EQ(source, label_2_); | 183 DCHECK_EQ(source, label_2_); |
| 190 delete_password_ = false; | 184 delete_password_ = false; |
| 191 Refresh(); | 185 Refresh(); |
| 192 } | 186 } |
| OLD | NEW |