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

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

Issue 2715213005: [Payments] Add the pay button, and control its enabled state (Closed)
Patch Set: addressed 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
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 <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 17 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
19 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 19 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 20 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
21 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
22 #include "components/autofill/core/browser/autofill_type.h" 22 #include "components/autofill/core/browser/autofill_type.h"
23 #include "components/autofill/core/browser/credit_card.h" 23 #include "components/autofill/core/browser/credit_card.h"
24 #include "components/autofill/core/browser/field_types.h" 24 #include "components/autofill/core/browser/field_types.h"
25 #include "components/autofill/core/browser/personal_data_manager.h" 25 #include "components/autofill/core/browser/personal_data_manager.h"
26 #include "components/payments/content/payment_request.h"
27 #include "components/payments/core/currency_formatter.h" 26 #include "components/payments/core/currency_formatter.h"
28 #include "components/strings/grit/components_strings.h" 27 #include "components/strings/grit/components_strings.h"
29 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
30 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/gfx/color_utils.h" 30 #include "ui/gfx/color_utils.h"
32 #include "ui/gfx/font.h" 31 #include "ui/gfx/font.h"
33 #include "ui/gfx/paint_vector_icon.h" 32 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/gfx/range/range.h" 33 #include "ui/gfx/range/range.h"
35 #include "ui/views/controls/button/label_button.h"
36 #include "ui/views/controls/button/md_text_button.h" 34 #include "ui/views/controls/button/md_text_button.h"
37 #include "ui/views/controls/image_view.h" 35 #include "ui/views/controls/image_view.h"
38 #include "ui/views/controls/label.h" 36 #include "ui/views/controls/label.h"
39 #include "ui/views/controls/styled_label.h" 37 #include "ui/views/controls/styled_label.h"
40 #include "ui/views/layout/fill_layout.h" 38 #include "ui/views/layout/fill_layout.h"
41 #include "ui/views/layout/grid_layout.h" 39 #include "ui/views/layout/grid_layout.h"
42 #include "ui/views/vector_icons.h" 40 #include "ui/views/vector_icons.h"
43 #include "ui/views/view.h" 41 #include "ui/views/view.h"
44 42
45 namespace payments { 43 namespace payments {
46 namespace { 44 namespace {
47 45
48 constexpr int kFirstTagValue = static_cast<int>( 46 constexpr int kFirstTagValue = static_cast<int>(
49 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); 47 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
50 48
51 enum class PaymentSheetViewControllerTags { 49 enum class PaymentSheetViewControllerTags {
52 // The tag for the button that navigates to the Order Summary sheet. 50 // The tag for the button that navigates to the Order Summary sheet.
53 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue, 51 SHOW_ORDER_SUMMARY_BUTTON = kFirstTagValue,
54 SHOW_SHIPPING_BUTTON, 52 SHOW_SHIPPING_BUTTON,
55 SHOW_PAYMENT_METHOD_BUTTON, 53 SHOW_PAYMENT_METHOD_BUTTON,
56 SHOW_CONTACT_INFO_BUTTON, 54 SHOW_CONTACT_INFO_BUTTON,
55 PAY_BUTTON
57 }; 56 };
58 57
59 int ComputeWidestNameColumnViewWidth() { 58 int ComputeWidestNameColumnViewWidth() {
60 // The name colums in each row should all have the same width, large enough to 59 // The name colums in each row should all have the same width, large enough to
61 // accomodate the longest piece of text they contain. Because of this, each 60 // accomodate the longest piece of text they contain. Because of this, each
62 // row's GridLayout requires its first column to have a fixed width of the 61 // row's GridLayout requires its first column to have a fixed width of the
63 // correct size. To measure the required size, layout a label with each 62 // correct size. To measure the required size, layout a label with each
64 // section name, measure its width, then initialize |widest_column_width| 63 // section name, measure its width, then initialize |widest_column_width|
65 // with the largest value. 64 // with the largest value.
66 std::vector<int> section_names{ 65 std::vector<int> section_names{
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 159
161 return std::move(row); 160 return std::move(row);
162 } 161 }
163 162
164 } // namespace 163 } // namespace
165 164
166 PaymentSheetViewController::PaymentSheetViewController( 165 PaymentSheetViewController::PaymentSheetViewController(
167 PaymentRequest* request, 166 PaymentRequest* request,
168 PaymentRequestDialogView* dialog) 167 PaymentRequestDialogView* dialog)
169 : PaymentRequestSheetController(request, dialog), 168 : PaymentRequestSheetController(request, dialog),
170 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) {} 169 pay_button_(nullptr),
170 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) {
171 request->AddObserver(this);
172 }
171 173
172 PaymentSheetViewController::~PaymentSheetViewController() {} 174 PaymentSheetViewController::~PaymentSheetViewController() {}
173 175
174 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { 176 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
175 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 177 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
176 178
177 views::GridLayout* layout = new views::GridLayout(content_view.get()); 179 views::GridLayout* layout = new views::GridLayout(content_view.get());
178 content_view->SetLayoutManager(layout); 180 content_view->SetLayoutManager(layout);
179 views::ColumnSet* columns = layout->AddColumnSet(0); 181 views::ColumnSet* columns = layout->AddColumnSet(0);
180 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 182 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
181 1, views::GridLayout::USE_PREF, 0, 0); 183 1, views::GridLayout::USE_PREF, 0, 0);
182 184
183 layout->StartRow(0, 0); 185 layout->StartRow(0, 0);
184 layout->AddView(CreatePaymentSheetSummaryRow().release()); 186 layout->AddView(CreatePaymentSheetSummaryRow().release());
185 layout->StartRow(1, 0); 187 layout->StartRow(1, 0);
186 layout->AddView(CreateShippingRow().release()); 188 layout->AddView(CreateShippingRow().release());
187 layout->StartRow(0, 0); 189 layout->StartRow(0, 0);
188 layout->AddView(CreatePaymentMethodRow().release()); 190 layout->AddView(CreatePaymentMethodRow().release());
189 layout->StartRow(1, 0); 191 layout->StartRow(1, 0);
190 layout->AddView(CreateContactInfoRow().release()); 192 layout->AddView(CreateContactInfoRow().release());
191 193
192 return CreatePaymentView( 194 return CreatePaymentView(
193 CreateSheetHeaderView( 195 CreateSheetHeaderView(
194 false, 196 false,
195 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), 197 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
196 this), 198 this),
197 std::move(content_view)); 199 std::move(content_view));
198 } 200 }
199 201
202 std::unique_ptr<views::Button>
203 PaymentSheetViewController::CreatePrimaryButton() {
204 std::unique_ptr<views::Button> button(
205 views::MdTextButton::CreateSecondaryUiBlueButton(
206 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON)));
207 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG));
208 button->set_id(static_cast<int>(DialogViewID::PAYMENT_SHEET_PAY_BUTTON));
209 pay_button_ = button.get();
210 UpdatePayButtonState(request()->is_ready_to_pay());
211 return button;
212 }
213
214 void PaymentSheetViewController::OnSelectedInformationChanged() {
215 UpdatePayButtonState(request()->is_ready_to_pay());
216 }
217
200 void PaymentSheetViewController::ButtonPressed( 218 void PaymentSheetViewController::ButtonPressed(
201 views::Button* sender, const ui::Event& event) { 219 views::Button* sender, const ui::Event& event) {
202 switch (sender->tag()) { 220 switch (sender->tag()) {
203 case static_cast<int>( 221 case static_cast<int>(
204 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): 222 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON):
205 dialog()->ShowOrderSummary(); 223 dialog()->ShowOrderSummary();
206 break; 224 break;
207 225
208 case static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON): 226 case static_cast<int>(PaymentSheetViewControllerTags::SHOW_SHIPPING_BUTTON):
209 dialog()->ShowShippingListSheet(); 227 dialog()->ShowShippingListSheet();
210 break; 228 break;
211 229
212 case static_cast<int>( 230 case static_cast<int>(
213 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON): 231 PaymentSheetViewControllerTags::SHOW_PAYMENT_METHOD_BUTTON):
214 dialog()->ShowPaymentMethodSheet(); 232 dialog()->ShowPaymentMethodSheet();
215 break; 233 break;
216 234
217 case static_cast<int>( 235 case static_cast<int>(
218 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON): 236 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON):
219 // TODO(tmartino): Transition to contact info page once it exists. 237 // TODO(tmartino): Transition to contact info page once it exists.
220 break; 238 break;
221 239
222 default: 240 default:
223 PaymentRequestSheetController::ButtonPressed(sender, event); 241 PaymentRequestSheetController::ButtonPressed(sender, event);
224 break; 242 break;
225 } 243 }
226 } 244 }
227 245
246 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) {
247 pay_button_->SetEnabled(enabled);
248 }
249
228 std::unique_ptr<views::View> 250 std::unique_ptr<views::View>
229 PaymentSheetViewController::CreateOrderSummarySectionContent() { 251 PaymentSheetViewController::CreateOrderSummarySectionContent() {
230 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( 252 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter(
231 request()->details()->total->amount->currency, 253 request()->details()->total->amount->currency,
232 request()->details()->total->amount->currency_system, 254 request()->details()->total->amount->currency_system,
233 g_browser_process->GetApplicationLocale()); 255 g_browser_process->GetApplicationLocale());
234 base::string16 label_value = l10n_util::GetStringFUTF16( 256 base::string16 label_value = l10n_util::GetStringFUTF16(
235 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, 257 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT,
236 base::UTF8ToUTF16(request()->details()->total->label), 258 base::UTF8ToUTF16(request()->details()->total->label),
237 base::UTF8ToUTF16(formatter->formatted_currency_code()), 259 base::UTF8ToUTF16(formatter->formatted_currency_code()),
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), 386 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr),
365 widest_name_column_view_width_); 387 widest_name_column_view_width_);
366 section->set_tag(static_cast<int>( 388 section->set_tag(static_cast<int>(
367 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); 389 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON));
368 section->set_id( 390 section->set_id(
369 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); 391 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION));
370 return section; 392 return section;
371 } 393 }
372 394
373 } // namespace payments 395 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698