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

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

Issue 2742813004: [Payments] Refactor into PaymentRequestState and Spec (Closed)
Patch Set: don't stop rebasin' 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/payment_method_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 12 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 13 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
14 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 14 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
16 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
17 #include "components/autofill/core/browser/autofill_type.h" 17 #include "components/autofill/core/browser/autofill_type.h"
18 #include "components/autofill/core/browser/credit_card.h" 18 #include "components/autofill/core/browser/credit_card.h"
19 #include "components/payments/content/payment_request.h" 19 #include "components/payments/content/payment_request.h"
20 #include "components/payments/content/payment_request_state.h"
20 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
21 #include "third_party/skia/include/core/SkColor.h" 22 #include "third_party/skia/include/core/SkColor.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/paint_vector_icon.h" 24 #include "ui/gfx/paint_vector_icon.h"
24 #include "ui/views/controls/button/label_button.h" 25 #include "ui/views/controls/button/label_button.h"
25 #include "ui/views/controls/button/md_text_button.h" 26 #include "ui/views/controls/button/md_text_button.h"
26 #include "ui/views/layout/box_layout.h" 27 #include "ui/views/layout/box_layout.h"
27 #include "ui/views/layout/grid_layout.h" 28 #include "ui/views/layout/grid_layout.h"
28 #include "ui/views/vector_icons.h" 29 #include "ui/views/vector_icons.h"
29 30
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 119
119 return std::move(row); 120 return std::move(row);
120 } 121 }
121 122
122 void SelectedStateChanged() override { 123 void SelectedStateChanged() override {
123 // This could be called before CreateItemView, so before |checkmark_| is 124 // This could be called before CreateItemView, so before |checkmark_| is
124 // instantiated. 125 // instantiated.
125 if (checkmark_) 126 if (checkmark_)
126 checkmark_->SetVisible(selected()); 127 checkmark_->SetVisible(selected());
127 128
128 request()->SetSelectedCreditCard(card_); 129 request()->state()->SetSelectedCreditCard(card_);
129 } 130 }
130 131
131 // views::ButtonListener: 132 // views::ButtonListener:
132 void ButtonPressed(views::Button* sender, const ui::Event& event) override { 133 void ButtonPressed(views::Button* sender, const ui::Event& event) override {
133 if (IsComplete()) { 134 if (IsComplete()) {
134 list()->SelectItem(this); 135 list()->SelectItem(this);
135 } else { 136 } else {
136 // TODO(anthonyvd): Display the editor, pre-populated with the data that 137 // TODO(anthonyvd): Display the editor, pre-populated with the data that
137 // already exists in |card|. 138 // already exists in |card|.
138 } 139 }
(...skipping 11 matching lines...) Expand all
150 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem); 151 DISALLOW_COPY_AND_ASSIGN(PaymentMethodListItem);
151 }; 152 };
152 153
153 } // namespace 154 } // namespace
154 155
155 PaymentMethodViewController::PaymentMethodViewController( 156 PaymentMethodViewController::PaymentMethodViewController(
156 PaymentRequest* request, 157 PaymentRequest* request,
157 PaymentRequestDialogView* dialog) 158 PaymentRequestDialogView* dialog)
158 : PaymentRequestSheetController(request, dialog) { 159 : PaymentRequestSheetController(request, dialog) {
159 const std::vector<autofill::CreditCard*>& available_cards = 160 const std::vector<autofill::CreditCard*>& available_cards =
160 request->credit_cards(); 161 request->state()->credit_cards();
161 162
162 for (autofill::CreditCard* card : available_cards) { 163 for (autofill::CreditCard* card : available_cards) {
163 std::unique_ptr<PaymentMethodListItem> item = 164 std::unique_ptr<PaymentMethodListItem> item =
164 base::MakeUnique<PaymentMethodListItem>( 165 base::MakeUnique<PaymentMethodListItem>(
165 card, request, &payment_method_list_, 166 card, request, &payment_method_list_,
166 card == request->selected_credit_card()); 167 card == request->state()->selected_credit_card());
167 payment_method_list_.AddItem(std::move(item)); 168 payment_method_list_.AddItem(std::move(item));
168 } 169 }
169 } 170 }
170 171
171 PaymentMethodViewController::~PaymentMethodViewController() {} 172 PaymentMethodViewController::~PaymentMethodViewController() {}
172 173
173 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() { 174 std::unique_ptr<views::View> PaymentMethodViewController::CreateView() {
174 std::unique_ptr<views::View> list_view = 175 std::unique_ptr<views::View> list_view =
175 payment_method_list_.CreateListView(); 176 payment_method_list_.CreateListView();
176 list_view->set_id( 177 list_view->set_id(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 210 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
210 dialog()->ShowCreditCardEditor(); 211 dialog()->ShowCreditCardEditor();
211 break; 212 break;
212 default: 213 default:
213 PaymentRequestSheetController::ButtonPressed(sender, event); 214 PaymentRequestSheetController::ButtonPressed(sender, event);
214 break; 215 break;
215 } 216 }
216 } 217 }
217 218
218 } // namespace payments 219 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698