Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_controller_impl.cc

Issue 2727233003: Uses child views in Autofill Popup so we can trigger (Closed)
Patch Set: (int) to NSInteger Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 just_created = true; 94 just_created = true;
100 } 95 }
101 96
102 #if !defined(OS_ANDROID) 97 #if !defined(OS_ANDROID)
103 // Android displays the long text with ellipsis using the view attributes. 98 // Android displays the long text with ellipsis using the view attributes.
104 99
105 layout_model_.UpdatePopupBounds(); 100 layout_model_.UpdatePopupBounds();
106 101
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 (int i = 0; i < GetLineCount(); ++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_ >= GetLineCount())
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
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
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
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(int 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();
291 } 288 }
292 289
293 content::WebContents* AutofillPopupControllerImpl::web_contents() { 290 content::WebContents* AutofillPopupControllerImpl::web_contents() {
(...skipping 11 matching lines...) Expand all
305 bool AutofillPopupControllerImpl::IsRTL() const { 302 bool AutofillPopupControllerImpl::IsRTL() const {
306 return controller_common_->is_rtl(); 303 return controller_common_->is_rtl();
307 } 304 }
308 305
309 const std::vector<autofill::Suggestion> 306 const std::vector<autofill::Suggestion>
310 AutofillPopupControllerImpl::GetSuggestions() { 307 AutofillPopupControllerImpl::GetSuggestions() {
311 return suggestions_; 308 return suggestions_;
312 } 309 }
313 310
314 #if !defined(OS_ANDROID) 311 #if !defined(OS_ANDROID)
315 int AutofillPopupControllerImpl::GetElidedValueWidthForRow(size_t row) { 312 int AutofillPopupControllerImpl::GetElidedValueWidthForRow(int row) {
316 return gfx::GetStringWidth(GetElidedValueAt(row), 313 return gfx::GetStringWidth(GetElidedValueAt(row),
317 layout_model_.GetValueFontListForRow(row)); 314 layout_model_.GetValueFontListForRow(row));
318 } 315 }
319 316
320 int AutofillPopupControllerImpl::GetElidedLabelWidthForRow(size_t row) { 317 int AutofillPopupControllerImpl::GetElidedLabelWidthForRow(int row) {
321 return gfx::GetStringWidth(GetElidedLabelAt(row), 318 return gfx::GetStringWidth(GetElidedLabelAt(row),
322 layout_model_.GetLabelFontListForRow(row)); 319 layout_model_.GetLabelFontListForRow(row));
323 } 320 }
324 #endif 321 #endif
325 322
326 size_t AutofillPopupControllerImpl::GetLineCount() const { 323 int AutofillPopupControllerImpl::GetLineCount() const {
327 return suggestions_.size(); 324 return suggestions_.size();
328 } 325 }
329 326
330 const autofill::Suggestion& AutofillPopupControllerImpl::GetSuggestionAt( 327 const autofill::Suggestion& AutofillPopupControllerImpl::GetSuggestionAt(
331 size_t row) const { 328 int row) const {
332 return suggestions_[row]; 329 return suggestions_[row];
333 } 330 }
334 331
335 const base::string16& AutofillPopupControllerImpl::GetElidedValueAt( 332 const base::string16& AutofillPopupControllerImpl::GetElidedValueAt(
336 size_t row) const { 333 int row) const {
337 return elided_values_[row]; 334 return elided_values_[row];
338 } 335 }
339 336
340 const base::string16& AutofillPopupControllerImpl::GetElidedLabelAt( 337 const base::string16& AutofillPopupControllerImpl::GetElidedLabelAt(
341 size_t row) const { 338 int row) const {
342 return elided_labels_[row]; 339 return elided_labels_[row];
343 } 340 }
344 341
345 bool AutofillPopupControllerImpl::GetRemovalConfirmationText( 342 bool AutofillPopupControllerImpl::GetRemovalConfirmationText(
346 int list_index, 343 int list_index,
347 base::string16* title, 344 base::string16* title,
348 base::string16* body) { 345 base::string16* body) {
349 return delegate_->GetDeletionConfirmationText( 346 return delegate_->GetDeletionConfirmationText(
350 suggestions_[list_index].value, suggestions_[list_index].frontend_id, 347 suggestions_[list_index].value, suggestions_[list_index].frontend_id,
351 title, body); 348 title, body);
352 } 349 }
353 350
354 bool AutofillPopupControllerImpl::RemoveSuggestion(int list_index) { 351 bool AutofillPopupControllerImpl::RemoveSuggestion(int list_index) {
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 == *selected_line_
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<int> 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<int> 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, GetLineCount());
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 int 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 = selected_line_.value_or(0) - 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;
440 } 435 }
441 436
442 if (new_selected_line <= kNoSelection) 437 if (new_selected_line < 0)
443 new_selected_line = GetLineCount() - 1; 438 new_selected_line = GetLineCount() - 1;
444 439
445 SetSelectedLine(new_selected_line); 440 SetSelectedLine(new_selected_line);
446 } 441 }
447 442
448 bool AutofillPopupControllerImpl::RemoveSelectedLine() { 443 bool AutofillPopupControllerImpl::RemoveSelectedLine() {
449 if (selected_line_ == kNoSelection) 444 if (!selected_line_)
450 return false; 445 return false;
451 446
452 DCHECK_GE(selected_line_, 0); 447 DCHECK_LT(*selected_line_, GetLineCount());
453 DCHECK_LT(selected_line_, static_cast<int>(GetLineCount())); 448 return RemoveSuggestion(*selected_line_);
454 return RemoveSuggestion(selected_line_);
455 } 449 }
456 450
457 bool AutofillPopupControllerImpl::CanAccept(int id) { 451 bool AutofillPopupControllerImpl::CanAccept(int id) {
458 return id != POPUP_ITEM_ID_SEPARATOR && 452 return id != POPUP_ITEM_ID_SEPARATOR &&
459 id != POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE && 453 id != POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE &&
460 id != POPUP_ITEM_ID_TITLE; 454 id != POPUP_ITEM_ID_TITLE;
461 } 455 }
462 456
463 bool AutofillPopupControllerImpl::HasSuggestions() { 457 bool AutofillPopupControllerImpl::HasSuggestions() {
464 if (suggestions_.empty()) 458 if (suggestions_.empty())
(...skipping 10 matching lines...) Expand all
475 const std::vector<autofill::Suggestion>& suggestions) { 469 const std::vector<autofill::Suggestion>& suggestions) {
476 suggestions_ = suggestions; 470 suggestions_ = suggestions;
477 elided_values_.resize(suggestions.size()); 471 elided_values_.resize(suggestions.size());
478 elided_labels_.resize(suggestions.size()); 472 elided_labels_.resize(suggestions.size());
479 for (size_t i = 0; i < suggestions.size(); i++) { 473 for (size_t i = 0; i < suggestions.size(); i++) {
480 elided_values_[i] = suggestions[i].value; 474 elided_values_[i] = suggestions[i].value;
481 elided_labels_[i] = suggestions[i].label; 475 elided_labels_[i] = suggestions[i].label;
482 } 476 }
483 } 477 }
484 478
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() { 479 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() {
496 return weak_ptr_factory_.GetWeakPtr(); 480 return weak_ptr_factory_.GetWeakPtr();
497 } 481 }
498 482
499 #if !defined(OS_ANDROID) 483 #if !defined(OS_ANDROID)
500 void AutofillPopupControllerImpl::ElideValueAndLabelForRow( 484 void AutofillPopupControllerImpl::ElideValueAndLabelForRow(
501 size_t row, 485 int row,
502 int available_width) { 486 int available_width) {
503 int value_width = gfx::GetStringWidth( 487 int value_width = gfx::GetStringWidth(
504 suggestions_[row].value, layout_model_.GetValueFontListForRow(row)); 488 suggestions_[row].value, layout_model_.GetValueFontListForRow(row));
505 int label_width = gfx::GetStringWidth( 489 int label_width = gfx::GetStringWidth(
506 suggestions_[row].label, layout_model_.GetLabelFontListForRow(row)); 490 suggestions_[row].label, layout_model_.GetLabelFontListForRow(row));
507 int total_text_length = value_width + label_width; 491 int total_text_length = value_width + label_width;
508 492
509 // The line can have no strings if it represents a UI element, such as 493 // The line can have no strings if it represents a UI element, such as
510 // a separator line. 494 // a separator line.
511 if (total_text_length == 0) 495 if (total_text_length == 0)
(...skipping 12 matching lines...) Expand all
524 } 508 }
525 #endif 509 #endif
526 510
527 void AutofillPopupControllerImpl::ClearState() { 511 void AutofillPopupControllerImpl::ClearState() {
528 // Don't clear view_, because otherwise the popup will have to get regenerated 512 // Don't clear view_, because otherwise the popup will have to get regenerated
529 // and this will cause flickering. 513 // and this will cause flickering.
530 suggestions_.clear(); 514 suggestions_.clear();
531 elided_values_.clear(); 515 elided_values_.clear();
532 elided_labels_.clear(); 516 elided_labels_.clear();
533 517
534 selected_line_ = kNoSelection; 518 selected_line_.reset();
535 } 519 }
536 520
537 } // namespace autofill 521 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698