Home | History | Annotate | Download | only in tray
      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_TRAY_SYSTEM_TRAY_ITEM_H_
      6 #define ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "ash/shelf/shelf_types.h"
     10 #include "ash/system/user/login_status.h"
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 
     14 namespace views {
     15 class View;
     16 }
     17 
     18 namespace ash {
     19 
     20 class SystemTray;
     21 
     22 namespace internal {
     23 class TrayItemView;
     24 }
     25 
     26 class ASH_EXPORT SystemTrayItem {
     27  public:
     28   explicit SystemTrayItem(SystemTray* system_tray);
     29   virtual ~SystemTrayItem();
     30 
     31   // Create* functions may return NULL if nothing should be displayed for the
     32   // type of view. The default implementations return NULL.
     33 
     34   // Returns a view to be displayed in the system tray. If this returns NULL,
     35   // then this item is not displayed in the tray.
     36   // NOTE: The returned view should almost always be a TrayItemView, which
     37   // automatically resizes the widget when the size of the view changes, and
     38   // adds animation when the visibility of the view changes. If a view wants to
     39   // avoid this behavior, then it should not be a TrayItemView.
     40   virtual views::View* CreateTrayView(user::LoginStatus status);
     41 
     42   // Returns a view for the item to be displayed in the list. This view can be
     43   // displayed with a number of other tray items, so this should not be too
     44   // big.
     45   virtual views::View* CreateDefaultView(user::LoginStatus status);
     46 
     47   // Returns a detailed view for the item. This view is displayed standalone.
     48   virtual views::View* CreateDetailedView(user::LoginStatus status);
     49 
     50   // Returns a notification view for the item. This view is displayed with
     51   // other notifications and should be the same size as default views.
     52   virtual views::View* CreateNotificationView(user::LoginStatus status);
     53 
     54   // These functions are called when the corresponding view item is about to be
     55   // removed. An item should do appropriate cleanup in these functions.
     56   // The default implementation does nothing.
     57   virtual void DestroyTrayView();
     58   virtual void DestroyDefaultView();
     59   virtual void DestroyDetailedView();
     60   virtual void DestroyNotificationView();
     61 
     62   // Updates the tray view (if applicable) when the user's login status changes.
     63   // It is not necessary the update the default or detailed view, since the
     64   // default/detailed popup is closed when login status changes. The default
     65   // implementation does nothing.
     66   virtual void UpdateAfterLoginStatusChange(user::LoginStatus status);
     67 
     68   // Updates the tray view (if applicable) when shelf's alignment changes.
     69   // The default implementation does nothing.
     70   virtual void UpdateAfterShelfAlignmentChange(ShelfAlignment alignment);
     71 
     72   // Shows the detailed view for this item. If the main popup for the tray is
     73   // currently visible, then making this call would use the existing window to
     74   // display the detailed item. The detailed item will inherit the bounds of the
     75   // existing window.
     76   // If there is no existing view, then this is equivalent to calling
     77   // PopupDetailedView(0, true).
     78   void TransitionDetailedView();
     79 
     80   // Pops up the detailed view for this item. An item can request to show its
     81   // detailed view using this function (e.g. from an observer callback when
     82   // something, e.g. volume, network availability etc. changes). If
     83   // |for_seconds| is non-zero, then the popup is closed after the specified
     84   // time.
     85   void PopupDetailedView(int for_seconds, bool activate);
     86 
     87   // Continue showing the currently-shown detailed view, if any, for
     88   // |for_seconds| seconds.  The caller is responsible for checking that the
     89   // currently-shown view is for this item.
     90   void SetDetailedViewCloseDelay(int for_seconds);
     91 
     92   // Hides the detailed view for this item.
     93   void HideDetailedView();
     94 
     95   // Shows a notification for this item.
     96   void ShowNotificationView();
     97 
     98   // Hides the notification for this item.
     99   void HideNotificationView();
    100 
    101   // Returns true if item should hide the arrow.
    102   virtual bool ShouldHideArrow() const;
    103 
    104   // Returns true if this item needs to force the launcher to be visible when
    105   // the launcher is in the auto-hide state. Default is true.
    106   virtual bool ShouldShowLauncher() const;
    107 
    108   // Returns the system tray that this item belongs to.
    109   SystemTray* system_tray() const { return system_tray_; }
    110 
    111   bool restore_focus() const { return restore_focus_; }
    112   void set_restore_focus(bool restore_focus) {
    113     restore_focus_ = restore_focus;
    114   }
    115 
    116  private:
    117   SystemTray* system_tray_;
    118   bool restore_focus_;
    119 
    120   DISALLOW_COPY_AND_ASSIGN(SystemTrayItem);
    121 };
    122 
    123 }  // namespace ash
    124 
    125 #endif  // ASH_SYSTEM_TRAY_SYSTEM_TRAY_ITEM_H_
    126