Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill_popup_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/ui/autofill/autofill_popup_view.h" | 12 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
| 13 #include "chrome/browser/ui/autofill/popup_constants.h" | 13 #include "chrome/browser/ui/autofill/popup_constants.h" |
| 14 #include "components/autofill/core/browser/autofill_popup_delegate.h" | 14 #include "components/autofill/core/browser/autofill_popup_delegate.h" |
| 15 #include "components/autofill/core/common/autofill_enums.h" | |
| 15 #include "content/public/browser/native_web_keyboard_event.h" | 16 #include "content/public/browser/native_web_keyboard_event.h" |
| 16 #include "grit/webkit_resources.h" | 17 #include "grit/webkit_resources.h" |
| 17 #include "third_party/WebKit/public/web/WebAutofillClient.h" | |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 20 #include "ui/gfx/rect_conversions.h" | 20 #include "ui/gfx/rect_conversions.h" |
| 21 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 22 #include "ui/gfx/text_elider.h" | 22 #include "ui/gfx/text_elider.h" |
| 23 #include "ui/gfx/text_utils.h" | 23 #include "ui/gfx/text_utils.h" |
| 24 #include "ui/gfx/vector2d.h" | 24 #include "ui/gfx/vector2d.h" |
| 25 | 25 |
| 26 using base::WeakPtr; | 26 using base::WeakPtr; |
| 27 using blink::WebAutofillClient; | |
| 28 | 27 |
| 29 namespace autofill { | 28 namespace autofill { |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 // Used to indicate that no line is currently selected by the user. | 31 // Used to indicate that no line is currently selected by the user. |
| 33 const int kNoSelection = -1; | 32 const int kNoSelection = -1; |
| 34 | 33 |
| 35 // The vertical height of each row in pixels. | 34 // The vertical height of each row in pixels. |
| 36 const size_t kRowHeight = 24; | 35 const size_t kRowHeight = 24; |
| 37 | 36 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 delegate_->OnPopupShown(); | 181 delegate_->OnPopupShown(); |
| 183 controller_common_->RegisterKeyPressCallback(); | 182 controller_common_->RegisterKeyPressCallback(); |
| 184 } | 183 } |
| 185 | 184 |
| 186 void AutofillPopupControllerImpl::UpdateDataListValues( | 185 void AutofillPopupControllerImpl::UpdateDataListValues( |
| 187 const std::vector<base::string16>& values, | 186 const std::vector<base::string16>& values, |
| 188 const std::vector<base::string16>& labels) { | 187 const std::vector<base::string16>& labels) { |
| 189 // Remove all the old data list values, which should always be at the top of | 188 // Remove all the old data list values, which should always be at the top of |
| 190 // the list if they are present. | 189 // the list if they are present. |
| 191 while (!identifiers_.empty() && | 190 while (!identifiers_.empty() && |
| 192 identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry) { | 191 identifiers_[0] == MenuItemIDDataListEntry) { |
|
Ilya Sherman
2014/02/11 22:21:33
nit: Looks like this line no longer needs to wrap.
gnana
2014/02/12 13:34:09
Done.
| |
| 193 names_.erase(names_.begin()); | 192 names_.erase(names_.begin()); |
| 194 subtexts_.erase(subtexts_.begin()); | 193 subtexts_.erase(subtexts_.begin()); |
| 195 icons_.erase(icons_.begin()); | 194 icons_.erase(icons_.begin()); |
| 196 identifiers_.erase(identifiers_.begin()); | 195 identifiers_.erase(identifiers_.begin()); |
| 197 } | 196 } |
| 198 | 197 |
| 199 // If there are no new data list values, exit (clearing the separator if there | 198 // If there are no new data list values, exit (clearing the separator if there |
| 200 // is one). | 199 // is one). |
| 201 if (values.empty()) { | 200 if (values.empty()) { |
| 202 if (!identifiers_.empty() && | 201 if (!identifiers_.empty() && |
| 203 identifiers_[0] == WebAutofillClient::MenuItemIDSeparator) { | 202 identifiers_[0] == MenuItemIDSeparator) { |
|
Ilya Sherman
2014/02/11 22:21:33
nit: Looks like this line no longer needs to wrap.
gnana
2014/02/12 13:34:09
Done.
| |
| 204 names_.erase(names_.begin()); | 203 names_.erase(names_.begin()); |
| 205 subtexts_.erase(subtexts_.begin()); | 204 subtexts_.erase(subtexts_.begin()); |
| 206 icons_.erase(icons_.begin()); | 205 icons_.erase(icons_.begin()); |
| 207 identifiers_.erase(identifiers_.begin()); | 206 identifiers_.erase(identifiers_.begin()); |
| 208 } | 207 } |
| 209 | 208 |
| 210 // The popup contents have changed, so either update the bounds or hide it. | 209 // The popup contents have changed, so either update the bounds or hide it. |
| 211 if (HasSuggestions()) | 210 if (HasSuggestions()) |
| 212 UpdateBoundsAndRedrawPopup(); | 211 UpdateBoundsAndRedrawPopup(); |
| 213 else | 212 else |
| 214 Hide(); | 213 Hide(); |
| 215 | 214 |
| 216 return; | 215 return; |
| 217 } | 216 } |
| 218 | 217 |
| 219 // Add a separator if there are any other values. | 218 // Add a separator if there are any other values. |
| 220 if (!identifiers_.empty() && | 219 if (!identifiers_.empty() && |
| 221 identifiers_[0] != WebAutofillClient::MenuItemIDSeparator) { | 220 identifiers_[0] != MenuItemIDSeparator) { |
|
Ilya Sherman
2014/02/11 22:21:33
nit: Looks like this line no longer needs to wrap.
gnana
2014/02/12 13:34:09
Done.
| |
| 222 names_.insert(names_.begin(), base::string16()); | 221 names_.insert(names_.begin(), base::string16()); |
| 223 subtexts_.insert(subtexts_.begin(), base::string16()); | 222 subtexts_.insert(subtexts_.begin(), base::string16()); |
| 224 icons_.insert(icons_.begin(), base::string16()); | 223 icons_.insert(icons_.begin(), base::string16()); |
| 225 identifiers_.insert(identifiers_.begin(), | 224 identifiers_.insert(identifiers_.begin(), MenuItemIDSeparator); |
| 226 WebAutofillClient::MenuItemIDSeparator); | |
| 227 } | 225 } |
| 228 | 226 |
| 229 | 227 |
| 230 names_.insert(names_.begin(), values.begin(), values.end()); | 228 names_.insert(names_.begin(), values.begin(), values.end()); |
| 231 subtexts_.insert(subtexts_.begin(), labels.begin(), labels.end()); | 229 subtexts_.insert(subtexts_.begin(), labels.begin(), labels.end()); |
| 232 | 230 |
| 233 // Add the values that are the same for all data list elements. | 231 // Add the values that are the same for all data list elements. |
| 234 icons_.insert(icons_.begin(), values.size(), base::string16()); | 232 icons_.insert(icons_.begin(), values.size(), base::string16()); |
| 235 identifiers_.insert(identifiers_.begin(), | 233 identifiers_.insert(identifiers_.begin(), |
| 236 values.size(), | 234 values.size(), |
|
Evan Stade
2014/02/11 18:56:39
bad indent
gnana
2014/02/12 13:34:09
Done.
| |
| 237 WebAutofillClient::MenuItemIDDataListEntry); | 235 MenuItemIDDataListEntry); |
| 238 | 236 |
| 239 UpdateBoundsAndRedrawPopup(); | 237 UpdateBoundsAndRedrawPopup(); |
| 240 } | 238 } |
| 241 | 239 |
| 242 void AutofillPopupControllerImpl::Hide() { | 240 void AutofillPopupControllerImpl::Hide() { |
| 243 controller_common_->RemoveKeyPressCallback(); | 241 controller_common_->RemoveKeyPressCallback(); |
| 244 if (delegate_.get()) | 242 if (delegate_.get()) |
| 245 delegate_->OnPopupHidden(); | 243 delegate_->OnPopupHidden(); |
| 246 | 244 |
| 247 if (view_) | 245 if (view_) |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 } | 336 } |
| 339 | 337 |
| 340 return -1; | 338 return -1; |
| 341 } | 339 } |
| 342 | 340 |
| 343 bool AutofillPopupControllerImpl::CanDelete(size_t index) const { | 341 bool AutofillPopupControllerImpl::CanDelete(size_t index) const { |
| 344 // TODO(isherman): Native AddressBook suggestions on Mac and Android should | 342 // TODO(isherman): Native AddressBook suggestions on Mac and Android should |
| 345 // not be considered to be deleteable. | 343 // not be considered to be deleteable. |
| 346 int id = identifiers_[index]; | 344 int id = identifiers_[index]; |
| 347 return id > 0 || | 345 return id > 0 || |
| 348 id == WebAutofillClient::MenuItemIDAutocompleteEntry || | 346 id == MenuItemIDAutocompleteEntry || |
| 349 id == WebAutofillClient::MenuItemIDPasswordEntry; | 347 id == MenuItemIDPasswordEntry; |
| 350 } | 348 } |
| 351 | 349 |
| 352 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { | 350 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { |
| 353 return identifiers_[index] == WebAutofillClient::MenuItemIDWarningMessage; | 351 return identifiers_[index] == MenuItemIDWarningMessage; |
| 354 } | 352 } |
| 355 | 353 |
| 356 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { | 354 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { |
| 357 int top = kPopupBorderThickness; | 355 int top = kPopupBorderThickness; |
| 358 for (size_t i = 0; i < index; ++i) { | 356 for (size_t i = 0; i < index; ++i) { |
| 359 top += GetRowHeightFromId(identifiers()[i]); | 357 top += GetRowHeightFromId(identifiers()[i]); |
| 360 } | 358 } |
| 361 | 359 |
| 362 return gfx::Rect( | 360 return gfx::Rect( |
| 363 kPopupBorderThickness, | 361 kPopupBorderThickness, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 404 return icons_; | 402 return icons_; |
| 405 } | 403 } |
| 406 | 404 |
| 407 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { | 405 const std::vector<int>& AutofillPopupControllerImpl::identifiers() const { |
| 408 return identifiers_; | 406 return identifiers_; |
| 409 } | 407 } |
| 410 | 408 |
| 411 #if !defined(OS_ANDROID) | 409 #if !defined(OS_ANDROID) |
| 412 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( | 410 const gfx::FontList& AutofillPopupControllerImpl::GetNameFontListForRow( |
| 413 size_t index) const { | 411 size_t index) const { |
| 414 if (identifiers_[index] == WebAutofillClient::MenuItemIDWarningMessage) | 412 if (identifiers_[index] == MenuItemIDWarningMessage) |
| 415 return warning_font_list_; | 413 return warning_font_list_; |
| 416 | 414 |
| 417 return name_font_list_; | 415 return name_font_list_; |
| 418 } | 416 } |
| 419 | 417 |
| 420 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { | 418 const gfx::FontList& AutofillPopupControllerImpl::subtext_font_list() const { |
| 421 return subtext_font_list_; | 419 return subtext_font_list_; |
| 422 } | 420 } |
| 423 #endif | 421 #endif |
| 424 | 422 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 | 532 |
| 535 if (y <= current_height) | 533 if (y <= current_height) |
| 536 return i; | 534 return i; |
| 537 } | 535 } |
| 538 | 536 |
| 539 // The y value goes beyond the popup so stop the selection at the last line. | 537 // The y value goes beyond the popup so stop the selection at the last line. |
| 540 return identifiers().size() - 1; | 538 return identifiers().size() - 1; |
| 541 } | 539 } |
| 542 | 540 |
| 543 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { | 541 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { |
| 544 if (identifier == WebAutofillClient::MenuItemIDSeparator) | 542 if (identifier == MenuItemIDSeparator) |
| 545 return kSeparatorHeight; | 543 return kSeparatorHeight; |
| 546 | 544 |
| 547 return kRowHeight; | 545 return kRowHeight; |
| 548 } | 546 } |
| 549 | 547 |
| 550 bool AutofillPopupControllerImpl::CanAccept(int id) { | 548 bool AutofillPopupControllerImpl::CanAccept(int id) { |
| 551 return id != WebAutofillClient::MenuItemIDSeparator && | 549 return id != MenuItemIDSeparator && |
|
Evan Stade
2014/02/11 18:56:39
unwrap?
gnana
2014/02/12 13:34:09
Done.
| |
| 552 id != WebAutofillClient::MenuItemIDWarningMessage; | 550 id != MenuItemIDWarningMessage; |
| 553 } | 551 } |
| 554 | 552 |
| 555 bool AutofillPopupControllerImpl::HasSuggestions() { | 553 bool AutofillPopupControllerImpl::HasSuggestions() { |
| 556 return identifiers_.size() != 0 && | 554 return identifiers_.size() != 0 && |
| 557 (identifiers_[0] > 0 || | 555 (identifiers_[0] > 0 || |
| 558 identifiers_[0] == | 556 identifiers_[0] == |
|
Evan Stade
2014/02/11 18:56:39
un-wrap
gnana
2014/02/12 13:34:09
Done.
| |
| 559 WebAutofillClient::MenuItemIDAutocompleteEntry || | 557 MenuItemIDAutocompleteEntry || |
| 560 identifiers_[0] == WebAutofillClient::MenuItemIDPasswordEntry || | 558 identifiers_[0] == MenuItemIDPasswordEntry || |
| 561 identifiers_[0] == WebAutofillClient::MenuItemIDDataListEntry); | 559 identifiers_[0] == MenuItemIDDataListEntry); |
| 562 } | 560 } |
| 563 | 561 |
| 564 void AutofillPopupControllerImpl::SetValues( | 562 void AutofillPopupControllerImpl::SetValues( |
| 565 const std::vector<base::string16>& names, | 563 const std::vector<base::string16>& names, |
| 566 const std::vector<base::string16>& subtexts, | 564 const std::vector<base::string16>& subtexts, |
| 567 const std::vector<base::string16>& icons, | 565 const std::vector<base::string16>& icons, |
| 568 const std::vector<int>& identifiers) { | 566 const std::vector<int>& identifiers) { |
| 569 names_ = names; | 567 names_ = names; |
| 570 full_names_ = names; | 568 full_names_ = names; |
| 571 subtexts_ = subtexts; | 569 subtexts_ = subtexts; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 names_.clear(); | 651 names_.clear(); |
| 654 subtexts_.clear(); | 652 subtexts_.clear(); |
| 655 icons_.clear(); | 653 icons_.clear(); |
| 656 identifiers_.clear(); | 654 identifiers_.clear(); |
| 657 full_names_.clear(); | 655 full_names_.clear(); |
| 658 | 656 |
| 659 selected_line_ = kNoSelection; | 657 selected_line_ = kNoSelection; |
| 660 } | 658 } |
| 661 | 659 |
| 662 } // namespace autofill | 660 } // namespace autofill |
| OLD | NEW |