Chromium Code Reviews| 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 "base/memory/ptr_util.h" | |
| 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | |
| 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | |
| 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | |
| 11 #include "chrome/grit/generated_resources.h" | |
| 12 #include "components/payments/payment_request.h" | |
| 13 #include "components/strings/grit/components_strings.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "ui/gfx/paint_vector_icon.h" | |
| 16 #include "ui/views/controls/image_view.h" | |
| 17 #include "ui/views/layout/box_layout.h" | |
| 18 #include "ui/views/layout/grid_layout.h" | |
| 19 #include "ui/views/vector_icons.h" | |
| 20 | |
| 21 namespace payments { | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 class ContactInfoListItem : public payments::PaymentRequestItemList::Item, | |
| 26 public views::ButtonListener { | |
| 27 public: | |
| 28 ContactInfoListItem(autofill::AutofillProfile* profile, | |
| 29 PaymentRequest* request, | |
| 30 PaymentRequestItemList* list, | |
| 31 bool selected) | |
| 32 : payments::PaymentRequestItemList::Item(request, list, selected), | |
| 33 profile_(profile) {} | |
| 34 ~ContactInfoListItem() override {} | |
| 35 | |
| 36 private: | |
| 37 std::unique_ptr<views::View> CreateItemView() override { | |
|
Mathieu
2017/02/28 17:35:59
This will be similar to the shipping addresses lis
anthonyvd
2017/02/28 18:36:27
Yeah. I can refactor all of this once this CL and
| |
| 38 std::unique_ptr<PaymentRequestRowView> row = | |
| 39 base::MakeUnique<PaymentRequestRowView>(this); | |
| 40 views::GridLayout* layout = new views::GridLayout(row.get()); | |
| 41 layout->SetInsets( | |
| 42 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, | |
| 43 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets); | |
| 44 row->SetLayoutManager(layout); | |
| 45 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 46 | |
| 47 // A column for the contact info | |
| 48 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
| 49 views::GridLayout::USE_PREF, 0, 0); | |
| 50 | |
| 51 // A padding column that resizes to take up the empty space between the | |
| 52 // leading and trailing parts. | |
| 53 columns->AddPaddingColumn(1, 0); | |
| 54 | |
| 55 // A column for the checkmark when the row is selected. | |
| 56 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
| 57 0, views::GridLayout::USE_PREF, 0, 0); | |
| 58 | |
| 59 layout->StartRow(0, 0); | |
| 60 std::unique_ptr<views::View> contact_info_label = GetContactInfoLabel( | |
| 61 AddressStyleType::DETAILED, std::string(), *profile_, true, true, true); | |
|
Mathieu
2017/02/28 17:35:59
Put a TODO to hook this up with the request option
anthonyvd
2017/02/28 18:36:27
The issue with that is that we're also calling Get
Mathieu
2017/02/28 21:15:16
Yeah ok you're right, it's more unit-testable if w
anthonyvd
2017/03/01 15:27:55
Ack.
| |
| 62 contact_info_label->set_can_process_events_within_subtree(false); | |
| 63 layout->AddView(contact_info_label.release()); | |
| 64 | |
| 65 checkmark_ = base::MakeUnique<views::ImageView>(); | |
| 66 checkmark_->set_id( | |
| 67 static_cast<int>(DialogViewID::CONTACT_INFO_ITEM_CHECKMARK_VIEW)); | |
| 68 checkmark_->set_owned_by_client(); | |
| 69 checkmark_->set_can_process_events_within_subtree(false); | |
| 70 checkmark_->SetImage( | |
| 71 gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265)); | |
| 72 layout->AddView(checkmark_.get()); | |
| 73 if (!selected()) | |
| 74 checkmark_->SetVisible(false); | |
| 75 | |
| 76 return std::move(row); | |
| 77 } | |
| 78 | |
| 79 void SelectedStateChanged() override {} | |
| 80 | |
| 81 void ButtonPressed(views::Button* sender, const ui::Event& event) override {} | |
| 82 | |
| 83 autofill::AutofillProfile* profile_; | |
| 84 std::unique_ptr<views::ImageView> checkmark_; | |
| 85 | |
| 86 DISALLOW_COPY_AND_ASSIGN(ContactInfoListItem); | |
| 87 }; | |
| 88 | |
| 89 } // namespace | |
| 90 | |
| 91 ContactInfoViewController::ContactInfoViewController( | |
| 92 PaymentRequest* request, | |
| 93 PaymentRequestDialogView* dialog) | |
| 94 : PaymentRequestSheetController(request, dialog) { | |
| 95 const std::vector<autofill::AutofillProfile*>& profiles = | |
| 96 request->contact_profiles(); | |
| 97 for (autofill::AutofillProfile* profile : profiles) { | |
| 98 std::unique_ptr<ContactInfoListItem> item = | |
| 99 base::MakeUnique<ContactInfoListItem>( | |
| 100 profile, request, &contact_info_list_, | |
| 101 profile == request->selected_contact_profile()); | |
| 102 contact_info_list_.AddItem(std::move(item)); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 ContactInfoViewController::~ContactInfoViewController() {} | |
| 107 | |
| 108 std::unique_ptr<views::View> ContactInfoViewController::CreateView() { | |
| 109 std::unique_ptr<views::View> list_view = contact_info_list_.CreateListView(); | |
| 110 | |
| 111 return CreatePaymentView( | |
| 112 CreateSheetHeaderView(true, | |
| 113 l10n_util::GetStringUTF16( | |
| 114 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME), | |
| 115 this), | |
| 116 std::move(list_view)); | |
| 117 } | |
| 118 | |
| 119 } // namespace payments | |
| OLD | NEW |