1 // Copyright (c) 2012 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_TRAY_USER_H_ 6 #define ASH_SYSTEM_USER_TRAY_USER_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/session_state_delegate.h" 10 #include "ash/system/tray/system_tray_item.h" 11 #include "ash/system/user/user_observer.h" 12 #include "base/compiler_specific.h" 13 14 namespace gfx { 15 class Rect; 16 class Point; 17 } 18 19 namespace views { 20 class ImageView; 21 class Label; 22 } 23 24 namespace ash { 25 namespace internal { 26 27 namespace tray { 28 class UserView; 29 class RoundedImageView; 30 } 31 32 class ASH_EXPORT TrayUser : public SystemTrayItem, 33 public UserObserver { 34 public: 35 // The given |multiprofile_index| is the user number in a multi profile 36 // scenario. Index #0 is the running user, the other indices are other logged 37 // in users (if there are any). Depending on the multi user mode, there will 38 // be either one (index #0) or all users be visible in the system tray. 39 TrayUser(SystemTray* system_tray, MultiProfileIndex index); 40 virtual ~TrayUser(); 41 42 // Allows unit tests to see if the item was created. 43 enum TestState { 44 HIDDEN, // The item is hidden. 45 SHOWN, // The item gets presented to the user. 46 HOVERED, // The item is hovered and presented to the user. 47 ACTIVE, // The item was clicked and can add a user. 48 ACTIVE_BUT_DISABLED // The item was clicked anc cannot add a user. 49 }; 50 TestState GetStateForTest() const; 51 52 // Checks if a drag and drop operation would be able to land a window on this 53 // |point_in_screen|. 54 bool CanDropWindowHereToTransferToUser(const gfx::Point& point_in_screen); 55 56 // Try to re-parent the |window| to a new owner. Returns true if the window 57 // got transfered. 58 bool TransferWindowToUser(aura::Window* window); 59 60 // Returns the bounds of the user panel in screen coordinates. 61 // Note: This only works when the panel shown. 62 gfx::Rect GetUserPanelBoundsInScreenForTest() const; 63 64 private: 65 // Overridden from SystemTrayItem. 66 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; 67 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; 68 virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE; 69 virtual void DestroyTrayView() OVERRIDE; 70 virtual void DestroyDefaultView() OVERRIDE; 71 virtual void DestroyDetailedView() OVERRIDE; 72 virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; 73 virtual void UpdateAfterShelfAlignmentChange( 74 ShelfAlignment alignment) OVERRIDE; 75 76 // Overridden from UserObserver. 77 virtual void OnUserUpdate() OVERRIDE; 78 virtual void OnUserAddedToSession() OVERRIDE; 79 80 void UpdateAvatarImage(user::LoginStatus status); 81 82 // Get the user index which should be used for the tray icon of this item. 83 MultiProfileIndex GetTrayIndex(); 84 85 // Return the radius for the tray item to use. 86 int GetTrayItemRadius(); 87 88 // Updates the layout of this item. 89 void UpdateLayoutOfItem(); 90 91 // The user index to use. 92 MultiProfileIndex multiprofile_index_; 93 94 tray::UserView* user_; 95 96 // View that contains label and/or avatar. 97 views::View* layout_view_; 98 tray::RoundedImageView* avatar_; 99 views::Label* label_; 100 101 DISALLOW_COPY_AND_ASSIGN(TrayUser); 102 }; 103 104 } // namespace internal 105 } // namespace ash 106 107 #endif // ASH_SYSTEM_USER_TRAY_USER_H_ 108