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_TRAY_NOTIFICATION_VIEW_H_ 6 #define ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_ 7 8 #include "base/timer/timer.h" 9 #include "ui/views/controls/button/image_button.h" 10 #include "ui/views/controls/slide_out_view.h" 11 12 namespace gfx { 13 class ImageSkia; 14 } 15 16 namespace views { 17 class ImageView; 18 } 19 20 namespace ash { 21 22 class SystemTrayItem; 23 24 namespace internal { 25 26 // A view for closable notification views, laid out like: 27 // ------------------- 28 // | icon contents x | 29 // ----------------v-- 30 // The close button will call OnClose() when clicked. 31 class TrayNotificationView : public views::SlideOutView, 32 public views::ButtonListener { 33 public: 34 // If icon_id is 0, no icon image will be set. SetIconImage can be called 35 // to later set the icon image. 36 TrayNotificationView(SystemTrayItem* owner, int icon_id); 37 virtual ~TrayNotificationView(); 38 39 // InitView must be called once with the contents to be displayed. 40 void InitView(views::View* contents); 41 42 // Sets/updates the icon image. 43 void SetIconImage(const gfx::ImageSkia& image); 44 45 // Gets the icons image. 46 const gfx::ImageSkia& GetIconImage() const; 47 48 // Replaces the contents view. 49 void UpdateView(views::View* new_contents); 50 51 // Replaces the contents view and updates the icon image. 52 void UpdateViewAndImage(views::View* new_contents, 53 const gfx::ImageSkia& image); 54 55 // Autoclose timer operations. 56 void StartAutoCloseTimer(int seconds); 57 void StopAutoCloseTimer(); 58 void RestartAutoCloseTimer(); 59 60 // Overridden from ButtonListener. 61 virtual void ButtonPressed(views::Button* sender, 62 const ui::Event& event) OVERRIDE; 63 64 // Overridden from views::View. 65 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; 66 67 // Overridden from ui::EventHandler. 68 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 69 70 protected: 71 // Called when the close button is pressed. Does nothing by default. 72 virtual void OnClose(); 73 // Called when the notification is clicked on. Does nothing by default. 74 virtual void OnClickAction(); 75 76 // Overridden from views::SlideOutView. 77 virtual void OnSlideOut() OVERRIDE; 78 79 SystemTrayItem* owner() { return owner_; } 80 81 private: 82 void HandleClose(); 83 void HandleClickAction(); 84 85 SystemTrayItem* owner_; 86 int icon_id_; 87 views::ImageView* icon_; 88 89 int autoclose_delay_; 90 base::OneShotTimer<TrayNotificationView> autoclose_; 91 92 DISALLOW_COPY_AND_ASSIGN(TrayNotificationView); 93 }; 94 95 } // namespace internal 96 } // namespace ash 97 98 #endif // ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_ 99