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

Side by Side Diff: chrome/browser/ui/views/payments/contact_info_view_controller.cc

Issue 2725623004: [Web Payments] Add the contact info screen. (Closed)
Patch Set: Address some comments. Created 3 years, 9 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
(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 {
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 // TODO(anthonyvd): derive the following boolean options from the requested
61 // options in the PaymentRequest object.
62 std::unique_ptr<views::View> contact_info_label = GetContactInfoLabel(
63 AddressStyleType::DETAILED, std::string(), *profile_, true, true, true);
64 contact_info_label->set_can_process_events_within_subtree(false);
65 layout->AddView(contact_info_label.release());
66
67 checkmark_ = base::MakeUnique<views::ImageView>();
68 checkmark_->set_id(
69 static_cast<int>(DialogViewID::CONTACT_INFO_ITEM_CHECKMARK_VIEW));
70 checkmark_->set_owned_by_client();
71 checkmark_->set_can_process_events_within_subtree(false);
72 checkmark_->SetImage(
73 gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265));
74 layout->AddView(checkmark_.get());
75 if (!selected())
76 checkmark_->SetVisible(false);
77
78 return std::move(row);
79 }
80
81 void SelectedStateChanged() override {}
82
83 void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
84
85 autofill::AutofillProfile* profile_;
86 std::unique_ptr<views::ImageView> checkmark_;
87
88 DISALLOW_COPY_AND_ASSIGN(ContactInfoListItem);
89 };
90
91 } // namespace
92
93 ContactInfoViewController::ContactInfoViewController(
94 PaymentRequest* request,
95 PaymentRequestDialogView* dialog)
96 : PaymentRequestSheetController(request, dialog) {
97 const std::vector<autofill::AutofillProfile*>& profiles =
98 request->contact_profiles();
99 for (autofill::AutofillProfile* profile : profiles) {
100 std::unique_ptr<ContactInfoListItem> item =
101 base::MakeUnique<ContactInfoListItem>(
102 profile, request, &contact_info_list_,
103 profile == request->selected_contact_profile());
104 contact_info_list_.AddItem(std::move(item));
105 }
106 }
107
108 ContactInfoViewController::~ContactInfoViewController() {}
109
110 std::unique_ptr<views::View> ContactInfoViewController::CreateView() {
111 std::unique_ptr<views::View> list_view = contact_info_list_.CreateListView();
112
113 return CreatePaymentView(
114 CreateSheetHeaderView(true,
115 l10n_util::GetStringUTF16(
116 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
117 this),
118 std::move(list_view));
119 }
120
121 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698