Chromium Code Reviews| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 #include "ui/views/layout/fill_layout.h" | 86 #include "ui/views/layout/fill_layout.h" |
| 87 #include "ui/views/layout/grid_layout.h" | 87 #include "ui/views/layout/grid_layout.h" |
| 88 #include "ui/views/layout/layout_constants.h" | 88 #include "ui/views/layout/layout_constants.h" |
| 89 #include "ui/views/widget/widget.h" | 89 #include "ui/views/widget/widget.h" |
| 90 | 90 |
| 91 namespace { | 91 namespace { |
| 92 | 92 |
| 93 // Helpers -------------------------------------------------------------------- | 93 // Helpers -------------------------------------------------------------------- |
| 94 | 94 |
| 95 const int kButtonHeight = 32; | 95 const int kButtonHeight = 32; |
| 96 const int kCurrentProfileMenuItemHeight = 56; | |
| 96 const int kPasswordCombinedFixedGaiaViewWidth = 360; | 97 const int kPasswordCombinedFixedGaiaViewWidth = 360; |
| 97 const int kFixedGaiaViewWidth = 448; | 98 const int kFixedGaiaViewWidth = 448; |
| 98 const int kFixedAccountRemovalViewWidth = 280; | 99 const int kFixedAccountRemovalViewWidth = 280; |
| 99 const int kFixedSwitchUserViewWidth = 320; | 100 const int kFixedSwitchUserViewWidth = 320; |
| 100 const int kLargeImageSide = 88; | 101 const int kLargeImageSide = 88; |
| 101 const int kMdImageSide = 40; | 102 const int kMdImageSide = 40; |
| 102 | 103 |
| 103 // Spacing between the edge of the material design user menu and the | 104 // Spacing between the edge of the material design user menu and the |
| 104 // top/bottom or left/right of the menu items. | 105 // top/bottom or left/right of the menu items. |
| 105 const int kMaterialMenuEdgeMargin = 16; | 106 const int kMaterialMenuEdgeMargin = 16; |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 public: | 307 public: |
| 307 explicit SizedContainer(const gfx::Size& preferred_size) | 308 explicit SizedContainer(const gfx::Size& preferred_size) |
| 308 : preferred_size_(preferred_size) {} | 309 : preferred_size_(preferred_size) {} |
| 309 | 310 |
| 310 gfx::Size GetPreferredSize() const override { return preferred_size_; } | 311 gfx::Size GetPreferredSize() const override { return preferred_size_; } |
| 311 | 312 |
| 312 private: | 313 private: |
| 313 gfx::Size preferred_size_; | 314 gfx::Size preferred_size_; |
| 314 }; | 315 }; |
| 315 | 316 |
| 316 // NonInteractiveContainer ------------------------------------------------- | |
| 317 | |
| 318 // A simple container view that does not process events within subtree. | |
| 319 class NonInteractiveContainer : public views::View { | |
| 320 public: | |
| 321 NonInteractiveContainer() {} | |
| 322 | |
| 323 // views::CanProcessEventsWithinSubtree: | |
| 324 bool CanProcessEventsWithinSubtree() const override { return false; } | |
| 325 | |
| 326 private: | |
| 327 DISALLOW_COPY_AND_ASSIGN(NonInteractiveContainer); | |
| 328 }; | |
| 329 | |
| 330 // A view to host the GAIA webview overlapped with a back button. This class | 317 // A view to host the GAIA webview overlapped with a back button. This class |
| 331 // is needed to reparent the back button inside a native view so that on | 318 // is needed to reparent the back button inside a native view so that on |
| 332 // windows, user input can be be properly routed to the button. | 319 // windows, user input can be be properly routed to the button. |
| 333 class HostView : public views::View { | 320 class HostView : public views::View { |
| 334 public: | 321 public: |
| 335 HostView() {} | 322 HostView() {} |
| 336 | 323 |
| 337 private: | 324 private: |
| 338 // views::View: | 325 // views::View: |
| 339 void ViewHierarchyChanged( | 326 void ViewHierarchyChanged( |
| (...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1739 const AvatarMenu::Item& avatar_item, | 1726 const AvatarMenu::Item& avatar_item, |
| 1740 bool is_guest) { | 1727 bool is_guest) { |
| 1741 views::View* view = new views::View(); | 1728 views::View* view = new views::View(); |
| 1742 view->SetLayoutManager( | 1729 view->SetLayoutManager( |
| 1743 new views::BoxLayout(views::BoxLayout::kVertical, 0, | 1730 new views::BoxLayout(views::BoxLayout::kVertical, 0, |
| 1744 views::kRelatedControlVerticalSpacing, 0)); | 1731 views::kRelatedControlVerticalSpacing, 0)); |
| 1745 | 1732 |
| 1746 // Container for the profile photo and avatar/user name. | 1733 // Container for the profile photo and avatar/user name. |
| 1747 BackgroundColorHoverButton* current_profile_card = | 1734 BackgroundColorHoverButton* current_profile_card = |
| 1748 new BackgroundColorHoverButton(this, base::string16()); | 1735 new BackgroundColorHoverButton(this, base::string16()); |
| 1736 views::GridLayout* grid_layout = new views::GridLayout(current_profile_card); | |
| 1737 current_profile_card->SetLayoutManager(grid_layout); | |
| 1738 views::ColumnSet* columns = grid_layout->AddColumnSet(0); | |
| 1739 columns->AddPaddingColumn(0, kMaterialMenuEdgeMargin); | |
| 1740 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
| 1741 views::GridLayout::USE_PREF, 0, 0); | |
| 1742 columns->AddPaddingColumn( | |
| 1743 0, kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing()); | |
| 1744 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
| 1745 views::GridLayout::USE_PREF, 0, 0); | |
| 1746 columns->AddPaddingColumn(0, kMaterialMenuEdgeMargin); | |
| 1747 grid_layout->AddPaddingRow(0, 0); | |
| 1748 grid_layout->StartRow(0, 0, avatar_item.signed_in | |
| 1749 ? (kCurrentProfileMenuItemHeight / 2) | |
|
msarda
2017/02/20 17:01:46
Do you need this new "magic" constant kCurrentProf
msarda
2017/02/20 17:01:46
Should you divide by 2 if there is a single line?
jlebel
2017/02/21 08:28:16
If I don't set the height as half of the total hei
jlebel
2017/02/21 08:28:16
Done.
| |
| 1750 : kCurrentProfileMenuItemHeight); | |
| 1749 current_profile_card_ = current_profile_card; | 1751 current_profile_card_ = current_profile_card; |
| 1750 | 1752 |
| 1751 // Profile picture, left-aligned. | 1753 // Profile picture, left-aligned. |
| 1752 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( | 1754 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( |
| 1753 this, avatar_item.icon, !is_guest, browser_->profile()); | 1755 this, avatar_item.icon, !is_guest, browser_->profile()); |
| 1754 | 1756 |
| 1755 // Profile name, left-aligned to the right of profile icon. | 1757 // Profile name, left-aligned to the right of profile icon. |
| 1756 views::Label* current_profile_name = new views::Label( | 1758 views::Label* current_profile_name = new views::Label( |
| 1757 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); | 1759 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); |
| 1758 current_profile_card->set_title(current_profile_name); | 1760 current_profile_card->set_title(current_profile_name); |
| 1759 current_profile_name->SetFontList( | 1761 current_profile_name->SetFontList( |
| 1760 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 1762 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 1761 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); | 1763 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); |
| 1762 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1764 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1763 NonInteractiveContainer* profile_name_container = | |
| 1764 new NonInteractiveContainer(); | |
| 1765 int name_container_v_spacing = | |
| 1766 (current_profile_photo->GetPreferredSize().height() - | |
| 1767 current_profile_name->GetPreferredSize().height()) / 2; | |
| 1768 views::BoxLayout* profile_name_layout = new views::BoxLayout( | |
| 1769 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0); | |
| 1770 profile_name_container->SetLayoutManager(profile_name_layout); | |
| 1771 profile_name_container->AddChildView(current_profile_name); | |
| 1772 | 1765 |
| 1773 const int between_child_spacing = | 1766 // The grid layout contains one row if not signed in, and 2 if signed in (the |
| 1774 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing(); | 1767 // second row is for the email created later). Therefore, the profile photo is |
| 1775 current_profile_card_->SetLayoutManager(new views::BoxLayout( | 1768 // over 2 rows if signed in. |
| 1776 views::BoxLayout::kHorizontal, 0, | 1769 grid_layout->AddView(current_profile_photo, 1, avatar_item.signed_in ? 2 : 1); |
| 1777 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); | 1770 grid_layout->AddView(current_profile_name, 1, 1, views::GridLayout::LEADING, |
| 1778 current_profile_card_->AddChildView(current_profile_photo); | 1771 avatar_item.signed_in ? views::GridLayout::TRAILING |
| 1779 current_profile_card_->AddChildView(profile_name_container); | 1772 : views::GridLayout::CENTER); |
| 1780 current_profile_card_->SetMinSize(gfx::Size( | 1773 current_profile_card_->SetMinSize(gfx::Size( |
| 1781 GetFixedMenuWidth(), current_profile_photo->GetPreferredSize().height() + | 1774 GetFixedMenuWidth(), current_profile_photo->GetPreferredSize().height() + |
| 1782 2 * views::kRelatedControlSmallVerticalSpacing)); | 1775 2 * views::kRelatedControlSmallVerticalSpacing)); |
| 1783 view->AddChildView(current_profile_card_); | 1776 view->AddChildView(current_profile_card_); |
| 1784 | 1777 |
| 1785 if (is_guest) { | 1778 if (is_guest) { |
| 1786 current_profile_card_->SetEnabled(false); | 1779 current_profile_card_->SetEnabled(false); |
| 1787 return view; | 1780 return view; |
| 1788 } | 1781 } |
| 1789 | 1782 |
| 1790 const base::string16 profile_name = | 1783 const base::string16 profile_name = |
| 1791 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); | 1784 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); |
| 1792 | 1785 |
| 1793 // The available links depend on the type of profile that is active. | 1786 // The available links depend on the type of profile that is active. |
| 1794 if (avatar_item.signed_in) { | 1787 if (avatar_item.signed_in) { |
| 1795 if (switches::IsEnableAccountConsistency()) { | 1788 if (switches::IsEnableAccountConsistency()) { |
| 1796 base::string16 button_text = l10n_util::GetStringUTF16( | 1789 base::string16 button_text = l10n_util::GetStringUTF16( |
| 1797 IsProfileChooser(view_mode_) | 1790 IsProfileChooser(view_mode_) |
| 1798 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON | 1791 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON |
| 1799 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 1792 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 1800 manage_accounts_button_ = | 1793 manage_accounts_button_ = |
| 1801 new BackgroundColorHoverButton(this, button_text); | 1794 new BackgroundColorHoverButton(this, button_text); |
| 1802 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1795 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1803 manage_accounts_button_->SetMinSize( | 1796 manage_accounts_button_->SetMinSize( |
| 1804 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); | 1797 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); |
| 1805 view->AddChildView(manage_accounts_button_); | 1798 view->AddChildView(manage_accounts_button_); |
|
msarda
2017/02/20 17:01:46
I think the view will not be properly displayed in
jlebel
2017/02/21 08:28:16
Done.
| |
| 1806 } else { | 1799 } else { |
| 1807 views::Label* email_label = new views::Label(avatar_item.username); | 1800 views::Label* email_label = new views::Label(avatar_item.username); |
| 1808 current_profile_card->set_subtitle(email_label); | 1801 current_profile_card->set_subtitle(email_label); |
| 1809 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); | 1802 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
| 1810 email_label->SetEnabled(false); | 1803 email_label->SetEnabled(false); |
| 1811 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1804 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1812 name_container_v_spacing = | 1805 grid_layout->StartRow(1, 0); |
| 1813 (current_profile_photo->GetPreferredSize().height() - | 1806 // Skip first column for the profile icon. |
| 1814 current_profile_name->GetPreferredSize().height() - | 1807 grid_layout->SkipColumns(1); |
| 1815 email_label->GetPreferredSize().height()) / 2; | 1808 grid_layout->AddView(email_label, 1, 1, views::GridLayout::LEADING, |
| 1816 profile_name_layout->set_inside_border_insets( | 1809 views::GridLayout::LEADING); |
| 1817 gfx::Insets(name_container_v_spacing, 0)); | |
| 1818 profile_name_container->AddChildView(email_label); | |
| 1819 } | 1810 } |
| 1820 | 1811 |
| 1821 current_profile_card_->SetAccessibleName( | 1812 current_profile_card_->SetAccessibleName( |
| 1822 l10n_util::GetStringFUTF16( | 1813 l10n_util::GetStringFUTF16( |
| 1823 IDS_PROFILES_EDIT_SIGNED_IN_PROFILE_ACCESSIBLE_NAME, | 1814 IDS_PROFILES_EDIT_SIGNED_IN_PROFILE_ACCESSIBLE_NAME, |
| 1824 profile_name, | 1815 profile_name, |
| 1825 avatar_item.username)); | 1816 avatar_item.username)); |
| 1826 return view; | 1817 return view; |
| 1827 } | 1818 } |
| 1828 | 1819 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2380 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2371 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2381 IncognitoModePrefs::DISABLED; | 2372 IncognitoModePrefs::DISABLED; |
| 2382 return incognito_available && !browser_->profile()->IsGuestSession(); | 2373 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2383 } | 2374 } |
| 2384 | 2375 |
| 2385 void ProfileChooserView::PostActionPerformed( | 2376 void ProfileChooserView::PostActionPerformed( |
| 2386 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2377 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2387 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2378 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2388 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2379 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2389 } | 2380 } |
| OLD | NEW |