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" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 | 33 |
34 // Used to indicate that no line is currently selected by the user. | 34 // Used to indicate that no line is currently selected by the user. |
35 const int kNoSelection = -1; | 35 const int kNoSelection = -1; |
36 | 36 |
37 // The vertical height of each row in pixels. | 37 // The vertical height of each row in pixels. |
38 const size_t kRowHeight = 24; | 38 const size_t kRowHeight = 24; |
39 | 39 |
40 // The vertical height of a separator in pixels. | 40 // The vertical height of a separator in pixels. |
41 const size_t kSeparatorHeight = 1; | 41 const size_t kSeparatorHeight = 1; |
42 | 42 |
43 #if !defined(OS_ANDROID) | 43 #if !defined(OS_ANDROID) || defined(USE_AURA) |
44 // Size difference between name and label in pixels. | 44 // Size difference between name and label in pixels. |
45 const int kLabelFontSizeDelta = -2; | 45 const int kLabelFontSizeDelta = -2; |
46 | 46 |
47 const size_t kNamePadding = AutofillPopupView::kNamePadding; | 47 const size_t kNamePadding = AutofillPopupView::kNamePadding; |
48 const size_t kIconPadding = AutofillPopupView::kIconPadding; | 48 const size_t kIconPadding = AutofillPopupView::kIconPadding; |
49 const size_t kEndPadding = AutofillPopupView::kEndPadding; | 49 const size_t kEndPadding = AutofillPopupView::kEndPadding; |
50 #endif | 50 #endif |
51 | 51 |
52 struct DataResource { | 52 struct DataResource { |
53 const char* name; | 53 const char* name; |
54 int id; | 54 int id; |
55 }; | 55 }; |
56 | 56 |
57 const DataResource kDataResources[] = { | 57 const DataResource kDataResources[] = { |
58 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX }, | 58 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX }, |
59 { "dinersCC", IDR_AUTOFILL_CC_GENERIC }, | 59 { "dinersCC", IDR_AUTOFILL_CC_GENERIC }, |
60 { "discoverCC", IDR_AUTOFILL_CC_DISCOVER }, | 60 { "discoverCC", IDR_AUTOFILL_CC_DISCOVER }, |
61 { "genericCC", IDR_AUTOFILL_CC_GENERIC }, | 61 { "genericCC", IDR_AUTOFILL_CC_GENERIC }, |
62 { "jcbCC", IDR_AUTOFILL_CC_GENERIC }, | 62 { "jcbCC", IDR_AUTOFILL_CC_GENERIC }, |
63 { "masterCardCC", IDR_AUTOFILL_CC_MASTERCARD }, | 63 { "masterCardCC", IDR_AUTOFILL_CC_MASTERCARD }, |
64 { "visaCC", IDR_AUTOFILL_CC_VISA }, | 64 { "visaCC", IDR_AUTOFILL_CC_VISA }, |
65 #if defined(OS_ANDROID) | 65 #if defined(OS_ANDROID) && !defined(USE_AURA) |
66 { "scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW }, | 66 { "scanCreditCardIcon", IDR_AUTOFILL_CC_SCAN_NEW }, |
67 { "settings", IDR_AUTOFILL_SETTINGS }, | 67 { "settings", IDR_AUTOFILL_SETTINGS }, |
68 #endif | 68 #endif |
69 }; | 69 }; |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 // static | 73 // static |
74 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetOrCreate( | 74 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetOrCreate( |
75 WeakPtr<AutofillPopupControllerImpl> previous, | 75 WeakPtr<AutofillPopupControllerImpl> previous, |
(...skipping 30 matching lines...) Expand all Loading... | |
106 text_direction, | 106 text_direction, |
107 container_view, | 107 container_view, |
108 web_contents)), | 108 web_contents)), |
109 view_(NULL), | 109 view_(NULL), |
110 delegate_(delegate), | 110 delegate_(delegate), |
111 weak_ptr_factory_(this) { | 111 weak_ptr_factory_(this) { |
112 ClearState(); | 112 ClearState(); |
113 controller_common_->SetKeyPressCallback( | 113 controller_common_->SetKeyPressCallback( |
114 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, | 114 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, |
115 base::Unretained(this))); | 115 base::Unretained(this))); |
116 #if !defined(OS_ANDROID) | 116 #if !defined(OS_ANDROID) || defined(USE_AURA) |
117 label_font_list_ = value_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta); | 117 label_font_list_ = value_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta); |
118 title_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::BOLD); | 118 title_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::BOLD); |
119 #if defined(OS_MACOSX) | 119 #if defined(OS_MACOSX) |
120 // There is no italic version of the system font. | 120 // There is no italic version of the system font. |
121 warning_font_list_ = value_font_list_; | 121 warning_font_list_ = value_font_list_; |
122 #else | 122 #else |
123 warning_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::ITALIC); | 123 warning_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::ITALIC); |
124 #endif | 124 #endif |
125 #endif | 125 #endif |
126 } | 126 } |
127 | 127 |
128 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} | 128 AutofillPopupControllerImpl::~AutofillPopupControllerImpl() {} |
129 | 129 |
130 void AutofillPopupControllerImpl::Show( | 130 void AutofillPopupControllerImpl::Show( |
131 const std::vector<autofill::Suggestion>& suggestions) { | 131 const std::vector<autofill::Suggestion>& suggestions) { |
132 SetValues(suggestions); | 132 SetValues(suggestions); |
133 DCHECK_EQ(suggestions_.size(), elided_values_.size()); | 133 DCHECK_EQ(suggestions_.size(), elided_values_.size()); |
134 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); | 134 DCHECK_EQ(suggestions_.size(), elided_labels_.size()); |
135 | 135 |
136 #if !defined(OS_ANDROID) | 136 #if !defined(OS_ANDROID) || defined(USE_AURA) |
137 // Android displays the long text with ellipsis using the view attributes. | 137 // Android displays the long text with ellipsis using the view attributes. |
138 | 138 |
139 UpdatePopupBounds(); | 139 UpdatePopupBounds(); |
140 int popup_width = popup_bounds().width(); | 140 int popup_width = popup_bounds().width(); |
141 | 141 |
142 // Elide the name and label strings so that the popup fits in the available | 142 // Elide the name and label strings so that the popup fits in the available |
143 // space. | 143 // space. |
144 for (size_t i = 0; i < suggestions_.size(); ++i) { | 144 for (size_t i = 0; i < suggestions_.size(); ++i) { |
145 int value_width = | 145 int value_width = |
146 gfx::GetStringWidth(suggestions_[i].value, GetValueFontListForRow(i)); | 146 gfx::GetStringWidth(suggestions_[i].value, GetValueFontListForRow(i)); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 AcceptSelectedLine(); | 303 AcceptSelectedLine(); |
304 return false; | 304 return false; |
305 case ui::VKEY_RETURN: | 305 case ui::VKEY_RETURN: |
306 return AcceptSelectedLine(); | 306 return AcceptSelectedLine(); |
307 default: | 307 default: |
308 return false; | 308 return false; |
309 } | 309 } |
310 } | 310 } |
311 | 311 |
312 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { | 312 void AutofillPopupControllerImpl::UpdateBoundsAndRedrawPopup() { |
313 #if !defined(OS_ANDROID) | 313 #if !defined(OS_ANDROID) || defined(USE_AURA) |
314 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, | 314 // TODO(csharp): Since UpdatePopupBounds can change the position of the popup, |
315 // the popup could end up jumping from above the element to below it. | 315 // the popup could end up jumping from above the element to below it. |
316 // It is unclear if it is better to keep the popup where it was, or if it | 316 // It is unclear if it is better to keep the popup where it was, or if it |
317 // should try and move to its desired position. | 317 // should try and move to its desired position. |
318 UpdatePopupBounds(); | 318 UpdatePopupBounds(); |
319 #endif | 319 #endif |
320 | 320 |
321 view_->UpdateBoundsAndRedrawPopup(); | 321 view_->UpdateBoundsAndRedrawPopup(); |
322 } | 322 } |
323 | 323 |
(...skipping 28 matching lines...) Expand all Loading... | |
352 int AutofillPopupControllerImpl::GetIconResourceID( | 352 int AutofillPopupControllerImpl::GetIconResourceID( |
353 const base::string16& resource_name) const { | 353 const base::string16& resource_name) const { |
354 int result = -1; | 354 int result = -1; |
355 for (size_t i = 0; i < arraysize(kDataResources); ++i) { | 355 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
356 if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) { | 356 if (resource_name == base::ASCIIToUTF16(kDataResources[i].name)) { |
357 result = kDataResources[i].id; | 357 result = kDataResources[i].id; |
358 break; | 358 break; |
359 } | 359 } |
360 } | 360 } |
361 | 361 |
362 #if defined(OS_ANDROID) | 362 #if defined(OS_ANDROID) && !defined(USE_AURA) |
363 if (result == IDR_AUTOFILL_CC_SCAN_NEW && IsKeyboardAccessoryEnabled()) | 363 if (result == IDR_AUTOFILL_CC_SCAN_NEW && IsKeyboardAccessoryEnabled()) |
364 result = IDR_AUTOFILL_CC_SCAN_NEW_KEYBOARD_ACCESSORY; | 364 result = IDR_AUTOFILL_CC_SCAN_NEW_KEYBOARD_ACCESSORY; |
365 #endif // OS_ANDROID | 365 #endif |
366 | 366 |
367 return result; | 367 return result; |
368 } | 368 } |
369 | 369 |
370 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { | 370 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { |
371 return suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; | 371 return suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; |
372 } | 372 } |
373 | 373 |
374 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { | 374 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { |
375 int top = kPopupBorderThickness; | 375 int top = kPopupBorderThickness; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 if (HasSuggestions()) { | 453 if (HasSuggestions()) { |
454 delegate_->ClearPreviewedForm(); | 454 delegate_->ClearPreviewedForm(); |
455 UpdateBoundsAndRedrawPopup(); | 455 UpdateBoundsAndRedrawPopup(); |
456 } else { | 456 } else { |
457 Hide(); | 457 Hide(); |
458 } | 458 } |
459 | 459 |
460 return true; | 460 return true; |
461 } | 461 } |
462 | 462 |
463 #if !defined(OS_ANDROID) | 463 #if !defined(OS_ANDROID) || defined(USE_AURA) |
464 const gfx::FontList& AutofillPopupControllerImpl::GetValueFontListForRow( | 464 const gfx::FontList& AutofillPopupControllerImpl::GetValueFontListForRow( |
465 size_t index) const { | 465 size_t index) const { |
466 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) | 466 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) |
467 return warning_font_list_; | 467 return warning_font_list_; |
468 | 468 |
469 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_TITLE) | 469 if (suggestions_[index].frontend_id == POPUP_ITEM_ID_TITLE) |
470 return title_font_list_; | 470 return title_font_list_; |
471 | 471 |
472 return value_font_list_; | 472 return value_font_list_; |
473 } | 473 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 void AutofillPopupControllerImpl::ShowView() { | 596 void AutofillPopupControllerImpl::ShowView() { |
597 view_->Show(); | 597 view_->Show(); |
598 } | 598 } |
599 | 599 |
600 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { | 600 void AutofillPopupControllerImpl::InvalidateRow(size_t row) { |
601 DCHECK(0 <= row); | 601 DCHECK(0 <= row); |
602 DCHECK(row < suggestions_.size()); | 602 DCHECK(row < suggestions_.size()); |
603 view_->InvalidateRow(row); | 603 view_->InvalidateRow(row); |
604 } | 604 } |
605 | 605 |
606 #if !defined(OS_ANDROID) | 606 #if !defined(OS_ANDROID) || defined(USE_AURA) |
607 int AutofillPopupControllerImpl::GetDesiredPopupWidth() const { | 607 int AutofillPopupControllerImpl::GetDesiredPopupWidth() const { |
608 int popup_width = controller_common_->RoundedElementBounds().width(); | 608 int popup_width = controller_common_->RoundedElementBounds().width(); |
609 for (size_t i = 0; i < GetLineCount(); ++i) { | 609 for (size_t i = 0; i < GetLineCount(); ++i) { |
610 int row_size = | 610 int row_size = |
611 gfx::GetStringWidth(GetElidedValueAt(i), value_font_list_) + | 611 gfx::GetStringWidth(GetElidedValueAt(i), value_font_list_) + |
612 gfx::GetStringWidth(GetElidedLabelAt(i), label_font_list_) + | 612 gfx::GetStringWidth(GetElidedLabelAt(i), label_font_list_) + |
613 RowWidthWithoutText(i); | 613 RowWidthWithoutText(i); |
614 | 614 |
615 popup_width = std::max(popup_width, row_size); | 615 popup_width = std::max(popup_width, row_size); |
616 } | 616 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 | 650 |
651 return row_size; | 651 return row_size; |
652 } | 652 } |
653 | 653 |
654 void AutofillPopupControllerImpl::UpdatePopupBounds() { | 654 void AutofillPopupControllerImpl::UpdatePopupBounds() { |
655 int popup_width = GetDesiredPopupWidth(); | 655 int popup_width = GetDesiredPopupWidth(); |
656 int popup_height = GetDesiredPopupHeight(); | 656 int popup_height = GetDesiredPopupHeight(); |
657 | 657 |
658 popup_bounds_ = controller_common_->GetPopupBounds(popup_width, popup_height); | 658 popup_bounds_ = controller_common_->GetPopupBounds(popup_width, popup_height); |
659 } | 659 } |
660 #endif // !defined(OS_ANDROID) | 660 #endif |
mfomitchev
2015/11/16 22:45:32
nit: When the ifdef spawns a few dozen lines like
bshe
2015/11/17 17:03:23
The problem of comment is that it could be easily
| |
661 | 661 |
662 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() { | 662 WeakPtr<AutofillPopupControllerImpl> AutofillPopupControllerImpl::GetWeakPtr() { |
663 return weak_ptr_factory_.GetWeakPtr(); | 663 return weak_ptr_factory_.GetWeakPtr(); |
664 } | 664 } |
665 | 665 |
666 void AutofillPopupControllerImpl::ClearState() { | 666 void AutofillPopupControllerImpl::ClearState() { |
667 // Don't clear view_, because otherwise the popup will have to get regenerated | 667 // Don't clear view_, because otherwise the popup will have to get regenerated |
668 // and this will cause flickering. | 668 // and this will cause flickering. |
669 | 669 |
670 popup_bounds_ = gfx::Rect(); | 670 popup_bounds_ = gfx::Rect(); |
671 | 671 |
672 suggestions_.clear(); | 672 suggestions_.clear(); |
673 elided_values_.clear(); | 673 elided_values_.clear(); |
674 elided_labels_.clear(); | 674 elided_labels_.clear(); |
675 | 675 |
676 selected_line_ = kNoSelection; | 676 selected_line_ = kNoSelection; |
677 } | 677 } |
678 | 678 |
679 } // namespace autofill | 679 } // namespace autofill |
OLD | NEW |