Chromium Code Reviews| Index: chrome/browser/ui/views/payments/payment_method_view_controller.cc |
| diff --git a/chrome/browser/ui/views/payments/payment_method_view_controller.cc b/chrome/browser/ui/views/payments/payment_method_view_controller.cc |
| index 0c98740092576b4b4e848892b0fccf9006b3b34e..e86b4577110821a3dfcf7b82100faf8f9dd91802 100644 |
| --- a/chrome/browser/ui/views/payments/payment_method_view_controller.cc |
| +++ b/chrome/browser/ui/views/payments/payment_method_view_controller.cc |
| @@ -8,16 +8,25 @@ |
| #include <utility> |
| #include "base/memory/ptr_util.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| +#include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| #include "chrome/grit/generated_resources.h" |
| +#include "components/autofill/core/browser/autofill_type.h" |
| +#include "components/autofill/core/browser/credit_card.h" |
| #include "components/payments/payment_request.h" |
| #include "components/strings/grit/components_strings.h" |
| +#include "third_party/skia/include/core/SkColor.h" |
| #include "ui/base/l10n/l10n_util.h" |
| +#include "ui/gfx/paint_vector_icon.h" |
| #include "ui/views/controls/button/label_button.h" |
| #include "ui/views/controls/button/md_text_button.h" |
| -#include "ui/views/layout/fill_layout.h" |
| +#include "ui/views/layout/box_layout.h" |
| +#include "ui/views/layout/grid_layout.h" |
| +#include "ui/views/vector_icons.h" |
| + |
| namespace payments { |
| @@ -32,36 +41,129 @@ enum class PaymentMethodViewControllerTags : int { |
| ADD_CREDIT_CARD_BUTTON = kFirstTagValue, |
| }; |
| +class PaymentMethodListItem : public payments::PaymentRequestItemList::Item, |
| + public views::ButtonListener { |
| + public: |
| + explicit PaymentMethodListItem(autofill::CreditCard* card) : card_(card) {} |
|
please use gerrit instead
2017/02/14 00:29:14
// Does not take ownership of |card|, which shoul
anthonyvd
2017/02/22 20:15:21
Yep, done.
|
| + ~PaymentMethodListItem() override {} |
| + |
| + private: |
| + std::unique_ptr<views::View> CreateItemView() override { |
|
please use gerrit instead
2017/02/14 00:29:14
// payments::PaymentRequestItemList::Item implemen
anthonyvd
2017/02/22 20:15:21
Done.
|
| + std::unique_ptr<PaymentRequestRowView> row = |
| + base::MakeUnique<PaymentRequestRowView>(this); |
| + views::GridLayout* layout = new views::GridLayout(row.get()); |
| + layout->SetInsets(kPaymentRequestRowVerticalInsets, |
| + kPaymentRequestRowHorizontalInsets, |
| + kPaymentRequestRowVerticalInsets, |
| + kPaymentRequestRowHorizontalInsets); |
| + row->SetLayoutManager(layout); |
| + views::ColumnSet* columns = layout->AddColumnSet(0); |
| + |
| + // A column for the masked number and name on card |
| + columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + |
| + // A padding column that resizes to take up the empty space between the |
| + // leading and trailing parts. |
| + columns->AddPaddingColumn(1, 0); |
| + |
| + // A column for the checkmark when the row is selected. |
| + columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + |
| + // A column for the card icon |
| + columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + |
| + // A column for the edit button |
| + columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| + 0, views::GridLayout::USE_PREF, 0, 0); |
| + |
| + layout->StartRow(0, 0); |
| + std::unique_ptr<views::View> card_info_container = |
| + base::MakeUnique<views::View>(); |
| + card_info_container->set_can_process_events_within_subtree(false); |
| + |
| + std::unique_ptr<views::BoxLayout> box_layout = |
| + base::MakeUnique<views::BoxLayout>(views::BoxLayout::kVertical, |
| + 0, |
| + kPaymentRequestRowVerticalInsets, |
| + 0); |
| + box_layout->set_cross_axis_alignment( |
| + views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| + card_info_container->SetLayoutManager(box_layout.release()); |
| + |
| + card_info_container->AddChildView( |
| + new views::Label(card_->TypeAndLastFourDigits())); |
| + card_info_container->AddChildView(new views::Label( |
| + card_->GetInfo(autofill::AutofillType(autofill::CREDIT_CARD_NAME_FULL), |
| + g_browser_process->GetApplicationLocale()))); |
| + layout->AddView(card_info_container.release()); |
| + |
| + std::unique_ptr<views::ImageView> checkmark = |
| + base::MakeUnique<views::ImageView>(); |
| + checkmark->set_interactive(false); |
| + checkmark->SetImage( |
| + gfx::CreateVectorIcon(views::kMenuCheckIcon, 0xFF609265)); |
| + layout->AddView(checkmark.release()); |
| + |
| + layout->AddView(CreateCreditCardIconView(card_).release()); |
|
please use gerrit instead
2017/02/14 00:29:14
Great to see use of std::uniqiue_ptr and .release(
anthonyvd
2017/02/22 20:15:21
Yeah I'm glad we agreed on just using unique_ptr e
|
| + |
| + return std::move(row); |
| + } |
| + |
| + // views::ButtonListener: |
| + void ButtonPressed(views::Button* sender, const ui::Event& event) override { |
| + |
|
please use gerrit instead
2017/02/14 00:29:14
Remove extra line.
anthonyvd
2017/02/22 20:15:21
Done.
|
| + } |
| + |
| + autofill::CreditCard* card_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); |
| +}; |
| + |
| } // namespace |
| PaymentMethodViewController::PaymentMethodViewController( |
| PaymentRequest* request, |
| PaymentRequestDialogView* dialog) |
| - : PaymentRequestSheetController(request, dialog) {} |
| + : PaymentRequestSheetController(request, dialog) { |
| + std::vector<autofill::CreditCard*> available_cards = request->credit_cards(); |
|
please use gerrit instead
2017/02/14 00:29:14
This makes a copy of the vector, which is expensiv
anthonyvd
2017/02/22 20:15:21
Good catch, done! (Although I would hope that the
|
| + |
| + for (autofill::CreditCard* card : available_cards) { |
| + payment_method_list_.AddItem(base::MakeUnique<PaymentMethodListItem>(card)); |
| + } |
| +} |
| PaymentMethodViewController::~PaymentMethodViewController() {} |
| std::unique_ptr<views::View> PaymentMethodViewController::CreateView() { |
| - std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
| + return CreatePaymentView(CreateSheetHeaderView( |
| + true, |
| + l10n_util::GetStringUTF16( |
| + IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| + this), |
| + payment_method_list_.CreateListView()); |
| +} |
| - views::FillLayout* layout = new views::FillLayout(); |
| - content_view->SetLayoutManager(layout); |
| +std::unique_ptr<views::View> PaymentMethodViewController::CreateExtraView() { |
| + std::unique_ptr<views::View> extra_view = base::MakeUnique<views::View>(); |
| + |
| + extra_view->SetLayoutManager(new views::BoxLayout( |
| + views::BoxLayout::kHorizontal, |
| + kPaymentRequestRowHorizontalInsets, |
| + kPaymentRequestRowVerticalInsets, |
| + kPaymentRequestButtonSpacing)); |
| - // Create the "Add a card" button. |
| views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( |
| this, l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_CREDITCARD_CAPTION)); |
| button->set_tag(static_cast<int>( |
| PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON)); |
| button->set_id( |
| static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON)); |
| - content_view->AddChildView(button); |
| + extra_view->AddChildView(button); |
| - return CreatePaymentView(CreateSheetHeaderView( |
| - true, |
| - l10n_util::GetStringUTF16( |
| - IDS_PAYMENT_REQUEST_PAYMENT_METHOD_SECTION_NAME), |
| - this), |
| - std::move(content_view)); |
| + return extra_view; |
| } |
| void PaymentMethodViewController::ButtonPressed(views::Button* sender, |