| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/views/payments/contact_info_view_controller.h" |
| 6 |
| 7 #include <string> |
| 8 #include <vector> |
| 9 |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 12 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "components/payments/content/payment_request.h" |
| 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/gfx/paint_vector_icon.h" |
| 19 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/layout/box_layout.h" |
| 21 #include "ui/views/layout/grid_layout.h" |
| 22 #include "ui/views/vector_icons.h" |
| 23 |
| 24 namespace payments { |
| 25 |
| 26 namespace { |
| 27 |
| 28 class ContactInfoListItem : public payments::PaymentRequestItemList::Item, |
| 29 public views::ButtonListener { |
| 30 public: |
| 31 // Constructs a ContactInfoListItem object owned by |list|. |request| is the |
| 32 // PaymentRequest object that is represented by the current instance of the |
| 33 // dialog. |profile| is the AutofillProfile that this specific list item |
| 34 // represents. It's a cached profile owned by |request|. |
| 35 ContactInfoListItem(autofill::AutofillProfile* profile, |
| 36 PaymentRequest* request, |
| 37 PaymentRequestItemList* list, |
| 38 bool selected) |
| 39 : payments::PaymentRequestItemList::Item(request, list, selected), |
| 40 profile_(profile) {} |
| 41 ~ContactInfoListItem() override {} |
| 42 |
| 43 private: |
| 44 // payments::PaymentRequestItemList::Item: |
| 45 std::unique_ptr<views::View> CreateItemView() override { |
| 46 std::unique_ptr<PaymentRequestRowView> row = |
| 47 base::MakeUnique<PaymentRequestRowView>(this); |
| 48 views::GridLayout* layout = new views::GridLayout(row.get()); |
| 49 layout->SetInsets( |
| 50 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, |
| 51 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets); |
| 52 row->SetLayoutManager(layout); |
| 53 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 54 |
| 55 // A column for the contact info |
| 56 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
| 57 views::GridLayout::USE_PREF, 0, 0); |
| 58 // A padding column that resizes to take up the empty space between the |
| 59 // leading and trailing parts. |
| 60 columns->AddPaddingColumn(1, 0); |
| 61 |
| 62 // A column for the checkmark when the row is selected. |
| 63 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 64 0, views::GridLayout::USE_PREF, 0, 0); |
| 65 |
| 66 layout->StartRow(0, 0); |
| 67 // TODO(anthonyvd): derive the following boolean options from the requested |
| 68 // options in the PaymentRequest object. |
| 69 std::unique_ptr<views::View> contact_info_label = GetContactInfoLabel( |
| 70 AddressStyleType::DETAILED, std::string(), *profile_, true, true, true); |
| 71 contact_info_label->set_can_process_events_within_subtree(false); |
| 72 layout->AddView(contact_info_label.release()); |
| 73 |
| 74 checkmark_ = base::MakeUnique<views::ImageView>(); |
| 75 checkmark_->set_id( |
| 76 static_cast<int>(DialogViewID::CONTACT_INFO_ITEM_CHECKMARK_VIEW)); |
| 77 checkmark_->set_owned_by_client(); |
| 78 checkmark_->set_can_process_events_within_subtree(false); |
| 79 checkmark_->SetImage( |
| 80 gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265)); |
| 81 layout->AddView(checkmark_.get()); |
| 82 if (!selected()) |
| 83 checkmark_->SetVisible(false); |
| 84 |
| 85 return std::move(row); |
| 86 } |
| 87 |
| 88 // payments::PaymentRequestItemList::Item: |
| 89 void SelectedStateChanged() override {} |
| 90 |
| 91 // views::ButtonListener: |
| 92 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} |
| 93 |
| 94 autofill::AutofillProfile* profile_; |
| 95 std::unique_ptr<views::ImageView> checkmark_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(ContactInfoListItem); |
| 98 }; |
| 99 |
| 100 } // namespace |
| 101 |
| 102 ContactInfoViewController::ContactInfoViewController( |
| 103 PaymentRequest* request, |
| 104 PaymentRequestDialogView* dialog) |
| 105 : PaymentRequestSheetController(request, dialog) { |
| 106 const std::vector<autofill::AutofillProfile*>& profiles = |
| 107 request->contact_profiles(); |
| 108 for (autofill::AutofillProfile* profile : profiles) { |
| 109 std::unique_ptr<ContactInfoListItem> item = |
| 110 base::MakeUnique<ContactInfoListItem>( |
| 111 profile, request, &contact_info_list_, |
| 112 profile == request->selected_contact_profile()); |
| 113 contact_info_list_.AddItem(std::move(item)); |
| 114 } |
| 115 } |
| 116 |
| 117 ContactInfoViewController::~ContactInfoViewController() {} |
| 118 |
| 119 std::unique_ptr<views::View> ContactInfoViewController::CreateView() { |
| 120 std::unique_ptr<views::View> list_view = contact_info_list_.CreateListView(); |
| 121 |
| 122 return CreatePaymentView( |
| 123 CreateSheetHeaderView(true, |
| 124 l10n_util::GetStringUTF16( |
| 125 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), |
| 126 this), |
| 127 std::move(list_view)); |
| 128 } |
| 129 |
| 130 } // namespace payments |
| OLD | NEW |