| 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_dialog_view.h" | 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool CanBeSelected() const override { | 77 bool CanBeSelected() const override { |
| 78 // TODO(crbug.com/709454): Check for profile completeness. Currently a giant | 78 // TODO(crbug.com/709454): Check for profile completeness. Currently a giant |
| 79 // hack to test the UI. | 79 // hack to test the UI. |
| 80 return !profile_->GetRawInfo(autofill::ADDRESS_HOME_ZIP).empty(); | 80 return !profile_->GetRawInfo(autofill::ADDRESS_HOME_ZIP).empty(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void PerformSelectionFallback() override { | 83 void PerformSelectionFallback() override { |
| 84 dialog_->ShowShippingAddressEditor(profile_); | 84 parent_view_->ShowEditor(profile_); |
| 85 } | 85 } |
| 86 | 86 |
| 87 ProfileListViewController* parent_view_; | 87 ProfileListViewController* parent_view_; |
| 88 autofill::AutofillProfile* profile_; | 88 autofill::AutofillProfile* profile_; |
| 89 PaymentRequestDialogView* dialog_; | 89 PaymentRequestDialogView* dialog_; |
| 90 | 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(ProfileItem); | 91 DISALLOW_COPY_AND_ASSIGN(ProfileItem); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // The ProfileListViewController subtype for the Shipping address list | 94 // The ProfileListViewController subtype for the Shipping address list |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 std::unique_ptr<views::View> GetLabel( | 108 std::unique_ptr<views::View> GetLabel( |
| 109 autofill::AutofillProfile* profile) override { | 109 autofill::AutofillProfile* profile) override { |
| 110 return GetShippingAddressLabel(AddressStyleType::DETAILED, | 110 return GetShippingAddressLabel(AddressStyleType::DETAILED, |
| 111 state()->GetApplicationLocale(), *profile); | 111 state()->GetApplicationLocale(), *profile); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void SelectProfile(autofill::AutofillProfile* profile) override { | 114 void SelectProfile(autofill::AutofillProfile* profile) override { |
| 115 state()->SetSelectedShippingProfile(profile); | 115 state()->SetSelectedShippingProfile(profile); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void ShowEditor(autofill::AutofillProfile* profile) override { |
| 119 dialog()->ShowShippingAddressEditor(profile); |
| 120 } |
| 121 |
| 118 autofill::AutofillProfile* GetSelectedProfile() override { | 122 autofill::AutofillProfile* GetSelectedProfile() override { |
| 119 return state()->selected_shipping_profile(); | 123 return state()->selected_shipping_profile(); |
| 120 } | 124 } |
| 121 | 125 |
| 122 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 126 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 123 return state()->shipping_profiles(); | 127 return state()->shipping_profiles(); |
| 124 } | 128 } |
| 125 | 129 |
| 126 DialogViewID GetDialogViewId() override { | 130 DialogViewID GetDialogViewId() override { |
| 127 return DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW; | 131 return DialogViewID::SHIPPING_ADDRESS_SHEET_LIST_VIEW; |
| 128 } | 132 } |
| 129 | 133 |
| 130 base::string16 GetSheetTitle() override { | 134 base::string16 GetSheetTitle() override { |
| 131 return GetShippingAddressSectionString(spec()->shipping_type()); | 135 return GetShippingAddressSectionString(spec()->shipping_type()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 int GetSecondaryButtonTextId() override { | 138 int GetSecondaryButtonTextId() override { |
| 135 return IDS_AUTOFILL_ADD_ADDRESS_CAPTION; | 139 return IDS_AUTOFILL_ADD_ADDRESS_CAPTION; |
| 136 } | 140 } |
| 137 | 141 |
| 138 int GetSecondaryButtonTag() override { | 142 int GetSecondaryButtonTag() override { |
| 139 return static_cast<int>( | 143 return static_cast<int>( |
| 140 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON); | 144 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON); |
| 141 } | 145 } |
| 142 | 146 |
| 143 int GetSecondaryButtonViewId() override { | 147 int GetSecondaryButtonViewId() override { |
| 144 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); | 148 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); |
| 145 } | 149 } |
| 146 | 150 |
| 147 void OnSecondaryButtonPressed() override { | |
| 148 dialog()->ShowShippingAddressEditor(); | |
| 149 } | |
| 150 | |
| 151 private: | 151 private: |
| 152 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); | 152 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 class ContactProfileViewController : public ProfileListViewController { | 155 class ContactProfileViewController : public ProfileListViewController { |
| 156 public: | 156 public: |
| 157 ContactProfileViewController(PaymentRequestSpec* spec, | 157 ContactProfileViewController(PaymentRequestSpec* spec, |
| 158 PaymentRequestState* state, | 158 PaymentRequestState* state, |
| 159 PaymentRequestDialogView* dialog) | 159 PaymentRequestDialogView* dialog) |
| 160 : ProfileListViewController(spec, state, dialog) { | 160 : ProfileListViewController(spec, state, dialog) { |
| 161 PopulateList(); | 161 PopulateList(); |
| 162 } | 162 } |
| 163 ~ContactProfileViewController() override {} | 163 ~ContactProfileViewController() override {} |
| 164 | 164 |
| 165 protected: | 165 protected: |
| 166 // ProfileListViewController: | 166 // ProfileListViewController: |
| 167 std::unique_ptr<views::View> GetLabel( | 167 std::unique_ptr<views::View> GetLabel( |
| 168 autofill::AutofillProfile* profile) override { | 168 autofill::AutofillProfile* profile) override { |
| 169 return GetContactInfoLabel(AddressStyleType::DETAILED, | 169 return GetContactInfoLabel(AddressStyleType::DETAILED, |
| 170 state()->GetApplicationLocale(), *profile, | 170 state()->GetApplicationLocale(), *profile, |
| 171 *spec()); | 171 *spec()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 void SelectProfile(autofill::AutofillProfile* profile) override { | 174 void SelectProfile(autofill::AutofillProfile* profile) override { |
| 175 state()->SetSelectedContactProfile(profile); | 175 state()->SetSelectedContactProfile(profile); |
| 176 } | 176 } |
| 177 | 177 |
| 178 void ShowEditor(autofill::AutofillProfile* profile) override { |
| 179 dialog()->ShowContactInfoEditor(profile); |
| 180 } |
| 181 |
| 178 autofill::AutofillProfile* GetSelectedProfile() override { | 182 autofill::AutofillProfile* GetSelectedProfile() override { |
| 179 return state()->selected_contact_profile(); | 183 return state()->selected_contact_profile(); |
| 180 } | 184 } |
| 181 | 185 |
| 182 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 186 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 183 return state()->contact_profiles(); | 187 return state()->contact_profiles(); |
| 184 } | 188 } |
| 185 | 189 |
| 186 DialogViewID GetDialogViewId() override { | 190 DialogViewID GetDialogViewId() override { |
| 187 return DialogViewID::CONTACT_INFO_SHEET_LIST_VIEW; | 191 return DialogViewID::CONTACT_INFO_SHEET_LIST_VIEW; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 198 | 202 |
| 199 int GetSecondaryButtonTag() override { | 203 int GetSecondaryButtonTag() override { |
| 200 return static_cast<int>( | 204 return static_cast<int>( |
| 201 PaymentMethodViewControllerTags::ADD_CONTACT_BUTTON); | 205 PaymentMethodViewControllerTags::ADD_CONTACT_BUTTON); |
| 202 } | 206 } |
| 203 | 207 |
| 204 int GetSecondaryButtonViewId() override { | 208 int GetSecondaryButtonViewId() override { |
| 205 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CONTACT_BUTTON); | 209 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CONTACT_BUTTON); |
| 206 } | 210 } |
| 207 | 211 |
| 208 void OnSecondaryButtonPressed() override { | |
| 209 // TODO(crbug.com/704263): Add Contact Editor. | |
| 210 } | |
| 211 | |
| 212 private: | 212 private: |
| 213 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); | 213 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 } // namespace | 216 } // namespace |
| 217 | 217 |
| 218 // static | 218 // static |
| 219 std::unique_ptr<ProfileListViewController> | 219 std::unique_ptr<ProfileListViewController> |
| 220 ProfileListViewController::GetShippingProfileViewController( | 220 ProfileListViewController::GetShippingProfileViewController( |
| 221 PaymentRequestSpec* spec, | 221 PaymentRequestSpec* spec, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 button->set_tag(GetSecondaryButtonTag()); | 272 button->set_tag(GetSecondaryButtonTag()); |
| 273 button->set_id(GetSecondaryButtonViewId()); | 273 button->set_id(GetSecondaryButtonViewId()); |
| 274 extra_view->AddChildView(button); | 274 extra_view->AddChildView(button); |
| 275 | 275 |
| 276 return extra_view; | 276 return extra_view; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void ProfileListViewController::ButtonPressed(views::Button* sender, | 279 void ProfileListViewController::ButtonPressed(views::Button* sender, |
| 280 const ui::Event& event) { | 280 const ui::Event& event) { |
| 281 if (sender->tag() == GetSecondaryButtonTag()) | 281 if (sender->tag() == GetSecondaryButtonTag()) |
| 282 OnSecondaryButtonPressed(); | 282 ShowEditor(nullptr); |
| 283 else | 283 else |
| 284 PaymentRequestSheetController::ButtonPressed(sender, event); | 284 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 285 } | 285 } |
| 286 | 286 |
| 287 } // namespace payments | 287 } // namespace payments |
| OLD | NEW |