1 // Copyright 2013 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_CHROMEOS_SCREEN_TRAY_ITEM_H_ 6 #define ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_ 7 8 #include "ash/system/tray/system_tray.h" 9 #include "ash/system/tray/system_tray_item.h" 10 #include "ash/system/tray/system_tray_notifier.h" 11 #include "ash/system/tray/tray_item_view.h" 12 #include "ash/system/tray/tray_notification_view.h" 13 #include "ash/system/tray/tray_popup_label_button.h" 14 #include "ui/message_center/notification_delegate.h" 15 #include "ui/views/controls/button/button.h" 16 #include "ui/views/controls/image_view.h" 17 18 namespace views { 19 class View; 20 } 21 22 namespace ash { 23 class ScreenTrayItem; 24 25 namespace tray { 26 27 class ScreenTrayView : public TrayItemView { 28 public: 29 ScreenTrayView(ScreenTrayItem* screen_tray_item, int icon_id); 30 virtual ~ScreenTrayView(); 31 32 void Update(); 33 34 private: 35 ScreenTrayItem* screen_tray_item_; 36 37 DISALLOW_COPY_AND_ASSIGN(ScreenTrayView); 38 }; 39 40 class ScreenStatusView : public views::View, 41 public views::ButtonListener { 42 public: 43 ScreenStatusView(ScreenTrayItem* screen_tray_item, 44 int icon_id, 45 const base::string16& label_text, 46 const base::string16& stop_button_text); 47 virtual ~ScreenStatusView(); 48 49 // Overridden from views::View. 50 virtual void Layout() OVERRIDE; 51 52 // Overridden from views::ButtonListener. 53 virtual void ButtonPressed(views::Button* sender, 54 const ui::Event& event) OVERRIDE; 55 56 void CreateItems(); 57 void Update(); 58 59 private: 60 ScreenTrayItem* screen_tray_item_; 61 views::ImageView* icon_; 62 views::Label* label_; 63 TrayPopupLabelButton* stop_button_; 64 int icon_id_; 65 base::string16 label_text_; 66 base::string16 stop_button_text_; 67 68 DISALLOW_COPY_AND_ASSIGN(ScreenStatusView); 69 }; 70 71 class ScreenNotificationDelegate : public message_center::NotificationDelegate { 72 public: 73 explicit ScreenNotificationDelegate(ScreenTrayItem* screen_tray); 74 75 // message_center::NotificationDelegate overrides: 76 virtual void Display() OVERRIDE; 77 virtual void Error() OVERRIDE; 78 virtual void Close(bool by_user) OVERRIDE; 79 virtual void Click() OVERRIDE; 80 virtual void ButtonClick(int button_index) OVERRIDE; 81 82 protected: 83 virtual ~ScreenNotificationDelegate(); 84 85 private: 86 ScreenTrayItem* screen_tray_; 87 88 DISALLOW_COPY_AND_ASSIGN(ScreenNotificationDelegate); 89 }; 90 91 } // namespace tray 92 93 94 // The base tray item for screen capture and screen sharing. The 95 // Start method brings up a notification and a tray item, and the user 96 // can stop the screen capture/sharing by pressing the stop button. 97 class ASH_EXPORT ScreenTrayItem : public SystemTrayItem { 98 public: 99 explicit ScreenTrayItem(SystemTray* system_tray); 100 virtual ~ScreenTrayItem(); 101 102 tray::ScreenTrayView* tray_view() { return tray_view_; } 103 void set_tray_view(tray::ScreenTrayView* tray_view) { 104 tray_view_ = tray_view; 105 } 106 107 tray::ScreenStatusView* default_view() { return default_view_; } 108 void set_default_view(tray::ScreenStatusView* default_view) { 109 default_view_ = default_view; 110 } 111 112 bool is_started() const { return is_started_; } 113 void set_is_started(bool is_started) { is_started_ = is_started; } 114 115 void Update(); 116 void Start(const base::Closure& stop_callback); 117 void Stop(); 118 119 // Creates or updates the notification for the tray item. 120 virtual void CreateOrUpdateNotification() = 0; 121 122 // Returns the id of the notification for the tray item. 123 virtual std::string GetNotificationId() = 0; 124 125 // Overridden from SystemTrayItem. 126 virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE = 0; 127 virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE = 0; 128 virtual void DestroyTrayView() OVERRIDE; 129 virtual void DestroyDefaultView() OVERRIDE; 130 virtual void UpdateAfterShelfAlignmentChange( 131 ShelfAlignment alignment) OVERRIDE; 132 133 private: 134 tray::ScreenTrayView* tray_view_; 135 tray::ScreenStatusView* default_view_; 136 bool is_started_; 137 base::Closure stop_callback_; 138 139 DISALLOW_COPY_AND_ASSIGN(ScreenTrayItem); 140 }; 141 142 } // namespace ash 143 144 #endif // ASH_SYSTEM_CHROMEOS_SCREEN_TRAY_ITEM_H_ 145