Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/autofill/password_generation_popup_controller_impl.h " | 5 #include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h " |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversion_utils.h" | 9 #include "base/strings/utf_string_conversion_utils.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 switch (event.windowsKeyCode) { | 98 switch (event.windowsKeyCode) { |
| 99 case ui::VKEY_UP: | 99 case ui::VKEY_UP: |
| 100 case ui::VKEY_DOWN: | 100 case ui::VKEY_DOWN: |
| 101 PasswordSelected(true); | 101 PasswordSelected(true); |
| 102 return true; | 102 return true; |
| 103 case ui::VKEY_ESCAPE: | 103 case ui::VKEY_ESCAPE: |
| 104 Hide(); | 104 Hide(); |
| 105 return true; | 105 return true; |
| 106 case ui::VKEY_RETURN: | 106 case ui::VKEY_RETURN: |
| 107 case ui::VKEY_TAB: | 107 case ui::VKEY_TAB: |
| 108 // We supress tab if the password is selected because we will | 108 // We supress tab if the password is selected because we will |
|
Evan Stade
2014/01/31 21:55:55
suppress
Garrett Casto
2014/01/31 22:01:41
Done.
| |
| 109 // automatically advance focus anyway. | 109 // automatically advance focus anyway. |
| 110 return PossiblyAcceptPassword(); | 110 if (PossiblyAcceptPassword()) { |
| 111 Hide(); | |
| 112 return true; | |
| 113 } else { | |
| 114 return false; | |
| 115 } | |
| 111 default: | 116 default: |
| 112 return false; | 117 return false; |
| 113 } | 118 } |
| 114 } | 119 } |
| 115 | 120 |
| 116 bool PasswordGenerationPopupControllerImpl::PossiblyAcceptPassword() { | 121 bool PasswordGenerationPopupControllerImpl::PossiblyAcceptPassword() { |
| 117 if (password_selected_) | 122 if (password_selected_) |
| 118 PasswordAccepted(); | 123 PasswordAccepted(); |
|
Evan Stade
2014/01/31 21:55:55
could you fix this by instead changing this functi
Garrett Casto
2014/01/31 22:01:41
Done.
| |
| 119 | 124 |
| 120 return password_selected_; | 125 return password_selected_; |
| 121 } | 126 } |
| 122 | 127 |
| 123 void PasswordGenerationPopupControllerImpl::PasswordSelected(bool selected) { | 128 void PasswordGenerationPopupControllerImpl::PasswordSelected(bool selected) { |
| 124 password_selected_ = selected; | 129 password_selected_ = selected; |
| 125 view_->UpdateBoundsAndRedrawPopup(); | 130 view_->UpdateBoundsAndRedrawPopup(); |
| 126 } | 131 } |
| 127 | 132 |
| 128 void PasswordGenerationPopupControllerImpl::PasswordAccepted() { | 133 void PasswordGenerationPopupControllerImpl::PasswordAccepted() { |
| 129 web_contents()->GetRenderViewHost()->Send( | 134 web_contents()->GetRenderViewHost()->Send( |
| 130 new AutofillMsg_GeneratedPasswordAccepted( | 135 new AutofillMsg_GeneratedPasswordAccepted( |
| 131 web_contents()->GetRenderViewHost()->GetRoutingID(), | 136 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 132 current_password_)); | 137 current_password_)); |
| 133 password_manager_->SetFormHasGeneratedPassword(form_); | 138 password_manager_->SetFormHasGeneratedPassword(form_); |
| 134 Hide(); | |
| 135 } | 139 } |
| 136 | 140 |
| 137 int PasswordGenerationPopupControllerImpl::GetDesiredWidth() { | 141 int PasswordGenerationPopupControllerImpl::GetDesiredWidth() { |
| 138 // Minimum width we want to display the password. | 142 // Minimum width we want to display the password. |
| 139 int minimum_length_for_text = 2 * kHorizontalPadding + | 143 int minimum_length_for_text = 2 * kHorizontalPadding + |
| 140 font_.GetExpectedTextWidth(kMinimumWidth) + | 144 font_.GetExpectedTextWidth(kMinimumWidth) + |
| 141 2 * kPopupBorderThickness; | 145 2 * kPopupBorderThickness; |
| 142 | 146 |
| 143 // If the width of the field is longer than the minimum, use that instead. | 147 // If the width of the field is longer than the minimum, use that instead. |
| 144 return std::max(minimum_length_for_text, | 148 return std::max(minimum_length_for_text, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 view_ = PasswordGenerationPopupView::Create(this); | 204 view_ = PasswordGenerationPopupView::Create(this); |
| 201 view_->Show(); | 205 view_->Show(); |
| 202 } | 206 } |
| 203 | 207 |
| 204 controller_common_.RegisterKeyPressCallback(); | 208 controller_common_.RegisterKeyPressCallback(); |
| 205 | 209 |
| 206 if (observer_) | 210 if (observer_) |
| 207 observer_->OnPopupShown(); | 211 observer_->OnPopupShown(); |
| 208 } | 212 } |
| 209 | 213 |
| 214 void PasswordGenerationPopupControllerImpl::HideAndDestroy() { | |
| 215 Hide(); | |
| 216 } | |
| 217 | |
| 210 void PasswordGenerationPopupControllerImpl::Hide() { | 218 void PasswordGenerationPopupControllerImpl::Hide() { |
| 211 controller_common_.RemoveKeyPressCallback(); | 219 controller_common_.RemoveKeyPressCallback(); |
| 212 | 220 |
| 213 if (view_) | 221 if (view_) |
| 214 view_->Hide(); | 222 view_->Hide(); |
| 215 | 223 |
| 216 if (observer_) | 224 if (observer_) |
| 217 observer_->OnPopupHidden(); | 225 observer_->OnPopupHidden(); |
| 218 | 226 |
| 219 delete this; | 227 delete this; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 235 } | 243 } |
| 236 | 244 |
| 237 void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint( | 245 void PasswordGenerationPopupControllerImpl::SetSelectionAtPoint( |
| 238 const gfx::Point& point) { | 246 const gfx::Point& point) { |
| 239 if (password_bounds_.Contains(point)) | 247 if (password_bounds_.Contains(point)) |
| 240 PasswordSelected(true); | 248 PasswordSelected(true); |
| 241 } | 249 } |
| 242 | 250 |
| 243 void PasswordGenerationPopupControllerImpl::AcceptSelectionAtPoint( | 251 void PasswordGenerationPopupControllerImpl::AcceptSelectionAtPoint( |
| 244 const gfx::Point& point) { | 252 const gfx::Point& point) { |
| 245 if (password_bounds_.Contains(point)) | 253 if (password_bounds_.Contains(point)) { |
| 246 PasswordAccepted(); | 254 PasswordAccepted(); |
| 255 Hide(); | |
| 256 } | |
| 247 } | 257 } |
| 248 | 258 |
| 249 void PasswordGenerationPopupControllerImpl::SelectionCleared() { | 259 void PasswordGenerationPopupControllerImpl::SelectionCleared() { |
| 250 PasswordSelected(false); | 260 PasswordSelected(false); |
| 251 } | 261 } |
| 252 | 262 |
| 253 bool PasswordGenerationPopupControllerImpl::ShouldRepostEvent( | 263 bool PasswordGenerationPopupControllerImpl::ShouldRepostEvent( |
| 254 const ui::MouseEvent& event) { | 264 const ui::MouseEvent& event) { |
| 255 return false; | 265 return false; |
| 256 } | 266 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 | 302 |
| 293 base::string16 PasswordGenerationPopupControllerImpl::HelpText() { | 303 base::string16 PasswordGenerationPopupControllerImpl::HelpText() { |
| 294 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_PROMPT); | 304 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_PROMPT); |
| 295 } | 305 } |
| 296 | 306 |
| 297 base::string16 PasswordGenerationPopupControllerImpl::LearnMoreLink() { | 307 base::string16 PasswordGenerationPopupControllerImpl::LearnMoreLink() { |
| 298 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_LEARN_MORE_LINK); | 308 return l10n_util::GetStringUTF16(IDS_PASSWORD_GENERATION_LEARN_MORE_LINK); |
| 299 } | 309 } |
| 300 | 310 |
| 301 } // namespace autofill | 311 } // namespace autofill |
| OLD | NEW |