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.
5 #ifndef ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_
6 #define ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_
8 #include "base/timer/timer.h"
9 #include "ui/views/controls/button/image_button.h"
10 #include "ui/views/controls/slide_out_view.h"
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 {
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();
39 // InitView must be called once with the contents to be displayed.
40 void InitView(views::View* contents);
42 // Sets/updates the icon image.
43 void SetIconImage(const gfx::ImageSkia& image);
45 // Gets the icons image.
46 const gfx::ImageSkia& GetIconImage() const;
48 // Replaces the contents view.
49 void UpdateView(views::View* new_contents);
51 // Replaces the contents view and updates the icon image.
52 void UpdateViewAndImage(views::View* new_contents,
53 const gfx::ImageSkia& image);
55 // Autoclose timer operations.
56 void StartAutoCloseTimer(int seconds);
57 void StopAutoCloseTimer();
58 void RestartAutoCloseTimer();
60 // Overridden from ButtonListener.
61 virtual void ButtonPressed(views::Button* sender,
62 const ui::Event& event) OVERRIDE;
64 // Overridden from views::View.
65 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
67 // Overridden from ui::EventHandler.
68 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
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();
76 // Overridden from views::SlideOutView.
77 virtual void OnSlideOut() OVERRIDE;
79 SystemTrayItem* owner() { return owner_; }
83 void HandleClickAction();
85 SystemTrayItem* owner_;
87 views::ImageView* icon_;
90 base::OneShotTimer<TrayNotificationView> autoclose_;
92 DISALLOW_COPY_AND_ASSIGN(TrayNotificationView);
95 } // namespace internal
98 #endif // ASH_SYSTEM_TRAY_TRAY_NOTIFICATION_VIEW_H_