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

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

Issue 2625183002: [WebPayments] Adding Shipping Address and Contact Info display to order summary (Closed)
Patch Set: 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/string_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/ui/views/payments/payment_request_address_util.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" 14 #include "chrome/browser/ui/views/payments/payment_request_dialog.h"
13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
14 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
15 #include "components/payments/payment_request.h" 17 #include "components/payments/payment_request.h"
16 #include "components/strings/grit/components_strings.h" 18 #include "components/strings/grit/components_strings.h"
17 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 #include "ui/gfx/color_utils.h" 21 #include "ui/gfx/color_utils.h"
20 #include "ui/gfx/font.h" 22 #include "ui/gfx/font.h"
21 #include "ui/gfx/geometry/insets.h" 23 #include "ui/gfx/geometry/insets.h"
22 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
23 #include "ui/gfx/range/range.h" 25 #include "ui/gfx/range/range.h"
24 #include "ui/gfx/vector_icons_public.h" 26 #include "ui/gfx/vector_icons_public.h"
25 #include "ui/views/border.h" 27 #include "ui/views/border.h"
26 #include "ui/views/controls/button/custom_button.h" 28 #include "ui/views/controls/button/custom_button.h"
27 #include "ui/views/controls/button/label_button.h" 29 #include "ui/views/controls/button/label_button.h"
28 #include "ui/views/controls/button/md_text_button.h" 30 #include "ui/views/controls/button/md_text_button.h"
29 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
30 #include "ui/views/controls/label.h" 32 #include "ui/views/controls/label.h"
31 #include "ui/views/controls/styled_label.h" 33 #include "ui/views/controls/styled_label.h"
32 #include "ui/views/layout/grid_layout.h" 34 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/view.h" 35 #include "ui/views/view.h"
34 36
35 namespace payments { 37 namespace payments {
36 namespace { 38 namespace {
37 39
40 constexpr int kFirstTagValue = static_cast<int>(
41 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
42
38 enum class PaymentSheetViewControllerTags { 43 enum class PaymentSheetViewControllerTags {
39 // The tag for the button that navigates to the Order Summary sheet. 44 // The tag for the button that navigates to the Order Summary sheet.
40 SHOW_ORDER_SUMMARY_BUTTON = static_cast<int>( 45 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue,
41 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX), 46 SHOW_SHIPPING_BUTTON = kFirstTagValue + 1,
anthonyvd 2017/01/12 15:42:11 No need for the explicit value on enum members aft
tmartino 2017/01/18 17:28:24 Done
42 }; 47 };
43 48
44 // Creates a clickable row to be displayed in the Payment Sheet. It contains 49 // Creates a clickable row to be displayed in the Payment Sheet. It contains
45 // a section name and some content, followed by a chevron as a clickability 50 // a section name and some content, followed by a chevron as a clickability
46 // affordance. Both, either, or none of |content_view| and |extra_content_view| 51 // affordance. Both, either, or none of |content_view| and |extra_content_view|
47 // may be present, the difference between the two being that content is pinned 52 // may be present, the difference between the two being that content is pinned
48 // to the left and extra_content is pinned to the right. 53 // to the left and extra_content is pinned to the right.
49 // The row also displays a light gray horizontal ruler on its lower boundary. 54 // The row also displays a light gray horizontal ruler on its lower boundary.
50 // +----------------------------+ 55 // +----------------------------+
51 // | Name | Content | Extra | > | 56 // | Name | Content | Extra | > |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 layout->SkipColumns(1); 106 layout->SkipColumns(1);
102 } 107 }
103 108
104 views::ImageView* chevron = new views::ImageView(); 109 views::ImageView* chevron = new views::ImageView();
105 chevron->SetImage(gfx::CreateVectorIcon( 110 chevron->SetImage(gfx::CreateVectorIcon(
106 gfx::VectorIconId::SUBMENU_ARROW, 111 gfx::VectorIconId::SUBMENU_ARROW,
107 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); 112 color_utils::DeriveDefaultIconColor(name_label->enabled_color())));
108 layout->AddView(chevron); 113 layout->AddView(chevron);
109 } 114 }
110 115
116 private:
111 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow); 117 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow);
112 }; 118 };
113 119
114 } // namespace 120 } // namespace
115 121
116 PaymentSheetViewController::PaymentSheetViewController( 122 PaymentSheetViewController::PaymentSheetViewController(
117 PaymentRequest* request, 123 PaymentRequest* request,
118 PaymentRequestDialog* dialog) 124 PaymentRequestDialog* dialog)
119 : PaymentRequestSheetController(request, dialog) {} 125 : PaymentRequestSheetController(request, dialog) {}
120 126
121 PaymentSheetViewController::~PaymentSheetViewController() {} 127 PaymentSheetViewController::~PaymentSheetViewController() {}
122 128
123 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { 129 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
124 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 130 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
125 131
126 views::GridLayout* layout = new views::GridLayout(content_view.get()); 132 views::GridLayout* layout = new views::GridLayout(content_view.get());
127 content_view->SetLayoutManager(layout); 133 content_view->SetLayoutManager(layout);
128 views::ColumnSet* columns = layout->AddColumnSet(0); 134 views::ColumnSet* columns = layout->AddColumnSet(0);
129 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 135 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
130 1, views::GridLayout::USE_PREF, 0, 0); 136 1, views::GridLayout::USE_PREF, 0, 0);
131 137
132 layout->StartRow(0, 0); 138 layout->StartRow(0, 0);
133 layout->AddView(CreatePaymentSheetSummaryRow().release()); 139 layout->AddView(CreatePaymentSheetSummaryRow().release());
134 140
141 layout->StartRow(1, 0);
anthonyvd 2017/01/12 15:42:11 Do you have the first parameter here set to 0 on p
tmartino 2017/01/18 17:28:24 It doesn't have that effect here; the new row appe
142 layout->AddView(CreatePaymentSheetShippingRow().release());
143
135 return CreatePaymentView( 144 return CreatePaymentView(
136 CreateSheetHeaderView( 145 CreateSheetHeaderView(
137 false, 146 false,
138 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), 147 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
139 this), 148 this),
140 std::move(content_view)); 149 std::move(content_view));
141 } 150 }
142 151
143 void PaymentSheetViewController::ButtonPressed( 152 void PaymentSheetViewController::ButtonPressed(
144 views::Button* sender, const ui::Event& event) { 153 views::Button* sender, const ui::Event& event) {
145 switch (sender->tag()) { 154 switch (sender->tag()) {
146 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): 155 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG):
147 dialog()->CloseDialog(); 156 dialog()->CloseDialog();
148 break; 157 break;
149 case static_cast<int>( 158 case static_cast<int>(
150 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): 159 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON):
151 dialog()->ShowOrderSummary(); 160 dialog()->ShowOrderSummary();
152 break; 161 break;
162 case static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON):
163 // TODO(tmartino): Transition to shipping page once it exists.
164 break;
153 default: 165 default:
154 NOTREACHED(); 166 NOTREACHED();
155 } 167 }
156 } 168 }
157 169
158 std::unique_ptr<views::View> 170 std::unique_ptr<views::View>
159 PaymentSheetViewController::CreateOrderSummarySectionContent() { 171 PaymentSheetViewController::CreateOrderSummarySectionContent() {
160 base::string16 label_value = l10n_util::GetStringFUTF16( 172 base::string16 label_value = l10n_util::GetStringFUTF16(
161 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, 173 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT,
162 base::ASCIIToUTF16(request()->details()->total->label), 174 base::ASCIIToUTF16(request()->details()->total->label),
163 base::ASCIIToUTF16(request()->details()->total->amount->currency), 175 base::ASCIIToUTF16(request()->details()->total->amount->currency),
164 base::ASCIIToUTF16(request()->details()->total->amount->value)); 176 base::ASCIIToUTF16(request()->details()->total->amount->value));
165 177
166 return base::MakeUnique<views::Label>(label_value); 178 return base::MakeUnique<views::Label>(label_value);
167 } 179 }
168 180
169 std::unique_ptr<views::Button> 181 std::unique_ptr<views::Button>
170 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { 182 PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
171 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>( 183 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>(
172 this, 184 this,
173 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), 185 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME),
174 std::unique_ptr<views::View>(nullptr), 186 std::unique_ptr<views::View>(nullptr),
175 CreateOrderSummarySectionContent()); 187 CreateOrderSummarySectionContent());
176 section->set_tag(static_cast<int>( 188 section->set_tag(static_cast<int>(
177 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); 189 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON));
178 return section; 190 return section;
179 } 191 }
180 192
193 std::unique_ptr<views::View>
194 PaymentSheetViewController::CreateShippingSectionContent() {
195 return payments::GetPaymentRequestAddressLabel(
196 AddressFormatType::SHIPPING_SUMMARY, "", GetDummyProfile().get());
anthonyvd 2017/01/12 15:42:11 GetDummyProfile().get() here would likely delete t
tmartino 2017/01/18 17:28:24 Done (per your other suggestion)
197 }
198
199 std::unique_ptr<views::Button>
200 PaymentSheetViewController::CreatePaymentSheetShippingRow() {
201 std::unique_ptr<views::Button> section = base::MakeUnique<PaymentSheetRow>(
202 this,
203 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME),
204 CreateShippingSectionContent(), std::unique_ptr<views::View>(nullptr));
205 section->set_tag(
206 static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON));
207 return section;
208 }
209
181 } // namespace payments 210 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698