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/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/ui/autofill/autofill_popup_view.h" | 13 #include "chrome/browser/ui/autofill/autofill_popup_view.h" |
14 #include "chrome/browser/ui/autofill/popup_constants.h" | 14 #include "chrome/browser/ui/autofill/popup_constants.h" |
15 #include "components/autofill/core/browser/autofill_popup_delegate.h" | 15 #include "components/autofill/core/browser/autofill_popup_delegate.h" |
16 #include "components/autofill/core/browser/popup_item_ids.h" | 16 #include "components/autofill/core/browser/popup_item_ids.h" |
17 #include "components/autofill/core/browser/suggestion.h" | 17 #include "components/autofill/core/browser/suggestion.h" |
18 #include "components/autofill/core/common/autofill_util.h" | 18 #include "components/autofill/core/common/autofill_util.h" |
19 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
20 #include "grit/components_scaled_resources.h" | 20 #include "grit/components_scaled_resources.h" |
21 #include "ui/base/resource/material_design/material_design_controller.h" | |
21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
23 #include "ui/gfx/geometry/rect_conversions.h" | 24 #include "ui/gfx/geometry/rect_conversions.h" |
24 #include "ui/gfx/geometry/vector2d.h" | 25 #include "ui/gfx/geometry/vector2d.h" |
25 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
26 #include "ui/gfx/text_elider.h" | 27 #include "ui/gfx/text_elider.h" |
27 #include "ui/gfx/text_utils.h" | 28 #include "ui/gfx/text_utils.h" |
28 | 29 |
29 using base::WeakPtr; | 30 using base::WeakPtr; |
30 | 31 |
31 namespace autofill { | 32 namespace autofill { |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Used to indicate that no line is currently selected by the user. | 35 // Used to indicate that no line is currently selected by the user. |
35 const int kNoSelection = -1; | 36 const int kNoSelection = -1; |
36 | 37 |
37 // The vertical height of each row in pixels. | 38 // The vertical height of each row in pixels. |
38 const size_t kRowHeight = 24; | 39 const size_t kRowHeight = 24; |
40 const size_t kMaterialRowHeight = 36; | |
41 | |
42 // The vertical height of the option row in pixel. | |
43 const size_t kMaterialOptionRowHeight = 44; | |
39 | 44 |
40 // The vertical height of a separator in pixels. | 45 // The vertical height of a separator in pixels. |
41 const size_t kSeparatorHeight = 1; | 46 const size_t kSeparatorHeight = 1; |
42 | 47 |
43 #if !defined(OS_ANDROID) || defined(USE_AURA) | 48 #if !defined(OS_ANDROID) || defined(USE_AURA) |
44 // Size difference between name and label in pixels. | 49 // Size difference between name and label in pixels. |
45 const int kLabelFontSizeDelta = -2; | 50 const int kLabelFontSizeDelta = -2; |
51 const int kMaterialLabelFontSizeDelta = -3; | |
46 | 52 |
47 const size_t kNamePadding = AutofillPopupView::kNamePadding; | 53 const size_t kNamePadding = AutofillPopupView::kNamePadding; |
48 const size_t kIconPadding = AutofillPopupView::kIconPadding; | 54 const size_t kIconPadding = AutofillPopupView::kIconPadding; |
49 const size_t kEndPadding = AutofillPopupView::kEndPadding; | 55 const size_t kEndPadding = AutofillPopupView::kEndPadding; |
56 const size_t kMaterialEndPadding = AutofillPopupView::kMaterialEndPadding; | |
50 #endif | 57 #endif |
51 | 58 |
52 struct DataResource { | 59 struct DataResource { |
53 const char* name; | 60 const char* name; |
54 int id; | 61 int id; |
55 }; | 62 }; |
56 | 63 |
57 const DataResource kDataResources[] = { | 64 const DataResource kDataResources[] = { |
58 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX }, | 65 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX }, |
59 { "dinersCC", IDR_AUTOFILL_CC_GENERIC }, | 66 { "dinersCC", IDR_AUTOFILL_CC_GENERIC }, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 container_view, | 114 container_view, |
108 web_contents)), | 115 web_contents)), |
109 view_(NULL), | 116 view_(NULL), |
110 delegate_(delegate), | 117 delegate_(delegate), |
111 weak_ptr_factory_(this) { | 118 weak_ptr_factory_(this) { |
112 ClearState(); | 119 ClearState(); |
113 controller_common_->SetKeyPressCallback( | 120 controller_common_->SetKeyPressCallback( |
114 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, | 121 base::Bind(&AutofillPopupControllerImpl::HandleKeyPressEvent, |
115 base::Unretained(this))); | 122 base::Unretained(this))); |
116 #if !defined(OS_ANDROID) || defined(USE_AURA) | 123 #if !defined(OS_ANDROID) || defined(USE_AURA) |
117 label_font_list_ = value_font_list_.DeriveWithSizeDelta(kLabelFontSizeDelta); | 124 label_font_list_ = value_font_list_.DeriveWithSizeDelta( |
125 ui::MaterialDesignController::IsModeMaterial() | |
Evan Stade
2015/12/14 21:37:44
please don't reuse this flag. I'm not sure we need
| |
126 ? kMaterialLabelFontSizeDelta | |
127 : kLabelFontSizeDelta); | |
118 title_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::BOLD); | 128 title_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::BOLD); |
119 #if defined(OS_MACOSX) | 129 #if defined(OS_MACOSX) |
120 // There is no italic version of the system font. | 130 // There is no italic version of the system font. |
121 warning_font_list_ = value_font_list_; | 131 warning_font_list_ = value_font_list_; |
122 #else | 132 #else |
123 warning_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::ITALIC); | 133 warning_font_list_ = value_font_list_.DeriveWithStyle(gfx::Font::ITALIC); |
124 #endif | 134 #endif |
125 #endif | 135 #endif |
126 } | 136 } |
127 | 137 |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
370 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { | 380 bool AutofillPopupControllerImpl::IsWarning(size_t index) const { |
371 return suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; | 381 return suggestions_[index].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; |
372 } | 382 } |
373 | 383 |
374 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { | 384 gfx::Rect AutofillPopupControllerImpl::GetRowBounds(size_t index) { |
375 int top = kPopupBorderThickness; | 385 int top = kPopupBorderThickness; |
376 for (size_t i = 0; i < index; ++i) { | 386 for (size_t i = 0; i < index; ++i) { |
377 top += GetRowHeightFromId(suggestions_[i].frontend_id); | 387 top += GetRowHeightFromId(suggestions_[i].frontend_id); |
378 } | 388 } |
379 | 389 |
380 return gfx::Rect( | 390 return gfx::Rect(kPopupBorderThickness, top, |
381 kPopupBorderThickness, | 391 popup_bounds_.width() - 2 * kPopupBorderThickness, |
382 top, | 392 GetRowHeightFromId(suggestions_[index].frontend_id)); |
383 popup_bounds_.width() - 2 * kPopupBorderThickness, | |
384 GetRowHeightFromId(suggestions_[index].frontend_id)); | |
385 } | 393 } |
386 | 394 |
387 void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) { | 395 void AutofillPopupControllerImpl::SetPopupBounds(const gfx::Rect& bounds) { |
388 popup_bounds_ = bounds; | 396 popup_bounds_ = bounds; |
389 UpdateBoundsAndRedrawPopup(); | 397 UpdateBoundsAndRedrawPopup(); |
390 } | 398 } |
391 | 399 |
392 const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const { | 400 const gfx::Rect& AutofillPopupControllerImpl::popup_bounds() const { |
393 return popup_bounds_; | 401 return popup_bounds_; |
394 } | 402 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 } | 564 } |
557 | 565 |
558 // The y value goes beyond the popup so stop the selection at the last line. | 566 // The y value goes beyond the popup so stop the selection at the last line. |
559 return GetLineCount() - 1; | 567 return GetLineCount() - 1; |
560 } | 568 } |
561 | 569 |
562 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { | 570 int AutofillPopupControllerImpl::GetRowHeightFromId(int identifier) const { |
563 if (identifier == POPUP_ITEM_ID_SEPARATOR) | 571 if (identifier == POPUP_ITEM_ID_SEPARATOR) |
564 return kSeparatorHeight; | 572 return kSeparatorHeight; |
565 | 573 |
574 if (ui::MaterialDesignController::IsModeMaterial()) { | |
575 if (identifier == POPUP_ITEM_ID_AUTOFILL_OPTIONS) | |
Evan Stade
2015/12/14 21:37:44
ternary operator
| |
576 return kMaterialOptionRowHeight; | |
577 else | |
578 return kMaterialRowHeight; | |
579 } | |
580 | |
566 return kRowHeight; | 581 return kRowHeight; |
567 } | 582 } |
568 | 583 |
569 bool AutofillPopupControllerImpl::CanAccept(int id) { | 584 bool AutofillPopupControllerImpl::CanAccept(int id) { |
570 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE && | 585 return id != POPUP_ITEM_ID_SEPARATOR && id != POPUP_ITEM_ID_WARNING_MESSAGE && |
571 id != POPUP_ITEM_ID_TITLE; | 586 id != POPUP_ITEM_ID_TITLE; |
572 } | 587 } |
573 | 588 |
574 bool AutofillPopupControllerImpl::HasSuggestions() { | 589 bool AutofillPopupControllerImpl::HasSuggestions() { |
575 if (suggestions_.empty()) | 590 if (suggestions_.empty()) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 int popup_height = 2 * kPopupBorderThickness; | 637 int popup_height = 2 * kPopupBorderThickness; |
623 | 638 |
624 for (size_t i = 0; i < suggestions_.size(); ++i) { | 639 for (size_t i = 0; i < suggestions_.size(); ++i) { |
625 popup_height += GetRowHeightFromId(suggestions_[i].frontend_id); | 640 popup_height += GetRowHeightFromId(suggestions_[i].frontend_id); |
626 } | 641 } |
627 | 642 |
628 return popup_height; | 643 return popup_height; |
629 } | 644 } |
630 | 645 |
631 int AutofillPopupControllerImpl::RowWidthWithoutText(int row) const { | 646 int AutofillPopupControllerImpl::RowWidthWithoutText(int row) const { |
632 int row_size = kEndPadding; | 647 int row_size = ui::MaterialDesignController::IsModeMaterial() |
648 ? kMaterialEndPadding | |
649 : kEndPadding; | |
633 | 650 |
634 if (!elided_labels_[row].empty()) | 651 if (!elided_labels_[row].empty()) |
635 row_size += kNamePadding; | 652 row_size += kNamePadding; |
636 | 653 |
637 // Add the Autofill icon size, if required. | 654 // Add the Autofill icon size, if required. |
638 const base::string16& icon = suggestions_[row].icon; | 655 const base::string16& icon = suggestions_[row].icon; |
639 if (!icon.empty()) { | 656 if (!icon.empty()) { |
640 int icon_width = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 657 int icon_width = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
641 GetIconResourceID(icon)).Width(); | 658 GetIconResourceID(icon)).Width(); |
642 row_size += icon_width + kIconPadding; | 659 row_size += icon_width + kIconPadding; |
643 } | 660 } |
644 | 661 |
645 // Add the padding at the end. | 662 // Add the padding at the end. |
646 row_size += kEndPadding; | 663 row_size += ui::MaterialDesignController::IsModeMaterial() |
664 ? kMaterialEndPadding | |
665 : kEndPadding; | |
647 | 666 |
648 // Add room for the popup border. | 667 // Add room for the popup border. |
649 row_size += 2 * kPopupBorderThickness; | 668 row_size += 2 * kPopupBorderThickness; |
650 | 669 |
651 return row_size; | 670 return row_size; |
652 } | 671 } |
653 | 672 |
654 void AutofillPopupControllerImpl::UpdatePopupBounds() { | 673 void AutofillPopupControllerImpl::UpdatePopupBounds() { |
655 int popup_width = GetDesiredPopupWidth(); | 674 int popup_width = GetDesiredPopupWidth(); |
656 int popup_height = GetDesiredPopupHeight(); | 675 int popup_height = GetDesiredPopupHeight(); |
(...skipping 13 matching lines...) Expand all Loading... | |
670 popup_bounds_ = gfx::Rect(); | 689 popup_bounds_ = gfx::Rect(); |
671 | 690 |
672 suggestions_.clear(); | 691 suggestions_.clear(); |
673 elided_values_.clear(); | 692 elided_values_.clear(); |
674 elided_labels_.clear(); | 693 elided_labels_.clear(); |
675 | 694 |
676 selected_line_ = kNoSelection; | 695 selected_line_ = kNoSelection; |
677 } | 696 } |
678 | 697 |
679 } // namespace autofill | 698 } // namespace autofill |
OLD | NEW |