| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/profile_list_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/profile_list_view_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 9 #include "components/payments/content/payment_request_spec.h" | 9 #include "components/payments/content/payment_request_spec.h" |
| 10 #include "components/payments/content/payment_request_state.h" | 10 #include "components/payments/content/payment_request_state.h" |
| 11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/views/controls/image_view.h" | |
| 14 #include "ui/views/layout/grid_layout.h" | |
| 15 | 13 |
| 16 namespace payments { | 14 namespace payments { |
| 17 | 15 |
| 18 namespace { | 16 namespace { |
| 19 | 17 |
| 20 class ProfileItem : public PaymentRequestItemList::Item { | 18 class ProfileItem : public PaymentRequestItemList::Item { |
| 21 public: | 19 public: |
| 22 // Constructs an object owned by |parent_list|, representing one element in | 20 // Constructs an object owned by |parent_list|, representing one element in |
| 23 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that | 21 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that |
| 24 // are represented by the current instance of the dialog. |parent_view| points | 22 // are represented by the current instance of the dialog. |parent_view| points |
| 25 // to the controller which owns |parent_list|. |profile| is the | 23 // to the controller which owns |parent_list|. |profile| is the |
| 26 // AutofillProfile that this specific list item represents. It's a cached | 24 // AutofillProfile that this specific list item represents. It's a cached |
| 27 // profile owned by |state|. | 25 // profile owned by |state|. |
| 28 ProfileItem(autofill::AutofillProfile* profile, | 26 ProfileItem(autofill::AutofillProfile* profile, |
| 29 PaymentRequestSpec* spec, | 27 PaymentRequestSpec* spec, |
| 30 PaymentRequestState* state, | 28 PaymentRequestState* state, |
| 31 PaymentRequestItemList* parent_list, | 29 PaymentRequestItemList* parent_list, |
| 32 ProfileListViewController* parent_view, | 30 ProfileListViewController* parent_view, |
| 33 bool selected) | 31 bool selected) |
| 34 : payments::PaymentRequestItemList::Item(spec, | 32 : payments::PaymentRequestItemList::Item(spec, |
| 35 state, | 33 state, |
| 36 parent_list, | 34 parent_list, |
| 37 selected), | 35 selected), |
| 38 parent_view_(parent_view), | 36 parent_view_(parent_view), |
| 39 profile_(profile) {} | 37 profile_(profile) {} |
| 40 ~ProfileItem() override {} | 38 ~ProfileItem() override {} |
| 41 | 39 |
| 42 private: | 40 private: |
| 43 // payments::PaymentRequestItemList::Item: | 41 // payments::PaymentRequestItemList::Item: |
| 44 std::unique_ptr<views::View> CreateItemView() override { | 42 std::unique_ptr<views::View> CreateContentView() override { |
| 45 DCHECK(profile_); | 43 DCHECK(profile_); |
| 46 | 44 |
| 47 std::unique_ptr<views::View> content = parent_view_->GetLabel(profile_); | 45 return parent_view_->GetLabel(profile_); |
| 48 | |
| 49 std::unique_ptr<PaymentRequestRowView> row = | |
| 50 base::MakeUnique<PaymentRequestRowView>(this); | |
| 51 views::GridLayout* layout = new views::GridLayout(row.get()); | |
| 52 row->SetLayoutManager(layout); | |
| 53 | |
| 54 layout->SetInsets( | |
| 55 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets, | |
| 56 kPaymentRequestRowVerticalInsets, | |
| 57 kPaymentRequestRowHorizontalInsets + kPaymentRequestRowExtraRightInset); | |
| 58 | |
| 59 // Add a column listing the profile information. | |
| 60 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 61 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, | |
| 62 views::GridLayout::USE_PREF, 0, 0); | |
| 63 | |
| 64 columns->AddPaddingColumn(1, 0); | |
| 65 | |
| 66 // Add a column for the checkmark shown next to the selected profile. | |
| 67 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
| 68 0, views::GridLayout::USE_PREF, 0, 0); | |
| 69 | |
| 70 layout->StartRow(0, 0); | |
| 71 content->set_can_process_events_within_subtree(false); | |
| 72 layout->AddView(content.release()); | |
| 73 | |
| 74 checkmark_ = CreateCheckmark(selected()); | |
| 75 layout->AddView(checkmark_.get()); | |
| 76 | |
| 77 return std::move(row); | |
| 78 } | 46 } |
| 79 | 47 |
| 80 void SelectedStateChanged() override {} | 48 void SelectedStateChanged() override {} |
| 81 | 49 |
| 50 bool CanBeSelected() const override { |
| 51 // TODO(anthonyvd): Check for profile completedness. |
| 52 return true; |
| 53 } |
| 54 |
| 55 void PerformSelectionFallback() override { |
| 56 // TODO(anthonyvd): Open the editor pre-populated with this profile's data. |
| 57 } |
| 58 |
| 82 ProfileListViewController* parent_view_; | 59 ProfileListViewController* parent_view_; |
| 83 autofill::AutofillProfile* profile_; | 60 autofill::AutofillProfile* profile_; |
| 84 std::unique_ptr<views::ImageView> checkmark_; | |
| 85 | 61 |
| 86 DISALLOW_COPY_AND_ASSIGN(ProfileItem); | 62 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
| 87 }; | 63 }; |
| 88 | 64 |
| 89 // The ProfileListViewController subtype for the Shipping address list | 65 // The ProfileListViewController subtype for the Shipping address list |
| 90 // screen of the Payment Request flow. | 66 // screen of the Payment Request flow. |
| 91 class ShippingProfileViewController : public ProfileListViewController { | 67 class ShippingProfileViewController : public ProfileListViewController { |
| 92 public: | 68 public: |
| 93 ShippingProfileViewController(PaymentRequestSpec* spec, | 69 ShippingProfileViewController(PaymentRequestSpec* spec, |
| 94 PaymentRequestState* state, | 70 PaymentRequestState* state, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 profile, spec(), state(), &list_, this, profile == selected_profile)); | 162 profile, spec(), state(), &list_, this, profile == selected_profile)); |
| 187 } | 163 } |
| 188 | 164 |
| 189 return CreatePaymentView( | 165 return CreatePaymentView( |
| 190 CreateSheetHeaderView( | 166 CreateSheetHeaderView( |
| 191 /* show_back_arrow = */ true, GetHeaderString(), this), | 167 /* show_back_arrow = */ true, GetHeaderString(), this), |
| 192 list_.CreateListView()); | 168 list_.CreateListView()); |
| 193 } | 169 } |
| 194 | 170 |
| 195 } // namespace payments | 171 } // namespace payments |
| OLD | NEW |