OLD | NEW |
| (Empty) |
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 "chrome/browser/ui/browser_window.h" | |
14 #include "google_apis/gaia/oauth2_token_service.h" | |
15 #include "ui/views/bubble/bubble_delegate.h" | |
16 #include "ui/views/controls/button/button.h" | |
17 #include "ui/views/controls/button/menu_button_listener.h" | |
18 #include "ui/views/controls/link_listener.h" | |
19 #include "ui/views/controls/styled_label_listener.h" | |
20 #include "ui/views/controls/textfield/textfield_controller.h" | |
21 | |
22 class EditableProfilePhoto; | |
23 class EditableProfileName; | |
24 | |
25 namespace gfx { | |
26 class Image; | |
27 } | |
28 | |
29 namespace views { | |
30 class GridLayout; | |
31 class ImageButton; | |
32 class Link; | |
33 class LabelButton; | |
34 } | |
35 | |
36 class Browser; | |
37 | |
38 // This bubble view is displayed when the user clicks on the avatar button. | |
39 // It displays a list of profiles and allows users to switch between profiles. | |
40 class ProfileChooserView : public views::BubbleDelegateView, | |
41 public views::ButtonListener, | |
42 public views::LinkListener, | |
43 public views::MenuButtonListener, | |
44 public views::TextfieldController, | |
45 public AvatarMenuObserver, | |
46 public OAuth2TokenService::Observer { | |
47 public: | |
48 // Different views that can be displayed in the bubble. | |
49 enum BubbleViewMode { | |
50 // Shows a "fast profile switcher" view. | |
51 BUBBLE_VIEW_MODE_PROFILE_CHOOSER, | |
52 // Shows a list of accounts for the active user. | |
53 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | |
54 // Shows a web view for primary sign in. | |
55 BUBBLE_VIEW_MODE_GAIA_SIGNIN, | |
56 // Shows a web view for adding secondary accounts. | |
57 BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, | |
58 // Shows a view for confirming account removal. | |
59 BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL | |
60 }; | |
61 | |
62 // Shows the bubble if one is not already showing. This allows us to easily | |
63 // make a button toggle the bubble on and off when clicked: we unconditionally | |
64 // call this function when the button is clicked and if the bubble isn't | |
65 // showing it will appear while if it is showing, nothing will happen here and | |
66 // the existing bubble will auto-close due to focus loss. | |
67 static void ShowBubble(BubbleViewMode view_mode, | |
68 views::View* anchor_view, | |
69 views::BubbleBorder::Arrow arrow, | |
70 views::BubbleBorder::BubbleAlignment border_alignment, | |
71 const gfx::Rect& anchor_rect, | |
72 Browser* browser); | |
73 static bool IsShowing(); | |
74 static void Hide(); | |
75 | |
76 // We normally close the bubble any time it becomes inactive but this can lead | |
77 // to flaky tests where unexpected UI events are triggering this behavior. | |
78 // Tests should call this with "false" for more consistent operation. | |
79 static void clear_close_on_deactivate_for_testing() { | |
80 close_on_deactivate_for_testing_ = false; | |
81 } | |
82 | |
83 private: | |
84 friend class NewAvatarMenuButtonTest; | |
85 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut); | |
86 | |
87 typedef std::vector<size_t> Indexes; | |
88 typedef std::map<views::Button*, int> ButtonIndexes; | |
89 typedef std::map<views::View*, std::string> AccountButtonIndexes; | |
90 | |
91 ProfileChooserView(views::View* anchor_view, | |
92 views::BubbleBorder::Arrow arrow, | |
93 const gfx::Rect& anchor_rect, | |
94 Browser* browser); | |
95 virtual ~ProfileChooserView(); | |
96 | |
97 // views::BubbleDelegateView: | |
98 virtual void Init() OVERRIDE; | |
99 virtual void WindowClosing() OVERRIDE; | |
100 | |
101 // views::ButtonListener: | |
102 virtual void ButtonPressed(views::Button* sender, | |
103 const ui::Event& event) OVERRIDE; | |
104 | |
105 // views::LinkListener: | |
106 virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE; | |
107 | |
108 // views::MenuButtonListener: | |
109 virtual void OnMenuButtonClicked(views::View* source, | |
110 const gfx::Point& point) OVERRIDE; | |
111 // views::TextfieldController: | |
112 virtual bool HandleKeyEvent(views::Textfield* sender, | |
113 const ui::KeyEvent& key_event) OVERRIDE; | |
114 | |
115 // AvatarMenuObserver: | |
116 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE; | |
117 | |
118 // OAuth2TokenService::Observer overrides. | |
119 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; | |
120 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; | |
121 | |
122 static ProfileChooserView* profile_bubble_; | |
123 static bool close_on_deactivate_for_testing_; | |
124 | |
125 void ResetView(); | |
126 | |
127 // Shows either the profile chooser or the account management views. | |
128 void ShowView(BubbleViewMode view_to_display, | |
129 AvatarMenu* avatar_menu); | |
130 | |
131 // Creates a tutorial card for the profile |avatar_item|. |tutorial_shown| | |
132 // indicates if the tutorial card is already shown in the last active view. | |
133 views::View* CreateTutorialView( | |
134 const AvatarMenu::Item& current_avatar_item, bool tutorial_shown); | |
135 | |
136 // Creates the main profile card for the profile |avatar_item|. |is_guest| | |
137 // is used to determine whether to show any Sign in/Sign out/Manage accounts | |
138 // links. | |
139 views::View* CreateCurrentProfileView( | |
140 const AvatarMenu::Item& avatar_item, | |
141 bool is_guest); | |
142 views::View* CreateGuestProfileView(); | |
143 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show); | |
144 views::View* CreateOptionsView(bool enable_lock); | |
145 | |
146 // Account Management view for the profile |avatar_item|. | |
147 views::View* CreateCurrentProfileEditableView( | |
148 const AvatarMenu::Item& avatar_item); | |
149 views::View* CreateCurrentProfileAccountsView( | |
150 const AvatarMenu::Item& avatar_item); | |
151 void CreateAccountButton(views::GridLayout* layout, | |
152 const std::string& account, | |
153 bool is_primary_account, | |
154 int width); | |
155 | |
156 // Creates a webview showing the gaia signin page. | |
157 views::View* CreateGaiaSigninView(bool add_secondary_account); | |
158 | |
159 // Creates a view to confirm account removal for |account_id_to_remove_|. | |
160 views::View* CreateAccountRemovalView(); | |
161 | |
162 void RemoveAccount(); | |
163 | |
164 scoped_ptr<AvatarMenu> avatar_menu_; | |
165 Browser* browser_; | |
166 | |
167 // Other profiles used in the "fast profile switcher" view. | |
168 ButtonIndexes open_other_profile_indexes_map_; | |
169 | |
170 // Accounts associated with the current profile. | |
171 AccountButtonIndexes current_profile_accounts_map_; | |
172 | |
173 // Links and buttons displayed in the tutorial card. | |
174 views::Link* tutorial_learn_more_link_; | |
175 views::LabelButton* tutorial_ok_button_; | |
176 | |
177 // Links displayed in the active profile card. | |
178 views::Link* manage_accounts_link_; | |
179 views::Link* signin_current_profile_link_; | |
180 | |
181 // The profile name and photo in the active profile card. Owned by the | |
182 // views hierarchy. | |
183 EditableProfilePhoto* current_profile_photo_; | |
184 EditableProfileName* current_profile_name_; | |
185 | |
186 // Action buttons. | |
187 views::LabelButton* users_button_; | |
188 views::LabelButton* lock_button_; | |
189 views::LabelButton* add_account_button_; | |
190 | |
191 // Buttons displayed in the gaia signin view. | |
192 views::ImageButton* gaia_signin_cancel_button_; | |
193 | |
194 // Links and buttons displayed in the account removal view. | |
195 views::LabelButton* remove_account_and_relaunch_button_; | |
196 views::ImageButton* account_removal_cancel_button_; | |
197 | |
198 // Records the account id to remove. | |
199 std::string account_id_to_remove_; | |
200 | |
201 // Active view mode. | |
202 BubbleViewMode view_mode_; | |
203 | |
204 // Whether the tutorial is currently shown. | |
205 bool tutorial_showing_; | |
206 | |
207 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView); | |
208 }; | |
209 | |
210 #endif // CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_ | |
OLD | NEW |