1 // Copyright 2014 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_PROFILES_NEW_AVATAR_BUTTON_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_
8 #include "chrome/browser/profiles/profile_info_cache_observer.h"
9 #include "components/signin/core/browser/signin_error_controller.h"
10 #include "ui/views/controls/button/menu_button.h"
14 // Avatar button that displays the active profile's name in the caption area.
15 class NewAvatarButton : public views::MenuButton,
16 public ProfileInfoCacheObserver,
17 public SigninErrorController::Observer {
19 // Different button styles that can be applied.
20 enum AvatarButtonStyle {
21 THEMED_BUTTON, // Used in a themed browser window.
22 NATIVE_BUTTON, // Used in a native aero or metro window.
25 NewAvatarButton(views::ButtonListener* listener,
26 const base::string16& profile_name,
27 AvatarButtonStyle button_style,
29 virtual ~NewAvatarButton();
32 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
33 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
36 friend class NewAvatarMenuButtonTest;
37 friend class ProfileChooserViewBrowserTest;
38 FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
39 FRIEND_TEST_ALL_PREFIXES(ProfileChooserViewBrowserTest, ViewProfileUMA);
41 // ProfileInfoCacheObserver:
42 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE;
43 virtual void OnProfileWasRemoved(
44 const base::FilePath& profile_path,
45 const base::string16& profile_name) OVERRIDE;
46 virtual void OnProfileNameChanged(
47 const base::FilePath& profile_path,
48 const base::string16& old_profile_name) OVERRIDE;
49 virtual void OnProfileSupervisedUserIdChanged(
50 const base::FilePath& profile_path) OVERRIDE;
52 // SigninErrorController::Observer:
53 virtual void OnErrorChanged() OVERRIDE;
55 // Called when the profile info cache has changed, which means we might
56 // have to re-display the profile name.
57 void UpdateAvatarButtonAndRelayoutParent();
61 // This is used to check if the bubble was showing during the mouse pressed
62 // event. If this is true then the mouse released event is ignored to prevent
63 // the bubble from reshowing.
64 bool suppress_mouse_released_action_;
66 DISALLOW_COPY_AND_ASSIGN(NewAvatarButton);
69 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_