| 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/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 // BackgroundColorHoverButton ------------------------------------------------- | 179 // BackgroundColorHoverButton ------------------------------------------------- |
| 180 | 180 |
| 181 // A custom button that allows for setting a background color when hovered over. | 181 // A custom button that allows for setting a background color when hovered over. |
| 182 class BackgroundColorHoverButton : public views::LabelButton { | 182 class BackgroundColorHoverButton : public views::LabelButton { |
| 183 public: | 183 public: |
| 184 BackgroundColorHoverButton(views::ButtonListener* listener, | 184 BackgroundColorHoverButton(views::ButtonListener* listener, |
| 185 const base::string16& text) | 185 const base::string16& text) |
| 186 : views::LabelButton(listener, text) { | 186 : views::LabelButton(listener, text) { |
| 187 SetImageLabelSpacing(views::kItemLabelSpacing); | 187 SetImageLabelSpacing(switches::IsMaterialDesignUserMenu() |
| 188 ? (kMaterialMenuEdgeMargin - 2) |
| 189 : views::kItemLabelSpacing); |
| 188 const int button_margin = switches::IsMaterialDesignUserMenu() | 190 const int button_margin = switches::IsMaterialDesignUserMenu() |
| 189 ? kMaterialMenuEdgeMargin | 191 ? kMaterialMenuEdgeMargin |
| 190 : views::kButtonHEdgeMarginNew; | 192 : views::kButtonHEdgeMarginNew; |
| 191 SetBorder( | 193 SetBorder( |
| 192 views::Border::CreateEmptyBorder(0, button_margin, 0, button_margin)); | 194 views::Border::CreateEmptyBorder(0, button_margin, 0, button_margin)); |
| 193 SetFocusForPlatform(); | 195 SetFocusForPlatform(); |
| 194 set_request_focus_on_press(true); | 196 set_request_focus_on_press(true); |
| 195 } | 197 } |
| 196 | 198 |
| 197 BackgroundColorHoverButton(views::ButtonListener* listener, | 199 BackgroundColorHoverButton(views::ButtonListener* listener, |
| (...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 | 1694 |
| 1693 return view; | 1695 return view; |
| 1694 } | 1696 } |
| 1695 | 1697 |
| 1696 views::View* ProfileChooserView::CreateOptionsView(bool display_lock, | 1698 views::View* ProfileChooserView::CreateOptionsView(bool display_lock, |
| 1697 AvatarMenu* avatar_menu) { | 1699 AvatarMenu* avatar_menu) { |
| 1698 views::View* view = new views::View(); | 1700 views::View* view = new views::View(); |
| 1699 views::GridLayout* layout = | 1701 views::GridLayout* layout = |
| 1700 CreateSingleColumnLayout(view, GetFixedMenuWidth()); | 1702 CreateSingleColumnLayout(view, GetFixedMenuWidth()); |
| 1701 | 1703 |
| 1704 const bool is_guest = browser_->profile()->IsGuestSession(); |
| 1702 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16; | 1705 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16; |
| 1703 if (switches::IsMaterialDesignUserMenu()) { | 1706 if (switches::IsMaterialDesignUserMenu()) { |
| 1704 // Add the user switching buttons | 1707 // Add the user switching buttons |
| 1705 const int kProfileIconSize = 18; | 1708 const int kProfileIconSize = 18; |
| 1706 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); | 1709 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); |
| 1707 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 1710 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 1708 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 1711 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 1709 if (!item.active) { | 1712 if (!item.active) { |
| 1710 gfx::Image image = profiles::GetSizedAvatarIcon( | 1713 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 1711 item.icon, true, kProfileIconSize, kProfileIconSize, | 1714 item.icon, true, kProfileIconSize, kProfileIconSize, |
| 1712 profiles::SHAPE_CIRCLE); | 1715 profiles::SHAPE_CIRCLE); |
| 1713 views::LabelButton* button = new BackgroundColorHoverButton( | 1716 views::LabelButton* button = new BackgroundColorHoverButton( |
| 1714 this, profiles::GetProfileSwitcherTextForItem(item), | 1717 this, profiles::GetProfileSwitcherTextForItem(item), |
| 1715 *image.ToImageSkia()); | 1718 *image.ToImageSkia()); |
| 1719 button->SetImageLabelSpacing(kMaterialMenuEdgeMargin); |
| 1716 open_other_profile_indexes_map_[button] = i; | 1720 open_other_profile_indexes_map_[button] = i; |
| 1717 | 1721 |
| 1718 layout->StartRow(1, 0); | 1722 layout->StartRow(1, 0); |
| 1719 layout->AddView(button); | 1723 layout->AddView(button); |
| 1720 } | 1724 } |
| 1721 } | 1725 } |
| 1722 | 1726 |
| 1723 // Add the "Guest" button for browsing as guest | 1727 // Add the "Guest" button for browsing as guest |
| 1724 if (!browser_->profile()->IsGuestSession()) { | 1728 if (!is_guest) { |
| 1725 PrefService* service = g_browser_process->local_state(); | 1729 PrefService* service = g_browser_process->local_state(); |
| 1726 DCHECK(service); | 1730 DCHECK(service); |
| 1727 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { | 1731 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { |
| 1728 guest_profile_button_ = new BackgroundColorHoverButton( | 1732 guest_profile_button_ = new BackgroundColorHoverButton( |
| 1729 this, l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME), | 1733 this, l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME), |
| 1730 gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_CIRCLE, kIconSize, | 1734 gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_CIRCLE, kIconSize, |
| 1731 gfx::kChromeIconGrey)); | 1735 gfx::kChromeIconGrey)); |
| 1732 layout->StartRow(1, 0); | 1736 layout->StartRow(1, 0); |
| 1733 layout->AddView(guest_profile_button_); | 1737 layout->AddView(guest_profile_button_); |
| 1734 } | 1738 } |
| 1735 } | 1739 } |
| 1736 } | 1740 } |
| 1737 | 1741 |
| 1738 base::string16 text = browser_->profile()->IsGuestSession() ? | 1742 base::string16 text; |
| 1739 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : | 1743 gfx::VectorIconId settings_icon; |
| 1740 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); | 1744 if (switches::IsMaterialDesignUserMenu()) { |
| 1741 gfx::VectorIconId settings_icon = gfx::VectorIconId::ACCOUNT_BOX; | 1745 text = is_guest |
| 1742 if (!browser_->profile()->IsGuestSession() | 1746 ? l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) |
| 1743 && switches::IsMaterialDesignUserMenu()) { | 1747 : l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); |
| 1744 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); | 1748 settings_icon = |
| 1745 settings_icon = gfx::VectorIconId::SETTINGS; | 1749 is_guest ? gfx::VectorIconId::CLOSE_ALL : gfx::VectorIconId::SETTINGS; |
| 1750 } else { |
| 1751 text = is_guest |
| 1752 ? l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) |
| 1753 : l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); |
| 1754 settings_icon = gfx::VectorIconId::ACCOUNT_BOX; |
| 1746 } | 1755 } |
| 1747 users_button_ = new BackgroundColorHoverButton( | 1756 users_button_ = new BackgroundColorHoverButton( |
| 1748 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize, | 1757 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize, |
| 1749 gfx::kChromeIconGrey)); | 1758 gfx::kChromeIconGrey)); |
| 1750 | 1759 |
| 1751 layout->StartRow(1, 0); | 1760 layout->StartRow(1, 0); |
| 1752 layout->AddView(users_button_); | 1761 layout->AddView(users_button_); |
| 1753 | 1762 |
| 1754 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) { | 1763 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) { |
| 1755 layout->StartRow(1, 0); | 1764 layout->StartRow(1, 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1769 layout->StartRow(1, 0); | 1778 layout->StartRow(1, 0); |
| 1770 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 1779 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 1771 } | 1780 } |
| 1772 | 1781 |
| 1773 lock_button_ = new BackgroundColorHoverButton( | 1782 lock_button_ = new BackgroundColorHoverButton( |
| 1774 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), | 1783 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), |
| 1775 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, | 1784 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, |
| 1776 gfx::kChromeIconGrey)); | 1785 gfx::kChromeIconGrey)); |
| 1777 layout->StartRow(1, 0); | 1786 layout->StartRow(1, 0); |
| 1778 layout->AddView(lock_button_); | 1787 layout->AddView(lock_button_); |
| 1779 } else if (switches::IsMaterialDesignUserMenu() && | 1788 } else if (switches::IsMaterialDesignUserMenu() && !is_guest) { |
| 1780 !browser_->profile()->IsGuestSession()) { | |
| 1781 int num_browsers = 0; | 1789 int num_browsers = 0; |
| 1782 for (auto* browser : *BrowserList::GetInstance()) { | 1790 for (auto* browser : *BrowserList::GetInstance()) { |
| 1783 if (browser->profile()->GetOriginalProfile() == | 1791 if (browser->profile()->GetOriginalProfile() == |
| 1784 browser_->profile()->GetOriginalProfile()) | 1792 browser_->profile()->GetOriginalProfile()) |
| 1785 num_browsers++; | 1793 num_browsers++; |
| 1786 } | 1794 } |
| 1787 if (num_browsers > 1) { | 1795 if (num_browsers > 1) { |
| 1788 close_all_windows_button_ = new BackgroundColorHoverButton( | 1796 close_all_windows_button_ = new BackgroundColorHoverButton( |
| 1789 this, | 1797 this, |
| 1790 l10n_util::GetStringUTF16(IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON), | 1798 l10n_util::GetStringUTF16(IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON), |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2158 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2166 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2159 IncognitoModePrefs::DISABLED; | 2167 IncognitoModePrefs::DISABLED; |
| 2160 return incognito_available && !browser_->profile()->IsGuestSession(); | 2168 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2161 } | 2169 } |
| 2162 | 2170 |
| 2163 void ProfileChooserView::PostActionPerformed( | 2171 void ProfileChooserView::PostActionPerformed( |
| 2164 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2172 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2165 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2173 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2166 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2174 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2167 } | 2175 } |
| OLD | NEW |