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

Unified Diff: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc

Issue 2815723002: [Web Payments] Add Spinners and timeout while waiting for UpdateWith (Closed)
Patch Set: Address comments. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
index c7706ff744650a9127975665bf5f521cf2748418..ef5295bd0b6b3bf073a4877a647c644aca49cbd2 100644
--- a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
+++ b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
@@ -186,6 +186,40 @@ std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout(
return layout;
}
+std::unique_ptr<views::View> CreateCheckingSpinnerView() {
+ std::unique_ptr<views::View> container = base::MakeUnique<views::View>();
+
+ std::unique_ptr<views::Throbber> throbber =
+ base::MakeUnique<views::Throbber>();
+ throbber->Start();
+ std::unique_ptr<views::GridLayout> layout =
+ base::MakeUnique<views::GridLayout>(container.get());
+ views::ColumnSet* throbber_columns = layout->AddColumnSet(0);
+ throbber_columns->AddPaddingColumn(0.5, 0);
+ throbber_columns->AddColumn(views::GridLayout::Alignment::CENTER,
+ views::GridLayout::Alignment::TRAILING, 0,
+ views::GridLayout::SizeType::USE_PREF, 0, 0);
+ throbber_columns->AddPaddingColumn(0.5, 0);
+
+ views::ColumnSet* label_columns = layout->AddColumnSet(1);
+ label_columns->AddPaddingColumn(0.5, 0);
+ label_columns->AddColumn(views::GridLayout::Alignment::CENTER,
+ views::GridLayout::Alignment::LEADING, 0,
+ views::GridLayout::SizeType::USE_PREF, 0, 0);
+ label_columns->AddPaddingColumn(0.5, 0);
+
+ layout->StartRow(0.5, 0);
+ layout->AddView(throbber.release());
+
+ layout->StartRow(0.5, 1);
+ layout->AddView(new views::Label(
+ l10n_util::GetStringUTF16(IDS_PAYMENTS_CHECKING_OPTION)));
+
+ container->SetLayoutManager(layout.release());
+
+ return container;
+}
+
} // namespace
PaymentSheetViewController::PaymentSheetViewController(
@@ -194,7 +228,8 @@ PaymentSheetViewController::PaymentSheetViewController(
PaymentRequestDialogView* dialog)
: PaymentRequestSheetController(spec, state, dialog),
pay_button_(nullptr),
- widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) {
+ widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()),
+ current_update_reason_(PaymentRequestSpec::UpdateReason::NONE) {
spec->AddObserver(this);
state->AddObserver(this);
}
@@ -204,7 +239,14 @@ PaymentSheetViewController::~PaymentSheetViewController() {
state()->RemoveObserver(this);
}
+void PaymentSheetViewController::OnStartUpdating(
+ PaymentRequestSpec::UpdateReason reason) {
+ current_update_reason_ = reason;
+ UpdateContentView();
+}
+
void PaymentSheetViewController::OnSpecUpdated() {
+ current_update_reason_ = PaymentRequestSpec::UpdateReason::NONE;
UpdateContentView();
}
@@ -394,12 +436,17 @@ PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
std::unique_ptr<views::View>
PaymentSheetViewController::CreateShippingSectionContent() {
- auto* profile = state()->selected_shipping_profile();
+ if (current_update_reason_ ==
+ PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS) {
+ return CreateCheckingSpinnerView();
+ } else {
+ auto* profile = state()->selected_shipping_profile();
- return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY,
- state()->GetApplicationLocale(),
- *profile)
- : base::MakeUnique<views::Label>(base::string16());
+ return profile ? GetShippingAddressLabel(AddressStyleType::SUMMARY,
+ state()->GetApplicationLocale(),
+ *profile)
+ : base::MakeUnique<views::Label>(base::string16());
+ }
}
// Creates the Shipping row, which contains a "Shipping address" label, the
@@ -501,16 +548,25 @@ std::unique_ptr<views::Button>
PaymentSheetViewController::CreateShippingOptionRow() {
mojom::PaymentShippingOption* selected_option =
spec()->selected_shipping_option();
- if (!selected_option)
+ if (!selected_option &&
+ current_update_reason_ !=
+ PaymentRequestSpec::UpdateReason::SHIPPING_OPTION) {
return nullptr;
+ }
+
+ std::unique_ptr<views::View> option_row_content =
+ current_update_reason_ ==
+ PaymentRequestSpec::UpdateReason::SHIPPING_OPTION
+ ? CreateCheckingSpinnerView()
+ : CreateShippingOptionLabel(selected_option,
+ selected_option
+ ? spec()->GetFormattedCurrencyAmount(
+ selected_option->amount->value)
+ : base::ASCIIToUTF16(""));
- std::unique_ptr<views::View> option_label = CreateShippingOptionLabel(
- selected_option, selected_option ? spec()->GetFormattedCurrencyAmount(
- selected_option->amount->value)
- : base::ASCIIToUTF16(""));
std::unique_ptr<views::Button> section = CreatePaymentSheetRow(
this, GetShippingOptionSectionString(spec()->shipping_type()),
- std::move(option_label), std::unique_ptr<views::View>(nullptr),
+ std::move(option_row_content), std::unique_ptr<views::View>(nullptr),
widest_name_column_view_width_);
section->set_tag(static_cast<int>(
PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON));
« no previous file with comments | « chrome/browser/ui/views/payments/payment_sheet_view_controller.h ('k') | components/payments/content/payment_request_spec.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698