OLD | NEW |
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 <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 "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/payments/payment_request_impl.h" |
12 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" | 13 #include "chrome/browser/ui/views/payments/payment_request_dialog.h" |
13 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 14 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
14 #include "chrome/grit/generated_resources.h" | 15 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/strings/grit/components_strings.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" |
15 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/gfx/color_utils.h" |
| 20 #include "ui/gfx/font.h" |
| 21 #include "ui/gfx/geometry/insets.h" |
| 22 #include "ui/gfx/paint_vector_icon.h" |
| 23 #include "ui/gfx/range/range.h" |
| 24 #include "ui/gfx/vector_icons/vector_icons.h" |
| 25 #include "ui/views/border.h" |
| 26 #include "ui/views/controls/button/custom_button.h" |
16 #include "ui/views/controls/button/label_button.h" | 27 #include "ui/views/controls/button/label_button.h" |
17 #include "ui/views/controls/button/md_text_button.h" | 28 #include "ui/views/controls/button/md_text_button.h" |
| 29 #include "ui/views/controls/image_view.h" |
| 30 #include "ui/views/controls/label.h" |
| 31 #include "ui/views/controls/styled_label.h" |
18 #include "ui/views/layout/grid_layout.h" | 32 #include "ui/views/layout/grid_layout.h" |
19 #include "ui/views/view.h" | 33 #include "ui/views/view.h" |
20 | 34 |
| 35 namespace payments { |
21 namespace { | 36 namespace { |
22 | 37 |
23 // The tag for the button that navigates to the Order Summary sheet. | 38 enum class PaymentSheetViewControllerTags { |
24 constexpr int kOrderSummaryTag = 0; | 39 // The tag for the button that navigates to the Order Summary sheet. |
| 40 SHOW_ORDER_SUMMARY_BUTTON = static_cast<int>( |
| 41 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX), |
| 42 }; |
| 43 |
| 44 // Creates a clickable row to be displayed in the Payment Sheet. It contains |
| 45 // a section name and some content, followed by a chevron as a clickability |
| 46 // affordance. Both, either, or none of |content_view| and |extra_content_view| |
| 47 // may be present, the difference between the two being that content is pinned |
| 48 // to the left and extra_content is pinned to the right. |
| 49 // The row also displays a light gray horizontal ruler on its lower boundary. |
| 50 // +----------------------------+ |
| 51 // | Name | Content | Extra | > | |
| 52 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler |
| 53 class PaymentSheetRow : public views::CustomButton { |
| 54 public: |
| 55 PaymentSheetRow(views::ButtonListener* listener, |
| 56 const base::string16& section_name, |
| 57 std::unique_ptr<views::View> content_view, |
| 58 std::unique_ptr<views::View> extra_content_view) |
| 59 : views::CustomButton(listener) { |
| 60 SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY)); |
| 61 views::GridLayout* layout = new views::GridLayout(this); |
| 62 |
| 63 constexpr int kRowVerticalInset = 18; |
| 64 // The rows have extra inset compared to the header so that their right edge |
| 65 // lines up with the close button's X rather than its invisible right edge. |
| 66 constexpr int kRowExtraRightInset = 8; |
| 67 layout->SetInsets( |
| 68 kRowVerticalInset, 0, kRowVerticalInset, kRowExtraRightInset); |
| 69 SetLayoutManager(layout); |
| 70 |
| 71 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 72 // A column for the section name. |
| 73 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, |
| 74 0, views::GridLayout::USE_PREF, 0, 0); |
| 75 // A column for the content. |
| 76 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
| 77 1, views::GridLayout::USE_PREF, 0, 0); |
| 78 // A column for the extra content. |
| 79 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 80 0, views::GridLayout::USE_PREF, 0, 0); |
| 81 |
| 82 constexpr int kPaddingColumnsWidth = 25; |
| 83 columns->AddPaddingColumn(0, kPaddingColumnsWidth); |
| 84 // A column for the chevron. |
| 85 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 86 0, views::GridLayout::USE_PREF, 0, 0); |
| 87 |
| 88 layout->StartRow(0, 0); |
| 89 views::Label* name_label = new views::Label(section_name); |
| 90 layout->AddView(name_label); |
| 91 |
| 92 if (content_view) { |
| 93 layout->AddView(content_view.release()); |
| 94 } else { |
| 95 layout->SkipColumns(1); |
| 96 } |
| 97 |
| 98 if (extra_content_view) { |
| 99 layout->AddView(extra_content_view.release()); |
| 100 } else { |
| 101 layout->SkipColumns(1); |
| 102 } |
| 103 |
| 104 views::ImageView* chevron = new views::ImageView(); |
| 105 chevron->SetImage(gfx::CreateVectorIcon( |
| 106 gfx::VectorIconId::SUBMENU_ARROW, |
| 107 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); |
| 108 layout->AddView(chevron); |
| 109 } |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow); |
| 112 }; |
25 | 113 |
26 } // namespace | 114 } // namespace |
27 | 115 |
28 namespace payments { | |
29 | |
30 PaymentSheetViewController::PaymentSheetViewController( | 116 PaymentSheetViewController::PaymentSheetViewController( |
31 PaymentRequestImpl* impl, PaymentRequestDialog* dialog) | 117 PaymentRequestImpl* impl, PaymentRequestDialog* dialog) |
32 : PaymentRequestSheetController(impl, dialog) {} | 118 : PaymentRequestSheetController(impl, dialog) {} |
33 | 119 |
34 PaymentSheetViewController::~PaymentSheetViewController() {} | 120 PaymentSheetViewController::~PaymentSheetViewController() {} |
35 | 121 |
36 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { | 122 std::unique_ptr<views::View> PaymentSheetViewController::CreateView() { |
37 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); | 123 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>(); |
38 | 124 |
39 views::GridLayout* layout = new views::GridLayout(content_view.get()); | 125 views::GridLayout* layout = new views::GridLayout(content_view.get()); |
40 content_view->SetLayoutManager(layout); | 126 content_view->SetLayoutManager(layout); |
41 views::ColumnSet* columns = layout->AddColumnSet(0); | 127 views::ColumnSet* columns = layout->AddColumnSet(0); |
42 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 128 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
43 0, views::GridLayout::USE_PREF, 0, 0); | 129 1, views::GridLayout::USE_PREF, 0, 0); |
44 | 130 |
45 layout->StartRow(0, 0); | 131 layout->StartRow(0, 0); |
46 views::LabelButton* order_summary_button = | 132 layout->AddView(CreatePaymentSheetSummaryRow().release()); |
47 views::MdTextButton::CreateSecondaryUiBlueButton( | |
48 this, base::ASCIIToUTF16("Order Summary")); | |
49 order_summary_button->set_tag(kOrderSummaryTag); | |
50 layout->AddView(order_summary_button); | |
51 | 133 |
52 return payments::CreatePaymentView( | 134 return CreatePaymentView( |
53 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), | 135 CreateSheetHeaderView( |
| 136 false, |
| 137 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_PAYMENT_SHEET_TITLE), |
| 138 this), |
54 std::move(content_view)); | 139 std::move(content_view)); |
55 } | 140 } |
56 | 141 |
57 void PaymentSheetViewController::ButtonPressed( | 142 void PaymentSheetViewController::ButtonPressed( |
58 views::Button* sender, const ui::Event& event) { | 143 views::Button* sender, const ui::Event& event) { |
59 DCHECK_EQ(kOrderSummaryTag, sender->tag()); | 144 switch (sender->tag()) { |
| 145 case static_cast<int>(PaymentRequestCommonTags::CLOSE_BUTTON_TAG): |
| 146 dialog()->CloseDialog(); |
| 147 break; |
| 148 case static_cast<int>( |
| 149 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON): |
| 150 dialog()->ShowOrderSummary(); |
| 151 break; |
| 152 default: |
| 153 NOTREACHED(); |
| 154 } |
| 155 } |
60 | 156 |
61 dialog()->ShowOrderSummary(); | 157 std::unique_ptr<views::View> |
| 158 PaymentSheetViewController::CreateOrderSummarySectionContent() { |
| 159 base::string16 label_value = |
| 160 l10n_util::GetStringFUTF16( |
| 161 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, |
| 162 base::ASCIIToUTF16(impl()->details()->total->label), |
| 163 base::ASCIIToUTF16(impl()->details()->total->amount->currency), |
| 164 base::ASCIIToUTF16(impl()->details()->total->amount->value)); |
| 165 |
| 166 return base::MakeUnique<views::Label>(label_value); |
| 167 } |
| 168 |
| 169 std::unique_ptr<views::View> |
| 170 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { |
| 171 std::unique_ptr<PaymentSheetRow> section = base::MakeUnique<PaymentSheetRow>( |
| 172 this, |
| 173 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), |
| 174 std::unique_ptr<views::View>(nullptr), |
| 175 CreateOrderSummarySectionContent()); |
| 176 section->set_tag(static_cast<int>( |
| 177 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
| 178 return section; |
62 } | 179 } |
63 | 180 |
64 } // namespace payments | 181 } // namespace payments |
OLD | NEW |