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 |
21 namespace { | 35 namespace { |
22 | 36 |
23 // The tag for the button that navigates to the Order Summary sheet. | 37 constexpr int kRowVerticalInset = 18; |
24 constexpr int kOrderSummaryTag = 0; | 38 // The rows have extra inset compared to the header so that their right edge |
39 // lines up with the close button's X rather than its invisible right edge. | |
40 constexpr int kRowExtraRightInset = 8; | |
41 | |
42 constexpr int kPaddingColumnsWidth = 25; | |
43 | |
44 enum PaymentSheetViewControllerTags { | |
45 // The tag for the button that navigates to the Order Summary sheet. | |
46 SHOW_ORDER_SUMMARY_BUTTON = payments::PAYMENT_REQUEST_COMMON_TAG_MAX, | |
47 }; | |
48 | |
49 // Creates a clickable row to be displayed in the Payment Sheet. It contains | |
50 // a section name and some content, followed by a chevron as a clickability | |
51 // affordance. Both, either, or none of |content_view| and |extra_content_view| | |
52 // may be present, the difference between the two being that content is pinned | |
53 // to the left and extra_content is pinned to the right. | |
54 // The row also displays a light gray horizontal ruler on its lower boundary. | |
55 // +----------------------------+ | |
56 // | Name | Content | Extra | > | | |
57 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ <-- ruler | |
58 class PaymentSheetRow : public views::CustomButton { | |
sky
2017/01/04 17:24:45
Do you really need to subclass here? Can't you cre
anthonyvd
2017/01/04 19:08:55
It's currently a subclass because the rows will ne
sky
2017/01/04 20:56:32
Indeed you are right. As you didn't override any f
| |
59 public: | |
60 PaymentSheetRow(views::ButtonListener* listener, | |
61 const base::string16& section_name, | |
62 std::unique_ptr<views::View> content_view, | |
63 std::unique_ptr<views::View> extra_content_view) | |
64 : views::CustomButton(listener) { | |
65 SetBorder(views::CreateSolidSidedBorder(0, 0, 1, 0, SK_ColorLTGRAY)); | |
66 views::GridLayout* layout = new views::GridLayout(this); | |
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 columns->AddPaddingColumn(0, kPaddingColumnsWidth); | |
82 // A column for the chevron. | |
83 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
84 0, views::GridLayout::USE_PREF, 0, 0); | |
85 | |
86 layout->StartRow(0, 0); | |
87 views::Label* name_label = new views::Label(section_name); | |
88 layout->AddView(name_label); | |
89 | |
90 if (content_view) { | |
91 layout->AddView(content_view.release()); | |
92 } else { | |
93 layout->SkipColumns(1); | |
94 } | |
95 | |
96 if (extra_content_view) { | |
97 layout->AddView(extra_content_view.release()); | |
98 } else { | |
99 layout->SkipColumns(1); | |
100 } | |
101 | |
102 views::ImageView* chevron = new views::ImageView(); | |
103 chevron->SetImage(gfx::CreateVectorIcon( | |
104 gfx::VectorIconId::SUBMENU_ARROW, | |
105 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); | |
106 layout->AddView(chevron); | |
107 } | |
108 | |
109 DISALLOW_COPY_AND_ASSIGN(PaymentSheetRow); | |
110 }; | |
25 | 111 |
26 } // namespace | 112 } // namespace |
27 | 113 |
28 namespace payments { | 114 namespace payments { |
29 | 115 |
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 if (sender->tag() == CLOSE_BUTTON_TAG) { |
sky
2017/01/04 17:24:45
no {}
optional: use a switch
anthonyvd
2017/01/04 19:08:55
Done.
| |
145 dialog()->CloseDialog(); | |
146 } else if (sender->tag() == SHOW_ORDER_SUMMARY_BUTTON) { | |
147 dialog()->ShowOrderSummary(); | |
148 } else { | |
149 NOTREACHED(); | |
150 } | |
151 } | |
60 | 152 |
61 dialog()->ShowOrderSummary(); | 153 std::unique_ptr<views::View> |
154 PaymentSheetViewController::CreateOrderSummarySectionContent() { | |
155 base::string16 label_value = | |
156 l10n_util::GetStringFUTF16( | |
157 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, | |
158 l10n_util::GetStringUTF16( | |
159 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL), | |
160 base::ASCIIToUTF16(impl()->details()->total->amount->value), | |
161 base::ASCIIToUTF16(impl()->details()->total->amount->currency)); | |
162 | |
163 return base::MakeUnique<views::Label>(label_value); | |
164 } | |
165 | |
166 std::unique_ptr<views::View> | |
167 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { | |
168 std::unique_ptr<PaymentSheetRow> section = base::MakeUnique<PaymentSheetRow>( | |
169 this, | |
170 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), | |
171 std::unique_ptr<views::View>(nullptr), | |
172 CreateOrderSummarySectionContent()); | |
173 section->set_tag(SHOW_ORDER_SUMMARY_BUTTON); | |
174 return section; | |
62 } | 175 } |
63 | 176 |
64 } // namespace payments | 177 } // namespace payments |
OLD | NEW |