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/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/optional.h" | |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 #include "chrome/browser/ui/autofill/autofill_popup_view.h" | 16 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
| 16 #include "components/autofill/core/browser/autofill_popup_delegate.h" | 17 #include "components/autofill/core/browser/autofill_popup_delegate.h" |
| 17 #include "components/autofill/core/browser/popup_item_ids.h" | 18 #include "components/autofill/core/browser/popup_item_ids.h" |
| 18 #include "components/autofill/core/browser/suggestion.h" | 19 #include "components/autofill/core/browser/suggestion.h" |
| 19 #include "content/public/browser/native_web_keyboard_event.h" | 20 #include "content/public/browser/native_web_keyboard_event.h" |
| 20 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
| 21 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 22 #include "ui/gfx/text_elider.h" | 23 #include "ui/gfx/text_elider.h" |
| 23 #include "ui/gfx/text_utils.h" | 24 #include "ui/gfx/text_utils.h" |
| 24 | 25 |
| 25 using base::WeakPtr; | 26 using base::WeakPtr; |
| 26 | 27 |
| 27 namespace autofill { | 28 namespace autofill { |
| 28 namespace { | |
| 29 | |
| 30 // Used to indicate that no line is currently selected by the user. | |
| 31 const int kNoSelection = -1; | |
| 32 | |
| 33 } // namespace | |
| 34 | 29 |
| 35 // static | 30 // static |
| 36 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetOrCreate( | 31 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetOrCreate( |
| 37 WeakPtr<AutofillPopupControllerImpl> previous, | 32 WeakPtr<AutofillPopupControllerImpl> previous, |
| 38 WeakPtr<AutofillPopupDelegate> delegate, | 33 WeakPtr<AutofillPopupDelegate> delegate, |
| 39 content::WebContents* web_contents, | 34 content::WebContents* web_contents, |
| 40 gfx::NativeView container_view, | 35 gfx::NativeView container_view, |
| 41 const gfx::RectF& element_bounds, | 36 const gfx::RectF& element_bounds, |
| 42 base::i18n::TextDirection text_direction) { | 37 base::i18n::TextDirection text_direction) { |
| 43 if (previous.get() && previous->web_contents() == web_contents && | 38 if (previous.get() && previous->web_contents() == web_contents && |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // Elide the name and label strings so that the popup fits in the available | 102 // Elide the name and label strings so that the popup fits in the available |
| 108 // space. | 103 // space. |
| 109 for (size_t i = 0; i < suggestions_.size(); ++i) { | 104 for (size_t i = 0; i < suggestions_.size(); ++i) { |
| 110 bool has_label = !suggestions_[i].label.empty(); | 105 bool has_label = !suggestions_[i].label.empty(); |
| 111 ElideValueAndLabelForRow( | 106 ElideValueAndLabelForRow( |
| 112 i, layout_model_.GetAvailableWidthForRow(i, has_label)); | 107 i, layout_model_.GetAvailableWidthForRow(i, has_label)); |
| 113 } | 108 } |
| 114 #endif | 109 #endif |
| 115 | 110 |
| 116 if (just_created) { | 111 if (just_created) { |
| 117 ShowView(); | 112 view_->Show(); |
| 118 } else { | 113 } else { |
| 119 UpdateBoundsAndRedrawPopup(); | 114 OnSuggestionsChanged(); |
| 120 } | 115 } |
| 121 | 116 |
| 122 controller_common_->RegisterKeyPressCallback(); | 117 controller_common_->RegisterKeyPressCallback(); |
| 123 delegate_->OnPopupShown(); | 118 delegate_->OnPopupShown(); |
| 124 | 119 |
| 125 DCHECK_EQ(suggestions_.size(), elided_values_.size()); | 120 DCHECK_EQ(suggestions_.size(), elided_values_.size()); |
| 126 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); | 121 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); |
| 127 } | 122 } |
| 128 | 123 |
| 129 void AutofillPopupControllerImpl::UpdateDataListValues( | 124 void AutofillPopupControllerImpl::UpdateDataListValues( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 146 if (values.empty()) { | 141 if (values.empty()) { |
| 147 if (!suggestions_.empty() && | 142 if (!suggestions_.empty() && |
| 148 suggestions_[0].frontend_id == POPUP_ITEM_ID_SEPARATOR) { | 143 suggestions_[0].frontend_id == POPUP_ITEM_ID_SEPARATOR) { |
| 149 suggestions_.erase(suggestions_.begin()); | 144 suggestions_.erase(suggestions_.begin()); |
| 150 elided_values_.erase(elided_values_.begin()); | 145 elided_values_.erase(elided_values_.begin()); |
| 151 elided_labels_.erase(elided_labels_.begin()); | 146 elided_labels_.erase(elided_labels_.begin()); |
| 152 } | 147 } |
| 153 | 148 |
| 154 // The popup contents have changed, so either update the bounds or hide it. | 149 // The popup contents have changed, so either update the bounds or hide it. |
| 155 if (HasSuggestions()) | 150 if (HasSuggestions()) |
| 156 UpdateBoundsAndRedrawPopup(); | 151 OnSuggestionsChanged(); |
| 157 else | 152 else |
| 158 Hide(); | 153 Hide(); |
| 159 | 154 |
| 160 return; | 155 return; |
| 161 } | 156 } |
| 162 | 157 |
| 163 // Add a separator if there are any other values. | 158 // Add a separator if there are any other values. |
| 164 if (!suggestions_.empty() && | 159 if (!suggestions_.empty() && |
| 165 suggestions_[0].frontend_id != POPUP_ITEM_ID_SEPARATOR) { | 160 suggestions_[0].frontend_id != POPUP_ITEM_ID_SEPARATOR) { |
| 166 suggestions_.insert(suggestions_.begin(), autofill::Suggestion()); | 161 suggestions_.insert(suggestions_.begin(), autofill::Suggestion()); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 178 for (size_t i = 0; i < values.size(); i++) { | 173 for (size_t i = 0; i < values.size(); i++) { |
| 179 suggestions_[i].value = values[i]; | 174 suggestions_[i].value = values[i]; |
| 180 suggestions_[i].label = labels[i]; | 175 suggestions_[i].label = labels[i]; |
| 181 suggestions_[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 176 suggestions_[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
| 182 | 177 |
| 183 // TODO(brettw) it looks like these should be elided. | 178 // TODO(brettw) it looks like these should be elided. |
| 184 elided_values_[i] = values[i]; | 179 elided_values_[i] = values[i]; |
| 185 elided_labels_[i] = labels[i]; | 180 elided_labels_[i] = labels[i]; |
| 186 } | 181 } |
| 187 | 182 |
| 188 UpdateBoundsAndRedrawPopup(); | 183 OnSuggestionsChanged(); |
| 189 DCHECK_EQ(suggestions_.size(), elided_values_.size()); | 184 DCHECK_EQ(suggestions_.size(), elided_values_.size()); |
| 190 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); | 185 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); |
| 191 } | 186 } |
| 192 | 187 |
| 193 void AutofillPopupControllerImpl::Hide() { | 188 void AutofillPopupControllerImpl::Hide() { |
| 194 controller_common_->RemoveKeyPressCallback(); | 189 controller_common_->RemoveKeyPressCallback(); |
| 195 if (delegate_) | 190 if (delegate_) |
| 196 delegate_->OnPopupHidden(); | 191 delegate_->OnPopupHidden(); |
| 197 | 192 |
| 198 if (view_) | 193 if (view_) |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 213 switch (event.windowsKeyCode) { | 208 switch (event.windowsKeyCode) { |
| 214 case ui::VKEY_UP: | 209 case ui::VKEY_UP: |
| 215 SelectPreviousLine(); | 210 SelectPreviousLine(); |
| 216 return true; | 211 return true; |
| 217 case ui::VKEY_DOWN: | 212 case ui::VKEY_DOWN: |
| 218 SelectNextLine(); | 213 SelectNextLine(); |
| 219 return true; | 214 return true; |
| 220 case ui::VKEY_PRIOR: // Page up. | 215 case ui::VKEY_PRIOR: // Page up. |
| 221 // Set no line and then select the next line in case the first line is not | 216 // Set no line and then select the next line in case the first line is not |
| 222 // selectable. | 217 // selectable. |
| 223 SetSelectedLine(kNoSelection); | 218 SetSelectedLine(base::nullopt); |
| 224 SelectNextLine(); | 219 SelectNextLine(); |
| 225 return true; | 220 return true; |
| 226 case ui::VKEY_NEXT: // Page down. | 221 case ui::VKEY_NEXT: // Page down. |
| 227 SetSelectedLine(GetLineCount() - 1); | 222 SetSelectedLine(GetLineCount() - 1); |
| 228 return true; | 223 return true; |
| 229 case ui::VKEY_ESCAPE: | 224 case ui::VKEY_ESCAPE: |
| 230 Hide(); | 225 Hide(); |
| 231 return true; | 226 return true; |
| 232 case ui::VKEY_DELETE: | 227 case ui::VKEY_DELETE: |
| 233 return (event.modifiers() & content::NativeWebKeyboardEvent::ShiftKey) && | 228 return (event.modifiers() & content::NativeWebKeyboardEvent::ShiftKey) && |
| 234 RemoveSelectedLine(); | 229 RemoveSelectedLine(); |
| 235 case ui::VKEY_TAB: | 230 case ui::VKEY_TAB: |
| 236 // A tab press should cause the selected line to be accepted, but still | 231 // A tab press should cause the selected line to be accepted, but still |
| 237 // return false so the tab key press propagates and changes the cursor | 232 // return false so the tab key press propagates and changes the cursor |
| 238 // location. | 233 // location. |
| 239 AcceptSelectedLine(); | 234 AcceptSelectedLine(); |
| 240 return false; | 235 return false; |
| 241 case ui::VKEY_RETURN: | 236 case ui::VKEY_RETURN: |
| 242 return AcceptSelectedLine(); | 237 return AcceptSelectedLine(); |
| 243 default: | 238 default: |
| 244 return false; | 239 return false; |
| 245 } | 240 } |
| 246 } | 241 } |
| 247 | 242 |
| 248 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { | 243 void AutofillPopupControllerImpl::OnSuggestionsChanged() { |
| 249 #if !defined(OS_ANDROID) | 244 #if !defined(OS_ANDROID) |
| 250 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, | 245 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, |
| 251 // the popup could end up jumping from above the element to below it. | 246 // the popup could end up jumping from above the element to below it. |
| 252 // It is unclear if it is better to keep the popup where it was, or if it | 247 // It is unclear if it is better to keep the popup where it was, or if it |
| 253 // should try and move to its desired position. | 248 // should try and move to its desired position. |
| 254 layout_model_.UpdatePopupBounds(); | 249 layout_model_.UpdatePopupBounds(); |
| 255 #endif | 250 #endif |
| 256 | 251 |
| 257 // Platform-specific draw call. | 252 // Platform-specific draw call. |
| 258 view_->UpdateBoundsAndRedrawPopup(); | 253 view_->OnSuggestionsChanged(); |
| 259 } | 254 } |
| 260 | 255 |
| 261 void AutofillPopupControllerImpl::SetSelectionAtPoint(const gfx::Point& point) { | 256 void AutofillPopupControllerImpl::SetSelectionAtPoint(const gfx::Point& point) { |
| 262 SetSelectedLine(layout_model_.LineFromY(point.y())); | 257 SetSelectedLine(layout_model_.LineFromY(point.y())); |
| 263 } | 258 } |
| 264 | 259 |
| 265 bool AutofillPopupControllerImpl::AcceptSelectedLine() { | 260 bool AutofillPopupControllerImpl::AcceptSelectedLine() { |
| 266 if (selected_line_ == kNoSelection) | 261 if (!selected_line_) |
| 267 return false; | 262 return false; |
| 268 | 263 |
| 269 DCHECK_GE(selected_line_, 0); | 264 DCHECK_LT(selected_line_.value(), GetLineCount()); |
| 270 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); | |
| 271 | 265 |
| 272 if (!CanAccept(suggestions_[selected_line_].frontend_id)) | 266 if (!CanAccept(suggestions_[selected_line_.value()].frontend_id)) |
|
Evan Stade
2017/03/16 17:39:00
*selected_line_
csashi
2017/03/16 22:42:05
Done.
| |
| 273 return false; | 267 return false; |
| 274 | 268 |
| 275 AcceptSuggestion(selected_line_); | 269 AcceptSuggestion(selected_line_.value()); |
| 276 return true; | 270 return true; |
| 277 } | 271 } |
| 278 | 272 |
| 279 void AutofillPopupControllerImpl::SelectionCleared() { | 273 void AutofillPopupControllerImpl::SelectionCleared() { |
| 280 SetSelectedLine(kNoSelection); | 274 SetSelectedLine(base::nullopt); |
| 281 } | 275 } |
| 282 | 276 |
| 283 void AutofillPopupControllerImpl::AcceptSuggestion(size_t index) { | 277 void AutofillPopupControllerImpl::AcceptSuggestion(size_t index) { |
| 284 const autofill::Suggestion& suggestion = suggestions_[index]; | 278 const autofill::Suggestion& suggestion = suggestions_[index]; |
| 285 delegate_->DidAcceptSuggestion(suggestion.value, suggestion.frontend_id, | 279 delegate_->DidAcceptSuggestion(suggestion.value, suggestion.frontend_id, |
| 286 index); | 280 index); |
| 287 } | 281 } |
| 288 | 282 |
| 289 gfx::Rect AutofillPopupControllerImpl::popup_bounds() const { | 283 gfx::Rect AutofillPopupControllerImpl::popup_bounds() const { |
| 290 return layout_model_.popup_bounds(); | 284 return layout_model_.popup_bounds(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 if (!delegate_->RemoveSuggestion(suggestions_[list_index].value, | 349 if (!delegate_->RemoveSuggestion(suggestions_[list_index].value, |
| 356 suggestions_[list_index].frontend_id)) { | 350 suggestions_[list_index].frontend_id)) { |
| 357 return false; | 351 return false; |
| 358 } | 352 } |
| 359 | 353 |
| 360 // Remove the deleted element. | 354 // Remove the deleted element. |
| 361 suggestions_.erase(suggestions_.begin() + list_index); | 355 suggestions_.erase(suggestions_.begin() + list_index); |
| 362 elided_values_.erase(elided_values_.begin() + list_index); | 356 elided_values_.erase(elided_values_.begin() + list_index); |
| 363 elided_labels_.erase(elided_labels_.begin() + list_index); | 357 elided_labels_.erase(elided_labels_.begin() + list_index); |
| 364 | 358 |
| 365 SetSelectedLine(kNoSelection); | 359 SetSelectedLine(base::nullopt); |
| 366 | 360 |
| 367 if (HasSuggestions()) { | 361 if (HasSuggestions()) { |
| 368 delegate_->ClearPreviewedForm(); | 362 delegate_->ClearPreviewedForm(); |
| 369 UpdateBoundsAndRedrawPopup(); | 363 OnSuggestionsChanged(); |
| 370 } else { | 364 } else { |
| 371 Hide(); | 365 Hide(); |
| 372 } | 366 } |
| 373 | 367 |
| 374 return true; | 368 return true; |
| 375 } | 369 } |
| 376 | 370 |
| 377 ui::NativeTheme::ColorId | 371 ui::NativeTheme::ColorId |
| 378 AutofillPopupControllerImpl::GetBackgroundColorIDForRow(int index) const { | 372 AutofillPopupControllerImpl::GetBackgroundColorIDForRow(int index) const { |
| 379 return index == selected_line_ ? | 373 return index == static_cast<int>(selected_line_.value()) |
| 380 ui::NativeTheme::kColorId_ResultsTableHoveredBackground : | 374 ? ui::NativeTheme::kColorId_ResultsTableHoveredBackground |
| 381 ui::NativeTheme::kColorId_ResultsTableNormalBackground; | 375 : ui::NativeTheme::kColorId_ResultsTableNormalBackground; |
| 382 } | 376 } |
| 383 | 377 |
| 384 int AutofillPopupControllerImpl::selected_line() const { | 378 base::Optional<size_t> AutofillPopupControllerImpl::selected_line() const { |
| 385 return selected_line_; | 379 return selected_line_; |
| 386 } | 380 } |
| 387 | 381 |
| 388 const AutofillPopupLayoutModel& AutofillPopupControllerImpl::layout_model() | 382 const AutofillPopupLayoutModel& AutofillPopupControllerImpl::layout_model() |
| 389 const { | 383 const { |
| 390 return layout_model_; | 384 return layout_model_; |
| 391 } | 385 } |
| 392 | 386 |
| 393 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { | 387 void AutofillPopupControllerImpl::SetSelectedLine( |
| 388 base::Optional<size_t> selected_line) { | |
| 394 if (selected_line_ == selected_line) | 389 if (selected_line_ == selected_line) |
| 395 return; | 390 return; |
| 396 | 391 |
| 397 if (selected_line_ != kNoSelection && | 392 if (selected_line) { |
| 398 static_cast<size_t>(selected_line_) < suggestions_.size()) | 393 DCHECK_LT(selected_line.value(), suggestions_.size()); |
| 399 InvalidateRow(selected_line_); | 394 if (!CanAccept(suggestions_[selected_line.value()].frontend_id)) |
| 395 selected_line = base::nullopt; | |
| 396 } | |
| 400 | 397 |
| 401 if (selected_line != kNoSelection) { | 398 view_->OnSelectedRowChanged(selected_line_, selected_line); |
|
Evan Stade
2017/03/16 17:39:00
calling this before you change the value of select
csashi
2017/03/16 22:42:05
Done.
Evan Stade
2017/03/17 14:11:54
Maybe, but then again in this CL the view is still
csashi
2017/03/17 16:30:35
Assuming SchedulePaintInRect on 2 rectangles is no
Evan Stade
2017/03/17 19:08:54
I'm only talking about the Views implementation ri
csashi
2017/03/17 21:55:21
Do you mean you want to have two function signatur
csashi
2017/03/17 22:52:26
I kept the function signature to pass both previo
| |
| 402 InvalidateRow(selected_line); | |
| 403 | |
| 404 if (!CanAccept(suggestions_[selected_line].frontend_id)) | |
| 405 selected_line = kNoSelection; | |
| 406 } | |
| 407 | 399 |
| 408 selected_line_ = selected_line; | 400 selected_line_ = selected_line; |
| 409 | 401 |
| 410 if (selected_line_ != kNoSelection) { | 402 if (selected_line_) { |
| 411 delegate_->DidSelectSuggestion(suggestions_[selected_line_].value, | 403 delegate_->DidSelectSuggestion( |
| 412 suggestions_[selected_line_].frontend_id); | 404 suggestions_[selected_line_.value()].value, |
| 405 suggestions_[selected_line_.value()].frontend_id); | |
| 413 } else { | 406 } else { |
| 414 delegate_->ClearPreviewedForm(); | 407 delegate_->ClearPreviewedForm(); |
| 415 } | 408 } |
| 416 } | 409 } |
| 417 | 410 |
| 418 void AutofillPopupControllerImpl::SelectNextLine() { | 411 void AutofillPopupControllerImpl::SelectNextLine() { |
| 419 int new_selected_line = selected_line_ + 1; | 412 size_t new_selected_line = selected_line_ ? selected_line_.value() + 1 : 0; |
| 420 | 413 |
| 421 // Skip over any lines that can't be selected. | 414 // Skip over any lines that can't be selected. |
| 422 while (static_cast<size_t>(new_selected_line) < GetLineCount() && | 415 while (new_selected_line < GetLineCount() && |
| 423 !CanAccept(suggestions_[new_selected_line].frontend_id)) { | 416 !CanAccept(suggestions_[new_selected_line].frontend_id)) { |
| 424 ++new_selected_line; | 417 ++new_selected_line; |
| 425 } | 418 } |
| 426 | 419 |
| 427 if (new_selected_line >= static_cast<int>(GetLineCount())) | 420 if (new_selected_line >= GetLineCount()) |
| 428 new_selected_line = 0; | 421 new_selected_line = 0; |
| 429 | 422 |
| 430 SetSelectedLine(new_selected_line); | 423 SetSelectedLine(new_selected_line); |
| 431 } | 424 } |
| 432 | 425 |
| 433 void AutofillPopupControllerImpl::SelectPreviousLine() { | 426 void AutofillPopupControllerImpl::SelectPreviousLine() { |
| 434 int new_selected_line = selected_line_ - 1; | 427 int new_selected_line; |
| 428 if (selected_line_) { | |
| 429 new_selected_line = selected_line_.value() - 1; | |
| 435 | 430 |
| 436 // Skip over any lines that can't be selected. | 431 // Skip over any lines that can't be selected. |
| 437 while (new_selected_line > kNoSelection && | 432 while (new_selected_line >= 0 && |
| 438 !CanAccept(GetSuggestionAt(new_selected_line).frontend_id)) { | 433 !CanAccept(GetSuggestionAt(new_selected_line).frontend_id)) { |
| 439 --new_selected_line; | 434 --new_selected_line; |
| 435 } | |
| 436 | |
| 437 if (new_selected_line < 0) | |
| 438 new_selected_line = GetLineCount() - 1; | |
| 439 } else { | |
| 440 new_selected_line = GetLineCount() - 1; | |
| 440 } | 441 } |
| 441 | 442 |
| 442 if (new_selected_line <= kNoSelection) | |
| 443 new_selected_line = GetLineCount() - 1; | |
| 444 | |
| 445 SetSelectedLine(new_selected_line); | 443 SetSelectedLine(new_selected_line); |
| 446 } | 444 } |
| 447 | 445 |
| 448 bool AutofillPopupControllerImpl::RemoveSelectedLine() { | 446 bool AutofillPopupControllerImpl::RemoveSelectedLine() { |
| 449 if (selected_line_ == kNoSelection) | 447 if (!selected_line_) |
| 450 return false; | 448 return false; |
| 451 | 449 |
| 452 DCHECK_GE(selected_line_, 0); | 450 DCHECK_LT(selected_line_.value(), GetLineCount()); |
| 453 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); | 451 return RemoveSuggestion(selected_line_.value()); |
| 454 return RemoveSuggestion(selected_line_); | |
| 455 } | 452 } |
| 456 | 453 |
| 457 bool AutofillPopupControllerImpl::CanAccept(int id) { | 454 bool AutofillPopupControllerImpl::CanAccept(int id) { |
| 458 return id != POPUP_ITEM_ID_SEPARATOR && | 455 return id != POPUP_ITEM_ID_SEPARATOR && |
| 459 id != POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE && | 456 id != POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE && |
| 460 id != POPUP_ITEM_ID_TITLE; | 457 id != POPUP_ITEM_ID_TITLE; |
| 461 } | 458 } |
| 462 | 459 |
| 463 bool AutofillPopupControllerImpl::HasSuggestions() { | 460 bool AutofillPopupControllerImpl::HasSuggestions() { |
| 464 if (suggestions_.empty()) | 461 if (suggestions_.empty()) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 475 const std::vector<autofill::Suggestion>& suggestions) { | 472 const std::vector<autofill::Suggestion>& suggestions) { |
| 476 suggestions_ = suggestions; | 473 suggestions_ = suggestions; |
| 477 elided_values_.resize(suggestions.size()); | 474 elided_values_.resize(suggestions.size()); |
| 478 elided_labels_.resize(suggestions.size()); | 475 elided_labels_.resize(suggestions.size()); |
| 479 for (size_t i = 0; i < suggestions.size(); i++) { | 476 for (size_t i = 0; i < suggestions.size(); i++) { |
| 480 elided_values_[i] = suggestions[i].value; | 477 elided_values_[i] = suggestions[i].value; |
| 481 elided_labels_[i] = suggestions[i].label; | 478 elided_labels_[i] = suggestions[i].label; |
| 482 } | 479 } |
| 483 } | 480 } |
| 484 | 481 |
| 485 void AutofillPopupControllerImpl::ShowView() { | |
| 486 view_->Show(); | |
| 487 } | |
| 488 | |
| 489 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { | |
| 490 DCHECK(0 <= row); | |
| 491 DCHECK(row < suggestions_.size()); | |
| 492 view_->InvalidateRow(row); | |
| 493 } | |
| 494 | |
| 495 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() { | 482 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() { |
| 496 return weak_ptr_factory_.GetWeakPtr(); | 483 return weak_ptr_factory_.GetWeakPtr(); |
| 497 } | 484 } |
| 498 | 485 |
| 499 #if !defined(OS_ANDROID) | 486 #if !defined(OS_ANDROID) |
| 500 void AutofillPopupControllerImpl::ElideValueAndLabelForRow( | 487 void AutofillPopupControllerImpl::ElideValueAndLabelForRow( |
| 501 size_t row, | 488 size_t row, |
| 502 int available_width) { | 489 int available_width) { |
| 503 int value_width = gfx::GetStringWidth( | 490 int value_width = gfx::GetStringWidth( |
| 504 suggestions_[row].value, layout_model_.GetValueFontListForRow(row)); | 491 suggestions_[row].value, layout_model_.GetValueFontListForRow(row)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 524 } | 511 } |
| 525 #endif | 512 #endif |
| 526 | 513 |
| 527 void AutofillPopupControllerImpl::ClearState() { | 514 void AutofillPopupControllerImpl::ClearState() { |
| 528 // Don't clear view_, because otherwise the popup will have to get regenerated | 515 // Don't clear view_, because otherwise the popup will have to get regenerated |
| 529 // and this will cause flickering. | 516 // and this will cause flickering. |
| 530 suggestions_.clear(); | 517 suggestions_.clear(); |
| 531 elided_values_.clear(); | 518 elided_values_.clear(); |
| 532 elided_labels_.clear(); | 519 elided_labels_.clear(); |
| 533 | 520 |
| 534 selected_line_ = kNoSelection; | 521 selected_line_.reset(); |
| 535 } | 522 } |
| 536 | 523 |
| 537 } // namespace autofill | 524 } // namespace autofill |
| OLD | NEW |