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 <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/strings/string_number_conversions.h" | |
15 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 19 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
19 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
20 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 21 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
21 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 22 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
22 #include "chrome/grit/chromium_strings.h" | 23 #include "chrome/grit/chromium_strings.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "chrome/grit/theme_resources.h" | 25 #include "chrome/grit/theme_resources.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 views::ImageView* chevron = new views::ImageView(); | 158 views::ImageView* chevron = new views::ImageView(); |
158 chevron->set_can_process_events_within_subtree(false); | 159 chevron->set_can_process_events_within_subtree(false); |
159 chevron->SetImage(gfx::CreateVectorIcon( | 160 chevron->SetImage(gfx::CreateVectorIcon( |
160 views::kSubmenuArrowIcon, | 161 views::kSubmenuArrowIcon, |
161 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); | 162 color_utils::DeriveDefaultIconColor(name_label->enabled_color()))); |
162 layout->AddView(chevron); | 163 layout->AddView(chevron); |
163 | 164 |
164 return std::move(row); | 165 return std::move(row); |
165 } | 166 } |
166 | 167 |
168 std::unique_ptr<views::GridLayout> CreateOrderSummarySectionContainerLayout( | |
Mathieu
2017/03/06 15:30:45
Let's document this a bit, including what |host| a
anthonyvd
2017/03/06 16:00:21
Oops, good call. Done.
| |
169 views::View* host, | |
170 bool trailing) { | |
171 std::unique_ptr<views::GridLayout> layout = | |
172 base::MakeUnique<views::GridLayout>(host); | |
173 | |
174 views::ColumnSet* columns = layout->AddColumnSet(0); | |
175 columns->AddColumn( | |
176 trailing ? views::GridLayout::TRAILING : views::GridLayout::LEADING, | |
177 views::GridLayout::LEADING, 1, views::GridLayout::USE_PREF, 0, 0); | |
178 | |
179 return layout; | |
180 } | |
181 | |
167 } // namespace | 182 } // namespace |
168 | 183 |
169 PaymentSheetViewController::PaymentSheetViewController( | 184 PaymentSheetViewController::PaymentSheetViewController( |
170 PaymentRequest* request, | 185 PaymentRequest* request, |
171 PaymentRequestDialogView* dialog) | 186 PaymentRequestDialogView* dialog) |
172 : PaymentRequestSheetController(request, dialog), | 187 : PaymentRequestSheetController(request, dialog), |
173 pay_button_(nullptr), | 188 pay_button_(nullptr), |
174 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { | 189 widest_name_column_view_width_(ComputeWidestNameColumnViewWidth()) { |
175 request->AddObserver(this); | 190 request->AddObserver(this); |
176 } | 191 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 pay_button_->SetEnabled(enabled); | 303 pay_button_->SetEnabled(enabled); |
289 } | 304 } |
290 | 305 |
291 std::unique_ptr<views::View> | 306 std::unique_ptr<views::View> |
292 PaymentSheetViewController::CreateOrderSummarySectionContent() { | 307 PaymentSheetViewController::CreateOrderSummarySectionContent() { |
293 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( | 308 CurrencyFormatter* formatter = request()->GetOrCreateCurrencyFormatter( |
294 request()->details()->total->amount->currency, | 309 request()->details()->total->amount->currency, |
295 request()->details()->total->amount->currency_system, | 310 request()->details()->total->amount->currency_system, |
296 g_browser_process->GetApplicationLocale()); | 311 g_browser_process->GetApplicationLocale()); |
297 base::string16 label_value = l10n_util::GetStringFUTF16( | 312 base::string16 label_value = l10n_util::GetStringFUTF16( |
298 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_TOTAL_FORMAT, | 313 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SHEET_TOTAL_FORMAT, |
299 base::UTF8ToUTF16(request()->details()->total->label), | |
300 base::UTF8ToUTF16(formatter->formatted_currency_code()), | 314 base::UTF8ToUTF16(formatter->formatted_currency_code()), |
301 formatter->Format(request()->details()->total->amount->value)); | 315 formatter->Format(request()->details()->total->amount->value)); |
302 | 316 |
303 return base::MakeUnique<views::Label>(label_value); | 317 return CreateBoldLabel(label_value); |
304 } | 318 } |
305 | 319 |
306 // Creates the Order Summary row, which contains an "Order Summary" label, | 320 // Creates the Order Summary row, which contains an "Order Summary" label, |
307 // a Total Amount label, and a Chevron. | 321 // an inline list of display items, a Total Amount label, and a Chevron. |
308 // +----------------------------------------------+ | 322 // +----------------------------------------------+ |
309 // | Order Summary Total USD $12.34 > | | 323 // | Order Summary Item 1 $ 1.34 | |
324 // | Item 2 $ 2.00 > | | |
325 // | 2 more items... | | |
326 // | Total USD $12.34 | | |
310 // +----------------------------------------------+ | 327 // +----------------------------------------------+ |
311 std::unique_ptr<views::Button> | 328 std::unique_ptr<views::Button> |
312 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { | 329 PaymentSheetViewController::CreatePaymentSheetSummaryRow() { |
330 std::unique_ptr<views::View> item_summary = base::MakeUnique<views::View>(); | |
Mathieu
2017/03/06 15:30:48
nit: item_summaries?
anthonyvd
2017/03/06 16:00:21
Done.
| |
331 std::unique_ptr<views::GridLayout> item_summary_layout = | |
332 CreateOrderSummarySectionContainerLayout(item_summary.get(), | |
333 false /* trailing */); | |
Mathieu
2017/03/06 15:30:49
nit: would prefer /*trailing=*/false otherwise it
anthonyvd
2017/03/06 16:00:21
Hah, didn't think about that! Done. I'll prefer th
| |
334 | |
335 std::unique_ptr<views::View> item_amounts = base::MakeUnique<views::View>(); | |
336 std::unique_ptr<views::GridLayout> item_amounts_layout = | |
337 CreateOrderSummarySectionContainerLayout(item_amounts.get(), | |
338 true /* trailing */); | |
339 | |
340 const std::vector<mojom::PaymentItemPtr>& items = | |
341 request()->details()->display_items; | |
342 // The inline items section contains the first 2 display items of the | |
343 // request's details, followed by a label indicating "N more items..." if | |
344 // there are more than 2 items in the details. The total label and amount | |
345 // always follow. | |
346 | |
Mathieu
2017/03/06 15:30:49
nit: remove extra line
anthonyvd
2017/03/06 16:00:20
Done.
| |
347 for (size_t i = 0; i < items.size() && i < 2; ++i) { | |
Mathieu
2017/03/06 15:30:45
constexpr int kMaxNumberOfItemsShown = 2; and reus
anthonyvd
2017/03/06 16:00:21
Done.
| |
348 item_summary_layout->StartRow(0, 0); | |
349 item_summary_layout->AddView( | |
350 new views::Label(base::ASCIIToUTF16(items[i]->label))); | |
351 | |
352 item_amounts_layout->StartRow(0, 0); | |
353 item_amounts_layout->AddView(new views::Label( | |
354 request()->GetFormattedCurrencyAmount(items[i]->amount->value))); | |
Mathieu
2017/03/06 15:30:47
this is nice! Could we update it in order_summary_
anthonyvd
2017/03/06 16:00:21
Sure, done.
| |
355 } | |
356 | |
357 int hidden_item_count = items.size() - 2; | |
358 if (hidden_item_count > 0) { | |
359 item_summary_layout->StartRow(0, 0); | |
360 views::Label* label = new views::Label( | |
361 l10n_util::GetStringFUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MORE_ITEMS, | |
362 base::IntToString16(hidden_item_count))); | |
363 label->SetAutoColorReadabilityEnabled(false); | |
364 constexpr SkColor kMoreItemsLightGray = 0xFF757575; | |
Mathieu
2017/03/06 15:30:49
In editor view controller I was doing this:
lab
anthonyvd
2017/03/06 16:00:20
(1) Done.
(2) It looks like SetAutoColorReadabilit
| |
365 label->SetEnabledColor(kMoreItemsLightGray); | |
366 item_summary_layout->AddView(label); | |
367 | |
368 item_amounts_layout->StartRow(0, 0); | |
369 item_amounts_layout->AddView(new views::Label(base::ASCIIToUTF16(""))); | |
370 } | |
371 | |
372 item_summary_layout->StartRow(0, 0); | |
373 item_summary_layout->AddView( | |
374 CreateBoldLabel(base::ASCIIToUTF16(request()->details()->total->label)) | |
Mathieu
2017/03/06 15:30:49
Where is the total amount being added?
anthonyvd
2017/03/06 16:00:21
The CreateOrderSummarySectionContent() call below
| |
375 .release()); | |
376 | |
377 item_amounts_layout->StartRow(0, 0); | |
378 item_amounts_layout->AddView(CreateOrderSummarySectionContent().release()); | |
379 | |
380 item_summary->SetLayoutManager(item_summary_layout.release()); | |
381 item_amounts->SetLayoutManager(item_amounts_layout.release()); | |
382 | |
313 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( | 383 std::unique_ptr<views::Button> section = CreatePaymentSheetRow( |
314 this, | 384 this, |
315 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), | 385 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_ORDER_SUMMARY_SECTION_NAME), |
316 std::unique_ptr<views::View>(nullptr), | 386 std::move(item_summary), std::move(item_amounts), |
317 CreateOrderSummarySectionContent(), | |
318 widest_name_column_view_width_); | 387 widest_name_column_view_width_); |
319 section->set_tag(static_cast<int>( | 388 section->set_tag(static_cast<int>( |
320 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); | 389 PaymentSheetViewControllerTags::SHOW_ORDER_SUMMARY_BUTTON)); |
321 section->set_id( | 390 section->set_id( |
322 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); | 391 static_cast<int>(DialogViewID::PAYMENT_SHEET_SUMMARY_SECTION)); |
323 return section; | 392 return section; |
324 } | 393 } |
325 | 394 |
326 std::unique_ptr<views::View> | 395 std::unique_ptr<views::View> |
327 PaymentSheetViewController::CreateShippingSectionContent() { | 396 PaymentSheetViewController::CreateShippingSectionContent() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), | 496 CreateContactInfoSectionContent(), std::unique_ptr<views::View>(nullptr), |
428 widest_name_column_view_width_); | 497 widest_name_column_view_width_); |
429 section->set_tag(static_cast<int>( | 498 section->set_tag(static_cast<int>( |
430 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); | 499 PaymentSheetViewControllerTags::SHOW_CONTACT_INFO_BUTTON)); |
431 section->set_id( | 500 section->set_id( |
432 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); | 501 static_cast<int>(DialogViewID::PAYMENT_SHEET_CONTACT_INFO_SECTION)); |
433 return section; | 502 return section; |
434 } | 503 } |
435 | 504 |
436 } // namespace payments | 505 } // namespace payments |
OLD | NEW |