| 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_row_view.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 11 #include "chrome/grit/generated_resources.h" |
| 10 #include "components/payments/content/payment_request_spec.h" | 12 #include "components/payments/content/payment_request_spec.h" |
| 11 #include "components/payments/content/payment_request_state.h" | 13 #include "components/payments/content/payment_request_state.h" |
| 12 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/views/controls/button/label_button.h" |
| 17 #include "ui/views/controls/button/md_text_button.h" |
| 18 #include "ui/views/controls/image_view.h" |
| 19 #include "ui/views/layout/box_layout.h" |
| 20 #include "ui/views/layout/grid_layout.h" |
| 14 | 21 |
| 15 namespace payments { | 22 namespace payments { |
| 16 | 23 |
| 17 namespace { | 24 namespace { |
| 18 | 25 |
| 26 constexpr int kFirstTagValue = static_cast<int>( |
| 27 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); |
| 28 |
| 29 enum class PaymentMethodViewControllerTags : int { |
| 30 // The tag for the button that triggers the "add address" flow. Starts at |
| 31 // |kFirstTagValue| not to conflict with tags common to all views. |
| 32 ADD_SHIPPING_ADDRESS_BUTTON = kFirstTagValue, |
| 33 ADD_CONTACT_BUTTON, |
| 34 }; |
| 35 |
| 19 class ProfileItem : public PaymentRequestItemList::Item { | 36 class ProfileItem : public PaymentRequestItemList::Item { |
| 20 public: | 37 public: |
| 21 // Constructs an object owned by |parent_list|, representing one element in | 38 // Constructs an object owned by |parent_list|, representing one element in |
| 22 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that | 39 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that |
| 23 // are represented by the current instance of the dialog. |parent_view| points | 40 // are represented by the current instance of the dialog. |parent_view| points |
| 24 // to the controller which owns |parent_list|. |profile| is the | 41 // to the controller which owns |parent_list|. |profile| is the |
| 25 // AutofillProfile that this specific list item represents. It's a cached | 42 // AutofillProfile that this specific list item represents. It's a cached |
| 26 // profile owned by |state|. | 43 // profile owned by |state|. |
| 27 ProfileItem(autofill::AutofillProfile* profile, | 44 ProfileItem(autofill::AutofillProfile* profile, |
| 28 PaymentRequestSpec* spec, | 45 PaymentRequestSpec* spec, |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 115 } |
| 99 | 116 |
| 100 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 117 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 101 return state()->shipping_profiles(); | 118 return state()->shipping_profiles(); |
| 102 } | 119 } |
| 103 | 120 |
| 104 base::string16 GetHeaderString() override { | 121 base::string16 GetHeaderString() override { |
| 105 return GetShippingAddressSectionString(spec()->options().shipping_type); | 122 return GetShippingAddressSectionString(spec()->options().shipping_type); |
| 106 } | 123 } |
| 107 | 124 |
| 125 int GetSecondaryButtonTextId() override { |
| 126 return IDS_AUTOFILL_ADD_ADDRESS_CAPTION; |
| 127 } |
| 128 |
| 129 int GetSecondaryButtonTag() override { |
| 130 return static_cast<int>( |
| 131 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON); |
| 132 } |
| 133 |
| 134 int GetSecondaryButtonViewId() override { |
| 135 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_SHIPPING_BUTTON); |
| 136 } |
| 137 |
| 138 void OnSecondaryButtonPressed() override { |
| 139 dialog()->ShowShippingAddressEditor(); |
| 140 } |
| 141 |
| 108 private: | 142 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); | 143 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); |
| 110 }; | 144 }; |
| 111 | 145 |
| 112 class ContactProfileViewController : public ProfileListViewController { | 146 class ContactProfileViewController : public ProfileListViewController { |
| 113 public: | 147 public: |
| 114 ContactProfileViewController(PaymentRequestSpec* spec, | 148 ContactProfileViewController(PaymentRequestSpec* spec, |
| 115 PaymentRequestState* state, | 149 PaymentRequestState* state, |
| 116 PaymentRequestDialogView* dialog) | 150 PaymentRequestDialogView* dialog) |
| 117 : ProfileListViewController(spec, state, dialog) {} | 151 : ProfileListViewController(spec, state, dialog) {} |
| (...skipping 19 matching lines...) Expand all Loading... |
| 137 | 171 |
| 138 std::vector<autofill::AutofillProfile*> GetProfiles() override { | 172 std::vector<autofill::AutofillProfile*> GetProfiles() override { |
| 139 return state()->contact_profiles(); | 173 return state()->contact_profiles(); |
| 140 } | 174 } |
| 141 | 175 |
| 142 base::string16 GetHeaderString() override { | 176 base::string16 GetHeaderString() override { |
| 143 return l10n_util::GetStringUTF16( | 177 return l10n_util::GetStringUTF16( |
| 144 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); | 178 IDS_PAYMENT_REQUEST_CONTACT_INFO_SECTION_NAME); |
| 145 } | 179 } |
| 146 | 180 |
| 181 int GetSecondaryButtonTextId() override { |
| 182 return IDS_AUTOFILL_ADD_CONTACT_CAPTION; |
| 183 } |
| 184 |
| 185 int GetSecondaryButtonTag() override { |
| 186 return static_cast<int>( |
| 187 PaymentMethodViewControllerTags::ADD_CONTACT_BUTTON); |
| 188 } |
| 189 |
| 190 int GetSecondaryButtonViewId() override { |
| 191 return static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CONTACT_BUTTON); |
| 192 } |
| 193 |
| 194 void OnSecondaryButtonPressed() override { |
| 195 // TODO(crbug.com/704263): Add Contact Editor. |
| 196 } |
| 197 |
| 147 private: | 198 private: |
| 148 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); | 199 DISALLOW_COPY_AND_ASSIGN(ContactProfileViewController); |
| 149 }; | 200 }; |
| 150 | 201 |
| 151 } // namespace | 202 } // namespace |
| 152 | 203 |
| 153 // static | 204 // static |
| 154 std::unique_ptr<ProfileListViewController> | 205 std::unique_ptr<ProfileListViewController> |
| 155 ProfileListViewController::GetShippingProfileViewController( | 206 ProfileListViewController::GetShippingProfileViewController( |
| 156 PaymentRequestSpec* spec, | 207 PaymentRequestSpec* spec, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 186 &list_, this, dialog(), | 237 &list_, this, dialog(), |
| 187 profile == selected_profile)); | 238 profile == selected_profile)); |
| 188 } | 239 } |
| 189 | 240 |
| 190 return CreatePaymentView( | 241 return CreatePaymentView( |
| 191 CreateSheetHeaderView( | 242 CreateSheetHeaderView( |
| 192 /* show_back_arrow = */ true, GetHeaderString(), this), | 243 /* show_back_arrow = */ true, GetHeaderString(), this), |
| 193 list_.CreateListView()); | 244 list_.CreateListView()); |
| 194 } | 245 } |
| 195 | 246 |
| 247 std::unique_ptr<views::View> |
| 248 ProfileListViewController::CreateExtraFooterView() { |
| 249 std::unique_ptr<views::View> extra_view = base::MakeUnique<views::View>(); |
| 250 |
| 251 extra_view->SetLayoutManager(new views::BoxLayout( |
| 252 views::BoxLayout::kHorizontal, 0, 0, kPaymentRequestButtonSpacing)); |
| 253 |
| 254 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( |
| 255 this, l10n_util::GetStringUTF16(GetSecondaryButtonTextId())); |
| 256 button->set_tag(GetSecondaryButtonTag()); |
| 257 button->set_id(GetSecondaryButtonViewId()); |
| 258 extra_view->AddChildView(button); |
| 259 |
| 260 return extra_view; |
| 261 } |
| 262 |
| 263 void ProfileListViewController::ButtonPressed(views::Button* sender, |
| 264 const ui::Event& event) { |
| 265 if (sender->tag() == GetSecondaryButtonTag()) |
| 266 OnSecondaryButtonPressed(); |
| 267 else |
| 268 PaymentRequestSheetController::ButtonPressed(sender, event); |
| 269 } |
| 270 |
| 196 } // namespace payments | 271 } // namespace payments |
| OLD | NEW |