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 |
211 std::unique_ptr<views::Label> currency_label = | 213 DCHECK(!bold || !hint_color); |
212 bold ? CreateBoldLabel(currency) | 214 std::unique_ptr<views::Label> currency_label; |
213 : base::MakeUnique<views::Label>(currency); | 215 if (bold) |
214 if (disabled_color) { | 216 currency_label = CreateBoldLabel(currency); |
215 currency_label->SetDisabledColor( | 217 else if (hint_color) |
216 currency_label->GetNativeTheme()->GetSystemColor( | 218 currency_label = CreateHintLabel(currency); |
217 ui::NativeTheme::kColorId_LabelDisabledColor)); | 219 else |
218 currency_label->SetEnabled(false); | 220 currency_label = base::MakeUnique<views::Label>(currency); |
219 } | 221 |
220 std::unique_ptr<views::Label> amount_label = | 222 std::unique_ptr<views::Label> amount_label = |
221 bold ? CreateBoldLabel(amount) : base::MakeUnique<views::Label>(amount); | 223 bold ? CreateBoldLabel(amount) : base::MakeUnique<views::Label>(amount); |
222 amount_label->SetMultiLine(true); | 224 amount_label->SetMultiLine(true); |
223 amount_label->SetAllowCharacterBreak(true); | 225 amount_label->SetAllowCharacterBreak(true); |
224 | 226 |
225 item_amount_layout->StartRow(0, 0); | 227 item_amount_layout->StartRow(0, 0); |
226 item_amount_layout->AddView(currency_label.release()); | 228 item_amount_layout->AddView(currency_label.release()); |
227 item_amount_layout->AddView(amount_label.release()); | 229 item_amount_layout->AddView(amount_label.release()); |
228 | 230 |
229 item_amount_line->SetLayoutManager(item_amount_layout.release()); | 231 item_amount_line->SetLayoutManager(item_amount_layout.release()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 283 |
282 // Creates a row with a button in place of the chevron and |truncated_content| | 284 // Creates a row with a button in place of the chevron and |truncated_content| |
283 // between |section_name| and the button. | 285 // between |section_name| and the button. |
284 // +------------------------------------------+ | 286 // +------------------------------------------+ |
285 // | Name | truncated_content | button_string | | 287 // | Name | truncated_content | button_string | |
286 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | 288 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
287 std::unique_ptr<views::Button> CreateWithButton( | 289 std::unique_ptr<views::Button> CreateWithButton( |
288 const base::string16& truncated_content, | 290 const base::string16& truncated_content, |
289 const base::string16& button_string, | 291 const base::string16& button_string, |
290 bool button_enabled) { | 292 bool button_enabled) { |
291 std::unique_ptr<views::Label> content_view = | 293 return CreateWithButton(CreateHintLabel(truncated_content, gfx::ALIGN_LEFT), |
292 base::MakeUnique<views::Label>(truncated_content); | 294 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 } | 295 } |
301 | 296 |
302 // Creates a row with a button in place of the chevron with the string between | 297 // 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". | 298 // |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 | 299 // |format_string| is used to assemble the truncated preview and the rest of |
305 // the content string. | 300 // the content string. |
306 // +----------------------------------------------+ | 301 // +----------------------------------------------+ |
307 // | Name | preview... and N more | button_string | | 302 // | Name | preview... and N more | button_string | |
308 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | 303 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
309 std::unique_ptr<views::Button> CreateWithButton( | 304 std::unique_ptr<views::Button> CreateWithButton( |
310 const base::string16& preview_text, | 305 const base::string16& preview_text, |
311 const base::string16& format_string, | 306 const base::string16& format_string, |
312 int n, | 307 int n, |
313 const base::string16& button_string, | 308 const base::string16& button_string, |
314 bool button_enabled) { | 309 bool button_enabled) { |
315 std::unique_ptr<PreviewEliderLabel> content_view = | 310 std::unique_ptr<PreviewEliderLabel> content_view = |
316 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n); | 311 base::MakeUnique<PreviewEliderLabel>(preview_text, format_string, n, |
| 312 STYLE_HINT); |
317 content_view->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 313 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, | 314 return CreateWithButton(std::move(content_view), button_string, |
323 button_enabled); | 315 button_enabled); |
324 } | 316 } |
325 | 317 |
326 private: | 318 private: |
327 // Creates a row with a button in place of the chevron. | 319 // Creates a row with a button in place of the chevron. |
328 // +------------------------------------------+ | 320 // +------------------------------------------+ |
329 // | Name | content_view | button_string | | 321 // | Name | content_view | button_string | |
330 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | 322 // +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ |
331 std::unique_ptr<views::Button> CreateWithButton( | 323 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(); | 540 bool is_mixed_currency = spec()->IsMixedCurrency(); |
549 // The inline items section contains the first 2 display items of the | 541 // 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 | 542 // 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 | 543 // there are more than 2 items in the details. The total label and amount |
552 // always follow. | 544 // always follow. |
553 constexpr int kMaxNumberOfItemsShown = 2; | 545 constexpr int kMaxNumberOfItemsShown = 2; |
554 int hidden_item_count = items.size() - kMaxNumberOfItemsShown; | 546 int hidden_item_count = items.size() - kMaxNumberOfItemsShown; |
555 if (hidden_item_count > 0) { | 547 if (hidden_item_count > 0) { |
556 layout->StartRow(0, 0); | 548 layout->StartRow(0, 0); |
557 std::unique_ptr<views::Label> label = | 549 std::unique_ptr<views::Label> label = |
558 base::MakeUnique<views::Label>(l10n_util::GetPluralStringFUTF16( | 550 CreateHintLabel(l10n_util::GetPluralStringFUTF16( |
559 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MORE_ITEMS, hidden_item_count)); | 551 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()); | 552 layout->AddView(label.release()); |
564 if (is_mixed_currency) { | 553 if (is_mixed_currency) { |
565 std::unique_ptr<views::Label> multiple_currency_label = | 554 std::unique_ptr<views::Label> multiple_currency_label = |
566 base::MakeUnique<views::Label>(l10n_util::GetStringUTF16( | 555 CreateHintLabel(l10n_util::GetStringUTF16( |
567 IDS_PAYMENT_REQUEST_ORDER_SUMMARY_MULTIPLE_CURRENCY_INDICATOR)); | 556 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()); | 557 layout->AddView(multiple_currency_label.release()); |
573 } | 558 } |
574 } | 559 } |
575 | 560 |
576 for (size_t i = 0; i < items.size() && i < kMaxNumberOfItemsShown; ++i) { | 561 for (size_t i = 0; i < items.size() && i < kMaxNumberOfItemsShown; ++i) { |
577 layout->StartRow(0, 0); | 562 layout->StartRow(0, 0); |
578 std::unique_ptr<views::Label> summary = | 563 std::unique_ptr<views::Label> summary = |
579 base::MakeUnique<views::Label>(base::UTF8ToUTF16(items[i]->label)); | 564 base::MakeUnique<views::Label>(base::UTF8ToUTF16(items[i]->label)); |
580 summary->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 565 summary->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
581 layout->AddView(summary.release()); | 566 layout->AddView(summary.release()); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 data_source_label->SetDefaultStyle(default_style); | 912 data_source_label->SetDefaultStyle(default_style); |
928 data_source_label->AddStyleRange( | 913 data_source_label->AddStyleRange( |
929 gfx::Range(link_begin, link_begin + link_length), | 914 gfx::Range(link_begin, link_begin + link_length), |
930 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 915 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
931 data_source_label->SizeToFit(0); | 916 data_source_label->SizeToFit(0); |
932 content_view->AddChildView(data_source_label.release()); | 917 content_view->AddChildView(data_source_label.release()); |
933 return content_view; | 918 return content_view; |
934 } | 919 } |
935 | 920 |
936 } // namespace payments | 921 } // namespace payments |
OLD | NEW |