| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 base::MakeUnique<views::GridLayout>(host); | 179 base::MakeUnique<views::GridLayout>(host); |
| 180 | 180 |
| 181 views::ColumnSet* columns = layout->AddColumnSet(0); | 181 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 182 columns->AddColumn( | 182 columns->AddColumn( |
| 183 trailing ? views::GridLayout::TRAILING : views::GridLayout::LEADING, | 183 trailing ? views::GridLayout::TRAILING : views::GridLayout::LEADING, |
| 184 views::GridLayout::LEADING, 1, views::GridLayout::USE_PREF, 0, 0); | 184 views::GridLayout::LEADING, 1, views::GridLayout::USE_PREF, 0, 0); |
| 185 | 185 |
| 186 return layout; | 186 return layout; |
| 187 } | 187 } |
| 188 | 188 |
| 189 std::unique_ptr<views::View> CreateCheckingSpinnerView() { |
| 190 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); |
| 191 |
| 192 std::unique_ptr<views::Throbber> throbber = |
| 193 base::MakeUnique<views::Throbber>(); |
| 194 throbber->Start(); |
| 195 std::unique_ptr<views::GridLayout> layout = |
| 196 base::MakeUnique<views::GridLayout>(container.get()); |
| 197 views::ColumnSet* throbber_columns = layout->AddColumnSet(0); |
| 198 throbber_columns->AddPaddingColumn(0.5, 0); |
| 199 throbber_columns->AddColumn(views::GridLayout::Alignment::CENTER, |
| 200 views::GridLayout::Alignment::TRAILING, 0, |
| 201 views::GridLayout::SizeType::USE_PREF, 0, 0); |
| 202 throbber_columns->AddPaddingColumn(0.5, 0); |
| 203 |
| 204 views::ColumnSet* label_columns = layout->AddColumnSet(1); |
| 205 label_columns->AddPaddingColumn(0.5, 0); |
| 206 label_columns->AddColumn(views::GridLayout::Alignment::CENTER, |
| 207 views::GridLayout::Alignment::LEADING, 0, |
| 208 views::GridLayout::SizeType::USE_PREF, 0, 0); |
| 209 label_columns->AddPaddingColumn(0.5, 0); |
| 210 |
| 211 layout->StartRow(0.5, 0); |
| 212 layout->AddView(throbber.release()); |
| 213 |
| 214 layout->StartRow(0.5, 1); |
| 215 layout->AddView(new views::Label( |
| 216 l10n_util::GetStringUTF16(IDS_PAYMENTS_CHECKING_OPTION))); |
| 217 |
| 218 container->SetLayoutManager(layout.release()); |
| 219 |
| 220 return container; |
| 221 } |
| 222 |
| 189 } // namespace | 223 } // namespace |
| 190 | 224 |
| 191 PaymentSheetViewController::PaymentSheetViewController( | 225 PaymentSheetViewController::PaymentSheetViewController( |
| 192 PaymentRequestSpec* spec, | 226 PaymentRequestSpec* spec, |
| 193 PaymentRequestState* state, | 227 PaymentRequestState* state, |
| 194 PaymentRequestDialogView* dialog) | 228 PaymentRequestDialogView* dialog) |
| 195 : PaymentRequestSheetController(spec, state, dialog), | 229 : PaymentRequestSheetController(spec, state, dialog), |
| 196 pay_button_(nullptr), | 230 pay_button_(nullptr), |
| 197 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { | 231 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()), |
| 232 current_update_reason_(PaymentRequestSpec::UpdateReason::NONE) { |
| 198 spec->AddObserver(this); | 233 spec->AddObserver(this); |
| 199 state->AddObserver(this); | 234 state->AddObserver(this); |
| 200 } | 235 } |
| 201 | 236 |
| 202 PaymentSheetViewController::~PaymentSheetViewController() { | 237 PaymentSheetViewController::~PaymentSheetViewController() { |
| 203 spec()->RemoveObserver(this); | 238 spec()->RemoveObserver(this); |
| 204 state()->RemoveObserver(this); | 239 state()->RemoveObserver(this); |
| 205 } | 240 } |
| 206 | 241 |
| 207 void PaymentSheetViewController::OnSpecUpdated() { | 242 void PaymentSheetViewController::OnStartUpdating( |
| 243 PaymentRequestSpec::UpdateReason reason) { |
| 244 current_update_reason_ = reason; |
| 208 UpdateContentView(); | 245 UpdateContentView(); |
| 209 } | 246 } |
| 210 | 247 |
| 248 void PaymentSheetViewController::OnSpecUpdated() { |
| 249 current_update_reason_ = PaymentRequestSpec::UpdateReason::NONE; |
| 250 UpdateContentView(); |
| 251 } |
| 252 |
| 211 void PaymentSheetViewController::OnSelectedInformationChanged() { | 253 void PaymentSheetViewController::OnSelectedInformationChanged() { |
| 212 UpdatePayButtonState(state()->is_ready_to_pay()); | 254 UpdatePayButtonState(state()->is_ready_to_pay()); |
| 213 UpdateContentView(); | 255 UpdateContentView(); |
| 214 } | 256 } |
| 215 | 257 |
| 216 std::unique_ptr<views::Button> | 258 std::unique_ptr<views::Button> |
| 217 PaymentSheetViewController::CreatePrimaryButton() { | 259 PaymentSheetViewController::CreatePrimaryButton() { |
| 218 std::unique_ptr<views::Button> button( | 260 std::unique_ptr<views::Button> button( |
| 219 views::MdTextButton::CreateSecondaryUiBlueButton( | 261 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 220 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); | 262 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 widest_name_column_view_width_); | 429 widest_name_column_view_width_); |
| 388 section->set_tag(static_cast<int>( | 430 section->set_tag(static_cast<int>( |
| 389 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | 431 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
| 390 section->set_id( | 432 section->set_id( |
| 391 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); | 433 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); |
| 392 return section; | 434 return section; |
| 393 } | 435 } |
| 394 | 436 |
| 395 std::unique_ptr<views::View> | 437 std::unique_ptr<views::View> |
| 396 PaymentSheetViewController::CreateShippingSectionContent() { | 438 PaymentSheetViewController::CreateShippingSectionContent() { |
| 397 auto* profile = state()->selected_shipping_profile(); | 439 if (current_update_reason_ == |
| 440 PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) { |
| 441 return CreateCheckingSpinnerView(); |
| 442 } else { |
| 443 auto* profile = state()->selected_shipping_profile(); |
| 398 | 444 |
| 399 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, | 445 return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY, |
| 400 state()->GetApplicationLocale(), | 446 state()->GetApplicationLocale(), |
| 401 *profile) | 447 *profile) |
| 402 : base::MakeUnique<views::Label>(base::string16()); | 448 : base::MakeUnique<views::Label>(base::string16()); |
| 449 } |
| 403 } | 450 } |
| 404 | 451 |
| 405 // Creates the Shipping row, which contains a "Shipping address" label, the | 452 // Creates the Shipping row, which contains a "Shipping address" label, the |
| 406 // user's selected shipping address, and a chevron. | 453 // user's selected shipping address, and a chevron. |
| 407 // +----------------------------------------------+ | 454 // +----------------------------------------------+ |
| 408 // | Shipping Address Barack Obama | | 455 // | Shipping Address Barack Obama | |
| 409 // | 1600 Pennsylvania Ave. > | | 456 // | 1600 Pennsylvania Ave. > | |
| 410 // | 1800MYPOTUS | | 457 // | 1800MYPOTUS | |
| 411 // +----------------------------------------------+ | 458 // +----------------------------------------------+ |
| 412 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { | 459 std::unique_ptr<views::Button> PaymentSheetViewController::CreateShippingRow() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 541 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
| 495 section->set_id( | 542 section->set_id( |
| 496 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 543 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
| 497 return section; | 544 return section; |
| 498 } | 545 } |
| 499 | 546 |
| 500 std::unique_ptr<views::Button> | 547 std::unique_ptr<views::Button> |
| 501 PaymentSheetViewController::CreateShippingOptionRow() { | 548 PaymentSheetViewController::CreateShippingOptionRow() { |
| 502 mojom::PaymentShippingOption* selected_option = | 549 mojom::PaymentShippingOption* selected_option = |
| 503 spec()->selected_shipping_option(); | 550 spec()->selected_shipping_option(); |
| 504 if (!selected_option) | 551 if (!selected_option && |
| 552 current_update_reason_ != |
| 553 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION) { |
| 505 return nullptr; | 554 return nullptr; |
| 555 } |
| 506 | 556 |
| 507 std::unique_ptr<views::View> option_label = CreateShippingOptionLabel( | 557 std::unique_ptr<views::View> option_row_content = |
| 508 selected_option, selected_option ? spec()->GetFormattedCurrencyAmount( | 558 current_update_reason_ == |
| 509 selected_option->amount->value) | 559 PaymentRequestSpec::UpdateReason::SHIPPING_OPTION |
| 510 : base::ASCIIToUTF16("")); | 560 ? CreateCheckingSpinnerView() |
| 561 : CreateShippingOptionLabel(selected_option, |
| 562 selected_option |
| 563 ? spec()->GetFormattedCurrencyAmount( |
| 564 selected_option->amount->value) |
| 565 : base::ASCIIToUTF16("")); |
| 566 |
| 511 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 567 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
| 512 this, GetShippingOptionSectionString(spec()->shipping_type()), | 568 this, GetShippingOptionSectionString(spec()->shipping_type()), |
| 513 std::move(option_label), std::unique_ptr<views::View>(nullptr), | 569 std::move(option_row_content), std::unique_ptr<views::View>(nullptr), |
| 514 widest_name_column_view_width_); | 570 widest_name_column_view_width_); |
| 515 section->set_tag(static_cast<int>( | 571 section->set_tag(static_cast<int>( |
| 516 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); | 572 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); |
| 517 section->set_id( | 573 section->set_id( |
| 518 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); | 574 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); |
| 519 return section; | 575 return section; |
| 520 } | 576 } |
| 521 | 577 |
| 522 } // namespace payments | 578 } // namespace payments |
| OLD | NEW |