• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ASH_SYSTEM_USER_USER_VIEW_H_
6 #define ASH_SYSTEM_USER_USER_VIEW_H_
7 
8 #include "ash/session/session_state_delegate.h"
9 #include "ash/system/tray/tray_constants.h"
10 #include "ash/system/user/login_status.h"
11 #include "ash/system/user/tray_user.h"
12 #include "base/macros.h"
13 #include "ui/views/controls/button/button.h"
14 #include "ui/views/focus/focus_manager.h"
15 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/mouse_watcher.h"
17 #include "ui/views/view.h"
18 
19 namespace gfx {
20 class Rect;
21 class Size;
22 }
23 
24 namespace views {
25 class FocusManager;
26 }
27 
28 namespace ash {
29 
30 class PopupMessage;
31 class SystemTrayItem;
32 
33 namespace tray {
34 
35 // The view of a user item in system tray bubble.
36 class UserView : public views::View,
37                  public views::ButtonListener,
38                  public views::MouseWatcherListener,
39                  public views::FocusChangeListener {
40  public:
41   UserView(SystemTrayItem* owner,
42            ash::user::LoginStatus login,
43            MultiProfileIndex index,
44            bool for_detailed_view);
45   virtual ~UserView();
46 
47   // Overridden from MouseWatcherListener:
48   virtual void MouseMovedOutOfHost() OVERRIDE;
49 
50   TrayUser::TestState GetStateForTest() const;
51   gfx::Rect GetBoundsInScreenOfUserButtonForTest();
52 
53  private:
54   // Overridden from views::View.
55   virtual gfx::Size GetPreferredSize() const OVERRIDE;
56   virtual int GetHeightForWidth(int width) const OVERRIDE;
57   virtual void Layout() OVERRIDE;
58 
59   // Overridden from views::ButtonListener.
60   virtual void ButtonPressed(views::Button* sender,
61                              const ui::Event& event) OVERRIDE;
62 
63   // Overridden from views::FocusChangeListener:
64   virtual void OnWillChangeFocus(View* focused_before,
65                                  View* focused_now) OVERRIDE;
66   virtual void OnDidChangeFocus(View* focused_before,
67                                 View* focused_now) OVERRIDE;
68 
69   void AddLogoutButton(user::LoginStatus login);
70   void AddUserCard(user::LoginStatus login);
71 
72   // Create the menu option to add another user. If |disabled| is set the user
73   // cannot actively click on the item.
74   void ToggleAddUserMenuOption();
75 
76   // Removes the add user menu option.
77   void RemoveAddUserMenuOption();
78 
79   MultiProfileIndex multiprofile_index_;
80   // The view of the user card.
81   views::View* user_card_view_;
82 
83   // This is the owner system tray item of this view.
84   SystemTrayItem* owner_;
85 
86   // True if |user_card_view_| is a |ButtonFromView| - otherwise it is only
87   // a |UserCardView|.
88   bool is_user_card_button_;
89 
90   views::View* logout_button_;
91   scoped_ptr<PopupMessage> popup_message_;
92   scoped_ptr<views::Widget> add_menu_option_;
93 
94   // False when the add user panel is visible but not activatable.
95   bool add_user_enabled_;
96 
97   // True if this view will be used inside detailed view.
98   bool for_detailed_view_;
99 
100   // The mouse watcher which takes care of out of window hover events.
101   scoped_ptr<views::MouseWatcher> mouse_watcher_;
102 
103   // The focus manager which we use to detect focus changes.
104   views::FocusManager* focus_manager_;
105 
106   DISALLOW_COPY_AND_ASSIGN(UserView);
107 };
108 
109 }  // namespace tray
110 }  // namespace ash
111 
112 #endif  // ASH_SYSTEM_USER_USER_VIEW_H_
113