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

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

Issue 2592833002: [WebPayments] Start populating the Payment Sheet. (Closed)
Patch Set: Address comments Created 3 years, 11 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/views/payments/payment_sheet_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/payments/payment_request_impl.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 14 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
14 #include "chrome/grit/generated_resources.h" 15 #include "chrome/grit/generated_resources.h"
16 #include "components/strings/grit/components_strings.h"
17 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/color_utils.h"
20 #include "ui/gfx/font.h"
21 #include "ui/gfx/geometry/insets.h"
22 #include "ui/gfx/paint_vector_icon.h"
23 #include "ui/gfx/range/range.h"
24 #include "ui/gfx/vector_icons/vector_icons.h"
25 #include "ui/views/border.h"
26 #include "ui/views/controls/button/custom_button.h"
16 #include "ui/views/controls/button/label_button.h" 27 #include "ui/views/controls/button/label_button.h"
17 #include "ui/views/controls/button/md_text_button.h" 28 #include "ui/views/controls/button/md_text_button.h"
29 #include "ui/views/controls/image_view.h"
30 #include "ui/views/controls/label.h"
31 #include "ui/views/controls/styled_label.h"
18 #include "ui/views/layout/grid_layout.h" 32 #include "ui/views/layout/grid_layout.h"
19 #include "ui/views/view.h" 33 #include "ui/views/view.h"
20 34
35 namespace payments {
36
please use gerrit instead 2017/01/04 19:17:11 nit: no blank line
anthonyvd 2017/01/05 16:45:42 Done.
21 namespace { 37 namespace {
22 38
23 // The tag for the button that navigates to the Order Summary sheet. 39 enum class PaymentSheetViewControllerTags {
24 constexpr int kOrderSummaryTag = 0; 40 // The tag for the button that navigates to the Order Summary sheet.
41 SHOW_ORDER_SUMMARY_BUTTON = static_cast<int>(
42 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX),
43 };
44
45 // Creates a clickable row to be displayed in the Payment Sheet. It contains
46 // a section name and some content, followed by a chevron as a clickability
47 // affordance. Both, either, or none of |content_view| and |extra_content_view|
48 // may be present, the difference between the two being that content is pinned
49 // to the left and extra_content is pinned to the right.
50 // The row also displays a light gray horizontal ruler on its lower boundary.
51 // +----------------------------+
52 // | Name | Content | Extra | > |
53 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler
54 class PaymentSheetRow : public views::CustomButton {
55 public:
56 PaymentSheetRow(views::ButtonListener* listener,
57 const base::string16& section_name,
58 std::unique_ptr<views::View> content_view,
59 std::unique_ptr<views::View> extra_content_view)
60 : views::CustomButton(listener) {
61 SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY));
62 views::GridLayout* layout = new views::GridLayout(this);
63
64 constexpr int kRowVerticalInset = 18;
65 // The rows have extra inset compared to the header so that their right edge
66 // lines up with the close button's X rather than its invisible right edge.
67 constexpr int kRowExtraRightInset = 8;
68 layout->SetInsets(
69 kRowVerticalInset, 0, kRowVerticalInset, kRowExtraRightInset);
70 SetLayoutManager(layout);
71
72 views::ColumnSet* columns = layout->AddColumnSet(0);
73 // A column for the section name.
74 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER,
75 0, views::GridLayout::USE_PREF, 0, 0);
76 // A column for the content.
77 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
78 1, views::GridLayout::USE_PREF, 0, 0);
79 // A column for the extra content.
80 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
81 0, views::GridLayout::USE_PREF, 0, 0);
82
83 constexpr int kPaddingColumnsWidth = 25;
84 columns->AddPaddingColumn(0, kPaddingColumnsWidth);
85 // A column for the chevron.
86 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
87 0, views::GridLayout::USE_PREF, 0, 0);
88
89 layout->StartRow(0, 0);
90 views::Label* name_label = new views::Label(section_name);
91 layout->AddView(name_label);
92
93 if (content_view) {
94 layout->AddView(content_view.release());
95 } else {
96 layout->SkipColumns(1);
97 }
98
99 if (extra_content_view) {
100 layout->AddView(extra_content_view.release());
101 } else {
102 layout->SkipColumns(1);
103 }
104
105 views::ImageView* chevron = new views::ImageView();
106 chevron->SetImage(gfx::CreateVectorIcon(
107 gfx::VectorIconId::SUBMENU_ARROW,
108 color_utils::DeriveDefaultIconColor(name_label->enabled_color())));
109 layout->AddView(chevron);
110
111 SetFocusForPlatform();
anthonyvd 2017/01/04 19:15:30 Hmm it looks like this isn't the only call needed
anthonyvd 2017/01/05 16:45:42 It turns out focus is hard! From what I can gathe
112 }
113
114 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow);
115 };
25 116
26 } // namespace 117 } // namespace
27 118
28 namespace payments {
29
30 PaymentSheetViewController::PaymentSheetViewController( 119 PaymentSheetViewController::PaymentSheetViewController(
31 PaymentRequestImpl* impl, PaymentRequestDialog* dialog) 120 PaymentRequestImpl* impl, PaymentRequestDialog* dialog)
32 : PaymentRequestSheetController(impl, dialog) {} 121 : PaymentRequestSheetController(impl, dialog) {}
33 122
34 PaymentSheetViewController::~PaymentSheetViewController() {} 123 PaymentSheetViewController::~PaymentSheetViewController() {}
35 124
36 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { 125 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
37 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 126 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
38 127
39 views::GridLayout* layout = new views::GridLayout(content_view.get()); 128 views::GridLayout* layout = new views::GridLayout(content_view.get());
40 content_view->SetLayoutManager(layout); 129 content_view->SetLayoutManager(layout);
41 views::ColumnSet* columns = layout->AddColumnSet(0); 130 views::ColumnSet* columns = layout->AddColumnSet(0);
42 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 131 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
43 0, views::GridLayout::USE_PREF, 0, 0); 132 1, views::GridLayout::USE_PREF, 0, 0);
44 133
45 layout->StartRow(0, 0); 134 layout->StartRow(0, 0);
46 views::LabelButton* order_summary_button = 135 layout->AddView(CreatePaymentSheetSummaryRow().release());
47 views::MdTextButton::CreateSecondaryUiBlueButton(
48 this, base::ASCIIToUTF16("Order Summary"));
49 order_summary_button->set_tag(kOrderSummaryTag);
50 layout->AddView(order_summary_button);
51 136
52 return payments::CreatePaymentView( 137 return CreatePaymentView(
53 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), 138 CreateSheetHeaderView(
139 false,
140 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
141 this),
54 std::move(content_view)); 142 std::move(content_view));
55 } 143 }
56 144
57 void PaymentSheetViewController::ButtonPressed( 145 void PaymentSheetViewController::ButtonPressed(
58 views::Button* sender, const ui::Event& event) { 146 views::Button* sender, const ui::Event& event) {
59 DCHECK_EQ(kOrderSummaryTag, sender->tag()); 147 switch (sender->tag()) {
148 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
149 dialog()->CloseDialog();
150 break;
151 case static_cast<int>(
152 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON):
153 dialog()->ShowOrderSummary();
154 break;
155 default:
156 NOTREACHED();
157 }
158 }
60 159
61 dialog()->ShowOrderSummary(); 160 std::unique_ptr<views::View>
161 PaymentSheetViewController::CreateOrderSummarySectionContent() {
162 base::string16 label_value =
163 l10n_util::GetStringFUTF16(
164 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT,
165 base::ASCIIToUTF16(impl()->details()->total->label),
166 base::ASCIIToUTF16(impl()->details()->total->amount->currency),
167 base::ASCIIToUTF16(impl()->details()->total->amount->value));
168
169 return base::MakeUnique<views::Label>(label_value);
170 }
171
172 std::unique_ptr<views::View>
173 PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
174 std::unique_ptr<PaymentSheetRow> section = base::MakeUnique<PaymentSheetRow>(
175 this,
176 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME),
177 std::unique_ptr<views::View>(nullptr),
178 CreateOrderSummarySectionContent());
179 section->set_tag(static_cast<int>(
180 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON));
181 return section;
62 } 182 }
63 183
64 } // namespace payments 184 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698