Chromium Code Reviews| 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/i18n/message_formatter.h" | 13 #include "base/i18n/message_formatter.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/chrome_pages.h" | 22 #include "chrome/browser/ui/chrome_pages.h" |
| 23 #include "chrome/browser/ui/views/harmony/chrome_typography.h" | |
| 23 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 24 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 24 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 25 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 25 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 26 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 26 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 27 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 28 #include "components/autofill/core/browser/field_types.h" | 29 #include "components/autofill/core/browser/field_types.h" |
| 29 #include "components/autofill/core/browser/personal_data_manager.h" | 30 #include "components/autofill/core/browser/personal_data_manager.h" |
| 30 #include "components/payments/content/payment_request_spec.h" | 31 #include "components/payments/content/payment_request_spec.h" |
| 31 #include "components/payments/content/payment_request_state.h" | 32 #include "components/payments/content/payment_request_state.h" |
| 32 #include "components/payments/core/currency_formatter.h" | 33 #include "components/payments/core/currency_formatter.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // A class that ensures proper elision of labels in the form | 79 // A class that ensures proper elision of labels in the form |
| 79 // "[preview] and N more" where preview might be elided to allow "and N more" to | 80 // "[preview] and N more" where preview might be elided to allow "and N more" to |
| 80 // be always visible. | 81 // be always visible. |
| 81 class PreviewEliderLabel : public views::Label { | 82 class PreviewEliderLabel : public views::Label { |
| 82 public: | 83 public: |
| 83 // Creates a PreviewEliderLabel where |preview_text| might be elided, | 84 // Creates a PreviewEliderLabel where |preview_text| might be elided, |
| 84 // |format_string| is the string with format argument numbers in ICU syntax | 85 // |format_string| is the string with format argument numbers in ICU syntax |
| 85 // and |n| is the "N more" item count. | 86 // and |n| is the "N more" item count. |
| 86 PreviewEliderLabel(const base::string16& preview_text, | 87 PreviewEliderLabel(const base::string16& preview_text, |
| 87 const base::string16& format_string, | 88 const base::string16& format_string, |
| 88 int n) | 89 int n, |
| 89 : views::Label(base::string16()), | 90 int text_style) |
| 91 : views::Label(base::string16(), views::style::CONTEXT_LABEL, text_style), | |
| 90 preview_text_(preview_text), | 92 preview_text_(preview_text), |
| 91 format_string_(format_string), | 93 format_string_(format_string), |
| 92 n_(n) {} | 94 n_(n) {} |
| 93 | 95 |
| 94 private: | 96 private: |
| 95 // Formats |preview_text_|, |format_string_|, and |n_| into a string that fits | 97 // Formats |preview_text_|, |format_string_|, and |n_| into a string that fits |
| 96 // inside of |pixel_width|, eliding |preview_text_| as required. | 98 // inside of |pixel_width|, eliding |preview_text_| as required. |
| 97 base::string16 CreateElidedString(int pixel_width) { | 99 base::string16 CreateElidedString(int pixel_width) { |
| 98 for (int preview_length = preview_text_.size(); preview_length > 0; | 100 for (int preview_length = preview_text_.size(); preview_length > 0; |
| 99 --preview_length) { | 101 --preview_length) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 } | 189 } |
| 188 | 190 |
| 189 layout->AddView(trailing_button.release()); | 191 layout->AddView(trailing_button.release()); |
| 190 | 192 |
| 191 return std::move(row); | 193 return std::move(row); |
| 192 } | 194 } |
| 193 | 195 |
| 194 std::unique_ptr<views::View> CreateInlineCurrencyAmountItem( | 196 std::unique_ptr<views::View> CreateInlineCurrencyAmountItem( |
| 195 const base::string16& currency, | 197 const base::string16& currency, |
| 196 const base::string16& amount, | 198 const base::string16& amount, |
| 197 bool disabled_color, | 199 bool hint_color, |
| 198 bool bold) { | 200 bool bold) { |
| 199 std::unique_ptr<views::View> item_amount_line = | 201 std::unique_ptr<views::View> item_amount_line = |
| 200 base::MakeUnique<views::View>(); | 202 base::MakeUnique<views::View>(); |
| 201 std::unique_ptr<views::GridLayout> item_amount_layout = | 203 std::unique_ptr<views::GridLayout> item_amount_layout = |
| 202 base::MakeUnique<views::GridLayout>(item_amount_line.get()); | 204 base::MakeUnique<views::GridLayout>(item_amount_line.get()); |
| 203 views::ColumnSet* item_amount_columns = item_amount_layout->AddColumnSet(0); | 205 views::ColumnSet* item_amount_columns = item_amount_layout->AddColumnSet(0); |
| 204 item_amount_columns->AddColumn(views::GridLayout::LEADING, | 206 item_amount_columns->AddColumn(views::GridLayout::LEADING, |
| 205 views::GridLayout::LEADING, 0, | 207 views::GridLayout::LEADING, 0, |
| 206 views::GridLayout::USE_PREF, 0, 0); | 208 views::GridLayout::USE_PREF, 0, 0); |
| 207 item_amount_columns->AddColumn(views::GridLayout::TRAILING, | 209 item_amount_columns->AddColumn(views::GridLayout::TRAILING, |
| 208 views::GridLayout::LEADING, 1, | 210 views::GridLayout::LEADING, 1, |
| 209 views::GridLayout::USE_PREF, 0, 0); | 211 views::GridLayout::USE_PREF, 0, 0); |
| 210 | 212 |
| 213 DCHECK(!bold || !hint_color); | |
| 211 std::unique_ptr<views::Label> currency_label = | 214 std::unique_ptr<views::Label> currency_label = |
| 212 bold ? CreateBoldLabel(currency) | 215 bold ? CreateBoldLabel(currency) |
| 213 : base::MakeUnique<views::Label>(currency); | 216 : (hint_color ? CreateHintLabel(currency) |
| 214 if (disabled_color) { | 217 : base::MakeUnique<views::Label>(currency)); |
|
Peter Kasting
2017/06/01 04:55:58
Nit: Nesting ?:s makes me unhappy.
tapted
2017/06/01 11:22:18
Done.
| |
| 215 currency_label->SetDisabledColor( | |
| 216 currency_label->GetNativeTheme()->GetSystemColor( | |
| 217 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 218 currency_label->SetEnabled(false); | |
| 219 } | |
| 220 std::unique_ptr<views::Label> amount_label = | 218 std::unique_ptr<views::Label> amount_label = |
| 221 bold ? CreateBoldLabel(amount) : base::MakeUnique<views::Label>(amount); | 219 bold ? CreateBoldLabel(amount) : base::MakeUnique<views::Label>(amount); |
| 222 amount_label->SetMultiLine(true); | 220 amount_label->SetMultiLine(true); |
| 223 amount_label->SetAllowCharacterBreak(true); | 221 amount_label->SetAllowCharacterBreak(true); |
| 224 | 222 |
| 225 item_amount_layout->StartRow(0, 0); | 223 item_amount_layout->StartRow(0, 0); |
| 226 item_amount_layout->AddView(currency_label.release()); | 224 item_amount_layout->AddView(currency_label.release()); |
| 227 item_amount_layout->AddView(amount_label.release()); | 225 item_amount_layout->AddView(amount_label.release()); |
| 228 | 226 |
| 229 item_amount_line->SetLayoutManager(item_amount_layout.release()); | 227 item_amount_line->SetLayoutManager(item_amount_layout.release()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 | 279 |
| 282 // Creates a row with a button in place of the chevron and |truncated_content| | 280 // Creates a row with a button in place of the chevron and |truncated_content| |
| 283 // between |section_name| and the button. | 281 // between |section_name| and the button. |
| 284 // +------------------------------------------+ | 282 // +------------------------------------------+ |
| 285 // | Name | truncated_content | button_string | | 283 // | Name | truncated_content | button_string | |
| 286 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | 284 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
| 287 std::unique_ptr<views::Button> CreateWithButton( | 285 std::unique_ptr<views::Button> CreateWithButton( |
| 288 const base::string16& truncated_content, | 286 const base::string16& truncated_content, |
| 289 const base::string16& button_string, | 287 const base::string16& button_string, |
| 290 bool button_enabled) { | 288 bool button_enabled) { |
| 291 std::unique_ptr<views::Label> content_view = | 289 return CreateWithButton(CreateHintLabel(truncated_content, gfx::ALIGN_LEFT), |
| 292 base::MakeUnique<views::Label>(truncated_content); | 290 button_string, button_enabled); |
| 293 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 294 content_view->SetDisabledColor( | |
| 295 content_view->GetNativeTheme()->GetSystemColor( | |
| 296 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 297 content_view->SetEnabled(false); | |
| 298 return CreateWithButton(std::move(content_view), button_string, | |
| 299 button_enabled); | |
| 300 } | 291 } |
| 301 | 292 |
| 302 // Creates a row with a button in place of the chevron with the string between | 293 // Creates a row with a button in place of the chevron with the string between |
| 303 // |section_name| and the button built as "|preview|... and |n| more". | 294 // |section_name| and the button built as "|preview|... and |n| more". |
| 304 // |format_string| is used to assemble the truncated preview and the rest of | 295 // |format_string| is used to assemble the truncated preview and the rest of |
| 305 // the content string. | 296 // the content string. |
| 306 // +----------------------------------------------+ | 297 // +----------------------------------------------+ |
| 307 // | Name | preview... and N more | button_string | | 298 // | Name | preview... and N more | button_string | |
| 308 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | 299 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
| 309 std::unique_ptr<views::Button> CreateWithButton( | 300 std::unique_ptr<views::Button> CreateWithButton( |
| 310 const base::string16& preview_text, | 301 const base::string16& preview_text, |
| 311 const base::string16& format_string, | 302 const base::string16& format_string, |
| 312 int n, | 303 int n, |
| 313 const base::string16& button_string, | 304 const base::string16& button_string, |
| 314 bool button_enabled) { | 305 bool button_enabled) { |
| 315 std::unique_ptr<PreviewEliderLabel> content_view = | 306 std::unique_ptr<PreviewEliderLabel> content_view = |
| 316 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n); | 307 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n, |
| 308 STYLE_HINT); | |
| 317 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 309 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 318 content_view->SetDisabledColor( | |
| 319 content_view->GetNativeTheme()->GetSystemColor( | |
| 320 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 321 content_view->SetEnabled(false); | |
| 322 return CreateWithButton(std::move(content_view), button_string, | 310 return CreateWithButton(std::move(content_view), button_string, |
| 323 button_enabled); | 311 button_enabled); |
| 324 } | 312 } |
| 325 | 313 |
| 326 private: | 314 private: |
| 327 // Creates a row with a button in place of the chevron. | 315 // Creates a row with a button in place of the chevron. |
| 328 // +------------------------------------------+ | 316 // +------------------------------------------+ |
| 329 // | Name | content_view | button_string | | 317 // | Name | content_view | button_string | |
| 330 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | 318 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
| 331 std::unique_ptr<views::Button> CreateWithButton( | 319 std::unique_ptr<views::Button> CreateWithButton( |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 bool is_mixed_currency = spec()->IsMixedCurrency(); | 536 bool is_mixed_currency = spec()->IsMixedCurrency(); |
| 549 // The inline items section contains the first 2 display items of the | 537 // The inline items section contains the first 2 display items of the |
| 550 // request's details, followed by a label indicating "N more items..." if | 538 // request's details, followed by a label indicating "N more items..." if |
| 551 // there are more than 2 items in the details. The total label and amount | 539 // there are more than 2 items in the details. The total label and amount |
| 552 // always follow. | 540 // always follow. |
| 553 constexpr int kMaxNumberOfItemsShown = 2; | 541 constexpr int kMaxNumberOfItemsShown = 2; |
| 554 int hidden_item_count = items.size() - kMaxNumberOfItemsShown; | 542 int hidden_item_count = items.size() - kMaxNumberOfItemsShown; |
| 555 if (hidden_item_count > 0) { | 543 if (hidden_item_count > 0) { |
| 556 layout->StartRow(0, 0); | 544 layout->StartRow(0, 0); |
| 557 std::unique_ptr<views::Label> label = | 545 std::unique_ptr<views::Label> label = |
| 558 base::MakeUnique<views::Label>(l10n_util::GetPluralStringFUTF16( | 546 CreateHintLabel(l10n_util::GetPluralStringFUTF16( |
| 559 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MORE_ITEMS, hidden_item_count)); | 547 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MORE_ITEMS, hidden_item_count)); |
| 560 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( | |
| 561 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 562 label->SetEnabled(false); | |
| 563 layout->AddView(label.release()); | 548 layout->AddView(label.release()); |
| 564 if (is_mixed_currency) { | 549 if (is_mixed_currency) { |
| 565 std::unique_ptr<views::Label> multiple_currency_label = | 550 std::unique_ptr<views::Label> multiple_currency_label = |
| 566 base::MakeUnique<views::Label>(l10n_util::GetStringUTF16( | 551 CreateHintLabel(l10n_util::GetStringUTF16( |
| 567 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MULTIPLE_CURRENCY_INDICATOR)); | 552 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MULTIPLE_CURRENCY_INDICATOR)); |
| 568 multiple_currency_label->SetDisabledColor( | |
| 569 multiple_currency_label->GetNativeTheme()->GetSystemColor( | |
| 570 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 571 multiple_currency_label->SetEnabled(false); | |
| 572 layout->AddView(multiple_currency_label.release()); | 553 layout->AddView(multiple_currency_label.release()); |
| 573 } | 554 } |
| 574 } | 555 } |
| 575 | 556 |
| 576 for (size_t i = 0; i < items.size() && i < kMaxNumberOfItemsShown; ++i) { | 557 for (size_t i = 0; i < items.size() && i < kMaxNumberOfItemsShown; ++i) { |
| 577 layout->StartRow(0, 0); | 558 layout->StartRow(0, 0); |
| 578 std::unique_ptr<views::Label> summary = | 559 std::unique_ptr<views::Label> summary = |
| 579 base::MakeUnique<views::Label>(base::UTF8ToUTF16(items[i]->label)); | 560 base::MakeUnique<views::Label>(base::UTF8ToUTF16(items[i]->label)); |
| 580 summary->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 561 summary->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 581 layout->AddView(summary.release()); | 562 layout->AddView(summary.release()); |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 927 data_source_label->SetDefaultStyle(default_style); | 908 data_source_label->SetDefaultStyle(default_style); |
| 928 data_source_label->AddStyleRange( | 909 data_source_label->AddStyleRange( |
| 929 gfx::Range(link_begin, link_begin + link_length), | 910 gfx::Range(link_begin, link_begin + link_length), |
| 930 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 911 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 931 data_source_label->SizeToFit(0); | 912 data_source_label->SizeToFit(0); |
| 932 content_view->AddChildView(data_source_label.release()); | 913 content_view->AddChildView(data_source_label.release()); |
| 933 return content_view; | 914 return content_view; |
| 934 } | 915 } |
| 935 | 916 |
| 936 } // namespace payments | 917 } // namespace payments |
| OLD | NEW |