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 if (selected_line_ && *selected_line_ >= suggestions_.size()) { |
Evan Stade
2017/03/18 00:47:03
nit: no curlies
csashi
2017/03/18 02:25:09
Done.
| |
115 selected_line_.reset(); | |
116 } | |
117 OnSuggestionsChanged(); | |
120 } | 118 } |
121 | 119 |
122 controller_common_->RegisterKeyPressCallback(); | 120 controller_common_->RegisterKeyPressCallback(); |
123 delegate_->OnPopupShown(); | 121 delegate_->OnPopupShown(); |
124 | 122 |
125 DCHECK_EQ(suggestions_.size(), elided_values_.size()); | 123 DCHECK_EQ(suggestions_.size(), elided_values_.size()); |
126 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); | 124 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); |
127 } | 125 } |
128 | 126 |
129 void AutofillPopupControllerImpl::UpdateDataListValues( | 127 void AutofillPopupControllerImpl::UpdateDataListValues( |
(...skipping 16 matching lines...) Expand all Loading... | |
146 if (values.empty()) { | 144 if (values.empty()) { |
147 if (!suggestions_.empty() && | 145 if (!suggestions_.empty() && |
148 suggestions_[0].frontend_id == POPUP_ITEM_ID_SEPARATOR) { | 146 suggestions_[0].frontend_id == POPUP_ITEM_ID_SEPARATOR) { |
149 suggestions_.erase(suggestions_.begin()); | 147 suggestions_.erase(suggestions_.begin()); |
150 elided_values_.erase(elided_values_.begin()); | 148 elided_values_.erase(elided_values_.begin()); |
151 elided_labels_.erase(elided_labels_.begin()); | 149 elided_labels_.erase(elided_labels_.begin()); |
152 } | 150 } |
153 | 151 |
154 // The popup contents have changed, so either update the bounds or hide it. | 152 // The popup contents have changed, so either update the bounds or hide it. |
155 if (HasSuggestions()) | 153 if (HasSuggestions()) |
156 UpdateBoundsAndRedrawPopup(); | 154 OnSuggestionsChanged(); |
157 else | 155 else |
158 Hide(); | 156 Hide(); |
159 | 157 |
160 return; | 158 return; |
161 } | 159 } |
162 | 160 |
163 // Add a separator if there are any other values. | 161 // Add a separator if there are any other values. |
164 if (!suggestions_.empty() && | 162 if (!suggestions_.empty() && |
165 suggestions_[0].frontend_id != POPUP_ITEM_ID_SEPARATOR) { | 163 suggestions_[0].frontend_id != POPUP_ITEM_ID_SEPARATOR) { |
166 suggestions_.insert(suggestions_.begin(), autofill::Suggestion()); | 164 suggestions_.insert(suggestions_.begin(), autofill::Suggestion()); |
(...skipping 11 matching lines...) Expand all Loading... | |
178 for (size_t i = 0; i < values.size(); i++) { | 176 for (size_t i = 0; i < values.size(); i++) { |
179 suggestions_[i].value = values[i]; | 177 suggestions_[i].value = values[i]; |
180 suggestions_[i].label = labels[i]; | 178 suggestions_[i].label = labels[i]; |
181 suggestions_[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 179 suggestions_[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
182 | 180 |
183 // TODO(brettw) it looks like these should be elided. | 181 // TODO(brettw) it looks like these should be elided. |
184 elided_values_[i] = values[i]; | 182 elided_values_[i] = values[i]; |
185 elided_labels_[i] = labels[i]; | 183 elided_labels_[i] = labels[i]; |
186 } | 184 } |
187 | 185 |
188 UpdateBoundsAndRedrawPopup(); | 186 OnSuggestionsChanged(); |
189 DCHECK_EQ(suggestions_.size(), elided_values_.size()); | 187 DCHECK_EQ(suggestions_.size(), elided_values_.size()); |
190 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); | 188 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); |
191 } | 189 } |
192 | 190 |
193 void AutofillPopupControllerImpl::Hide() { | 191 void AutofillPopupControllerImpl::Hide() { |
194 controller_common_->RemoveKeyPressCallback(); | 192 controller_common_->RemoveKeyPressCallback(); |
195 if (delegate_) | 193 if (delegate_) |
196 delegate_->OnPopupHidden(); | 194 delegate_->OnPopupHidden(); |
197 | 195 |
198 if (view_) | 196 if (view_) |
(...skipping 14 matching lines...) Expand all Loading... | |
213 switch (event.windowsKeyCode) { | 211 switch (event.windowsKeyCode) { |
214 case ui::VKEY_UP: | 212 case ui::VKEY_UP: |
215 SelectPreviousLine(); | 213 SelectPreviousLine(); |
216 return true; | 214 return true; |
217 case ui::VKEY_DOWN: | 215 case ui::VKEY_DOWN: |
218 SelectNextLine(); | 216 SelectNextLine(); |
219 return true; | 217 return true; |
220 case ui::VKEY_PRIOR: // Page up. | 218 case ui::VKEY_PRIOR: // Page up. |
221 // Set no line and then select the next line in case the first line is not | 219 // Set no line and then select the next line in case the first line is not |
222 // selectable. | 220 // selectable. |
223 SetSelectedLine(kNoSelection); | 221 SetSelectedLine(base::nullopt); |
224 SelectNextLine(); | 222 SelectNextLine(); |
225 return true; | 223 return true; |
226 case ui::VKEY_NEXT: // Page down. | 224 case ui::VKEY_NEXT: // Page down. |
227 SetSelectedLine(GetLineCount() - 1); | 225 SetSelectedLine(GetLineCount() - 1); |
228 return true; | 226 return true; |
229 case ui::VKEY_ESCAPE: | 227 case ui::VKEY_ESCAPE: |
230 Hide(); | 228 Hide(); |
231 return true; | 229 return true; |
232 case ui::VKEY_DELETE: | 230 case ui::VKEY_DELETE: |
233 return (event.modifiers() & content::NativeWebKeyboardEvent::ShiftKey) && | 231 return (event.modifiers() & content::NativeWebKeyboardEvent::ShiftKey) && |
234 RemoveSelectedLine(); | 232 RemoveSelectedLine(); |
235 case ui::VKEY_TAB: | 233 case ui::VKEY_TAB: |
236 // A tab press should cause the selected line to be accepted, but still | 234 // 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 | 235 // return false so the tab key press propagates and changes the cursor |
238 // location. | 236 // location. |
239 AcceptSelectedLine(); | 237 AcceptSelectedLine(); |
240 return false; | 238 return false; |
241 case ui::VKEY_RETURN: | 239 case ui::VKEY_RETURN: |
242 return AcceptSelectedLine(); | 240 return AcceptSelectedLine(); |
243 default: | 241 default: |
244 return false; | 242 return false; |
245 } | 243 } |
246 } | 244 } |
247 | 245 |
248 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { | 246 void AutofillPopupControllerImpl::OnSuggestionsChanged() { |
249 #if !defined(OS_ANDROID) | 247 #if !defined(OS_ANDROID) |
250 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, | 248 // 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. | 249 // 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 | 250 // 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. | 251 // should try and move to its desired position. |
254 layout_model_.UpdatePopupBounds(); | 252 layout_model_.UpdatePopupBounds(); |
255 #endif | 253 #endif |
256 | 254 |
257 // Platform-specific draw call. | 255 // Platform-specific draw call. |
258 view_->UpdateBoundsAndRedrawPopup(); | 256 view_->OnSuggestionsChanged(); |
259 } | 257 } |
260 | 258 |
261 void AutofillPopupControllerImpl::SetSelectionAtPoint(const gfx::Point& point) { | 259 void AutofillPopupControllerImpl::SetSelectionAtPoint(const gfx::Point& point) { |
262 SetSelectedLine(layout_model_.LineFromY(point.y())); | 260 SetSelectedLine(layout_model_.LineFromY(point.y())); |
263 } | 261 } |
264 | 262 |
265 bool AutofillPopupControllerImpl::AcceptSelectedLine() { | 263 bool AutofillPopupControllerImpl::AcceptSelectedLine() { |
266 if (selected_line_ == kNoSelection) | 264 if (!selected_line_) |
267 return false; | 265 return false; |
268 | 266 |
269 DCHECK_GE(selected_line_, 0); | 267 DCHECK_LT(*selected_line_, GetLineCount()); |
270 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); | |
271 | 268 |
272 if (!CanAccept(suggestions_[selected_line_].frontend_id)) | 269 if (!CanAccept(suggestions_[*selected_line_].frontend_id)) |
273 return false; | 270 return false; |
274 | 271 |
275 AcceptSuggestion(selected_line_); | 272 AcceptSuggestion(*selected_line_); |
276 return true; | 273 return true; |
277 } | 274 } |
278 | 275 |
279 void AutofillPopupControllerImpl::SelectionCleared() { | 276 void AutofillPopupControllerImpl::SelectionCleared() { |
280 SetSelectedLine(kNoSelection); | 277 SetSelectedLine(base::nullopt); |
281 } | 278 } |
282 | 279 |
283 void AutofillPopupControllerImpl::AcceptSuggestion(size_t index) { | 280 void AutofillPopupControllerImpl::AcceptSuggestion(size_t index) { |
284 const autofill::Suggestion& suggestion = suggestions_[index]; | 281 const autofill::Suggestion& suggestion = suggestions_[index]; |
285 delegate_->DidAcceptSuggestion(suggestion.value, suggestion.frontend_id, | 282 delegate_->DidAcceptSuggestion(suggestion.value, suggestion.frontend_id, |
286 index); | 283 index); |
287 } | 284 } |
288 | 285 |
289 gfx::Rect AutofillPopupControllerImpl::popup_bounds() const { | 286 gfx::Rect AutofillPopupControllerImpl::popup_bounds() const { |
290 return layout_model_.popup_bounds(); | 287 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, | 352 if (!delegate_->RemoveSuggestion(suggestions_[list_index].value, |
356 suggestions_[list_index].frontend_id)) { | 353 suggestions_[list_index].frontend_id)) { |
357 return false; | 354 return false; |
358 } | 355 } |
359 | 356 |
360 // Remove the deleted element. | 357 // Remove the deleted element. |
361 suggestions_.erase(suggestions_.begin() + list_index); | 358 suggestions_.erase(suggestions_.begin() + list_index); |
362 elided_values_.erase(elided_values_.begin() + list_index); | 359 elided_values_.erase(elided_values_.begin() + list_index); |
363 elided_labels_.erase(elided_labels_.begin() + list_index); | 360 elided_labels_.erase(elided_labels_.begin() + list_index); |
364 | 361 |
365 SetSelectedLine(kNoSelection); | 362 SetSelectedLine(base::nullopt); |
366 | 363 |
367 if (HasSuggestions()) { | 364 if (HasSuggestions()) { |
368 delegate_->ClearPreviewedForm(); | 365 delegate_->ClearPreviewedForm(); |
369 UpdateBoundsAndRedrawPopup(); | 366 OnSuggestionsChanged(); |
370 } else { | 367 } else { |
371 Hide(); | 368 Hide(); |
372 } | 369 } |
373 | 370 |
374 return true; | 371 return true; |
375 } | 372 } |
376 | 373 |
377 ui::NativeTheme::ColorId | 374 ui::NativeTheme::ColorId |
378 AutofillPopupControllerImpl::GetBackgroundColorIDForRow(int index) const { | 375 AutofillPopupControllerImpl::GetBackgroundColorIDForRow(int index) const { |
379 return index == selected_line_ ? | 376 return selected_line_ && index == static_cast<int>(*selected_line_) |
Evan Stade
2017/03/18 00:47:03
since some things are of type size_t and some are
csashi
2017/03/18 02:25:09
Acknowledged. There are many places where we are u
Evan Stade
2017/03/18 02:37:48
Yea, when changing things from size_t to int they
csashi
2017/03/18 03:51:37
Acknowledged.
| |
380 ui::NativeTheme::kColorId_ResultsTableHoveredBackground : | 377 ? ui::NativeTheme::kColorId_ResultsTableHoveredBackground |
381 ui::NativeTheme::kColorId_ResultsTableNormalBackground; | 378 : ui::NativeTheme::kColorId_ResultsTableNormalBackground; |
382 } | 379 } |
383 | 380 |
384 int AutofillPopupControllerImpl::selected_line() const { | 381 base::Optional<size_t> AutofillPopupControllerImpl::selected_line() const { |
385 return selected_line_; | 382 return selected_line_; |
386 } | 383 } |
387 | 384 |
388 const AutofillPopupLayoutModel& AutofillPopupControllerImpl::layout_model() | 385 const AutofillPopupLayoutModel& AutofillPopupControllerImpl::layout_model() |
389 const { | 386 const { |
390 return layout_model_; | 387 return layout_model_; |
391 } | 388 } |
392 | 389 |
393 void AutofillPopupControllerImpl::SetSelectedLine(int selected_line) { | 390 void AutofillPopupControllerImpl::SetSelectedLine( |
391 base::Optional<size_t> selected_line) { | |
394 if (selected_line_ == selected_line) | 392 if (selected_line_ == selected_line) |
395 return; | 393 return; |
396 | 394 |
397 if (selected_line_ != kNoSelection && | 395 if (selected_line) { |
398 static_cast<size_t>(selected_line_) < suggestions_.size()) | 396 DCHECK_LT(*selected_line, suggestions_.size()); |
399 InvalidateRow(selected_line_); | 397 if (!CanAccept(suggestions_[*selected_line].frontend_id)) |
400 | 398 selected_line = base::nullopt; |
401 if (selected_line != kNoSelection) { | |
402 InvalidateRow(selected_line); | |
403 | |
404 if (!CanAccept(suggestions_[selected_line].frontend_id)) | |
405 selected_line = kNoSelection; | |
406 } | 399 } |
407 | 400 |
401 auto previous_selected_line(selected_line_); | |
408 selected_line_ = selected_line; | 402 selected_line_ = selected_line; |
403 view_->OnSelectedRowChanged(previous_selected_line, selected_line_); | |
409 | 404 |
410 if (selected_line_ != kNoSelection) { | 405 if (selected_line_) { |
411 delegate_->DidSelectSuggestion(suggestions_[selected_line_].value, | 406 delegate_->DidSelectSuggestion(suggestions_[*selected_line_].value, |
412 suggestions_[selected_line_].frontend_id); | 407 suggestions_[*selected_line_].frontend_id); |
413 } else { | 408 } else { |
414 delegate_->ClearPreviewedForm(); | 409 delegate_->ClearPreviewedForm(); |
415 } | 410 } |
416 } | 411 } |
417 | 412 |
418 void AutofillPopupControllerImpl::SelectNextLine() { | 413 void AutofillPopupControllerImpl::SelectNextLine() { |
419 int new_selected_line = selected_line_ + 1; | 414 size_t new_selected_line = selected_line_ ? *selected_line_ + 1 : 0; |
420 | 415 |
421 // Skip over any lines that can't be selected. | 416 // Skip over any lines that can't be selected. |
422 while (static_cast<size_t>(new_selected_line) < GetLineCount() && | 417 while (new_selected_line < GetLineCount() && |
423 !CanAccept(suggestions_[new_selected_line].frontend_id)) { | 418 !CanAccept(suggestions_[new_selected_line].frontend_id)) { |
424 ++new_selected_line; | 419 ++new_selected_line; |
425 } | 420 } |
426 | 421 |
427 if (new_selected_line >= static_cast<int>(GetLineCount())) | 422 if (new_selected_line >= GetLineCount()) |
428 new_selected_line = 0; | 423 new_selected_line = 0; |
429 | 424 |
430 SetSelectedLine(new_selected_line); | 425 SetSelectedLine(new_selected_line); |
431 } | 426 } |
432 | 427 |
433 void AutofillPopupControllerImpl::SelectPreviousLine() { | 428 void AutofillPopupControllerImpl::SelectPreviousLine() { |
434 int new_selected_line = selected_line_ - 1; | 429 int new_selected_line; |
Evan Stade
2017/03/18 00:47:03
nit: int new_selected_line = selected_line_.value_
csashi
2017/03/18 02:25:09
Done. Did you mean selected_line_.value_or(GetLine
| |
430 if (selected_line_) { | |
431 new_selected_line = *selected_line_ - 1; | |
435 | 432 |
436 // Skip over any lines that can't be selected. | 433 // Skip over any lines that can't be selected. |
437 while (new_selected_line > kNoSelection && | 434 while (new_selected_line >= 0 && |
438 !CanAccept(GetSuggestionAt(new_selected_line).frontend_id)) { | 435 !CanAccept(GetSuggestionAt(new_selected_line).frontend_id)) { |
439 --new_selected_line; | 436 --new_selected_line; |
437 } | |
438 | |
439 if (new_selected_line < 0) | |
440 new_selected_line = GetLineCount() - 1; | |
441 } else { | |
442 new_selected_line = GetLineCount() - 1; | |
440 } | 443 } |
441 | 444 |
442 if (new_selected_line <= kNoSelection) | |
443 new_selected_line = GetLineCount() - 1; | |
444 | |
445 SetSelectedLine(new_selected_line); | 445 SetSelectedLine(new_selected_line); |
446 } | 446 } |
447 | 447 |
448 bool AutofillPopupControllerImpl::RemoveSelectedLine() { | 448 bool AutofillPopupControllerImpl::RemoveSelectedLine() { |
449 if (selected_line_ == kNoSelection) | 449 if (!selected_line_) |
450 return false; | 450 return false; |
451 | 451 |
452 DCHECK_GE(selected_line_, 0); | 452 DCHECK_LT(*selected_line_, GetLineCount()); |
453 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); | 453 return RemoveSuggestion(*selected_line_); |
454 return RemoveSuggestion(selected_line_); | |
455 } | 454 } |
456 | 455 |
457 bool AutofillPopupControllerImpl::CanAccept(int id) { | 456 bool AutofillPopupControllerImpl::CanAccept(int id) { |
458 return id != POPUP_ITEM_ID_SEPARATOR && | 457 return id != POPUP_ITEM_ID_SEPARATOR && |
459 id != POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE && | 458 id != POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE && |
460 id != POPUP_ITEM_ID_TITLE; | 459 id != POPUP_ITEM_ID_TITLE; |
461 } | 460 } |
462 | 461 |
463 bool AutofillPopupControllerImpl::HasSuggestions() { | 462 bool AutofillPopupControllerImpl::HasSuggestions() { |
464 if (suggestions_.empty()) | 463 if (suggestions_.empty()) |
(...skipping 10 matching lines...) Expand all Loading... | |
475 const std::vector<autofill::Suggestion>& suggestions) { | 474 const std::vector<autofill::Suggestion>& suggestions) { |
476 suggestions_ = suggestions; | 475 suggestions_ = suggestions; |
477 elided_values_.resize(suggestions.size()); | 476 elided_values_.resize(suggestions.size()); |
478 elided_labels_.resize(suggestions.size()); | 477 elided_labels_.resize(suggestions.size()); |
479 for (size_t i = 0; i < suggestions.size(); i++) { | 478 for (size_t i = 0; i < suggestions.size(); i++) { |
480 elided_values_[i] = suggestions[i].value; | 479 elided_values_[i] = suggestions[i].value; |
481 elided_labels_[i] = suggestions[i].label; | 480 elided_labels_[i] = suggestions[i].label; |
482 } | 481 } |
483 } | 482 } |
484 | 483 |
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() { | 484 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() { |
496 return weak_ptr_factory_.GetWeakPtr(); | 485 return weak_ptr_factory_.GetWeakPtr(); |
497 } | 486 } |
498 | 487 |
499 #if !defined(OS_ANDROID) | 488 #if !defined(OS_ANDROID) |
500 void AutofillPopupControllerImpl::ElideValueAndLabelForRow( | 489 void AutofillPopupControllerImpl::ElideValueAndLabelForRow( |
501 size_t row, | 490 size_t row, |
502 int available_width) { | 491 int available_width) { |
503 int value_width = gfx::GetStringWidth( | 492 int value_width = gfx::GetStringWidth( |
504 suggestions_[row].value, layout_model_.GetValueFontListForRow(row)); | 493 suggestions_[row].value, layout_model_.GetValueFontListForRow(row)); |
(...skipping 19 matching lines...) Expand all Loading... | |
524 } | 513 } |
525 #endif | 514 #endif |
526 | 515 |
527 void AutofillPopupControllerImpl::ClearState() { | 516 void AutofillPopupControllerImpl::ClearState() { |
528 // Don't clear view_, because otherwise the popup will have to get regenerated | 517 // Don't clear view_, because otherwise the popup will have to get regenerated |
529 // and this will cause flickering. | 518 // and this will cause flickering. |
530 suggestions_.clear(); | 519 suggestions_.clear(); |
531 elided_values_.clear(); | 520 elided_values_.clear(); |
532 elided_labels_.clear(); | 521 elided_labels_.clear(); |
533 | 522 |
534 selected_line_ = kNoSelection; | 523 selected_line_.reset(); |
535 } | 524 } |
536 | 525 |
537 } // namespace autofill | 526 } // namespace autofill |
OLD | NEW |