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

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

Issue 2759253002: [Web Payments] Implement item selection in lists. (Closed)
Patch Set: Assert back navigation in browser tests. 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_sheet_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 24 matching lines...) Expand all
35 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/color_utils.h" 36 #include "ui/gfx/color_utils.h"
37 #include "ui/gfx/font.h" 37 #include "ui/gfx/font.h"
38 #include "ui/gfx/paint_vector_icon.h" 38 #include "ui/gfx/paint_vector_icon.h"
39 #include "ui/gfx/range/range.h" 39 #include "ui/gfx/range/range.h"
40 #include "ui/views/controls/button/md_text_button.h" 40 #include "ui/views/controls/button/md_text_button.h"
41 #include "ui/views/controls/image_view.h" 41 #include "ui/views/controls/image_view.h"
42 #include "ui/views/controls/label.h" 42 #include "ui/views/controls/label.h"
43 #include "ui/views/controls/styled_label.h" 43 #include "ui/views/controls/styled_label.h"
44 #include "ui/views/layout/box_layout.h" 44 #include "ui/views/layout/box_layout.h"
45 #include "ui/views/layout/fill_layout.h"
45 #include "ui/views/layout/grid_layout.h" 46 #include "ui/views/layout/grid_layout.h"
46 #include "ui/views/vector_icons.h" 47 #include "ui/views/vector_icons.h"
47 #include "ui/views/view.h" 48 #include "ui/views/view.h"
48 49
49 namespace payments { 50 namespace payments {
50 namespace { 51 namespace {
51 52
52 constexpr int kFirstTagValue = static_cast<int>( 53 constexpr int kFirstTagValue = static_cast<int>(
53 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); 54 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
54 55
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return layout; 187 return layout;
187 } 188 }
188 189
189 } // namespace 190 } // namespace
190 191
191 PaymentSheetViewController::PaymentSheetViewController( 192 PaymentSheetViewController::PaymentSheetViewController(
192 PaymentRequestSpec* spec, 193 PaymentRequestSpec* spec,
193 PaymentRequestState* state, 194 PaymentRequestState* state,
194 PaymentRequestDialogView* dialog) 195 PaymentRequestDialogView* dialog)
195 : PaymentRequestSheetController(spec, state, dialog), 196 : PaymentRequestSheetController(spec, state, dialog),
197 container_view_(base::MakeUnique<views::View>()),
196 pay_button_(nullptr), 198 pay_button_(nullptr),
197 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { 199 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) {
200 container_view_->set_owned_by_client();
198 state->AddObserver(this); 201 state->AddObserver(this);
199 } 202 }
200 203
201 PaymentSheetViewController::~PaymentSheetViewController() { 204 PaymentSheetViewController::~PaymentSheetViewController() {
202 state()->RemoveObserver(this); 205 state()->RemoveObserver(this);
203 } 206 }
204 207
205 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { 208 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() {
206 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); 209 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
210 content_view->SetLayoutManager(new views::FillLayout);
207 211
208 views::GridLayout* layout = new views::GridLayout(content_view.get()); 212 UpdateContentView();
209 content_view->SetLayoutManager(layout); 213 content_view->AddChildView(container_view_.get());
210 views::ColumnSet* columns = layout->AddColumnSet(0);
211 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
212 1, views::GridLayout::USE_PREF, 0, 0);
213
214 // The shipping address and contact info rows are optional.
215 layout->StartRow(0, 0);
216 layout->AddView(CreatePaymentSheetSummaryRow().release());
217
218 if (spec()->request_shipping()) {
219 layout->StartRow(0, 0);
220 layout->AddView(CreateShippingRow().release());
221 layout->StartRow(0, 0);
222 layout->AddView(CreateShippingOptionRow().release());
223 }
224 layout->StartRow(0, 0);
225 layout->AddView(CreatePaymentMethodRow().release());
226 if (spec()->request_payer_name() || spec()->request_payer_email() ||
227 spec()->request_payer_phone()) {
228 layout->StartRow(0, 0);
229 layout->AddView(CreateContactInfoRow().release());
230 }
231 214
232 return CreatePaymentView( 215 return CreatePaymentView(
233 CreateSheetHeaderView( 216 CreateSheetHeaderView(
234 false, 217 false,
235 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), 218 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE),
236 this), 219 this),
237 std::move(content_view)); 220 std::move(content_view));
238 } 221 }
239 222
240 void PaymentSheetViewController::OnSelectedInformationChanged() { 223 void PaymentSheetViewController::OnSelectedInformationChanged() {
241 UpdatePayButtonState(state()->is_ready_to_pay()); 224 UpdatePayButtonState(state()->is_ready_to_pay());
225 UpdateContentView();
226 container_view_->Layout();
242 } 227 }
243 228
244 std::unique_ptr<views::Button> 229 std::unique_ptr<views::Button>
245 PaymentSheetViewController::CreatePrimaryButton() { 230 PaymentSheetViewController::CreatePrimaryButton() {
246 std::unique_ptr<views::Button> button( 231 std::unique_ptr<views::Button> button(
247 views::MdTextButton::CreateSecondaryUiBlueButton( 232 views::MdTextButton::CreateSecondaryUiBlueButton(
248 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); 233 this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON)));
249 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); 234 button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG));
250 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON)); 235 button->set_id(static_cast<int>(DialogViewID::PAY_BUTTON));
251 pay_button_ = button.get(); 236 pay_button_ = button.get();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 default: 296 default:
312 PaymentRequestSheetController::ButtonPressed(sender, event); 297 PaymentRequestSheetController::ButtonPressed(sender, event);
313 break; 298 break;
314 } 299 }
315 } 300 }
316 301
317 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { 302 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) {
318 pay_button_->SetEnabled(enabled); 303 pay_button_->SetEnabled(enabled);
319 } 304 }
320 305
306 void PaymentSheetViewController::UpdateContentView() {
307 container_view_->RemoveAllChildViews(/*delete_children=*/true);
308 views::GridLayout* layout = new views::GridLayout(container_view_.get());
309 container_view_->SetLayoutManager(layout);
310 views::ColumnSet* columns = layout->AddColumnSet(0);
311 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1,
312 views::GridLayout::USE_PREF, 0, 0);
313
314 // The shipping address and contact info rows are optional.
315 layout->StartRow(0, 0);
316 layout->AddView(CreatePaymentSheetSummaryRow().release());
317
318 if (spec()->request_shipping()) {
319 layout->StartRow(0, 0);
320 layout->AddView(CreateShippingRow().release());
321 layout->StartRow(0, 0);
322 layout->AddView(CreateShippingOptionRow().release());
323 }
324 layout->StartRow(0, 0);
325 layout->AddView(CreatePaymentMethodRow().release());
326 if (spec()->request_payer_name() || spec()->request_payer_email() ||
327 spec()->request_payer_phone()) {
328 layout->StartRow(0, 0);
329 layout->AddView(CreateContactInfoRow().release());
330 }
331 }
332
321 // Creates the Order Summary row, which contains an "Order Summary" label, 333 // Creates the Order Summary row, which contains an "Order Summary" label,
322 // an inline list of display items, a Total Amount label, and a Chevron. 334 // an inline list of display items, a Total Amount label, and a Chevron.
323 // +----------------------------------------------+ 335 // +----------------------------------------------+
324 // | Order Summary Item 1 $ 1.34 | 336 // | Order Summary Item 1 $ 1.34 |
325 // | Item 2 $ 2.00 > | 337 // | Item 2 $ 2.00 > |
326 // | 2 more items... | 338 // | 2 more items... |
327 // | Total USD $12.34 | 339 // | Total USD $12.34 |
328 // +----------------------------------------------+ 340 // +----------------------------------------------+
329 std::unique_ptr<views::Button> 341 std::unique_ptr<views::Button>
330 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { 342 PaymentSheetViewController::CreatePaymentSheetSummaryRow() {
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 std::move(option_label), std::unique_ptr<views::View>(nullptr), 531 std::move(option_label), std::unique_ptr<views::View>(nullptr),
520 widest_name_column_view_width_); 532 widest_name_column_view_width_);
521 section->set_tag(static_cast<int>( 533 section->set_tag(static_cast<int>(
522 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON)); 534 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON));
523 section->set_id( 535 section->set_id(
524 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION)); 536 static_cast<int>(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION));
525 return section; 537 return section;
526 } 538 }
527 539
528 } // namespace payments 540 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698