1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_
11 #include "chrome/browser/profiles/avatar_menu.h"
12 #include "chrome/browser/profiles/avatar_menu_observer.h"
13 #include "ui/views/bubble/bubble_delegate.h"
14 #include "ui/views/controls/button/button.h"
15 #include "ui/views/controls/link_listener.h"
16 #include "ui/views/controls/styled_label_listener.h"
29 class ProfileItemView;
31 // This bubble view is displayed when the user clicks on the avatar button.
32 // It displays a list of profiles and allows users to switch between profiles.
33 class ProfileChooserView : public views::BubbleDelegateView,
34 public views::ButtonListener,
35 public views::LinkListener,
36 public AvatarMenuObserver {
38 // Shows the bubble if one is not already showing. This allows us to easily
39 // make a button toggle the bubble on and off when clicked: we unconditionally
40 // call this function when the button is clicked and if the bubble isn't
41 // showing it will appear while if it is showing, nothing will happen here and
42 // the existing bubble will auto-close due to focus loss.
43 static void ShowBubble(views::View* anchor_view,
44 views::BubbleBorder::Arrow arrow,
45 views::BubbleBorder::BubbleAlignment border_alignment,
46 const gfx::Rect& anchor_rect,
48 static bool IsShowing();
51 // We normally close the bubble any time it becomes inactive but this can lead
52 // to flaky tests where unexpected UI events are triggering this behavior.
53 // Tests should call this with "false" for more consistent operation.
54 static void set_close_on_deactivate(bool close) {
55 close_on_deactivate_ = close;
59 friend class NewAvatarMenuButtonTest;
60 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
62 typedef std::vector<size_t> Indexes;
63 typedef std::map<views::Button*, int> ButtonIndexes;
65 // Different views that can be displayed in the bubble.
67 PROFILE_CHOOSER_VIEW, // Shows a "fast profile switcher" view.
68 ACCOUNT_MANAGEMENT_VIEW, // Shows a list of accounts for the active user.
69 GAIA_SIGNIN_VIEW, // Shows a web view for primary sign in.
70 GAIA_ADD_ACCOUNT_VIEW // Shows a web view for adding secondary accounts.
73 ProfileChooserView(views::View* anchor_view,
74 views::BubbleBorder::Arrow arrow,
75 const gfx::Rect& anchor_rect,
77 virtual ~ProfileChooserView();
79 // BubbleDelegateView:
80 virtual void Init() OVERRIDE;
81 virtual void WindowClosing() OVERRIDE;
84 virtual void ButtonPressed(views::Button* sender,
85 const ui::Event& event) OVERRIDE;
88 virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE;
90 // AvatarMenuObserver:
91 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE;
93 static ProfileChooserView* profile_bubble_;
94 static bool close_on_deactivate_;
96 void ResetLinksAndButtons();
98 // Shows either the profile chooser or the account management views.
99 void ShowView(BubbleViewMode view_to_display,
100 AvatarMenu* avatar_menu);
102 // Creates the main profile card for the profile |avatar_item|. |is_guest|
103 // is used to determine whether to show any Sign in/Sign out/Manage accounts
105 views::View* CreateCurrentProfileView(
106 const AvatarMenu::Item& avatar_item,
108 views::View* CreateGuestProfileView();
109 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show);
110 views::View* CreateOptionsView(bool is_guest_view);
112 // Account Management view for the profile |avatar_item|.
113 views::View* CreateCurrentProfileEditableView(
114 const AvatarMenu::Item& avatar_item);
115 views::View* CreateCurrentProfileAccountsView(
116 const AvatarMenu::Item& avatar_item);
118 scoped_ptr<AvatarMenu> avatar_menu_;
121 // Other profiles used in the "fast profile switcher" view.
122 ButtonIndexes open_other_profile_indexes_map_;
124 // Links displayed in the active profile card.
125 views::Link* manage_accounts_link_;
126 views::Link* signout_current_profile_link_;
127 views::Link* signin_current_profile_link_;
128 views::Link* change_photo_link_;
131 views::TextButton* guest_button_;
132 views::TextButton* end_guest_button_;
133 views::TextButton* add_user_button_;
134 views::TextButton* users_button_;
135 views::LabelButton* add_account_button_;
137 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView);
140 #endif // CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_