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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 public: | 306 public: |
| 307 explicit SizedContainer(const gfx::Size& preferred_size) | 307 explicit SizedContainer(const gfx::Size& preferred_size) |
| 308 : preferred_size_(preferred_size) {} | 308 : preferred_size_(preferred_size) {} |
| 309 | 309 |
| 310 gfx::Size GetPreferredSize() const override { return preferred_size_; } | 310 gfx::Size GetPreferredSize() const override { return preferred_size_; } |
| 311 | 311 |
| 312 private: | 312 private: |
| 313 gfx::Size preferred_size_; | 313 gfx::Size preferred_size_; |
| 314 }; | 314 }; |
| 315 | 315 |
| 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 | 316 // 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 | 317 // 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. | 318 // windows, user input can be be properly routed to the button. |
| 333 class HostView : public views::View { | 319 class HostView : public views::View { |
| 334 public: | 320 public: |
| 335 HostView() {} | 321 HostView() {} |
| 336 | 322 |
| 337 private: | 323 private: |
| 338 // views::View: | 324 // views::View: |
| 339 void ViewHierarchyChanged( | 325 void ViewHierarchyChanged( |
| (...skipping 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1739 const AvatarMenu::Item& avatar_item, | 1725 const AvatarMenu::Item& avatar_item, |
| 1740 bool is_guest) { | 1726 bool is_guest) { |
| 1741 views::View* view = new views::View(); | 1727 views::View* view = new views::View(); |
| 1742 view->SetLayoutManager( | 1728 view->SetLayoutManager( |
| 1743 new views::BoxLayout(views::BoxLayout::kVertical, 0, | 1729 new views::BoxLayout(views::BoxLayout::kVertical, 0, |
| 1744 views::kRelatedControlVerticalSpacing, 0)); | 1730 views::kRelatedControlVerticalSpacing, 0)); |
| 1745 | 1731 |
| 1746 // Container for the profile photo and avatar/user name. | 1732 // Container for the profile photo and avatar/user name. |
| 1747 BackgroundColorHoverButton* current_profile_card = | 1733 BackgroundColorHoverButton* current_profile_card = |
| 1748 new BackgroundColorHoverButton(this, base::string16()); | 1734 new BackgroundColorHoverButton(this, base::string16()); |
| 1735 views::GridLayout* grid_layout = new views::GridLayout(current_profile_card); | |
| 1736 current_profile_card->SetLayoutManager(grid_layout); | |
| 1737 views::ColumnSet* columns = grid_layout->AddColumnSet(0); | |
| 1738 columns->AddPaddingColumn(0, kMaterialMenuEdgeMargin); | |
| 1739 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | |
| 1740 views::GridLayout::USE_PREF, 0, 0); | |
| 1741 columns->AddPaddingColumn( | |
| 1742 0, kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing()); | |
| 1743 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | |
| 1744 views::GridLayout::USE_PREF, 0, 0); | |
| 1745 columns->AddPaddingColumn(0, kMaterialMenuEdgeMargin); | |
| 1746 grid_layout->AddPaddingRow(0, 0); | |
| 1747 int row_height = EditableProfilePhoto::icon_image_side() + | |
|
msarda
2017/02/21 08:51:48
I think this is actually the height of the entire
jlebel
2017/02/21 09:06:18
Done.
| |
| 1748 2 * (EditableProfilePhoto::badge_spacing() + | |
| 1749 views::kRelatedControlSmallVerticalSpacing); | |
| 1750 grid_layout->StartRow(0, 0, | |
| 1751 avatar_item.signed_in ? (row_height / 2) : row_height); | |
| 1749 current_profile_card_ = current_profile_card; | 1752 current_profile_card_ = current_profile_card; |
| 1750 | 1753 |
| 1751 // Profile picture, left-aligned. | 1754 // Profile picture, left-aligned. |
| 1752 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( | 1755 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( |
| 1753 this, avatar_item.icon, !is_guest, browser_->profile()); | 1756 this, avatar_item.icon, !is_guest, browser_->profile()); |
| 1754 | 1757 |
| 1755 // Profile name, left-aligned to the right of profile icon. | 1758 // Profile name, left-aligned to the right of profile icon. |
| 1756 views::Label* current_profile_name = new views::Label( | 1759 views::Label* current_profile_name = new views::Label( |
| 1757 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); | 1760 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); |
| 1758 current_profile_card->set_title(current_profile_name); | 1761 current_profile_card->set_title(current_profile_name); |
| 1759 current_profile_name->SetFontList( | 1762 current_profile_name->SetFontList( |
| 1760 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( | 1763 ui::ResourceBundle::GetSharedInstance().GetFontListWithDelta( |
| 1761 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); | 1764 1, gfx::Font::FontStyle::NORMAL, gfx::Font::Weight::MEDIUM)); |
| 1762 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1765 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 | 1766 |
| 1773 const int between_child_spacing = | 1767 // The grid layout contains one row if not signed in, and 2 if signed in (the |
| 1774 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing(); | 1768 // second row is for the email created later). Therefore, the profile photo is |
| 1775 current_profile_card_->SetLayoutManager(new views::BoxLayout( | 1769 // over 2 rows if signed in. |
| 1776 views::BoxLayout::kHorizontal, 0, | 1770 grid_layout->AddView(current_profile_photo, 1, avatar_item.signed_in ? 2 : 1); |
| 1777 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); | 1771 grid_layout->AddView(current_profile_name, 1, 1, views::GridLayout::LEADING, |
| 1778 current_profile_card_->AddChildView(current_profile_photo); | 1772 avatar_item.signed_in ? views::GridLayout::TRAILING |
| 1779 current_profile_card_->AddChildView(profile_name_container); | 1773 : views::GridLayout::CENTER); |
| 1780 current_profile_card_->SetMinSize(gfx::Size( | 1774 current_profile_card_->SetMinSize(gfx::Size( |
| 1781 GetFixedMenuWidth(), current_profile_photo->GetPreferredSize().height() + | 1775 GetFixedMenuWidth(), current_profile_photo->GetPreferredSize().height() + |
| 1782 2 * views::kRelatedControlSmallVerticalSpacing)); | 1776 2 * views::kRelatedControlSmallVerticalSpacing)); |
| 1783 view->AddChildView(current_profile_card_); | 1777 view->AddChildView(current_profile_card_); |
| 1784 | 1778 |
| 1785 if (is_guest) { | 1779 if (is_guest) { |
| 1786 current_profile_card_->SetEnabled(false); | 1780 current_profile_card_->SetEnabled(false); |
| 1787 return view; | 1781 return view; |
| 1788 } | 1782 } |
| 1789 | 1783 |
| 1790 const base::string16 profile_name = | 1784 const base::string16 profile_name = |
| 1791 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); | 1785 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); |
| 1792 | 1786 |
| 1793 // The available links depend on the type of profile that is active. | 1787 // The available links depend on the type of profile that is active. |
| 1794 if (avatar_item.signed_in) { | 1788 if (avatar_item.signed_in) { |
| 1789 grid_layout->StartRow(1, 0); | |
| 1790 // Skip first column for the profile icon. | |
| 1791 grid_layout->SkipColumns(1); | |
| 1795 if (switches::IsEnableAccountConsistency()) { | 1792 if (switches::IsEnableAccountConsistency()) { |
| 1796 base::string16 button_text = l10n_util::GetStringUTF16( | 1793 base::string16 button_text = l10n_util::GetStringUTF16( |
| 1797 IsProfileChooser(view_mode_) | 1794 IsProfileChooser(view_mode_) |
| 1798 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON | 1795 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON |
| 1799 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 1796 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 1800 manage_accounts_button_ = | 1797 manage_accounts_button_ = |
| 1801 new BackgroundColorHoverButton(this, button_text); | 1798 new BackgroundColorHoverButton(this, button_text); |
| 1802 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1799 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1803 manage_accounts_button_->SetMinSize( | 1800 manage_accounts_button_->SetMinSize( |
| 1804 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); | 1801 gfx::Size(GetFixedMenuWidth(), kButtonHeight)); |
| 1805 view->AddChildView(manage_accounts_button_); | 1802 grid_layout->AddView(manage_accounts_button_, 1, 1, |
| 1803 views::GridLayout::CENTER, | |
| 1804 views::GridLayout::CENTER); | |
| 1806 } else { | 1805 } else { |
| 1807 views::Label* email_label = new views::Label(avatar_item.username); | 1806 views::Label* email_label = new views::Label(avatar_item.username); |
| 1808 current_profile_card->set_subtitle(email_label); | 1807 current_profile_card->set_subtitle(email_label); |
| 1809 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); | 1808 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
| 1810 email_label->SetEnabled(false); | 1809 email_label->SetEnabled(false); |
| 1811 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1810 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1812 name_container_v_spacing = | 1811 grid_layout->AddView(email_label, 1, 1, views::GridLayout::LEADING, |
| 1813 (current_profile_photo->GetPreferredSize().height() - | 1812 views::GridLayout::LEADING); |
| 1814 current_profile_name->GetPreferredSize().height() - | |
| 1815 email_label->GetPreferredSize().height()) / 2; | |
| 1816 profile_name_layout->set_inside_border_insets( | |
| 1817 gfx::Insets(name_container_v_spacing, 0)); | |
| 1818 profile_name_container->AddChildView(email_label); | |
| 1819 } | 1813 } |
| 1820 | 1814 |
| 1821 current_profile_card_->SetAccessibleName( | 1815 current_profile_card_->SetAccessibleName( |
| 1822 l10n_util::GetStringFUTF16( | 1816 l10n_util::GetStringFUTF16( |
| 1823 IDS_PROFILES_EDIT_SIGNED_IN_PROFILE_ACCESSIBLE_NAME, | 1817 IDS_PROFILES_EDIT_SIGNED_IN_PROFILE_ACCESSIBLE_NAME, |
| 1824 profile_name, | 1818 profile_name, |
| 1825 avatar_item.username)); | 1819 avatar_item.username)); |
| 1826 return view; | 1820 return view; |
| 1827 } | 1821 } |
| 1828 | 1822 |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2380 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2374 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2381 IncognitoModePrefs::DISABLED; | 2375 IncognitoModePrefs::DISABLED; |
| 2382 return incognito_available && !browser_->profile()->IsGuestSession(); | 2376 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2383 } | 2377 } |
| 2384 | 2378 |
| 2385 void ProfileChooserView::PostActionPerformed( | 2379 void ProfileChooserView::PostActionPerformed( |
| 2386 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2380 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2387 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2381 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2388 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2382 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2389 } | 2383 } |
| OLD | NEW |