Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / profiles / new_avatar_button.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_
7
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"
11
12 class Browser;
13
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 {
18  public:
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.
23   };
24
25   NewAvatarButton(views::ButtonListener* listener,
26                   const base::string16& profile_name,
27                   AvatarButtonStyle button_style,
28                   Browser* browser);
29   virtual ~NewAvatarButton();
30
31   // Views::MenuButton
32   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
33   virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
34
35  private:
36   friend class NewAvatarMenuButtonTest;
37   friend class ProfileChooserViewBrowserTest;
38   FRIEND_TEST_ALL_PREFIXES(NewAvatarMenuButtonTest, SignOut);
39   FRIEND_TEST_ALL_PREFIXES(ProfileChooserViewBrowserTest, ViewProfileUMA);
40
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 OnProfileAvatarChanged(
50       const base::FilePath& profile_path) OVERRIDE;
51   virtual void OnProfileSupervisedUserIdChanged(
52       const base::FilePath& profile_path) OVERRIDE;
53
54   // SigninErrorController::Observer:
55   virtual void OnErrorChanged() OVERRIDE;
56
57   // Called when the profile info cache has changed, which means we might
58   // have to re-display the profile name.
59   void UpdateAvatarButtonAndRelayoutParent();
60
61   Browser* browser_;
62
63   // This is used to check if the bubble was showing during the mouse pressed
64   // event. If this is true then the mouse released event is ignored to prevent
65   // the bubble from reshowing.
66   bool suppress_mouse_released_action_;
67
68   DISALLOW_COPY_AND_ASSIGN(NewAvatarButton);
69 };
70
71 #endif  // CHROME_BROWSER_UI_VIEWS_PROFILES_NEW_AVATAR_BUTTON_H_