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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 #include "ui/views/layout/grid_layout.h" | 61 #include "ui/views/layout/grid_layout.h" |
62 #include "ui/views/layout/layout_constants.h" | 62 #include "ui/views/layout/layout_constants.h" |
63 #include "ui/views/widget/widget.h" | 63 #include "ui/views/widget/widget.h" |
64 | 64 |
65 namespace { | 65 namespace { |
66 | 66 |
67 // Helpers -------------------------------------------------------------------- | 67 // Helpers -------------------------------------------------------------------- |
68 | 68 |
69 const int kFixedMenuWidth = 250; | 69 const int kFixedMenuWidth = 250; |
70 const int kButtonHeight = 32; | 70 const int kButtonHeight = 32; |
71 const int kFixedGaiaViewHeight = 400; | 71 const int kFixedGaiaViewHeight = 440; |
72 const int kFixedGaiaViewWidth = 360; | 72 const int kFixedGaiaViewWidth = 360; |
73 const int kFixedAccountRemovalViewWidth = 280; | 73 const int kFixedAccountRemovalViewWidth = 280; |
74 const int kFixedSwitchUserViewWidth = 280; | 74 const int kFixedSwitchUserViewWidth = 280; |
75 const int kLargeImageSide = 88; | 75 const int kLargeImageSide = 88; |
76 | 76 |
77 // Creates a GridLayout with a single column. This ensures that all the child | 77 // Creates a GridLayout with a single column. This ensures that all the child |
78 // views added get auto-expanded to fill the full width of the bubble. | 78 // views added get auto-expanded to fill the full width of the bubble. |
79 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { | 79 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { |
80 views::GridLayout* layout = new views::GridLayout(view); | 80 views::GridLayout* layout = new views::GridLayout(view); |
81 view->SetLayoutManager(layout); | 81 view->SetLayoutManager(layout); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 423 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
424 | 424 |
425 layout->StartRow(1, 1); | 425 layout->StartRow(1, 1); |
426 layout->AddView(view); | 426 layout->AddView(view); |
427 | 427 |
428 return titled_view; | 428 return titled_view; |
429 } | 429 } |
430 | 430 |
431 private: | 431 private: |
432 virtual void Layout() OVERRIDE{ | 432 virtual void Layout() OVERRIDE{ |
433 back_button_->SetBounds( | 433 int back_button_width = back_button_->GetPreferredSize().width(); |
sky
2014/08/15 19:07:58
What if back_button_width > bounds().width()? Shou
guohui
2014/08/15 19:19:23
back button shows a static icon, so the width is f
| |
434 0, 0, back_button_->GetPreferredSize().width(), height()); | 434 back_button_->SetBounds(0, 0, back_button_width, height()); |
435 title_label_->SetBoundsRect(GetContentsBounds()); | 435 int label_padding = back_button_width + views::kButtonHEdgeMarginNew; |
436 title_label_->SetBounds( | |
437 label_padding, 0, width() - 2 * label_padding, height()); | |
436 } | 438 } |
437 | 439 |
438 virtual gfx::Size GetPreferredSize() const OVERRIDE{ | 440 virtual gfx::Size GetPreferredSize() const OVERRIDE{ |
439 int height = std::max(title_label_->GetPreferredSize().height(), | 441 int height = std::max(title_label_->GetPreferredSize().height(), |
440 back_button_->GetPreferredSize().height()); | 442 back_button_->GetPreferredSize().height()); |
441 return gfx::Size(width(), height); | 443 return gfx::Size(width(), height); |
442 } | 444 } |
443 | 445 |
444 views::ImageButton* back_button_; | 446 views::ImageButton* back_button_; |
445 views::Label* title_label_; | 447 views::Label* title_label_; |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 | 909 |
908 return view; | 910 return view; |
909 } | 911 } |
910 | 912 |
911 views::View* ProfileChooserView::CreateTutorialView( | 913 views::View* ProfileChooserView::CreateTutorialView( |
912 profiles::TutorialMode tutorial_mode, | 914 profiles::TutorialMode tutorial_mode, |
913 const base::string16& title_text, | 915 const base::string16& title_text, |
914 const base::string16& content_text, | 916 const base::string16& content_text, |
915 const base::string16& link_text, | 917 const base::string16& link_text, |
916 const base::string16& button_text, | 918 const base::string16& button_text, |
919 bool stack_button, | |
917 views::Link** link, | 920 views::Link** link, |
918 views::LabelButton** button) { | 921 views::LabelButton** button) { |
919 tutorial_mode_ = tutorial_mode; | 922 tutorial_mode_ = tutorial_mode; |
920 | 923 |
921 views::View* view = new views::View(); | 924 views::View* view = new views::View(); |
922 view->set_background(views::Background::CreateSolidBackground( | 925 view->set_background(views::Background::CreateSolidBackground( |
923 profiles::kAvatarTutorialBackgroundColor)); | 926 profiles::kAvatarTutorialBackgroundColor)); |
924 views::GridLayout* layout = CreateSingleColumnLayout(view, | 927 views::GridLayout* layout = CreateSingleColumnLayout(view, |
925 kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); | 928 kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); |
926 layout->SetInsets(views::kButtonVEdgeMarginNew, | 929 layout->SetInsets(views::kButtonVEdgeMarginNew, |
(...skipping 15 matching lines...) Expand all Loading... | |
942 // Adds body content. | 945 // Adds body content. |
943 views::Label* content_label = new views::Label(content_text); | 946 views::Label* content_label = new views::Label(content_text); |
944 content_label->SetMultiLine(true); | 947 content_label->SetMultiLine(true); |
945 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 948 content_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
946 content_label->SetAutoColorReadabilityEnabled(false); | 949 content_label->SetAutoColorReadabilityEnabled(false); |
947 content_label->SetEnabledColor(profiles::kAvatarTutorialContentTextColor); | 950 content_label->SetEnabledColor(profiles::kAvatarTutorialContentTextColor); |
948 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); | 951 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); |
949 layout->AddView(content_label); | 952 layout->AddView(content_label); |
950 | 953 |
951 // Adds links and buttons. | 954 // Adds links and buttons. |
952 views::ColumnSet* button_columns = layout->AddColumnSet(1); | 955 *button = new views::LabelButton(this, button_text); |
953 button_columns->AddColumn(views::GridLayout::LEADING, | 956 (*button)->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
954 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | 957 (*button)->SetStyle(views::Button::STYLE_BUTTON); |
955 button_columns->AddPaddingColumn( | 958 |
956 1, views::kUnrelatedControlHorizontalSpacing); | |
957 button_columns->AddColumn(views::GridLayout::TRAILING, | |
958 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | |
959 | 959 |
960 *link = CreateLink(link_text, this); | 960 *link = CreateLink(link_text, this); |
961 (*link)->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 961 (*link)->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
962 (*link)->SetAutoColorReadabilityEnabled(false); | 962 (*link)->SetAutoColorReadabilityEnabled(false); |
963 (*link)->SetEnabledColor(SK_ColorWHITE); | 963 (*link)->SetEnabledColor(SK_ColorWHITE); |
964 layout->StartRowWithPadding(1, 1, 0, views::kUnrelatedControlVerticalSpacing); | |
965 layout->AddView(*link); | |
966 | 964 |
967 *button = new views::LabelButton(this, button_text); | 965 if (stack_button) { |
968 (*button)->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 966 layout->StartRowWithPadding( |
969 (*button)->SetStyle(views::Button::STYLE_BUTTON); | 967 1, 0, 0, views::kUnrelatedControlVerticalSpacing); |
970 layout->AddView(*button); | 968 layout->AddView(*button); |
969 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); | |
970 (*link)->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
971 layout->AddView(*link); | |
972 } else { | |
973 views::ColumnSet* button_columns = layout->AddColumnSet(1); | |
974 button_columns->AddColumn(views::GridLayout::LEADING, | |
975 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | |
976 button_columns->AddPaddingColumn( | |
977 1, views::kUnrelatedControlHorizontalSpacing); | |
978 button_columns->AddColumn(views::GridLayout::TRAILING, | |
979 views::GridLayout::CENTER, 0, views::GridLayout::USE_PREF, 0, 0); | |
980 layout->StartRowWithPadding( | |
981 1, 1, 0, views::kUnrelatedControlVerticalSpacing); | |
982 layout->AddView(*link); | |
983 layout->AddView(*button); | |
984 } | |
971 | 985 |
972 return view; | 986 return view; |
973 } | 987 } |
974 | 988 |
975 views::View* ProfileChooserView::CreateCurrentProfileView( | 989 views::View* ProfileChooserView::CreateCurrentProfileView( |
976 const AvatarMenu::Item& avatar_item, | 990 const AvatarMenu::Item& avatar_item, |
977 bool is_guest) { | 991 bool is_guest) { |
978 views::View* view = new views::View(); | 992 views::View* view = new views::View(); |
979 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; | 993 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; |
980 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | 994 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1413 | 1427 |
1414 return CreateTutorialView( | 1428 return CreateTutorialView( |
1415 profiles::TUTORIAL_MODE_WELCOME_UPGRADE, | 1429 profiles::TUTORIAL_MODE_WELCOME_UPGRADE, |
1416 l10n_util::GetStringUTF16( | 1430 l10n_util::GetStringUTF16( |
1417 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE), | 1431 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE), |
1418 l10n_util::GetStringUTF16( | 1432 l10n_util::GetStringUTF16( |
1419 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT), | 1433 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT), |
1420 l10n_util::GetStringFUTF16( | 1434 l10n_util::GetStringFUTF16( |
1421 IDS_PROFILES_NOT_YOU, avatar_item.name), | 1435 IDS_PROFILES_NOT_YOU, avatar_item.name), |
1422 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON), | 1436 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON), |
1437 true /* stack_button */, | |
1423 &tutorial_not_you_link_, | 1438 &tutorial_not_you_link_, |
1424 &tutorial_see_whats_new_button_); | 1439 &tutorial_see_whats_new_button_); |
1425 } | 1440 } |
1426 | 1441 |
1427 views::View* ProfileChooserView::CreateSigninConfirmationView(){ | 1442 views::View* ProfileChooserView::CreateSigninConfirmationView(){ |
1428 return CreateTutorialView( | 1443 return CreateTutorialView( |
1429 profiles::TUTORIAL_MODE_CONFIRM_SIGNIN, | 1444 profiles::TUTORIAL_MODE_CONFIRM_SIGNIN, |
1430 l10n_util::GetStringUTF16(IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE), | 1445 l10n_util::GetStringUTF16(IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE), |
1431 l10n_util::GetStringUTF16( | 1446 l10n_util::GetStringUTF16( |
1432 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT), | 1447 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT), |
1433 l10n_util::GetStringUTF16(IDS_PROFILES_SYNC_SETTINGS_LINK), | 1448 l10n_util::GetStringUTF16(IDS_PROFILES_SYNC_SETTINGS_LINK), |
1434 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_OK_BUTTON), | 1449 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_OK_BUTTON), |
1450 false /* stack_button */, | |
1435 &tutorial_sync_settings_link_, | 1451 &tutorial_sync_settings_link_, |
1436 &tutorial_sync_settings_ok_button_); | 1452 &tutorial_sync_settings_ok_button_); |
1437 } | 1453 } |
1438 | 1454 |
1439 views::View* ProfileChooserView::CreateSwitchUserView() { | 1455 views::View* ProfileChooserView::CreateSwitchUserView() { |
1440 views::View* view = new views::View(); | 1456 views::View* view = new views::View(); |
1441 views::GridLayout* layout = CreateSingleColumnLayout( | 1457 views::GridLayout* layout = CreateSingleColumnLayout( |
1442 view, kFixedSwitchUserViewWidth); | 1458 view, kFixedSwitchUserViewWidth); |
1443 views::ColumnSet* columns = layout->AddColumnSet(1); | 1459 views::ColumnSet* columns = layout->AddColumnSet(1); |
1444 columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 1460 columns->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1497 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1513 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
1498 IncognitoModePrefs::DISABLED; | 1514 IncognitoModePrefs::DISABLED; |
1499 return incognito_available && !browser_->profile()->IsGuestSession(); | 1515 return incognito_available && !browser_->profile()->IsGuestSession(); |
1500 } | 1516 } |
1501 | 1517 |
1502 void ProfileChooserView::PostActionPerformed( | 1518 void ProfileChooserView::PostActionPerformed( |
1503 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1519 ProfileMetrics::ProfileDesktopMenu action_performed) { |
1504 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1520 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
1505 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1521 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
1506 } | 1522 } |
OLD | NEW |