OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 11 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
13 #include "chrome/browser/profiles/profile_window.h" | 13 #include "chrome/browser/profiles/profile_window.h" |
14 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
16 #include "chrome/browser/signin/signin_manager_factory.h" | 16 #include "chrome/browser/signin/signin_manager_factory.h" |
17 #include "chrome/browser/signin/signin_promo.h" | 17 #include "chrome/browser/signin/signin_promo.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_dialogs.h" | 19 #include "chrome/browser/ui/browser_dialogs.h" |
| 20 #include "chrome/browser/ui/chrome_pages.h" |
20 #include "chrome/browser/ui/singleton_tabs.h" | 21 #include "chrome/browser/ui/singleton_tabs.h" |
21 #include "chrome/browser/ui/views/profiles/user_manager_view.h" | 22 #include "chrome/browser/ui/views/profiles/user_manager_view.h" |
22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/profile_management_switches.h" | 24 #include "chrome/common/profile_management_switches.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" | 26 #include "components/signin/core/browser/mutable_profile_oauth2_token_service.h" |
26 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 27 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
27 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
28 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
29 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
30 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
31 #include "third_party/skia/include/core/SkColor.h" | 32 #include "third_party/skia/include/core/SkColor.h" |
32 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
34 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" |
36 #include "ui/gfx/image/image_skia.h" | 37 #include "ui/gfx/image/image_skia.h" |
37 #include "ui/gfx/text_elider.h" | 38 #include "ui/gfx/text_elider.h" |
38 #include "ui/native_theme/native_theme.h" | 39 #include "ui/native_theme/native_theme.h" |
39 #include "ui/views/controls/button/blue_button.h" | 40 #include "ui/views/controls/button/blue_button.h" |
40 #include "ui/views/controls/button/image_button.h" | 41 #include "ui/views/controls/button/image_button.h" |
41 #include "ui/views/controls/button/label_button.h" | 42 #include "ui/views/controls/button/label_button.h" |
42 #include "ui/views/controls/button/menu_button.h" | 43 #include "ui/views/controls/button/menu_button.h" |
43 #include "ui/views/controls/label.h" | 44 #include "ui/views/controls/label.h" |
44 #include "ui/views/controls/link.h" | 45 #include "ui/views/controls/link.h" |
45 #include "ui/views/controls/separator.h" | 46 #include "ui/views/controls/separator.h" |
| 47 #include "ui/views/controls/styled_label.h" |
46 #include "ui/views/controls/textfield/textfield.h" | 48 #include "ui/views/controls/textfield/textfield.h" |
47 #include "ui/views/controls/webview/webview.h" | 49 #include "ui/views/controls/webview/webview.h" |
48 #include "ui/views/layout/grid_layout.h" | 50 #include "ui/views/layout/grid_layout.h" |
49 #include "ui/views/layout/layout_constants.h" | 51 #include "ui/views/layout/layout_constants.h" |
50 #include "ui/views/widget/widget.h" | 52 #include "ui/views/widget/widget.h" |
51 | 53 |
52 namespace { | 54 namespace { |
53 | 55 |
54 // Helpers -------------------------------------------------------------------- | 56 // Helpers -------------------------------------------------------------------- |
55 | 57 |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 lear_more_url, | 637 lear_more_url, |
636 content::PAGE_TRANSITION_LINK); | 638 content::PAGE_TRANSITION_LINK); |
637 params.disposition = NEW_FOREGROUND_TAB; | 639 params.disposition = NEW_FOREGROUND_TAB; |
638 chrome::Navigate(¶ms); | 640 chrome::Navigate(¶ms); |
639 } else { | 641 } else { |
640 DCHECK(sender == signin_current_profile_link_); | 642 DCHECK(sender == signin_current_profile_link_); |
641 ShowView(BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); | 643 ShowView(BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); |
642 } | 644 } |
643 } | 645 } |
644 | 646 |
| 647 void ProfileChooserView::StyledLabelLinkClicked( |
| 648 const gfx::Range& range, int event_flags) { |
| 649 chrome::ShowSettings(browser_); |
| 650 } |
| 651 |
645 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, | 652 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, |
646 const ui::KeyEvent& key_event) { | 653 const ui::KeyEvent& key_event) { |
647 views::Textfield* name_textfield = | 654 views::Textfield* name_textfield = |
648 current_profile_name_->profile_name_textfield(); | 655 current_profile_name_->profile_name_textfield(); |
649 DCHECK(sender == name_textfield); | 656 DCHECK(sender == name_textfield); |
650 | 657 |
651 if (key_event.key_code() == ui::VKEY_RETURN || | 658 if (key_event.key_code() == ui::VKEY_RETURN || |
652 key_event.key_code() == ui::VKEY_TAB) { | 659 key_event.key_code() == ui::VKEY_TAB) { |
653 // Pressing Tab/Enter commits the new profile name, unless it's empty. | 660 // Pressing Tab/Enter commits the new profile name, unless it's empty. |
654 base::string16 new_profile_name = name_textfield->text(); | 661 base::string16 new_profile_name = name_textfield->text(); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 layout->AddView(new TitleCard(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE, this, | 1083 layout->AddView(new TitleCard(IDS_PROFILES_ACCOUNT_REMOVAL_TITLE, this, |
1077 &account_removal_cancel_button_)); | 1084 &account_removal_cancel_button_)); |
1078 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); | 1085 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); |
1079 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1086 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
1080 | 1087 |
1081 const std::string& primary_account = SigninManagerFactory::GetForProfile( | 1088 const std::string& primary_account = SigninManagerFactory::GetForProfile( |
1082 browser_->profile())->GetAuthenticatedUsername(); | 1089 browser_->profile())->GetAuthenticatedUsername(); |
1083 bool is_primary_account = primary_account == account_id_to_remove_; | 1090 bool is_primary_account = primary_account == account_id_to_remove_; |
1084 | 1091 |
1085 // Adds main text. | 1092 // Adds main text. |
1086 views::Label* content_label = new views::Label(is_primary_account ? | 1093 layout->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing); |
1087 l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, | |
1088 base::UTF8ToUTF16(account_id_to_remove_)) : | |
1089 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT)); | |
1090 | |
1091 content_label->SetMultiLine(true); | |
1092 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
1093 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1094 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1094 const gfx::FontList& small_font_list = | 1095 const gfx::FontList& small_font_list = |
1095 rb->GetFontList(ui::ResourceBundle::SmallFont); | 1096 rb->GetFontList(ui::ResourceBundle::SmallFont); |
1096 content_label->SetFontList(small_font_list); | 1097 |
1097 layout->StartRowWithPadding(1, 0, 0, views::kUnrelatedControlVerticalSpacing); | 1098 if (is_primary_account) { |
1098 layout->AddView(content_label); | 1099 std::vector<size_t> offsets; |
| 1100 const base::string16 settings_text = |
| 1101 l10n_util::GetStringUTF16(IDS_PROFILES_SETTINGS_LINK); |
| 1102 const base::string16 primmary_account_removal_text = |
| 1103 l10n_util::GetStringFUTF16(IDS_PROFILES_PRIMARY_ACCOUNT_REMOVAL_TEXT, |
| 1104 base::UTF8ToUTF16(account_id_to_remove_), settings_text, &offsets); |
| 1105 views::StyledLabel* primary_account_removal_label = |
| 1106 new views::StyledLabel(primmary_account_removal_text, this); |
| 1107 primary_account_removal_label->AddStyleRange( |
| 1108 gfx::Range(offsets[1], offsets[1] + settings_text.size()), |
| 1109 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 1110 primary_account_removal_label->SetBaseFontList(small_font_list); |
| 1111 layout->AddView(primary_account_removal_label); |
| 1112 } else { |
| 1113 views::Label* content_label = new views::Label( |
| 1114 l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_TEXT)); |
| 1115 content_label->SetMultiLine(true); |
| 1116 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1117 content_label->SetFontList(small_font_list); |
| 1118 layout->AddView(content_label); |
| 1119 } |
1099 | 1120 |
1100 // Adds button. | 1121 // Adds button. |
1101 if (!is_primary_account) { | 1122 if (!is_primary_account) { |
1102 remove_account_and_relaunch_button_ = new views::BlueButton( | 1123 remove_account_and_relaunch_button_ = new views::BlueButton( |
1103 this, l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)); | 1124 this, l10n_util::GetStringUTF16(IDS_PROFILES_ACCOUNT_REMOVAL_BUTTON)); |
1104 remove_account_and_relaunch_button_->SetHorizontalAlignment( | 1125 remove_account_and_relaunch_button_->SetHorizontalAlignment( |
1105 gfx::ALIGN_CENTER); | 1126 gfx::ALIGN_CENTER); |
1106 layout->StartRowWithPadding( | 1127 layout->StartRowWithPadding( |
1107 1, 0, 0, views::kUnrelatedControlVerticalSpacing); | 1128 1, 0, 0, views::kUnrelatedControlVerticalSpacing); |
1108 layout->AddView(remove_account_and_relaunch_button_); | 1129 layout->AddView(remove_account_and_relaunch_button_); |
1109 } else { | 1130 } else { |
1110 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 1131 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
1111 } | 1132 } |
1112 | 1133 |
1113 return view; | 1134 return view; |
1114 } | 1135 } |
OLD | NEW |