Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / profile_chooser_view.h
blobb0abbba980218344847e509db6f4c0c7b9d7b0b7
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_
8 #include <map>
9 #include <vector>
11 #include "chrome/browser/profiles/avatar_menu.h"
12 #include "chrome/browser/profiles/avatar_menu_observer.h"
13 #include "google_apis/gaia/oauth2_token_service.h"
14 #include "ui/views/bubble/bubble_delegate.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/controls/button/menu_button_listener.h"
17 #include "ui/views/controls/link_listener.h"
18 #include "ui/views/controls/styled_label_listener.h"
19 #include "ui/views/controls/textfield/textfield_controller.h"
21 class EditableProfilePhoto;
22 class EditableProfileName;
24 namespace gfx {
25 class Image;
28 namespace views {
29 class GridLayout;
30 class Link;
31 class TextButton;
32 class LabelButton;
35 class Browser;
37 // This bubble view is displayed when the user clicks on the avatar button.
38 // It displays a list of profiles and allows users to switch between profiles.
39 class ProfileChooserView : public views::BubbleDelegateView,
40 public views::ButtonListener,
41 public views::LinkListener,
42 public views::MenuButtonListener,
43 public views::TextfieldController,
44 public AvatarMenuObserver,
45 public OAuth2TokenService::Observer {
46 public:
47 // Shows the bubble if one is not already showing. This allows us to easily
48 // make a button toggle the bubble on and off when clicked: we unconditionally
49 // call this function when the button is clicked and if the bubble isn't
50 // showing it will appear while if it is showing, nothing will happen here and
51 // the existing bubble will auto-close due to focus loss.
52 static void ShowBubble(views::View* anchor_view,
53 views::BubbleBorder::Arrow arrow,
54 views::BubbleBorder::BubbleAlignment border_alignment,
55 const gfx::Rect& anchor_rect,
56 Browser* browser);
57 static bool IsShowing();
58 static void Hide();
60 // We normally close the bubble any time it becomes inactive but this can lead
61 // to flaky tests where unexpected UI events are triggering this behavior.
62 // Tests should call this with "false" for more consistent operation.
63 static void clear_close_on_deactivate_for_testing() {
64 close_on_deactivate_for_testing_ = false;
67 private:
68 friend class NewAvatarMenuButtonTest;
69 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
71 typedef std::vector<size_t> Indexes;
72 typedef std::map<views::Button*, int> ButtonIndexes;
73 typedef std::map<views::View*, std::string> AccountButtonIndexes;
75 // Different views that can be displayed in the bubble.
76 enum BubbleViewMode {
77 PROFILE_CHOOSER_VIEW, // Shows a "fast profile switcher" view.
78 ACCOUNT_MANAGEMENT_VIEW, // Shows a list of accounts for the active user.
79 GAIA_SIGNIN_VIEW, // Shows a web view for primary sign in.
80 GAIA_ADD_ACCOUNT_VIEW // Shows a web view for adding secondary accounts.
83 ProfileChooserView(views::View* anchor_view,
84 views::BubbleBorder::Arrow arrow,
85 const gfx::Rect& anchor_rect,
86 Browser* browser);
87 virtual ~ProfileChooserView();
89 // views::BubbleDelegateView:
90 virtual void Init() OVERRIDE;
91 virtual void WindowClosing() OVERRIDE;
93 // views::ButtonListener:
94 virtual void ButtonPressed(views::Button* sender,
95 const ui::Event& event) OVERRIDE;
97 // views::LinkListener:
98 virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE;
100 // views::MenuButtonListener:
101 virtual void OnMenuButtonClicked(views::View* source,
102 const gfx::Point& point) OVERRIDE;
103 // views::TextfieldController:
104 virtual bool HandleKeyEvent(views::Textfield* sender,
105 const ui::KeyEvent& key_event) OVERRIDE;
107 // AvatarMenuObserver:
108 virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE;
110 // OAuth2TokenService::Observer overrides.
111 virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE;
112 virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE;
114 static ProfileChooserView* profile_bubble_;
115 static bool close_on_deactivate_for_testing_;
117 void ResetView();
119 // Shows either the profile chooser or the account management views.
120 void ShowView(BubbleViewMode view_to_display,
121 AvatarMenu* avatar_menu);
123 // Creates the main profile card for the profile |avatar_item|. |is_guest|
124 // is used to determine whether to show any Sign in/Sign out/Manage accounts
125 // links.
126 views::View* CreateCurrentProfileView(
127 const AvatarMenu::Item& avatar_item,
128 bool is_guest);
129 views::View* CreateGuestProfileView();
130 views::View* CreateOtherProfilesView(const Indexes& avatars_to_show);
131 views::View* CreateOptionsView(bool is_guest_view);
133 // Account Management view for the profile |avatar_item|.
134 views::View* CreateCurrentProfileEditableView(
135 const AvatarMenu::Item& avatar_item);
136 views::View* CreateCurrentProfileAccountsView(
137 const AvatarMenu::Item& avatar_item);
138 void CreateAccountButton(views::GridLayout* layout,
139 const std::string& account,
140 bool is_primary_account);
142 scoped_ptr<AvatarMenu> avatar_menu_;
143 Browser* browser_;
145 // Other profiles used in the "fast profile switcher" view.
146 ButtonIndexes open_other_profile_indexes_map_;
148 // Accounts associated with the current profile.
149 AccountButtonIndexes current_profile_accounts_map_;
151 // Links displayed in the active profile card.
152 views::Link* manage_accounts_link_;
153 views::Link* signout_current_profile_link_;
154 views::Link* signin_current_profile_link_;
156 // The profile name and photo in the active profile card. Owned by the
157 // views hierarchy.
158 EditableProfilePhoto* current_profile_photo_;
159 EditableProfileName* current_profile_name_;
161 // Action buttons.
162 views::TextButton* guest_button_;
163 views::TextButton* end_guest_button_;
164 views::TextButton* add_user_button_;
165 views::TextButton* users_button_;
166 views::LabelButton* add_account_button_;
168 // Active view mode.
169 BubbleViewMode view_mode_;
171 DISALLOW_COPY_AND_ASSIGN(ProfileChooserView);
174 #endif // CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_