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

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 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,
please use gerrit instead 2017/03/01 17:10:14 Specify in a comment the ownership relationship fo
anthonyvd 2017/03/01 20:08:58 Done.
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 {
please use gerrit instead 2017/03/01 17:10:14 Put the name of the interface in a comment for thi
anthonyvd 2017/03/01 20:08:58 Done.
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 // A padding column that resizes to take up the empty space between the
51 // leading and trailing parts.
52 columns->AddPaddingColumn(1, 0);
53
54 // A column for the checkmark when the row is selected.
55 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
56 0, views::GridLayout::USE_PREF, 0, 0);
57
58 layout->StartRow(0, 0);
59 // TODO(anthonyvd): derive the following boolean options from the requested
60 // options in the PaymentRequest object.
61 std::unique_ptr<views::View> contact_info_label = GetContactInfoLabel(
62 AddressStyleType::DETAILED, std::string(), *profile_, true, true, true);
63 contact_info_label->set_can_process_events_within_subtree(false);
64 layout->AddView(contact_info_label.release());
65
66 checkmark_ = base::MakeUnique<views::ImageView>();
67 checkmark_->set_id(
68 static_cast<int>(DialogViewID::CONTACT_INFO_ITEM_CHECKMARK_VIEW));
69 checkmark_->set_owned_by_client();
70 checkmark_->set_can_process_events_within_subtree(false);
71 checkmark_->SetImage(
72 gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265));
73 layout->AddView(checkmark_.get());
74 if (!selected())
75 checkmark_->SetVisible(false);
76
77 return std::move(row);
78 }
79
80 void SelectedStateChanged() override {}
please use gerrit instead 2017/03/01 17:10:14 Put the name of the interface in a comment for thi
anthonyvd 2017/03/01 20:08:57 Done.
81
82 void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
please use gerrit instead 2017/03/01 17:10:14 Put the name of the interface in a comment for thi
anthonyvd 2017/03/01 20:08:58 Done.
83
84 autofill::AutofillProfile* profile_;
85 std::unique_ptr<views::ImageView> checkmark_;
86
87 DISALLOW_COPY_AND_ASSIGN(ContactInfoListItem);
88 };
89
90 } // namespace
91
92 ContactInfoViewController::ContactInfoViewController(
93 PaymentRequest* request,
94 PaymentRequestDialogView* dialog)
95 : PaymentRequestSheetController(request, dialog) {
96 const std::vector<autofill::AutofillProfile*>& profiles =
97 request->contact_profiles();
98 for (autofill::AutofillProfile* profile : profiles) {
99 std::unique_ptr<ContactInfoListItem> item =
100 base::MakeUnique<ContactInfoListItem>(
101 profile, request, &contact_info_list_,
102 profile == request->selected_contact_profile());
103 contact_info_list_.AddItem(std::move(item));
104 }
105 }
106
107 ContactInfoViewController::~ContactInfoViewController() {}
108
109 std::unique_ptr<views::View> ContactInfoViewController::CreateView() {
110 std::unique_ptr<views::View> list_view = contact_info_list_.CreateListView();
111
112 return CreatePaymentView(
113 CreateSheetHeaderView(true,
114 l10n_util::GetStringUTF16(
115 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME),
116 this),
117 std::move(list_view));
118 }
119
120 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698