| 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 "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 10 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // Constructs an object owned by |parent_list|, representing one element in | 45 // Constructs an object owned by |parent_list|, representing one element in |
| 46 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that | 46 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that |
| 47 // are represented by the current instance of the dialog. |parent_view| points | 47 // are represented by the current instance of the dialog. |parent_view| points |
| 48 // to the controller which owns |parent_list|. |profile| is the | 48 // to the controller which owns |parent_list|. |profile| is the |
| 49 // AutofillProfile that this specific list item represents. It's a cached | 49 // AutofillProfile that this specific list item represents. It's a cached |
| 50 // profile owned by |state|. | 50 // profile owned by |state|. |
| 51 ProfileItem(autofill::AutofillProfile* profile, | 51 ProfileItem(autofill::AutofillProfile* profile, |
| 52 PaymentRequestSpec* spec, | 52 PaymentRequestSpec* spec, |
| 53 PaymentRequestState* state, | 53 PaymentRequestState* state, |
| 54 PaymentRequestItemList* parent_list, | 54 PaymentRequestItemList* parent_list, |
| 55 ProfileListViewController* parent_view, | 55 ProfileListViewController* controller, |
| 56 PaymentRequestDialogView* dialog, | 56 PaymentRequestDialogView* dialog, |
| 57 bool selected) | 57 bool selected) |
| 58 : payments::PaymentRequestItemList::Item(spec, | 58 : payments::PaymentRequestItemList::Item(spec, |
| 59 state, | 59 state, |
| 60 parent_list, | 60 parent_list, |
| 61 selected), | 61 selected, |
| 62 parent_view_(parent_view), | 62 /*show_edit_button=*/true), |
| 63 controller_(controller), |
| 63 profile_(profile), | 64 profile_(profile), |
| 64 dialog_(dialog) {} | 65 dialog_(dialog) {} |
| 65 ~ProfileItem() override {} | 66 ~ProfileItem() override {} |
| 66 | 67 |
| 67 private: | 68 private: |
| 68 // payments::PaymentRequestItemList::Item: | 69 // payments::PaymentRequestItemList::Item: |
| 69 std::unique_ptr<views::View> CreateContentView() override { | 70 std::unique_ptr<views::View> CreateContentView() override { |
| 70 DCHECK(profile_); | 71 DCHECK(profile_); |
| 71 | 72 |
| 72 return parent_view_->GetLabel(profile_); | 73 return controller_->GetLabel(profile_); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void SelectedStateChanged() override { | 76 void SelectedStateChanged() override { |
| 76 if (selected()) { | 77 if (selected()) { |
| 77 parent_view_->SelectProfile(profile_); | 78 controller_->SelectProfile(profile_); |
| 78 dialog_->GoBack(); | 79 dialog_->GoBack(); |
| 79 } | 80 } |
| 80 } | 81 } |
| 81 | 82 |
| 82 bool IsEnabled() override { return parent_view_->IsEnabled(profile_); } | 83 bool IsEnabled() override { return controller_->IsEnabled(profile_); } |
| 83 | 84 |
| 84 bool CanBeSelected() override { | 85 bool CanBeSelected() override { |
| 85 // In order to be selectable, a profile entry needs to be enabled, and the | 86 // In order to be selectable, a profile entry needs to be enabled, and the |
| 86 // profile valid according to the controller. If either condition is false, | 87 // profile valid according to the controller. If either condition is false, |
| 87 // PerformSelectionFallback() is called. | 88 // PerformSelectionFallback() is called. |
| 88 return IsEnabled() && parent_view_->IsValidProfile(*profile_); | 89 return IsEnabled() && controller_->IsValidProfile(*profile_); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void PerformSelectionFallback() override { | 92 void PerformSelectionFallback() override { |
| 92 // If enabled, the editor is opened to complete the invalid profile. | 93 // If enabled, the editor is opened to complete the invalid profile. |
| 93 if (IsEnabled()) | 94 if (IsEnabled()) |
| 94 parent_view_->ShowEditor(profile_); | 95 controller_->ShowEditor(profile_); |
| 95 } | 96 } |
| 96 | 97 |
| 97 ProfileListViewController* parent_view_; | 98 void EditButtonPressed() override { controller_->ShowEditor(profile_); } |
| 99 |
| 100 ProfileListViewController* controller_; |
| 98 autofill::AutofillProfile* profile_; | 101 autofill::AutofillProfile* profile_; |
| 99 PaymentRequestDialogView* dialog_; | 102 PaymentRequestDialogView* dialog_; |
| 100 | 103 |
| 101 DISALLOW_COPY_AND_ASSIGN(ProfileItem); | 104 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
| 102 }; | 105 }; |
| 103 | 106 |
| 104 // The ProfileListViewController subtype for the Shipping address list | 107 // The ProfileListViewController subtype for the Shipping address list |
| 105 // screen of the Payment Request flow. | 108 // screen of the Payment Request flow. |
| 106 class ShippingProfileViewController : public ProfileListViewController { | 109 class ShippingProfileViewController : public ProfileListViewController { |
| 107 public: | 110 public: |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 385 |
| 383 void ProfileListViewController::ButtonPressed(views::Button* sender, | 386 void ProfileListViewController::ButtonPressed(views::Button* sender, |
| 384 const ui::Event& event) { | 387 const ui::Event& event) { |
| 385 if (sender->tag() == GetSecondaryButtonTag()) | 388 if (sender->tag() == GetSecondaryButtonTag()) |
| 386 ShowEditor(nullptr); | 389 ShowEditor(nullptr); |
| 387 else | 390 else |
| 388 PaymentRequestSheetController::ButtonPressed(sender, event); | 391 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 389 } | 392 } |
| 390 | 393 |
| 391 } // namespace payments | 394 } // namespace payments |
| OLD | NEW |