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

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

Issue 2720223004: Use PaymentRequestItemList for Shipping screen (Closed)
Patch Set: rebase Created 3 years, 10 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
« no previous file with comments | « chrome/browser/ui/views/payments/shipping_list_view_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/payments/shipping_list_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/shipping_list_view_controller.cc b/chrome/browser/ui/views/payments/shipping_list_view_controller.cc
index fee19bf87510033a596375c80246ec4f5cf77b6a..d9b38b7d0e0bb78eb62ed3ee29ec1e1c8ede71dd 100644
--- a/chrome/browser/ui/views/payments/shipping_list_view_controller.cc
+++ b/chrome/browser/ui/views/payments/shipping_list_view_controller.cc
@@ -13,66 +13,93 @@
#include "components/payments/content/payment_request.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/views/controls/image_view.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/grid_layout.h"
namespace payments {
+class ShippingListItem : public payments::PaymentRequestItemList::Item,
+ public views::ButtonListener {
+ public:
+ ShippingListItem(autofill::AutofillProfile* profile,
+ PaymentRequest* request,
+ PaymentRequestItemList* list,
+ bool selected)
+ : payments::PaymentRequestItemList::Item(request, list, selected),
+ profile_(profile) {}
+ ~ShippingListItem() override {}
+
+ private:
+ // payments::PaymentRequestItemList::Item:
+ std::unique_ptr<views::View> CreateItemView() override {
+ DCHECK(profile_);
+
+ // TODO(tmartino): Pass an actual locale in place of empty string.
+ std::unique_ptr<views::View> content = GetShippingAddressLabel(
+ AddressStyleType::DETAILED, std::string(), *profile_);
+
+ std::unique_ptr<PaymentRequestRowView> row =
+ base::MakeUnique<PaymentRequestRowView>(this);
+ views::GridLayout* layout = new views::GridLayout(row.get());
+ row->SetLayoutManager(layout);
+
+ layout->SetInsets(
+ kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
+ kPaymentRequestRowVerticalInsets,
+ kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset);
+
+ // Add a column listing the address.
+ views::ColumnSet* columns = layout->AddColumnSet(0);
+ columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+
+ columns->AddPaddingColumn(1, 0);
+
+ // Add a column for the checkmark shown next to the selected address.
+ columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ content->set_can_process_events_within_subtree(false);
+ layout->AddView(content.release());
+
+ checkmark_ = CreateCheckmark(selected());
+ layout->AddView(checkmark_.get());
+
+ return std::move(row);
+ }
+
+ void SelectedStateChanged() override {}
+
+ // views::ButtonListener:
+ void ButtonPressed(views::Button* sender, const ui::Event& event) override {}
+
+ autofill::AutofillProfile* profile_;
+ std::unique_ptr<views::ImageView> checkmark_;
+};
+
ShippingListViewController::ShippingListViewController(
PaymentRequest* request,
PaymentRequestDialogView* dialog)
- : PaymentRequestSheetController(request, dialog) {}
+ : PaymentRequestSheetController(request, dialog) {
+ auto* selected_profile = request->selected_shipping_profile();
+
+ for (auto* profile : request->shipping_profiles()) {
+ list_.AddItem(base::MakeUnique<ShippingListItem>(
+ profile, request, &list_, profile == selected_profile));
+ }
+}
ShippingListViewController::~ShippingListViewController() {}
std::unique_ptr<views::View> ShippingListViewController::CreateView() {
- std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
-
- views::BoxLayout* layout =
- new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
- layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
- layout->set_cross_axis_alignment(
- views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH);
- content_view->SetLayoutManager(layout);
-
- for (auto* profile : request()->shipping_profiles()) {
- // TODO(tmartino): Pass an actual locale in place of empty string.
- content_view->AddChildView(
- CreateAddressRow(GetShippingAddressLabel(AddressStyleType::DETAILED,
- std::string(), *profile))
- .release());
- }
-
return CreatePaymentView(
CreateSheetHeaderView(
/* show_back_arrow = */ true,
l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_SHIPPING_SECTION_NAME),
this),
- std::move(content_view));
-}
-
-std::unique_ptr<views::Button> ShippingListViewController::CreateAddressRow(
- std::unique_ptr<views::View> content) {
- std::unique_ptr<PaymentRequestRowView> row =
- base::MakeUnique<PaymentRequestRowView>(this);
- views::GridLayout* layout = new views::GridLayout(row.get());
- row->SetLayoutManager(layout);
-
- layout->SetInsets(
- kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
- kPaymentRequestRowVerticalInsets,
- kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset);
-
- // Add a column listing the address.
- views::ColumnSet* columns = layout->AddColumnSet(0);
- columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
- views::GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, 0);
- content->set_can_process_events_within_subtree(false);
- layout->AddView(content.release());
-
- return std::move(row);
+ list_.CreateListView());
}
} // namespace payments
« no previous file with comments | « chrome/browser/ui/views/payments/shipping_list_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698