- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / profile_chooser_view.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_
7
8 #include <map>
9 #include <vector>
10
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"
17
18 namespace gfx {
19 class Image;
20 }
21
22 namespace views {
23 class Link;
24 class TextButton;
25 class LabelButton;
26 }
27
28 class Browser;
29 class ProfileItemView;
30
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 {
37  public:
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,
47                          Browser* browser);
48   static bool IsShowing();
49   static void Hide();
50
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;
56   }
57
58  private:
59   friend class NewAvatarMenuButtonTest;
60   FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
61
62   typedef std::vector<size_t> Indexes;
63   typedef std::map<views::Button*, int> ButtonIndexes;
64
65   // Different views that can be displayed in the bubble.
66   enum BubbleViewMode {
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.
71   };
72
73   ProfileChooserView(views::View* anchor_view,
74                      views::BubbleBorder::Arrow arrow,
75                      const gfx::Rect& anchor_rect,
76                      Browser* browser);
77   virtual ~ProfileChooserView();
78
79   // BubbleDelegateView:
80   virtual void Init() OVERRIDE;
81   virtual void WindowClosing() OVERRIDE;
82
83   // ButtonListener:
84   virtual void ButtonPressed(views::Button* sender,
85                              const ui::Event& event) OVERRIDE;
86
87   // LinkListener:
88   virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE;
89
90   // AvatarMenuObserver:
91   virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE;
92
93   static ProfileChooserView* profile_bubble_;
94   static bool close_on_deactivate_;
95
96   void ResetLinksAndButtons();
97
98   // Shows either the profile chooser or the account management views.
99   void ShowView(BubbleViewMode view_to_display,
100                 AvatarMenu* avatar_menu);
101
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
104   // links.
105   views::View* CreateCurrentProfileView(
106       const AvatarMenu::Item& avatar_item,
107       bool is_guest);
108   views::View* CreateGuestProfileView();
109   views::View* CreateOtherProfilesView(const Indexes& avatars_to_show);
110   views::View* CreateOptionsView(bool is_guest_view);
111
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);
117
118   scoped_ptr<AvatarMenu> avatar_menu_;
119   Browser* browser_;
120
121   // Other profiles used in the "fast profile switcher" view.
122   ButtonIndexes open_other_profile_indexes_map_;
123
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_;
129
130   // Action buttons.
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_;
136
137   DISALLOW_COPY_AND_ASSIGN(ProfileChooserView);
138 };
139
140 #endif  // CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_