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