Home | History | Annotate | Download | only in user
      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/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 Size;
     17 }
     18 
     19 namespace views {
     20 class ImageView;
     21 class Label;
     22 }
     23 
     24 namespace ash {
     25 
     26 namespace tray {
     27 class RoundedImageView;
     28 class UserView;
     29 }
     30 
     31 class ASH_EXPORT TrayUser : public SystemTrayItem,
     32                             public UserObserver {
     33  public:
     34   // The given |multiprofile_index| is the user number in a multi profile
     35   // scenario. Index #0 is the running user, the other indices are other logged
     36   // in users (if there are any). Depending on the multi user mode, there will
     37   // be either one (index #0) or all users be visible in the system tray.
     38   TrayUser(SystemTray* system_tray, MultiProfileIndex index);
     39   virtual ~TrayUser();
     40 
     41   // Allows unit tests to see if the item was created.
     42   enum TestState {
     43     HIDDEN,               // The item is hidden.
     44     SHOWN,                // The item gets presented to the user.
     45     HOVERED,              // The item is hovered and presented to the user.
     46     ACTIVE,               // The item was clicked and can add a user.
     47     ACTIVE_BUT_DISABLED   // The item was clicked anc cannot add a user.
     48   };
     49   TestState GetStateForTest() const;
     50 
     51   // Returns the size of layout_view_.
     52   gfx::Size GetLayoutSizeForTest() const;
     53 
     54   // Returns the bounds of the user panel in screen coordinates.
     55   // Note: This only works when the panel shown.
     56   gfx::Rect GetUserPanelBoundsInScreenForTest() const;
     57 
     58   // Update the TrayUser as if the current LoginStatus is |status|.
     59   void UpdateAfterLoginStatusChangeForTest(user::LoginStatus status);
     60 
     61 
     62  private:
     63   // Overridden from SystemTrayItem.
     64   virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE;
     65   virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
     66   virtual views::View* CreateDetailedView(user::LoginStatus status) OVERRIDE;
     67   virtual void DestroyTrayView() OVERRIDE;
     68   virtual void DestroyDefaultView() OVERRIDE;
     69   virtual void DestroyDetailedView() OVERRIDE;
     70   virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE;
     71   virtual void UpdateAfterShelfAlignmentChange(
     72       ShelfAlignment alignment) OVERRIDE;
     73 
     74   // Overridden from UserObserver.
     75   virtual void OnUserUpdate() OVERRIDE;
     76   virtual void OnUserAddedToSession() OVERRIDE;
     77 
     78   void UpdateAvatarImage(user::LoginStatus status);
     79 
     80   // Get the user index which should be used for the tray icon of this item.
     81   MultiProfileIndex GetTrayIndex();
     82 
     83   // Updates the layout of this item.
     84   void UpdateLayoutOfItem();
     85 
     86   // The user index to use.
     87   MultiProfileIndex multiprofile_index_;
     88 
     89   tray::UserView* user_;
     90 
     91   // View that contains label and/or avatar.
     92   views::View* layout_view_;
     93   tray::RoundedImageView* avatar_;
     94   views::Label* label_;
     95 
     96   DISALLOW_COPY_AND_ASSIGN(TrayUser);
     97 };
     98 
     99 }  // namespace ash
    100 
    101 #endif  // ASH_SYSTEM_USER_TRAY_USER_H_
    102