Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
| 6 #define ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "ash/ash_export.h" | |
| 10 #include "ash/system/tray/tray_background_view.h" | |
| 11 #include "base/gtest_prod_util.h" | |
| 12 #include "ui/aura/event_filter.h" | |
| 13 | |
| 14 namespace aura { | |
| 15 class LocatedEvent; | |
| 16 } | |
| 17 | |
| 18 namespace gfx { | |
| 19 class ImageSkia; | |
| 20 } | |
| 21 | |
| 22 namespace views { | |
| 23 class ImageView; | |
| 24 } | |
| 25 | |
| 26 namespace ash { | |
| 27 | |
| 28 namespace internal { | |
| 29 class StatusAreaWidget; | |
| 30 class WebNotificationList; | |
| 31 } | |
| 32 | |
| 33 // Status area tray for showing browser and app notifications. The client | |
| 34 // (e.g. Chrome) calls [Add|Remove|Update]Notification to create and update | |
| 35 // notifications in the tray. It can also implement Delegate to receive | |
| 36 // callbacks when a notification is removed (closed), clicked on, or a menu | |
| 37 // item is triggered. | |
| 38 // | |
| 39 // Note: These are not related to system notifications (i.e NotificationView | |
| 40 // generated by SystemTrayItem). Visibility of one notification type or other | |
| 41 // is controlled by StatusAreaWidget. | |
| 42 | |
| 43 class ASH_EXPORT WebNotificationTray : public aura::EventFilter, | |
| 44 public internal::TrayBackgroundView { | |
| 45 public: | |
| 46 class Delegate { | |
| 47 public: | |
| 48 virtual ~Delegate() {} | |
| 49 | |
| 50 // Called when the notification associated with |notification_id| is | |
| 51 // removed (i.e. closed by the user). | |
| 52 virtual void NotificationRemoved(const std::string& notifcation_id) = 0; | |
| 53 | |
| 54 // Request to disable the extension associated with |notification_id|. | |
| 55 virtual void DisableExtension(const std::string& notifcation_id) = 0; | |
| 56 | |
| 57 // Request to disable notifications from the source of |notification_id|. | |
| 58 virtual void DisableNotificationsFromSource( | |
| 59 const std::string& notifcation_id) = 0; | |
| 60 | |
| 61 // Request to show the notification settings (|notification_id| is used | |
| 62 // to identify the requesting browser context). | |
| 63 virtual void ShowSettings(const std::string& notifcation_id) = 0; | |
| 64 | |
| 65 // Called when the notification body is clicked on. | |
| 66 virtual void OnClicked(const std::string& notifcation_id) = 0; | |
| 67 }; | |
| 68 | |
| 69 explicit WebNotificationTray(internal::StatusAreaWidget* status_area_widget); | |
| 70 virtual ~WebNotificationTray(); | |
| 71 | |
| 72 // Called once to set the delegate. | |
| 73 void SetDelegate(Delegate* delegate); | |
| 74 | |
| 75 // Add a new notification. Use SetNotificationImage to set the icon image. | |
| 76 void AddNotification(const std::string& id, | |
| 77 const string16& title, | |
| 78 const string16& message, | |
| 79 const string16& source, | |
| 80 const std::string& extension); | |
|
sadrul
2012/06/13 16:37:56
What are |source| and |extension|?
stevenjb
2012/06/13 19:05:02
Yeah, this comment is rather lacking. Much more de
| |
| 81 | |
| 82 // Update an existing notification. | |
| 83 void UpdateNotification(const std::string& id, | |
| 84 const string16& title, | |
| 85 const string16& message); | |
| 86 | |
| 87 // Remove an existing notification and notify the delegate. | |
| 88 void RemoveNotification(const std::string& id); | |
| 89 | |
| 90 // Remove all notifications and notify the delegate. | |
| 91 void RemoveAllNotifications(); | |
| 92 | |
| 93 // Set the notification image. | |
| 94 void SetNotificationImage(const std::string& id, | |
| 95 const gfx::ImageSkia& image); | |
| 96 | |
| 97 // Disable all notifications matching notification |id|. | |
| 98 void DisableByExtension(const std::string& id); | |
| 99 void DisableByUrl(const std::string& id); | |
| 100 | |
| 101 // Show the notification bubble. Should only be called by StatusAreaWidget. | |
| 102 void ShowBubble(); | |
| 103 | |
| 104 // Hide the notification bubble. Should only be called by StatusAreaWidget. | |
| 105 void HideBubble(); | |
| 106 | |
| 107 // Request the Delegate to the settings dialog. | |
| 108 void ShowSettings(const std::string& id); | |
| 109 | |
| 110 // Called when a notification is clicked on. Event is passed to the Delegate. | |
| 111 void OnClicked(const std::string& id); | |
| 112 | |
| 113 // Overridden from aura::EventFilter. | |
| 114 virtual bool PreHandleKeyEvent(aura::Window* target, | |
| 115 aura::KeyEvent* event) OVERRIDE; | |
| 116 virtual bool PreHandleMouseEvent(aura::Window* target, | |
| 117 aura::MouseEvent* event) OVERRIDE; | |
| 118 virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target, | |
| 119 aura::TouchEvent* event) OVERRIDE; | |
| 120 virtual ui::GestureStatus PreHandleGestureEvent( | |
| 121 aura::Window* target, | |
| 122 aura::GestureEvent* event) OVERRIDE; | |
| 123 | |
| 124 // Overridden from TrayBackgroundView. | |
| 125 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; | |
| 126 | |
| 127 // Overridden from internal::ActionableView. | |
| 128 virtual bool PerformAction(const views::Event& event) OVERRIDE; | |
| 129 | |
| 130 private: | |
| 131 class Bubble; | |
| 132 class BubbleContentsView; | |
| 133 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); | |
| 134 | |
| 135 int GetNotificationCount() const; | |
| 136 void UpdateIcon(); | |
| 137 void UpdateBubbleAndIcon(); | |
| 138 bool ProcessLocatedEvent(const aura::LocatedEvent& event); | |
| 139 | |
| 140 const internal::WebNotificationList* notification_list() const { | |
| 141 return notification_list_.get(); | |
| 142 } | |
| 143 views::View* tray_container() const { return tray_container_; } | |
| 144 Bubble* bubble() const { return bubble_.get(); } | |
| 145 | |
| 146 internal::StatusAreaWidget* status_area_widget_; // Unowned parent. | |
| 147 scoped_ptr<internal::WebNotificationList> notification_list_; | |
| 148 scoped_ptr<Bubble> bubble_; | |
| 149 views::View* tray_container_; | |
| 150 views::ImageView* icon_; | |
| 151 Delegate* delegate_; | |
| 152 | |
| 153 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); | |
| 154 }; | |
| 155 | |
| 156 } // namespace ash | |
| 157 | |
| 158 #endif // ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | |
| OLD | NEW |