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

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

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

Powered by Google App Engine
This is Rietveld 408576698