Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: chrome/browser/ui/views/payments/profile_list_view_controller.cc

Issue 2709093006: Adding new shipping address editor view to payment flow. (Closed)
Patch Set: Rebase and bot error fixes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
7 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
8 #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"
9 #include "components/payments/content/payment_request_spec.h" 12 #include "components/payments/content/payment_request_spec.h"
10 #include "components/payments/content/payment_request_state.h" 13 #include "components/payments/content/payment_request_state.h"
11 #include "components/strings/grit/components_strings.h" 14 #include "components/strings/grit/components_strings.h"
12 #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"
13 21
14 namespace payments { 22 namespace payments {
15 23
16 namespace { 24 namespace {
17 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 };
34
18 class ProfileItem : public PaymentRequestItemList::Item { 35 class ProfileItem : public PaymentRequestItemList::Item {
19 public: 36 public:
20 // Constructs an object owned by |parent_list|, representing one element in 37 // Constructs an object owned by |parent_list|, representing one element in
21 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that 38 // the list. |spec| and |state| are the PaymentRequestSpec/State objects that
22 // are represented by the current instance of the dialog. |parent_view| points 39 // are represented by the current instance of the dialog. |parent_view| points
23 // to the controller which owns |parent_list|. |profile| is the 40 // to the controller which owns |parent_list|. |profile| is the
24 // AutofillProfile that this specific list item represents. It's a cached 41 // AutofillProfile that this specific list item represents. It's a cached
25 // profile owned by |state|. 42 // profile owned by |state|.
26 ProfileItem(autofill::AutofillProfile* profile, 43 ProfileItem(autofill::AutofillProfile* profile,
27 PaymentRequestSpec* spec, 44 PaymentRequestSpec* spec,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 99
83 std::vector<autofill::AutofillProfile*> GetProfiles() override { 100 std::vector<autofill::AutofillProfile*> GetProfiles() override {
84 return state()->shipping_profiles(); 101 return state()->shipping_profiles();
85 } 102 }
86 103
87 base::string16 GetHeaderString() override { 104 base::string16 GetHeaderString() override {
88 return GetShippingAddressSectionString(spec()->options().shipping_type); 105 return GetShippingAddressSectionString(spec()->options().shipping_type);
89 } 106 }
90 107
91 private: 108 private:
109 // PaymentRequestSheetController:
110 std::unique_ptr<views::View> CreateExtraFooterView() override {
111 std::unique_ptr<views::View> extra_view = base::MakeUnique<views::View>();
112
113 extra_view->SetLayoutManager(new views::BoxLayout(
114 views::BoxLayout::kHorizontal, 0, 0, kPaymentRequestButtonSpacing));
115
116 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton(
117 this, l10n_util::GetStringUTF16(IDS_AUTOFILL_ADD_ADDRESS_CAPTION));
118 button->set_tag(static_cast<int>(
119 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON));
120 button->set_id(
121 static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON));
122 extra_view->AddChildView(button);
123
124 return extra_view;
125 }
126
127 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
128 switch (sender->tag()) {
129 case static_cast<int>(
130 PaymentMethodViewControllerTags::ADD_SHIPPING_ADDRESS_BUTTON):
131 dialog()->ShowShippingAddressEditor();
132 break;
133 default:
134 PaymentRequestSheetController::ButtonPressed(sender, event);
135 break;
136 }
137 }
138
92 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController); 139 DISALLOW_COPY_AND_ASSIGN(ShippingProfileViewController);
93 }; 140 };
94 141
95 class ContactProfileViewController : public ProfileListViewController { 142 class ContactProfileViewController : public ProfileListViewController {
96 public: 143 public:
97 ContactProfileViewController(PaymentRequestSpec* spec, 144 ContactProfileViewController(PaymentRequestSpec* spec,
98 PaymentRequestState* state, 145 PaymentRequestState* state,
99 PaymentRequestDialogView* dialog) 146 PaymentRequestDialogView* dialog)
100 : ProfileListViewController(spec, state, dialog) {} 147 : ProfileListViewController(spec, state, dialog) {}
101 ~ContactProfileViewController() override {} 148 ~ContactProfileViewController() override {}
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 profile, spec(), state(), &list_, this, profile == selected_profile)); 209 profile, spec(), state(), &list_, this, profile == selected_profile));
163 } 210 }
164 211
165 return CreatePaymentView( 212 return CreatePaymentView(
166 CreateSheetHeaderView( 213 CreateSheetHeaderView(
167 /* show_back_arrow = */ true, GetHeaderString(), this), 214 /* show_back_arrow = */ true, GetHeaderString(), this),
168 list_.CreateListView()); 215 list_.CreateListView());
169 } 216 }
170 217
171 } // namespace payments 218 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698