// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_ #include #include #include "chrome/browser/profiles/avatar_menu.h" #include "chrome/browser/profiles/avatar_menu_observer.h" #include "google_apis/gaia/oauth2_token_service.h" #include "ui/views/bubble/bubble_delegate.h" #include "ui/views/controls/button/button.h" #include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/controls/link_listener.h" #include "ui/views/controls/styled_label_listener.h" #include "ui/views/controls/textfield/textfield_controller.h" class EditableProfilePhoto; class EditableProfileName; namespace gfx { class Image; } namespace views { class GridLayout; class Link; class TextButton; class LabelButton; } class Browser; // This bubble view is displayed when the user clicks on the avatar button. // It displays a list of profiles and allows users to switch between profiles. class ProfileChooserView : public views::BubbleDelegateView, public views::ButtonListener, public views::LinkListener, public views::MenuButtonListener, public views::TextfieldController, public AvatarMenuObserver, public OAuth2TokenService::Observer { public: // Shows the bubble if one is not already showing. This allows us to easily // make a button toggle the bubble on and off when clicked: we unconditionally // call this function when the button is clicked and if the bubble isn't // showing it will appear while if it is showing, nothing will happen here and // the existing bubble will auto-close due to focus loss. static void ShowBubble(views::View* anchor_view, views::BubbleBorder::Arrow arrow, views::BubbleBorder::BubbleAlignment border_alignment, const gfx::Rect& anchor_rect, Browser* browser); static bool IsShowing(); static void Hide(); // We normally close the bubble any time it becomes inactive but this can lead // to flaky tests where unexpected UI events are triggering this behavior. // Tests should call this with "false" for more consistent operation. static void clear_close_on_deactivate_for_testing() { close_on_deactivate_for_testing_ = false; } private: friend class NewAvatarMenuButtonTest; FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut); typedef std::vector Indexes; typedef std::map ButtonIndexes; typedef std::map AccountButtonIndexes; // Different views that can be displayed in the bubble. enum BubbleViewMode { PROFILE_CHOOSER_VIEW, // Shows a "fast profile switcher" view. ACCOUNT_MANAGEMENT_VIEW, // Shows a list of accounts for the active user. GAIA_SIGNIN_VIEW, // Shows a web view for primary sign in. GAIA_ADD_ACCOUNT_VIEW // Shows a web view for adding secondary accounts. }; ProfileChooserView(views::View* anchor_view, views::BubbleBorder::Arrow arrow, const gfx::Rect& anchor_rect, Browser* browser); virtual ~ProfileChooserView(); // views::BubbleDelegateView: virtual void Init() OVERRIDE; virtual void WindowClosing() OVERRIDE; // views::ButtonListener: virtual void ButtonPressed(views::Button* sender, const ui::Event& event) OVERRIDE; // views::LinkListener: virtual void LinkClicked(views::Link* sender, int event_flags) OVERRIDE; // views::MenuButtonListener: virtual void OnMenuButtonClicked(views::View* source, const gfx::Point& point) OVERRIDE; // views::TextfieldController: virtual bool HandleKeyEvent(views::Textfield* sender, const ui::KeyEvent& key_event) OVERRIDE; // AvatarMenuObserver: virtual void OnAvatarMenuChanged(AvatarMenu* avatar_menu) OVERRIDE; // OAuth2TokenService::Observer overrides. virtual void OnRefreshTokenAvailable(const std::string& account_id) OVERRIDE; virtual void OnRefreshTokenRevoked(const std::string& account_id) OVERRIDE; static ProfileChooserView* profile_bubble_; static bool close_on_deactivate_for_testing_; void ResetView(); // Shows either the profile chooser or the account management views. void ShowView(BubbleViewMode view_to_display, AvatarMenu* avatar_menu); // Creates the main profile card for the profile |avatar_item|. |is_guest| // is used to determine whether to show any Sign in/Sign out/Manage accounts // links. views::View* CreateCurrentProfileView( const AvatarMenu::Item& avatar_item, bool is_guest); views::View* CreateGuestProfileView(); views::View* CreateOtherProfilesView(const Indexes& avatars_to_show); views::View* CreateOptionsView(bool is_guest_view); // Account Management view for the profile |avatar_item|. views::View* CreateCurrentProfileEditableView( const AvatarMenu::Item& avatar_item); views::View* CreateCurrentProfileAccountsView( const AvatarMenu::Item& avatar_item); void CreateAccountButton(views::GridLayout* layout, const std::string& account, bool is_primary_account, int width); scoped_ptr avatar_menu_; Browser* browser_; // Other profiles used in the "fast profile switcher" view. ButtonIndexes open_other_profile_indexes_map_; // Accounts associated with the current profile. AccountButtonIndexes current_profile_accounts_map_; // Links displayed in the active profile card. views::Link* manage_accounts_link_; views::Link* signout_current_profile_link_; views::Link* signin_current_profile_link_; // The profile name and photo in the active profile card. Owned by the // views hierarchy. EditableProfilePhoto* current_profile_photo_; EditableProfileName* current_profile_name_; // Action buttons. views::TextButton* guest_button_; views::TextButton* end_guest_button_; views::TextButton* add_user_button_; views::TextButton* users_button_; views::LabelButton* add_account_button_; // Active view mode. BubbleViewMode view_mode_; DISALLOW_COPY_AND_ASSIGN(ProfileChooserView); }; #endif // CHROME_BROWSER_UI_VIEWS_PROFILE_CHOOSER_VIEW_H_