Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: ash/system/web_notification/web_notification_tray.h

Issue 10546125: Add WebNotificationTray to the status area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make WebNotificationTray::Bubble a Widget::Observer; address nits Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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. |id| is a unique identifier, used to update or
76 // remove notifications. |title| and |meesage| describe the notification text.
77 // Use SetNotificationImage to set the icon image. If |extension_id| is
78 // provided then 'Disable extension' will appear in a dropdown menu and the
79 // id will be used to disable notifications from the extension. Otherwise if
80 // |display_source| is provided, a menu item showing the source and allowing
81 // notifications from that source to be disabled will be shown. All actual
82 // disabling is handled by the Delegate.
83 void AddNotification(const std::string& id,
84 const string16& title,
85 const string16& message,
86 const string16& display_source,
87 const std::string& extension_id);
88
89 // Update an existing notification.
90 void UpdateNotification(const std::string& id,
91 const string16& title,
92 const string16& message);
93
94 // Remove an existing notification and notify the delegate.
95 void RemoveNotification(const std::string& id);
96
97 // Remove all notifications and notify the delegate.
98 void RemoveAllNotifications();
99
100 // Set the notification image.
101 void SetNotificationImage(const std::string& id,
102 const gfx::ImageSkia& image);
103
104 // Disable all notifications matching notification |id|.
105 void DisableByExtension(const std::string& id);
106 void DisableByUrl(const std::string& id);
107
108 // Show the notification bubble. Should only be called by StatusAreaWidget.
109 void ShowBubble();
110
111 // Hide the notification bubble. Should only be called by StatusAreaWidget.
112 void HideBubble();
113
114 // Request the Delegate to the settings dialog.
115 void ShowSettings(const std::string& id);
116
117 // Called when a notification is clicked on. Event is passed to the Delegate.
118 void OnClicked(const std::string& id);
119
120 // Overridden from aura::EventFilter.
121 virtual bool PreHandleKeyEvent(aura::Window* target,
122 aura::KeyEvent* event) OVERRIDE;
123 virtual bool PreHandleMouseEvent(aura::Window* target,
124 aura::MouseEvent* event) OVERRIDE;
125 virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target,
126 aura::TouchEvent* event) OVERRIDE;
127 virtual ui::GestureStatus PreHandleGestureEvent(
128 aura::Window* target,
129 aura::GestureEvent* event) OVERRIDE;
130
131 // Overridden from TrayBackgroundView.
132 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
133
134 // Overridden from internal::ActionableView.
135 virtual bool PerformAction(const views::Event& event) OVERRIDE;
136
137 private:
138 class Bubble;
139 class BubbleContentsView;
140 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
141
142 int GetNotificationCount() const;
143 void UpdateIcon();
144 void UpdateBubbleAndIcon();
145 bool ProcessLocatedEvent(const aura::LocatedEvent& event);
146
147 const internal::WebNotificationList* notification_list() const {
148 return notification_list_.get();
149 }
150 views::View* tray_container() const { return tray_container_; }
151 Bubble* bubble() const { return bubble_.get(); }
152
153 internal::StatusAreaWidget* status_area_widget_; // Unowned parent.
154 scoped_ptr<internal::WebNotificationList> notification_list_;
155 scoped_ptr<Bubble> bubble_;
156 views::View* tray_container_;
157 views::ImageView* icon_;
158 Delegate* delegate_;
159
160 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
161 };
162
163 } // namespace ash
164
165 #endif // ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698