Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 | 187 |
| 188 } // namespace | 188 } // namespace |
| 189 | 189 |
| 190 PaymentSheetViewController::PaymentSheetViewController( | 190 PaymentSheetViewController::PaymentSheetViewController( |
| 191 PaymentRequestSpec* spec, | 191 PaymentRequestSpec* spec, |
| 192 PaymentRequestState* state, | 192 PaymentRequestState* state, |
| 193 PaymentRequestDialogView* dialog) | 193 PaymentRequestDialogView* dialog) |
| 194 : PaymentRequestSheetController(spec, state, dialog), | 194 : PaymentRequestSheetController(spec, state, dialog), |
| 195 pay_button_(nullptr), | 195 pay_button_(nullptr), |
| 196 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { | 196 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { |
| 197 spec->AddObserver(this); | |
| 197 state->AddObserver(this); | 198 state->AddObserver(this); |
| 198 } | 199 } |
| 199 | 200 |
| 200 PaymentSheetViewController::~PaymentSheetViewController() { | 201 PaymentSheetViewController::~PaymentSheetViewController() { |
| 202 spec()->RemoveObserver(this); | |
| 201 state()->RemoveObserver(this); | 203 state()->RemoveObserver(this); |
| 202 } | 204 } |
| 203 | 205 |
| 206 void PaymentSheetViewController::OnSpecUpdated() { | |
| 207 UpdateContentView(); | |
| 208 } | |
| 209 | |
| 204 void PaymentSheetViewController::OnSelectedInformationChanged() { | 210 void PaymentSheetViewController::OnSelectedInformationChanged() { |
| 205 UpdatePayButtonState(state()->is_ready_to_pay()); | 211 UpdatePayButtonState(state()->is_ready_to_pay()); |
| 206 UpdateContentView(); | 212 UpdateContentView(); |
| 207 } | 213 } |
| 208 | 214 |
| 209 std::unique_ptr<views::Button> | 215 std::unique_ptr<views::Button> |
| 210 PaymentSheetViewController::CreatePrimaryButton() { | 216 PaymentSheetViewController::CreatePrimaryButton() { |
| 211 std::unique_ptr<views::Button> button( | 217 std::unique_ptr<views::Button> button( |
| 212 views::MdTextButton::CreateSecondaryUiBlueButton( | 218 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 213 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); | 219 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 233 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | 239 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 234 views::GridLayout::USE_PREF, 0, 0); | 240 views::GridLayout::USE_PREF, 0, 0); |
| 235 | 241 |
| 236 // The shipping address and contact info rows are optional. | 242 // The shipping address and contact info rows are optional. |
| 237 layout->StartRow(0, 0); | 243 layout->StartRow(0, 0); |
| 238 layout->AddView(CreatePaymentSheetSummaryRow().release()); | 244 layout->AddView(CreatePaymentSheetSummaryRow().release()); |
| 239 | 245 |
| 240 if (spec()->request_shipping()) { | 246 if (spec()->request_shipping()) { |
| 241 layout->StartRow(0, 0); | 247 layout->StartRow(0, 0); |
| 242 layout->AddView(CreateShippingRow().release()); | 248 layout->AddView(CreateShippingRow().release()); |
| 243 layout->StartRow(0, 0); | 249 // It's possible for requestShipping to be true and for there to be no |
| 244 layout->AddView(CreateShippingOptionRow().release()); | 250 // shipping options yet (they will come in updateWith). |
| 251 // TODO(crbug.com/xxxxxx): Put a better placeholder row, instead of no row. | |
|
anthonyvd
2017/04/03 15:09:58
nit: you might want an actual bug # here.
Mathieu
2017/04/03 16:27:27
Done.
| |
| 252 std::unique_ptr<views::Button> shipping_row = CreateShippingOptionRow(); | |
| 253 if (shipping_row) { | |
| 254 layout->StartRow(0, 0); | |
| 255 layout->AddView(shipping_row.release()); | |
| 256 } | |
| 245 } | 257 } |
| 246 layout->StartRow(0, 0); | 258 layout->StartRow(0, 0); |
| 247 layout->AddView(CreatePaymentMethodRow().release()); | 259 layout->AddView(CreatePaymentMethodRow().release()); |
| 248 if (spec()->request_payer_name() || spec()->request_payer_email() || | 260 if (spec()->request_payer_name() || spec()->request_payer_email() || |
| 249 spec()->request_payer_phone()) { | 261 spec()->request_payer_phone()) { |
| 250 layout->StartRow(0, 0); | 262 layout->StartRow(0, 0); |
| 251 layout->AddView(CreateContactInfoRow().release()); | 263 layout->AddView(CreateContactInfoRow().release()); |
| 252 } | 264 } |
| 253 } | 265 } |
| 254 | 266 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | 388 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
| 377 section->set_id( | 389 section->set_id( |
| 378 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); | 390 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); |
| 379 return section; | 391 return section; |
| 380 } | 392 } |
| 381 | 393 |
| 382 std::unique_ptr<views::View> | 394 std::unique_ptr<views::View> |
| 383 PaymentSheetViewController::CreateShippingSectionContent() { | 395 PaymentSheetViewController::CreateShippingSectionContent() { |
| 384 auto* profile = state()->selected_shipping_profile(); | 396 auto* profile = state()->selected_shipping_profile(); |
| 385 | 397 |
| 386 return profile ? payments::GetShippingAddressLabel( | 398 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, |
| 387 AddressStyleType::SUMMARY, | 399 state()->GetApplicationLocale(), |
| 388 state()->GetApplicationLocale(), *profile) | 400 *profile) |
| 389 : base::MakeUnique<views::Label>(base::string16()); | 401 : base::MakeUnique<views::Label>(base::string16()); |
| 390 } | 402 } |
| 391 | 403 |
| 392 // Creates the Shipping row, which contains a "Shipping address" label, the | 404 // Creates the Shipping row, which contains a "Shipping address" label, the |
| 393 // user's selected shipping address, and a chevron. | 405 // user's selected shipping address, and a chevron. |
| 394 // +----------------------------------------------+ | 406 // +----------------------------------------------+ |
| 395 // | Shipping Address Barack Obama | | 407 // | Shipping Address Barack Obama | |
| 396 // | 1600 Pennsylvania Ave. > | | 408 // | 1600 Pennsylvania Ave. > | |
| 397 // | 1800MYPOTUS | | 409 // | 1800MYPOTUS | |
| 398 // +----------------------------------------------+ | 410 // +----------------------------------------------+ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 widest_name_column_view_width_); | 491 widest_name_column_view_width_); |
| 480 section->set_tag(static_cast<int>( | 492 section->set_tag(static_cast<int>( |
| 481 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 493 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
| 482 section->set_id( | 494 section->set_id( |
| 483 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 495 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
| 484 return section; | 496 return section; |
| 485 } | 497 } |
| 486 | 498 |
| 487 std::unique_ptr<views::Button> | 499 std::unique_ptr<views::Button> |
| 488 PaymentSheetViewController::CreateShippingOptionRow() { | 500 PaymentSheetViewController::CreateShippingOptionRow() { |
| 489 payments::mojom::PaymentShippingOption* selected_option = | 501 mojom::PaymentShippingOption* selected_option = |
| 490 state()->selected_shipping_option(); | 502 spec()->selected_shipping_option(); |
| 503 if (!selected_option) | |
| 504 return nullptr; | |
| 505 | |
| 491 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( | 506 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( |
| 492 selected_option, selected_option ? spec()->GetFormattedCurrencyAmount( | 507 selected_option, selected_option ? spec()->GetFormattedCurrencyAmount( |
| 493 selected_option->amount->value) | 508 selected_option->amount->value) |
| 494 : base::ASCIIToUTF16("")); | 509 : base::ASCIIToUTF16("")); |
| 495 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 510 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 496 this, GetShippingOptionSectionString(spec()->shipping_type()), | 511 this, GetShippingOptionSectionString(spec()->shipping_type()), |
| 497 std::move(option_label), std::unique_ptr<views::View>(nullptr), | 512 std::move(option_label), std::unique_ptr<views::View>(nullptr), |
| 498 widest_name_column_view_width_); | 513 widest_name_column_view_width_); |
| 499 section->set_tag(static_cast<int>( | 514 section->set_tag(static_cast<int>( |
| 500 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | 515 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); |
| 501 section->set_id( | 516 section->set_id( |
| 502 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | 517 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); |
| 503 return section; | 518 return section; |
| 504 } | 519 } |
| 505 | 520 |
| 506 } // namespace payments | 521 } // namespace payments |
| OLD | NEW |