Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h" | |
| 6 | |
| 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | |
| 8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | |
| 9 #include "components/strings/grit/components_strings.h" | |
| 10 #include "ui/base/l10n/l10n_util.h" | |
| 11 #include "ui/views/background.h" | |
| 12 #include "ui/views/controls/button/md_text_button.h" | |
| 13 #include "ui/views/layout/box_layout.h" | |
| 14 #include "ui/views/layout/grid_layout.h" | |
| 15 | |
| 16 | |
| 17 namespace payments { | |
| 18 | |
| 19 PaymentRequestSheetController::PaymentRequestSheetController( | |
| 20 PaymentRequest* request, PaymentRequestDialogView* dialog) | |
| 21 : request_(request), dialog_(dialog) { | |
| 22 DCHECK(request_); | |
| 23 DCHECK(dialog_); | |
| 24 } | |
| 25 | |
| 26 std::unique_ptr<views::Button> | |
| 27 PaymentRequestSheetController::CreatePrimaryButton() { | |
| 28 return nullptr; | |
| 29 } | |
| 30 | |
| 31 void PaymentRequestSheetController::ButtonPressed( | |
| 32 views::Button* sender, const ui::Event& event) { | |
| 33 switch (static_cast<PaymentRequestCommonTags>(sender->tag())) { | |
| 34 case PaymentRequestCommonTags::CLOSE_BUTTON_TAG: | |
| 35 dialog()->CloseDialog(); | |
|
Mathieu
2017/02/06 17:24:53
I think for most screens, the desired behavior of
| |
| 36 break; | |
| 37 case PaymentRequestCommonTags::BACK_BUTTON_TAG: | |
| 38 dialog()->GoBack(); | |
| 39 break; | |
| 40 case PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX: | |
| 41 NOTREACHED(); | |
| 42 break; | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 std::unique_ptr<views::View> PaymentRequestSheetController::CreatePaymentView( | |
| 47 std::unique_ptr<views::View> header_view, | |
| 48 std::unique_ptr<views::View> content_view) { | |
| 49 std::unique_ptr<views::View> view = base::MakeUnique<views::View>(); | |
| 50 view->set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); | |
| 51 | |
| 52 // Paint the sheets to layers, otherwise the MD buttons (which do paint to a | |
| 53 // layer) won't do proper clipping. | |
| 54 view->SetPaintToLayer(); | |
| 55 | |
| 56 views::GridLayout* layout = new views::GridLayout(view.get()); | |
| 57 view->SetLayoutManager(layout); | |
| 58 | |
| 59 constexpr int kTopInsetSize = 9; | |
| 60 constexpr int kBottomInsetSize = 18; | |
| 61 layout->SetInsets(kTopInsetSize, 0, kBottomInsetSize, 0); | |
| 62 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 63 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | |
| 64 1, views::GridLayout::USE_PREF, 0, 0); | |
| 65 | |
| 66 layout->StartRow(0, 0); | |
| 67 // |header_view| will be deleted when |view| is. | |
| 68 layout->AddView(header_view.release()); | |
| 69 | |
| 70 layout->StartRow(0, 0); | |
| 71 // |content_view| will be deleted when |view| is. | |
| 72 layout->AddView(content_view.release()); | |
| 73 | |
| 74 layout->AddPaddingRow(1, 0); | |
| 75 layout->StartRow(0, 0); | |
| 76 layout->AddView(CreateFooterView().release()); | |
| 77 | |
| 78 return view; | |
| 79 } | |
| 80 | |
| 81 std::unique_ptr<views::View> PaymentRequestSheetController::CreateFooterView() { | |
| 82 std::unique_ptr<views::View> container = base::MakeUnique<views::View>(); | |
| 83 | |
| 84 views::GridLayout* layout = new views::GridLayout(container.get()); | |
| 85 container->SetLayoutManager(layout); | |
| 86 | |
| 87 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 88 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, | |
| 89 0, views::GridLayout::USE_PREF, 0, 0); | |
| 90 columns->AddPaddingColumn(1, 0); | |
| 91 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
| 92 0, views::GridLayout::USE_PREF, 0, 0); | |
| 93 | |
| 94 layout->StartRow(0, 0); | |
| 95 std::unique_ptr<views::View> leading_buttons_container = | |
| 96 base::MakeUnique<views::View>(); | |
| 97 | |
| 98 // TODO(anthonyvd): Add the other buttons that can eventually go into this | |
| 99 // footer. | |
| 100 | |
| 101 layout->AddView(leading_buttons_container.release()); | |
| 102 | |
| 103 std::unique_ptr<views::View> trailing_buttons_container = | |
| 104 base::MakeUnique<views::View>(); | |
| 105 | |
| 106 constexpr int kButtonSpacing = 10; | |
| 107 trailing_buttons_container->SetLayoutManager(new views::BoxLayout( | |
| 108 views::BoxLayout::kHorizontal, | |
| 109 kPaymentRequestRowHorizontalInsets, | |
| 110 kPaymentRequestRowVerticalInsets, | |
| 111 kButtonSpacing)); | |
| 112 | |
| 113 std::unique_ptr<views::Button> primary_button = CreatePrimaryButton(); | |
| 114 if (primary_button) | |
| 115 trailing_buttons_container->AddChildView(primary_button.release()); | |
| 116 | |
| 117 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( | |
| 118 this, l10n_util::GetStringUTF16(IDS_CANCEL)); | |
| 119 button->set_tag(static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG)); | |
| 120 trailing_buttons_container->AddChildView(button); | |
| 121 | |
| 122 layout->AddView(trailing_buttons_container.release()); | |
| 123 | |
| 124 return container; | |
| 125 } | |
| 126 | |
| 127 } // namespace payments | |
| OLD | NEW |